@@ -108,12 +108,15 @@ class SharedPointSaleController extends BackendController | |||
if($sharedPointSale->load(\Yii::$app->request->post()) && $sharedPointSale->validate()) { | |||
$pointSaleWithSharing = $sharedPointSale->getPointSaleWithSharing(); | |||
if($this->getSharedPointSaleModule()->getManager()->confirmSharedPointSale($sharedPointSale, $pointSaleWithSharing, $this->getUserCurrent())) { | |||
$this->addFlash('success', "La demande de partage de point de vente a bien été acceptée."); | |||
$this->addFlash('success', "Le partage de point de vente a bien été confirmé"); | |||
} | |||
else { | |||
$this->addFlash('error', "Une erreur est survenue lors de l'annulation de la demande de partage."); | |||
$this->addFlash('error', "Une erreur est survenue lors de la confirmation du partage"); | |||
} | |||
} | |||
else { | |||
$this->addFlash('error', "Veuillez sélectionner un point de vente pour confirmer le partage"); | |||
} | |||
return $this->redirect(['index']); | |||
} |
@@ -102,7 +102,7 @@ $sharedPointSaleModule = $this->getSharedPointSaleModule(); | |||
<?php endif; ?> | |||
<?php $countSharedPointsSaleRequestsOthers = $sharedPointSaleModule->getResolver()->countSharedPointsSaleRequestsOthers(); ?> | |||
<?php if($countSharedPointsSaleRequestsOthers): ?> | |||
<?php if($countSharedPointsSaleRequestsOthers && Yii::$app->controller->id != 'shared-point-sale'): ?> | |||
<div class="alert alert-info"> | |||
<p> | |||
<i class="icon fa fa-share-alt"></i> |
@@ -42,6 +42,7 @@ use yii\grid\GridView; | |||
use yii\helpers\Html; | |||
$pointSaleModule = $this->getPointSaleModule(); | |||
$sharedPointSaleModule = $this->getSharedPointSaleModule(); | |||
$this->setTitle('Points de vente'); | |||
$this->addBreadcrumb($this->getTitle()); | |||
@@ -184,6 +185,17 @@ $this->addButton( | |||
} | |||
} | |||
], | |||
[ | |||
'label' => 'Partages', | |||
'format' => 'raw', | |||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | |||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||
'contentOptions' => ['class' => 'td-shared-point-sale column-hide-on-mobile'], | |||
'value' => function ($pointSale) use ($sharedPointSaleModule) { | |||
$countPointsSaleSharedWithPointSale = $sharedPointSaleModule->getResolver()->countPointsSaleSharedWithPointSale($pointSale); | |||
return '<a class="btn btn-'.($countPointsSaleSharedWithPointSale ? 'success' : 'default').'" href="'.Yii::$app->urlManager->createUrl(['shared-point-sale/index']).'" title="'.$sharedPointSaleModule->getResolver()->getPointsSaleSharedWithPointSaleAsTitle($pointSale).'">'.$countPointsSaleSharedWithPointSale.' <span class="fa fa-share-alt"></span></a>'; | |||
} | |||
], | |||
[ | |||
'class' => 'yii\grid\ActionColumn', | |||
'template' => '{update} {delete}', |
@@ -56,10 +56,12 @@ $this->addBreadcrumb('Partager') ; | |||
<div class="panel panel-default"> | |||
<div class="panel-body"> | |||
<?= $form->field($sharedPointSaleModel, 'id_point_sale') | |||
->dropDownList($pointSaleModule->getRepository()->populatePointSaleDropdownList()); ?> | |||
<?php $producerPopulateDropdownArray = $producerModule->getRepository()->populateProducerDropdown(); ?> | |||
->dropDownList($pointSaleModule->getRepository()->populatePointSaleDropdownList()) | |||
->label('Point de vente'); ?> | |||
<?php $producerPopulateDropdownArray = $producerModule->getRepository()->populateProducerDropdown(true); ?> | |||
<?= $form->field($sharedPointSaleModel, 'id_producer_with_sharing') | |||
->dropDownList($producerPopulateDropdownArray['data'], ['prompt' => '--','encode' => false,'options' => $producerPopulateDropdownArray['options']]);?> | |||
->dropDownList($producerPopulateDropdownArray['data'], ['prompt' => '--','encode' => false,'options' => $producerPopulateDropdownArray['options']]) | |||
->label('Producteur avec qui vous souhaitez le partager');?> | |||
</div> | |||
</div> | |||
<div class="form-group form-actions"> |
@@ -56,118 +56,139 @@ $this->addButton( | |||
); | |||
?> | |||
<div class="shared-point-sale-index"> | |||
<?php if(count($sharedPointsSaleRequestOfMe)): ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Mes demandes de partages en attente | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<table class="table table-striped table-bordered"> | |||
<thead> | |||
<tr> | |||
<td>Point de vente</td> | |||
<td>Producteur</td> | |||
<td></td> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<?php foreach($sharedPointsSaleRequestOfMe as $sharedPointSale): ?> | |||
<tr> | |||
<td><?= Html::encode($sharedPointSale->getPointSale()->getName()); ?></td> | |||
<td><?= Html::encode($sharedPointSale->getProducerWithSharing()->getName()); ?></td> | |||
<td> | |||
<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline', 'id' => $sharedPointSale->getId()]) ?>" class="btn btn-default">Annuler</a> | |||
</td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
<?php endif; ?> | |||
<?php if(count($sharedPointsSaleRequestOthers)): ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Demandes de partage des autres producteurs | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<table class="table table-striped table-bordered"> | |||
<thead> | |||
<tr> | |||
<td>Producteur</td> | |||
<td>Point de vente</td> | |||
<td></td> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<?php foreach($sharedPointsSaleRequestOthers as $sharedPointSale): ?> | |||
<tr> | |||
<td><?= Html::encode($sharedPointSale->getPointSale()->getProducer()->getName()); ?></td> | |||
<td><?= Html::encode($sharedPointSale->getPointSale()->getName()); ?></td> | |||
<td> | |||
<?php $form = ActiveForm::begin([ | |||
'enableClientValidation' => false, | |||
'action' => Yii::$app->urlManager->createUrl(['shared-point-sale/confirm', 'id' => $sharedPointSale->getId()]) | |||
]); ?> | |||
<?= $form->field($sharedPointSale, 'id_point_sale_with_sharing') | |||
->dropDownList($pointSaleModule->getRepository()->populatePointSaleDropdownList()) | |||
->label('Votre point de vente'); ?> | |||
<?= Html::submitButton('Confirmer', ['class' => 'btn btn-success', 'name' => 'save']) ?> | |||
<?php ActiveForm::end(); ?> | |||
</td> | |||
<td> | |||
<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline', 'id' => $sharedPointSale->getId()]) ?>" class="btn btn-danger">Décliner</a> | |||
</td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
<?php endif; ?> | |||
<div class="shared-point-sale-index"> | |||
<div class="row"> | |||
<div class="col-md-8"> | |||
<?php if(count($sharedPointsSaleRequestOfMe)): ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Mes demandes de partages en attente | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<table class="table table-striped table-bordered"> | |||
<tbody> | |||
<?php foreach($sharedPointsSaleRequestOfMe as $sharedPointSale): ?> | |||
<tr> | |||
<td> | |||
Vous souhaitez partager votre point de vente <strong><?= Html::encode($sharedPointSale->getPointSale()->getName()); ?></strong> | |||
avec le producteur <strong><?= Html::encode($sharedPointSale->getProducerWithSharing()->getName()); ?></strong> | |||
</td> | |||
<td> | |||
<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline', 'id' => $sharedPointSale->getId()]) ?>" class="btn btn-default">Annuler</a> | |||
</td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
<?php endif; ?> | |||
<?php if($sharedPointSaleModule->getResolver()->countPointsSaleShared()): ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Partages confirmés | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<table class="table table-striped table-bordered"> | |||
<thead> | |||
<tr> | |||
<td>Point de vente</td> | |||
<td>Partagé avec</td> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<?php foreach($pointsSaleArray as $pointSale): ?> | |||
<?php | |||
$pointsSaleSharedWithPointSaleArray = $sharedPointSaleModule->getResolver()->getPointsSaleSharedWithPointSale($pointSale); | |||
if(count($pointsSaleSharedWithPointSaleArray)): | |||
?> | |||
<?php if(count($sharedPointsSaleRequestOthers)): ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Demandes de partage des autres producteurs | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<table class="table table-striped table-bordered"> | |||
<tbody> | |||
<?php foreach($sharedPointsSaleRequestOthers as $sharedPointSale): ?> | |||
<tr> | |||
<td>Le producteur <strong><?= Html::encode($sharedPointSale->getPointSale()->getProducer()->getName()); ?></strong> | |||
souhaite partager son point de vente <strong><?= Html::encode($sharedPointSale->getPointSale()->getName()); ?></strong> | |||
avec vous. | |||
</td> | |||
<td> | |||
<?php $form = ActiveForm::begin([ | |||
'enableClientValidation' => false, | |||
'action' => Yii::$app->urlManager->createUrl(['shared-point-sale/confirm', 'id' => $sharedPointSale->getId()]) | |||
]); ?> | |||
<div class="row"> | |||
<div class="col-md-8"> | |||
<?= $form->field($sharedPointSale, 'id_point_sale_with_sharing') | |||
->dropDownList($pointSaleModule->getRepository()->populatePointSaleDropdownList()) | |||
->label('Votre point de vente correspondant') | |||
->hint('Absent de la liste ? <a href="'.Yii::$app->urlManager->createUrl(['point-sale/create']).'">Créer le point de vente</a>'); ?> | |||
</div> | |||
<div class="col-md-4"> | |||
<br /> | |||
<?= Html::submitButton('Confirmer', ['class' => 'btn btn-success', 'name' => 'save']) ?> | |||
</div> | |||
</div> | |||
<?php ActiveForm::end(); ?> | |||
</td> | |||
<td> | |||
<br /> | |||
<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline', 'id' => $sharedPointSale->getId()]) ?>" class="btn btn-danger"> | |||
Refuser | |||
</a> | |||
</td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
<?php endif; ?> | |||
<?php if($sharedPointSaleModule->getResolver()->countPointsSaleShared()): ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Partages confirmés | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<table class="table table-striped table-bordered"> | |||
<thead> | |||
<tr> | |||
<td><?= Html::encode($pointSale->getName()); ?></td> | |||
<td> | |||
<?php foreach($pointsSaleSharedWithPointSaleArray as $pointSaleSharedWithPointSale): ?> | |||
<?= Html::encode($pointSaleSharedWithPointSale->getProducer()->getName()); ?> | |||
<?php // Html::encode($pointSaleSharedWithPointSale->getName()); ?> | |||
<?php endforeach; ?> | |||
</td> | |||
<td>Point de vente</td> | |||
<td>Partagé avec</td> | |||
</tr> | |||
<?php endif; ?> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
</thead> | |||
<tbody> | |||
<?php foreach($pointsSaleArray as $pointSale): ?> | |||
<?php | |||
$pointsSaleSharedWithPointSaleArray = $sharedPointSaleModule->getResolver()->getPointsSaleSharedWithPointSale($pointSale); | |||
if(count($pointsSaleSharedWithPointSaleArray)): | |||
?> | |||
<tr> | |||
<td><?= Html::encode($pointSale->getName()); ?></td> | |||
<td> | |||
<?php foreach($pointsSaleSharedWithPointSaleArray as $pointSaleSharedWithPointSale): ?> | |||
<div> | |||
<?= Html::encode($pointSaleSharedWithPointSale->getProducer()->getName()); ?> | |||
- <?= Html::encode($pointSaleSharedWithPointSale->getName()); ?> | |||
<!--<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline']) ?>" class="btn btn-xs btn-default"> | |||
<span class="glyphicon glyphicon-remove"></span> | |||
</a>--> | |||
</div> | |||
<?php endforeach; ?> | |||
</td> | |||
</tr> | |||
<?php endif; ?> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
<?php endif; ?> | |||
</div> | |||
<div class="col-md-4"> | |||
<div class="callout callout-info"> | |||
<span class="glyphicon glyphicon-info-sign"></span> | |||
Cette fonctionnalité vous permet de partager des points de vente avec d'autres producteurs inscrits sur Souke.<br /> | |||
Quand vous partagez un point de vente avec un autre producteur, un lien vers votre boutique est | |||
proposé aux clients de ce producteur quand ils passent commande sur le point de vente en partage | |||
si vous avez une distribution de prévue ce jour-là.<br /> | |||
Cela peut se révèler pratique quand vous faites des distributions en commun avec d'autres producteurs. | |||
</div> | |||
</div> | |||
<?php endif; ?> | |||
</div> | |||
</div> |
@@ -36,9 +36,9 @@ class SharedPointSale extends ActiveRecordCommon | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id_point_sale' => 'Point de vente que vous souhaitez partager', | |||
'id_producer_with_sharing' => 'Producteur avec qui vous souhaitez partager un point de vente', | |||
'id_point_sale_with_sharing' => 'Point de vente du producteur avec qui vous souhaitez partager ce point de vente', | |||
'id_point_sale' => 'Point de vente', | |||
'id_producer_with_sharing' => 'Producteur', | |||
'id_point_sale_with_sharing' => 'Point de vente partagé', | |||
]; | |||
} | |||
@@ -5,6 +5,7 @@ namespace domain\PointSale\SharedPointSale; | |||
use domain\_\AbstractResolver; | |||
use domain\PointSale\PointSale\PointSale; | |||
use domain\PointSale\PointSale\PointSaleRepository; | |||
use yii\helpers\Html; | |||
class SharedPointSaleResolver extends AbstractResolver | |||
{ | |||
@@ -17,28 +18,51 @@ class SharedPointSaleResolver extends AbstractResolver | |||
$this->sharedPointSaleRepository = $this->loadService(SharedPointSaleRepository::class); | |||
} | |||
public function getPointsSaleSharedWithPointSale(PointSale $pointSale): array | |||
public function getPointsSaleSharedWithPointSale(PointSale $pointSale, array &$pointsSaleSharedWithPointSaleArray = []): array | |||
{ | |||
$pointsSaleSharedWithPointSaleArray = []; | |||
$idProducerContext = $this->getProducerContextId(); | |||
$sharedPointsSaleConfirmedArray = $this->sharedPointSaleRepository->findSharedPointsSaleConfirmedByPointSale($pointSale); | |||
foreach($sharedPointsSaleConfirmedArray as $sharedPointSaleConfirmed) { | |||
if($sharedPointSaleConfirmed->getPointSale()->id != $pointSale->id | |||
&& !in_array($sharedPointSaleConfirmed->getPointSale(), $pointsSaleSharedWithPointSaleArray)) { | |||
if ($sharedPointSaleConfirmed->getPointSale()->id != $pointSale->id | |||
&& !in_array($sharedPointSaleConfirmed->getPointSale(), $pointsSaleSharedWithPointSaleArray) | |||
&& $sharedPointSaleConfirmed->getPointSale()->getProducer()->id != $idProducerContext) { | |||
$pointsSaleSharedWithPointSaleArray[] = $sharedPointSaleConfirmed->getPointSale(); | |||
$this->getPointsSaleSharedWithPointSale($sharedPointSaleConfirmed->getPointSale(), $pointsSaleSharedWithPointSaleArray); | |||
} | |||
if($sharedPointSaleConfirmed->getPointSaleWithSharing()->id != $pointSale->id | |||
&& !in_array($sharedPointSaleConfirmed->getPointSaleWithSharing(), $pointsSaleSharedWithPointSaleArray)) { | |||
if ($sharedPointSaleConfirmed->getPointSaleWithSharing()->id != $pointSale->id | |||
&& !in_array($sharedPointSaleConfirmed->getPointSaleWithSharing(), $pointsSaleSharedWithPointSaleArray) | |||
&& $sharedPointSaleConfirmed->getProducerWithSharing()->id != $idProducerContext) { | |||
$pointsSaleSharedWithPointSaleArray[] = $sharedPointSaleConfirmed->getPointSaleWithSharing(); | |||
$this->getPointsSaleSharedWithPointSale($sharedPointSaleConfirmed->getPointSaleWithSharing(), $pointsSaleSharedWithPointSaleArray); | |||
} | |||
} | |||
return $pointsSaleSharedWithPointSaleArray; | |||
return array_unique($pointsSaleSharedWithPointSaleArray, SORT_REGULAR); | |||
} | |||
public function getPointsSaleSharedWithPointSaleAsTitle(PointSale $pointSale): string | |||
{ | |||
$title = ''; | |||
$pointsSaleSharedWithPointSale = $this->getPointsSaleSharedWithPointSale($pointSale); | |||
foreach($pointsSaleSharedWithPointSale as $pointSaleShared) { | |||
$title .= Html::encode($pointSaleShared->getProducer()->getName().' - '.$pointSaleShared->getName()).'
'; | |||
} | |||
return $title; | |||
} | |||
public function countPointsSaleSharedWithPointSale(PointSale $pointSale): int | |||
{ | |||
return count($this->getPointsSaleSharedWithPointSale($pointSale)); | |||
} | |||
public function hasPointSaleSharedWithPointSale(PointSale $pointSale): bool | |||
{ | |||
return (bool) count($this->getPointsSaleSharedWithPointSale($pointSale)); | |||
return (bool) $this->countPointsSaleSharedWithPointSale($pointSale); | |||
} | |||
public function countPointsSaleShared(): int |
@@ -77,8 +77,9 @@ class ProducerRepository extends AbstractRepository | |||
/** | |||
* Retourne la liste des établissements pour l'initialisation d'une listesélective. | |||
*/ | |||
public function populateProducerDropdown(): array | |||
public function populateProducerDropdown(bool $excludeProducerContext = false): array | |||
{ | |||
$producerContext = $this->getProducerContext(false); | |||
$producers = $this->createQuery() | |||
->filterIsActive() | |||
->orderBy('postcode, city ASC') | |||
@@ -89,20 +90,22 @@ class ProducerRepository extends AbstractRepository | |||
$optionsProducers = []; | |||
foreach ($producers as $p) { | |||
$departmentCode = substr($p->postcode, 0, 2); | |||
if (!key_exists('d' . $departmentCode, $dataProducers) && isset($departments[$departmentCode])) { | |||
$dataProducers['d' . $departmentCode] = '<strong>' . $departments[$departmentCode] . '</strong>'; | |||
$optionsProducers['d' . $departmentCode] = ['disabled' => true]; | |||
} | |||
if($excludeProducerContext && $producerContext && $producerContext->id != $p->id || !$excludeProducerContext) { | |||
$departmentCode = substr($p->postcode, 0, 2); | |||
if (!key_exists('d' . $departmentCode, $dataProducers) && isset($departments[$departmentCode])) { | |||
$dataProducers['d' . $departmentCode] = '<strong>' . $departments[$departmentCode] . '</strong>'; | |||
$optionsProducers['d' . $departmentCode] = ['disabled' => true]; | |||
} | |||
$dataProducers[$p->id] = '<span class="glyphicon glyphicon-lock"></span> ' . Html::encode( | |||
$p->name | |||
) . ' - ' . Html::encode($p->postcode) . ' ' . Html::encode( | |||
$p->city | |||
) . ' <span class="glyphicon glyphicon-lock"></span>'; | |||
$dataProducers[$p->id] = '<span class="glyphicon glyphicon-lock"></span> ' . Html::encode( | |||
$p->name | |||
) . ' - ' . Html::encode($p->postcode) . ' ' . Html::encode( | |||
$p->city | |||
) . ' <span class="glyphicon glyphicon-lock"></span>'; | |||
if (strlen($p->code)) { | |||
$optionsProducers[$p->id] = ['class' => 'lock']; | |||
if (strlen($p->code)) { | |||
$optionsProducers[$p->id] = ['class' => 'lock']; | |||
} | |||
} | |||
} | |||