Browse Source

Points de vente partagés

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
e0afb6a124
8 changed files with 202 additions and 137 deletions
  1. +5
    -2
      backend/controllers/SharedPointSaleController.php
  2. +1
    -1
      backend/views/layouts/content.php
  3. +12
    -0
      backend/views/point-sale/index.php
  4. +5
    -3
      backend/views/shared-point-sale/create.php
  5. +128
    -107
      backend/views/shared-point-sale/index.php
  6. +3
    -3
      domain/PointSale/SharedPointSale/SharedPointSale.php
  7. +32
    -8
      domain/PointSale/SharedPointSale/SharedPointSaleResolver.php
  8. +16
    -13
      domain/Producer/Producer/ProducerRepository.php

+ 5
- 2
backend/controllers/SharedPointSaleController.php View File

if($sharedPointSale->load(\Yii::$app->request->post()) && $sharedPointSale->validate()) { if($sharedPointSale->load(\Yii::$app->request->post()) && $sharedPointSale->validate()) {
$pointSaleWithSharing = $sharedPointSale->getPointSaleWithSharing(); $pointSaleWithSharing = $sharedPointSale->getPointSaleWithSharing();
if($this->getSharedPointSaleModule()->getManager()->confirmSharedPointSale($sharedPointSale, $pointSaleWithSharing, $this->getUserCurrent())) { 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 { 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']); return $this->redirect(['index']);
} }

+ 1
- 1
backend/views/layouts/content.php View File

<?php endif; ?> <?php endif; ?>


<?php $countSharedPointsSaleRequestsOthers = $sharedPointSaleModule->getResolver()->countSharedPointsSaleRequestsOthers(); ?> <?php $countSharedPointsSaleRequestsOthers = $sharedPointSaleModule->getResolver()->countSharedPointsSaleRequestsOthers(); ?>
<?php if($countSharedPointsSaleRequestsOthers): ?>
<?php if($countSharedPointsSaleRequestsOthers && Yii::$app->controller->id != 'shared-point-sale'): ?>
<div class="alert alert-info"> <div class="alert alert-info">
<p> <p>
<i class="icon fa fa-share-alt"></i> <i class="icon fa fa-share-alt"></i>

+ 12
- 0
backend/views/point-sale/index.php View File

use yii\helpers\Html; use yii\helpers\Html;


$pointSaleModule = $this->getPointSaleModule(); $pointSaleModule = $this->getPointSaleModule();
$sharedPointSaleModule = $this->getSharedPointSaleModule();


$this->setTitle('Points de vente'); $this->setTitle('Points de vente');
$this->addBreadcrumb($this->getTitle()); $this->addBreadcrumb($this->getTitle());
} }
} }
], ],
[
'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', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}', 'template' => '{update} {delete}',

+ 5
- 3
backend/views/shared-point-sale/create.php View File

<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<?= $form->field($sharedPointSaleModel, 'id_point_sale') <?= $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') <?= $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> </div>
<div class="form-group form-actions"> <div class="form-group form-actions">

+ 128
- 107
backend/views/shared-point-sale/index.php View File

); );
?> ?>


<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> <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> </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>
</div> </div>
<?php endif; ?>
</div>
</div> </div>

+ 3
- 3
domain/PointSale/SharedPointSale/SharedPointSale.php View File

public function attributeLabels() public function attributeLabels()
{ {
return [ 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é',
]; ];
} }



+ 32
- 8
domain/PointSale/SharedPointSale/SharedPointSaleResolver.php View File

use domain\_\AbstractResolver; use domain\_\AbstractResolver;
use domain\PointSale\PointSale\PointSale; use domain\PointSale\PointSale\PointSale;
use domain\PointSale\PointSale\PointSaleRepository; use domain\PointSale\PointSale\PointSaleRepository;
use yii\helpers\Html;


class SharedPointSaleResolver extends AbstractResolver class SharedPointSaleResolver extends AbstractResolver
{ {
$this->sharedPointSaleRepository = $this->loadService(SharedPointSaleRepository::class); $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); $sharedPointsSaleConfirmedArray = $this->sharedPointSaleRepository->findSharedPointsSaleConfirmedByPointSale($pointSale);


foreach($sharedPointsSaleConfirmedArray as $sharedPointSaleConfirmed) { 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(); $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(); $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()).'&#013;';
}

return $title;
}

public function countPointsSaleSharedWithPointSale(PointSale $pointSale): int
{
return count($this->getPointsSaleSharedWithPointSale($pointSale));
} }


public function hasPointSaleSharedWithPointSale(PointSale $pointSale): bool public function hasPointSaleSharedWithPointSale(PointSale $pointSale): bool
{ {
return (bool) count($this->getPointsSaleSharedWithPointSale($pointSale));
return (bool) $this->countPointsSaleSharedWithPointSale($pointSale);
} }


public function countPointsSaleShared(): int public function countPointsSaleShared(): int

+ 16
- 13
domain/Producer/Producer/ProducerRepository.php View File

/** /**
* Retourne la liste des établissements pour l'initialisation d'une listesélective. * 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() $producers = $this->createQuery()
->filterIsActive() ->filterIsActive()
->orderBy('postcode, city ASC') ->orderBy('postcode, city ASC')
$optionsProducers = []; $optionsProducers = [];


foreach ($producers as $p) { 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'];
}
} }
} }



Loading…
Cancel
Save