Browse Source

Parrainage producteurs

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
6bb93f68b9
12 changed files with 215 additions and 59 deletions
  1. +1
    -0
      backend/controllers/ProducerInvoiceController.php
  2. +68
    -33
      backend/views/producer-admin/_form.php
  3. +9
    -0
      backend/views/producer-admin/index.php
  4. +10
    -0
      backend/views/producer-invoice/index.php
  5. +34
    -15
      backend/views/sponsorship/index.php
  6. +9
    -3
      domain/Producer/Producer/Producer.php
  7. +25
    -0
      domain/Producer/Producer/ProducerSolver.php
  8. +20
    -3
      frontend/controllers/SiteController.php
  9. +11
    -0
      frontend/forms/SignupForm.php
  10. +13
    -0
      frontend/views/site/_signup_sponsorship_message.php
  11. +5
    -0
      frontend/views/site/signup.php
  12. +10
    -5
      frontend/views/site/signup_producer.php

+ 1
- 0
backend/controllers/ProducerInvoiceController.php View File

@@ -31,6 +31,7 @@ class ProducerInvoiceController extends BackendController
public function actionIndex()
{
return $this->render('index', [
'producer' => $this->getProducerCurrent(),
'invoicesArray' => $this->getProducerModule()
->getDolibarrUtils()
->getDolibarrProducerInvoices($this->getProducerCurrent())

+ 68
- 33
backend/views/producer-admin/_form.php View File

@@ -44,40 +44,75 @@ use yii\widgets\ActiveForm;

<?php $form = ActiveForm::begin(); ?>

<h3>Général</h3>
<?= $form->field($model, 'slug') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'type')->textInput(['placeholder' => 'Boulangerie, brasserie, ferme ...']); ?>
<?= $form->field($model, 'postcode') ?>
<?= $form->field($model, 'city') ?>
<?= $form->field($model, 'contact_email') ?>
<?= $form->field($model, 'latitude') ?>
<?= $form->field($model, 'longitude') ?>
<?= $form->field($model, 'code')->label('Code d\'accès') ?>
<?= $form->field($model, 'admin_comment')->textarea(['rows' => 7]) ?>
<?= $form->field($model, 'is_new')->checkbox() ?>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-th-list"></i>
Général
</h3>
</div>
<div class="panel-body">
<?= $form->field($model, 'slug') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'type')->textInput(['placeholder' => 'Boulangerie, brasserie, ferme ...']); ?>
<?= $form->field($model, 'postcode') ?>
<?= $form->field($model, 'city') ?>
<?= $form->field($model, 'contact_email') ?>
<?= $form->field($model, 'latitude') ?>
<?= $form->field($model, 'longitude') ?>
<?= $form->field($model, 'code')->label('Code d\'accès') ?>
<?= $form->field($model, 'admin_comment')->textarea(['rows' => 7]) ?>
<?= $form->field($model, 'is_new')->checkbox() ?>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-euro"></i>
Facturation
</h3>
</div>
<div class="panel-body">
<?= $form->field($model, 'option_billing_type')
->dropDownList(Producer::getBillingTypePopulateDropdown()); ?>
<?= $form->field($model, 'option_billing_frequency')
->dropDownList(Producer::getBillingFrequencyPopulateDropdown()); ?>
<?= $form->field($model, 'option_billing_reduction')
->dropDownList([
0 => 'Non',
1 => 'Oui'
]); ?>
<?= $form->field($model, 'option_billing_reduction_percentage') ?>
<?= $form->field($model, 'option_billing_permanent_transfer')
->dropDownList([
0 => 'Non',
1 => 'Oui'
]); ?>
<?= $form->field($model, 'option_billing_permanent_transfer_amount') ?>
<?= $form->field($model, 'dolibarr_socid') ?>
<?= $form->field($model, 'dolibarr_product_id') ?>
</div>
</div>

<h3>Facturation</h3>
<?= $form->field($model, 'option_billing_type')
->dropDownList(Producer::getBillingTypePopulateDropdown()); ?>
<?= $form->field($model, 'option_billing_frequency')
->dropDownList(Producer::getBillingFrequencyPopulateDropdown()); ?>
<?= $form->field($model, 'option_billing_reduction')
->dropDownList([
0 => 'Non',
1 => 'Oui'
]); ?>
<?= $form->field($model, 'option_billing_reduction_percentage') ?>
<?= $form->field($model, 'option_billing_permanent_transfer')
->dropDownList([
0 => 'Non',
1 => 'Oui'
]); ?>
<?= $form->field($model, 'option_billing_permanent_transfer_amount') ?>
<?= $form->field($model, 'dolibarr_socid') ?>
<?= $form->field($model, 'dolibarr_product_id') ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-users"></i>
Parrainage
</h3>
</div>
<div class="panel-body">
<?= $form->field($model, 'sponsorship_sponsor_reward')->checkbox() ?>
</div>
</div>
</div>
</div>

<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-success']) ?>
<div class="form-group form-actions">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>

+ 9
- 0
backend/views/producer-admin/index.php View File

@@ -122,11 +122,13 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico
$summaryQuaterly = $producerModule->getSummaryAmountsToBeBilled($producer, '3 derniers mois', 3);
$isBillingFrequencyBiannual = $producerModule->isBillingFrequencyBiannual($producer);
$summaryBiannual = $producerModule->getSummaryAmountsToBeBilled($producer, '6 derniers mois', 6);
$isBilled = false;

if(($isBillingFrequencyMonthly && $summaryMonthly)
|| ($isBillingFrequencyQuaterly && $summaryQuaterly)
|| ($isBillingFrequencyBiannual && $summaryBiannual)) {

$isBilled = true;
$str .= '<li>';
if ($isBillingFrequencyMonthly && $summaryMonthly) {
$str .= $summaryMonthly;
@@ -155,6 +157,13 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico

$str .= '</ul>';

if($isBilled && $producerModule->getSolver()->isFreeBillingPeriodSponsorship($producer)) {
$str .= "<br /><p><span class=\"glyphicon glyphicon-warning-sign\"></span> <strong>Pas de facturation, offre de parrainage jusqu'au ".$producerModule->getSolver()->getDateEndFreeBillingPeriodSponsorship($producer)->format('d/m/Y')."</strong></p>";
if(!$producer->getSponsorshipSponsorReward()) {
$str .= '<p><i class="fa fa-gift"></i> Créer un avoir de 30€ pour le parrain <strong>'.Html::encode($producer->getSponsoredBy()->getName()).'</strong> sur Dolibarr et valider la récompense parrain.</p>';
}
}

return $str;
}
],

+ 10
- 0
backend/views/producer-invoice/index.php View File

@@ -42,6 +42,8 @@ use yii\helpers\Html;
$this->setTitle('Mes factures') ;
$this->addBreadcrumb($this->getTitle()) ;

$producerModule = $this->getProducerModule();

?>

<?php if($invoicesArray && count($invoicesArray)): ?>
@@ -81,4 +83,12 @@ $this->addBreadcrumb($this->getTitle()) ;
<div class="callout callout-info">
<span class="glyphicon glyphicon-info-sign"></span> Vous n'avez encore aucune facture.
</div>

<?php if($producerModule->getSolver()->isFreeBillingPeriodSponsorship($producer)): ?>
<div class="callout callout-info">
<i class="fa fa-gift"></i>
Et comme vous avez été parrainé au moment de votre inscription, vous n'aurez pas de facture <em>Souke</em>
avant le <?= $producerModule->getSolver()->getDateEndFreeBillingPeriodSponsorship($producer)->format('d/m/Y'); ?>.
</div>
<?php endif; ?>
<?php endif; ?>

+ 34
- 15
backend/views/sponsorship/index.php View File

@@ -42,21 +42,35 @@ use yii\helpers\Html;
$this->setTitle('Parrainage') ;
$this->addBreadcrumb($this->getTitle()) ;

$sponsorshipLink = $this->getProducerModule()->getSolver()->getSponsorshipLink($producer);
$producerModule = $this->getProducerModule();
$sponsorshipLink = $producerModule->getSolver()->getSponsorshipLink($producer);

?>

<div class="alert alert-dark">
<p>
<i class="bi bi-link"></i>
Votre lien de parrainage : <br />
<strong>
<?= $sponsorshipLink ?>
<a class="btn btn-xs btn-default" id="sponsorship-link-copy" href="<?= $sponsorshipLink ?>" title="Copier le lien dans le presse-papier">
<span class="glyphicon glyphicon-link"></span>
</a>
</strong>
</p>
<?php if($producer->getSponsoredBy()): ?>
<div class="callout callout-info">
<i class="fa fa-users"></i>
Vous avez été parrainé par le producteur <strong><?= Html::encode($producer->getSponsoredBy()->getName()) ?></strong>.
<?php if($producerModule->getSolver()->isFreeBillingPeriodSponsorship($producer)): ?>
<br /><i class="fa fa-gift"></i>
Vous bénéficiez donc de 3 mois offerts et n'aurez pas de facture <em>Souke</em> avant le <?= $producerModule->getSolver()->getDateEndFreeBillingPeriodSponsorship($producer)->format('d/m/Y'); ?>.
<?php endif; ?>
</div>
<?php endif; ?>

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<span class="glyphicon glyphicon-link"></span>
Votre lien de partage
</h3>
</div>
<div class="panel-body">
<strong><?= $sponsorshipLink ?></strong>
<a class="btn btn-xs btn-default" id="sponsorship-link-copy" href="<?= $sponsorshipLink ?>" title="Copier le lien dans le presse-papier">
<span class="glyphicon glyphicon-copy"></span>
</a>
</div>
</div>

<div class="panel panel-default">
@@ -72,8 +86,13 @@ $sponsorshipLink = $this->getProducerModule()->getSolver()->getSponsorshipLink($
producteurs s'inscrit en suivant ce lien, il devient votre filleul et obtenez tous les deux une récompense :
</p>
<ul>
<li>Votre filleul démarre avec <strong>3 mois offerts</strong> d'utilisation du logiciel</li>
<li>Vous obtenez <strong>30€ d'avoir</strong> sur vos prochaines factures</li>
<li>
Votre filleul démarre sur le logiciel avec <strong>3 mois offerts</strong>.
</li>
<li>
Vous obtenez <strong>30€ de réduction</strong> sur vos prochaines factures dès lors que votre filleul
utilise le logiciel en production.
</li>
</ul>
</div>
</div>
@@ -104,7 +123,7 @@ $sponsorshipLink = $this->getProducerModule()->getSolver()->getSponsorshipLink($
</tbody>
</table>
<?php else: ?>
<p>Vous n'avez encore aucun producteur parrainé.</p>
<p>Vous n'avez encore parrainé aucun producteur.</p>
<?php endif; ?>
</div>
</div>

+ 9
- 3
domain/Producer/Producer/Producer.php View File

@@ -546,6 +546,7 @@ class Producer extends ActiveRecordCommon
'option_leave_period_message_title' => 'Titre du message des congés',
'option_leave_period_message' => 'Message des congés',
'option_credit_description' => "Description Cagnotte",
'sponsorship_sponsor_reward' => 'Récompense parrain',
];
}

@@ -565,14 +566,14 @@ class Producer extends ActiveRecordCommon
return $this;
}

public function getSponsoredBy(): ?User
public function getSponsoredBy(): ?Producer
{
return $this->sponsoredByRelation;
}

public function setSponsoredBy(User $user): self
public function setSponsoredBy(Producer $producer): self
{
$this->populateFieldObject('sponsored_by', 'sponsoredByRelation', $user);
$this->populateFieldObject('sponsored_by', 'sponsoredByRelation', $producer);
return $this;
}

@@ -638,6 +639,11 @@ class Producer extends ActiveRecordCommon
$this->populateFieldObject('id_user_group_default', 'userGroupDefault', $userGroup);
}

public function getSponsoredByRelation()
{
return $this->hasOne(Producer::class, ['id' => 'sponsored_by']);
}

// ---

public static function getBillingTypePopulateDropdown()

+ 25
- 0
domain/Producer/Producer/ProducerSolver.php View File

@@ -312,4 +312,29 @@ class ProducerSolver extends AbstractService implements SolverInterface
{
return \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/signup', 'from' => $producer->getSponsorshipCode()]);
}

public function getDateEndFreeBillingPeriodSponsorship(Producer $producer): ?\DateTime
{
if($producer->getSponsoredBy()) {
$dateStart = new \DateTime($producer->date_creation);
return $dateStart
->modify('+4 months')
->modify('first day of this month');
}

return null;
}

public function isFreeBillingPeriodSponsorship(Producer $producer): bool
{
if($producer->getSponsoredBy()) {
$dateNow = new \DateTime();
$dateEndFreeBillingPeriodSponsorship = $this->getDateEndFreeBillingPeriodSponsorship($producer);
if($dateNow < $dateEndFreeBillingPeriodSponsorship) {
return true;
}
}

return false;
}
}

+ 20
- 3
frontend/controllers/SiteController.php View File

@@ -353,8 +353,12 @@ class SiteController extends FrontendController
*/
public function actionSignup(string $type = 'user')
{
$sponsorshipFromCode = Yii::$app->request->get('from');
$sponsorshipProducerFrom = $this->findProducerSponsorshipByCode($sponsorshipFromCode);

$model = new SignupForm();
$model->option_user_producer = $type;
$model->sponsored_by = $sponsorshipProducerFrom ? $sponsorshipProducerFrom->id : false;
$producerModule = $this->getProducerModule();

if ($model->load(Yii::$app->request->post())) {
@@ -381,11 +385,11 @@ class SiteController extends FrontendController
$dataProducers = $producersArray['data'];
$optionsProducers = $producersArray['options'];


$paidFeaturesArray = $this->getFeatureModule()->getRepository()->findPaidFeatures();

return $this->render('signup', [
'model' => $model,
'sponsorshipProducerFrom' => $sponsorshipProducerFrom,
'dataProducers' => $dataProducers,
'dataProviderPrices' => $this->getDataProviderPrices(),
'paidFeaturesArray' => $paidFeaturesArray,
@@ -396,10 +400,12 @@ class SiteController extends FrontendController
public function actionSignupProducer()
{
$userCurrent = $this->getUserCurrent();
$sponsorshipFromCode = Yii::$app->request->get('from');
$sponsorshipProducerFrom = $this->findProducerSponsorshipByCode($sponsorshipFromCode);
if(!$userCurrent) {
// Lien parrainage
if(Yii::$app->request->get('from')) {
$this->redirect(['site/signup', 'from' => Yii::$app->request->get('from')]);
if($sponsorshipFromCode && strlen($sponsorshipFromCode)) {
$this->redirect(['site/signup', 'from' => $sponsorshipFromCode]);
}
else {
$this->redirect(['site/signup']);
@@ -409,6 +415,7 @@ class SiteController extends FrontendController
$model = new SignupForm();
$model->signup_producer_only = 'producer';
$model->option_user_producer = 'producer';
$model->sponsored_by = $sponsorshipProducerFrom ? $sponsorshipProducerFrom->id : false;

if ($model->load(Yii::$app->request->post())) {
$user = $model->signup($userCurrent);
@@ -419,11 +426,21 @@ class SiteController extends FrontendController

return $this->render('signup_producer', [
'model' => $model,
'sponsorshipProducerFrom' => $sponsorshipProducerFrom,
'dataProviderPrices' => $this->getDataProviderPrices(),
'paidFeaturesArray' => $this->getFeatureModule()->getRepository()->findPaidFeatures()
]);
}

public function findProducerSponsorshipByCode($sponsorshipFromCode)
{
$sponsorshipProducerFrom = null;
if($sponsorshipFromCode && strlen($sponsorshipFromCode)) {
$sponsorshipProducerFrom = $this->getProducerModule()->getRepository()->findOneProducerBySponsorshipCode($sponsorshipFromCode);
}
return $sponsorshipProducerFrom;
}

public function actionSignupConfirm($idProducerRedirect = null)
{
$producerModule = $this->getProducerModule();

+ 11
- 0
frontend/forms/SignupForm.php View File

@@ -74,6 +74,7 @@ class SignupForm extends Model
public $is_test;
public $newsletter = false;
public $newsletter_souke = false;
public $sponsored_by = false;

/**
* @inheritdoc
@@ -176,6 +177,7 @@ class SignupForm extends Model
['id_producer', 'required', 'message' => 'Champs obligatoire', 'when' => function ($model) {
return $this->option_user_producer == 'user';
}],
['sponsored_by', 'safe'],
['code', 'required', 'message' => 'Champs obligatoire', 'when' => function ($model) {
$producer = Producer::findOne($this->id_producer);
if ($producer) {
@@ -297,6 +299,15 @@ class SignupForm extends Model
$producerModule->initProducer($producer);
$producer->save();

// Parrainage
if($this->sponsored_by) {
$sponsorshipProducerSponsor = $producerModule->getRepository()->findOneProducerById($this->sponsored_by);
if($sponsorshipProducerSponsor) {
$producer->sponsored_by = $this->sponsored_by;
$producer->save();
}
}

/*
* Envoi d'un email à l'administrateur pour le prévenir
* qu'un nouveau producteur s'est inscrit

+ 13
- 0
frontend/views/site/_signup_sponsorship_message.php View File

@@ -0,0 +1,13 @@
<?php

use yii\helpers\Html;

?>

<?php if($sponsorshipProducerFrom): ?>
<div class="alert alert-dark">
<i class="bi bi-people-fill"></i>
Le producteur <strong><?= Html::encode($sponsorshipProducerFrom->getName()) ?></strong> vous propose de vous parrainer.
En vous inscrivant, profitez de <strong>3 mois offerts</strong> d'utilisation du logiciel !
</div>
<?php endif; ?>

+ 5
- 0
frontend/views/site/signup.php View File

@@ -57,6 +57,11 @@ $this->params['breadcrumbs'][] = $this->title;
les identifiants indiqués sur la page de <?= Html::a('connexion', \Yii::$app->urlManager->createUrl(['site/login'])); ?> pour vous identifier.
</div>
<?php else: ?>

<?= $this->render('_signup_sponsorship_message.php', [
'sponsorshipProducerFrom' => $sponsorshipProducerFrom
]); ?>

<?php $form = ActiveForm::begin(['id' => 'form-signup', 'enableClientValidation'=> false]); ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'password')->passwordInput() ?>

+ 10
- 5
frontend/views/site/signup_producer.php View File

@@ -52,6 +52,11 @@ $this->params['breadcrumbs'][] = $this->title;

<div class="row">
<div class="col-lg-5">

<?= $this->render('_signup_sponsorship_message.php', [
'sponsorshipProducerFrom' => $sponsorshipProducerFrom
]); ?>

<?php $form = ActiveForm::begin(['id' => 'form-signup','enableClientValidation'=> false]); ?>
<?= $form->field($model, 'name_producer') ?>
<?= $form->field($model, 'type')->textInput(['placeholder' => 'Boulangerie, brasserie, ferme ...']); ?>
@@ -62,7 +67,7 @@ $this->params['breadcrumbs'][] = $this->title;
'prompt' => '--',
])
->label('TVA à appliquer par défaut'); ?>
<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <button type="button" class="btn btn-xs btn-default btn-modal-cgv" data-toggle="modal" data-target="#modal-cgv">conditions générales de service</button> et les <button type="button" class="btn btn-xs btn-default btn-modal-prices" data-toggle="modal" data-target="#modal-prices">conditions tarifaires</button>.') ?>
<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <button type="button" class="btn btn-sm btn-secondary btn-modal-cgv" data-bs-toggle="modal" data-bs-target="#modal-cgv">conditions générales de service</button> et les <button type="button" class="btn btn-sm btn-secondary btn-modal-prices" data-bs-toggle="modal" data-bs-target="#modal-prices">conditions tarifaires</button>.') ?>

<?= $form->field($model, 'verifyCode')->widget(\yii\captcha\Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
@@ -82,14 +87,14 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Conditions générales de service</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?= $this->render('_cgv_content.php'); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
</div>
</div>
</div>
@@ -100,14 +105,14 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Tarifs</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?= $this->render('../site/_prices_producer', ['dataProviderPrices' => $dataProviderPrices, 'paidFeaturesArray' => $paidFeaturesArray]); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
</div>
</div>
</div>

Loading…
Cancel
Save