Browse Source

Points de vente partagés

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
9a6d6ea0d7
13 changed files with 294 additions and 44 deletions
  1. +20
    -5
      backend/controllers/SharedPointSaleController.php
  2. +15
    -1
      backend/views/layouts/content.php
  3. +1
    -1
      backend/views/layouts/left.php
  4. +86
    -4
      backend/views/shared-point-sale/index.php
  5. +2
    -2
      common/views/alert_message.php
  6. +1
    -1
      domain/Order/OrderStatus/OrderStatusDefinition.php
  7. +16
    -0
      domain/PointSale/PointSale/PointSale.php
  8. +41
    -28
      domain/PointSale/SharedPointSale/SharedPointSale.php
  9. +6
    -0
      domain/PointSale/SharedPointSale/SharedPointSaleModule.php
  10. +11
    -2
      domain/PointSale/SharedPointSale/SharedPointSaleRepository.php
  11. +28
    -0
      domain/PointSale/SharedPointSale/SharedPointSaleRepositoryQuery.php
  12. +62
    -0
      domain/PointSale/SharedPointSale/SharedPointSaleResolver.php
  13. +5
    -0
      domain/Producer/Producer/Producer.php

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



namespace backend\controllers; namespace backend\controllers;


use backend\controllers\BackendController;
use backend\forms\SharedPointSaleForm;
use backend\models\AccessUserProducerForm;
use domain\PointSale\SharedPointSale\SharedPointSale;
use domain\Feature\Feature\Feature; use domain\Feature\Feature\Feature;
use domain\User\User\UserSearch;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;




return $this->render('index', [ return $this->render('index', [
'sharedPointsSaleRequestOfMe' => $sharedPointSaleRepository->findSharedPointsSaleRequestsOfMe(), 'sharedPointsSaleRequestOfMe' => $sharedPointSaleRepository->findSharedPointsSaleRequestsOfMe(),
'sharedPointsSaleRequestOthers' => $sharedPointSaleRepository->findSharedPointsSaleRequestsOthers()
'sharedPointsSaleRequestOthers' => $sharedPointSaleRepository->findSharedPointsSaleRequestsOthers(),
'pointsSaleArray' => $this->getPointSaleModule()->getRepository()->findPointSales()
]); ]);
} }


]); ]);
} }


public function actionConfirm(int $id)
{
$sharedPointSale = $this->findSharedPointSale($id);
$sharedPointSale->scenario = SharedPointSale::SCENARIO_CONFIRM;
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.");
}
else {
$this->addFlash('error', "Une erreur est survenue lors de l'annulation de la demande de partage.");
}
}

return $this->redirect(['index']);
}

public function actionDecline(int $id) public function actionDecline(int $id)
{ {
$sharedPointSale = $this->findSharedPointSale($id); $sharedPointSale = $this->findSharedPointSale($id);

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



$producerModule = $this->getProducerModule(); $producerModule = $this->getProducerModule();
$adminSettingBag = $this->getSettingModule()->getAdminSettingBag(); $adminSettingBag = $this->getSettingModule()->getAdminSettingBag();
$sharedPointSaleModule = $this->getSharedPointSaleModule();


?> ?>
<div class="content-wrapper"> <div class="content-wrapper">
<?php $producer = GlobalParam::getCurrentProducer(); ?> <?php $producer = GlobalParam::getCurrentProducer(); ?>
<?php if($producer && !$producerModule->isUpToDateWithOpendistribVersion($producer) && $producer->option_display_message_new_opendistrib_version): ?> <?php if($producer && !$producerModule->isUpToDateWithOpendistribVersion($producer) && $producer->option_display_message_new_opendistrib_version): ?>
<div class="alert alert-success"> <div class="alert alert-success">
<p>Souke a été mis à jour vers la version <?= GlobalParam::getSoukeVersion() ?> ! <a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['development/index']) ?>">Découvrir les nouveautés</a></p>
<p>
<i class="icon fa fa-cogs"></i>
Souke a été mis à jour vers la version <?= GlobalParam::getSoukeVersion() ?> ! <a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['development/index']) ?>">Découvrir les nouveautés</a>
</p>
<a href="<?= Yii::$app->urlManager->createUrl(['producer/update-opendistrib-version']) ?>" class="close"><span aria-hidden="true">&times;</span></a> <a href="<?= Yii::$app->urlManager->createUrl(['producer/update-opendistrib-version']) ?>" class="close"><span aria-hidden="true">&times;</span></a>
</div> </div>
<?php endif; ?> <?php endif; ?>


<?php $countSharedPointsSaleRequestsOthers = $sharedPointSaleModule->getResolver()->countSharedPointsSaleRequestsOthers(); ?>
<?php if($countSharedPointsSaleRequestsOthers): ?>
<div class="alert alert-info">
<p>
<i class="icon fa fa-share-alt"></i>
Vous avez une demande de partage de point de vente en attente. <a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/index']) ?>">Voir</a>
</p>
</div>
<?php endif; ?>

<?php <?php
$flashTypeArray = ['error' => 'ban', 'danger' => 'ban', 'warning' => 'warning', 'info' => 'info', 'success' => 'check']; $flashTypeArray = ['error' => 'ban', 'danger' => 'ban', 'warning' => 'warning', 'info' => 'info', 'success' => 'check'];
foreach($flashTypeArray as $flashType => $icon) { foreach($flashTypeArray as $flashType => $icon) {

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

'active' => Yii::$app->controller->id == 'point-sale' || Yii::$app->controller->id == 'shared-point-sale', 'active' => Yii::$app->controller->id == 'point-sale' || Yii::$app->controller->id == 'shared-point-sale',
'items' => [ 'items' => [
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer], ['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Partagés', 'icon' => 'share-alt', 'url' => ['/shared-point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer && $featureChecker->isEnabled(Feature::ALIAS_SHARED_POINT_SALE)],
['label' => 'Partages', 'icon' => 'share-alt', 'url' => ['/shared-point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer && $featureChecker->isEnabled(Feature::ALIAS_SHARED_POINT_SALE)],
] ]
], ],
[ [

+ 86
- 4
backend/views/shared-point-sale/index.php View File

use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use yii\grid\GridView; use yii\grid\GridView;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm;


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


$this->setTitle('Points de vente partagés'); $this->setTitle('Points de vente partagés');
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"> <h3 class="panel-title">
Demandes de partage en attente
Mes demandes de partages en attente
</h3> </h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<tbody> <tbody>
<?php foreach($sharedPointsSaleRequestOfMe as $sharedPointSale): ?> <?php foreach($sharedPointsSaleRequestOfMe as $sharedPointSale): ?>
<tr> <tr>
<td><?= Html::encode($sharedPointSale->getPointSale()->name); ?></td>
<td><?= Html::encode($sharedPointSale->getProducerWithSharing()->name); ?></td>
<td><?= Html::encode($sharedPointSale->getPointSale()->getName()); ?></td>
<td><?= Html::encode($sharedPointSale->getProducerWithSharing()->getName()); ?></td>
<td> <td>
<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline', 'id' => $sharedPointSale->id]) ?>" class="btn btn-default">Annuler</a>
<a href="<?= Yii::$app->urlManager->createUrl(['shared-point-sale/decline', 'id' => $sharedPointSale->getId()]) ?>" class="btn btn-default">Annuler</a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php endif; ?> <?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; ?>

<?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)):
?>
<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>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
</div> </div>

+ 2
- 2
common/views/alert_message.php View File



<?php if($display && $message): ?> <?php if($display && $message): ?>
<div class="alert alert-<?= $type ?>"> <div class="alert alert-<?= $type ?>">
<?php if($title): ?>
<?php if(isset($title) && $title): ?>
<h4> <h4>
<?php if($icon): ?> <?php if($icon): ?>
<i class="icon fa fa-<?= $icon ?>"></i> <i class="icon fa fa-<?= $icon ?>"></i>
</h4> </h4>
<?php endif; ?> <?php endif; ?>
<p> <p>
<?php if(!$title && $icon): ?>
<?php if((!isset($title) || !$title) && $icon): ?>
<i class="icon fa fa-<?= $icon ?>"></i> <i class="icon fa fa-<?= $icon ?>"></i>
<?php endif; ?> <?php endif; ?>
<?php if(is_array($message)): ?> <?php if(is_array($message)): ?>

+ 1
- 1
domain/Order/OrderStatus/OrderStatusDefinition.php View File

{ {
return [ return [
OrderStatus::ALIAS_ORDERED => [ OrderStatus::ALIAS_ORDERED => [
'label' => 'Créée'
'label' => 'Ajoutée'
], ],
OrderStatus::ALIAS_UPDATED => [ OrderStatus::ALIAS_UPDATED => [
'label' => 'Modifiée' 'label' => 'Modifiée'

+ 16
- 0
domain/PointSale/PointSale/PointSale.php View File

use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use domain\Distribution\PointSaleDistribution\PointSaleDistribution; use domain\Distribution\PointSaleDistribution\PointSaleDistribution;
use domain\PointSale\UserPointSale\UserPointSale; use domain\PointSale\UserPointSale\UserPointSale;
use domain\Producer\Producer\Producer;
use domain\User\User\User; use domain\User\User\User;


/** /**
]; ];
} }


public function getName(): string
{
return $this->name;
}

public function getProducer(): Producer
{
return $this->producerRelation;
}

/* /*
* Relations * Relations
*/ */


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

public function getUserPointSale() public function getUserPointSale()
{ {
return $this->hasMany(UserPointSale::class, ['id_point_sale' => 'id']); return $this->hasMany(UserPointSale::class, ['id_point_sale' => 'id']);

+ 41
- 28
domain/PointSale/SharedPointSale/SharedPointSale.php View File



class SharedPointSale extends ActiveRecordCommon class SharedPointSale extends ActiveRecordCommon
{ {
/* Yii */

public const SCENARIO_CONFIRM = 'confirm';

public static function tableName()
{
return 'shared_point_sale';
}

public function rules()
{
return [
[['id_point_sale', 'id_producer_with_sharing', 'created_at', 'created_by'], 'required'],
['id_point_sale_with_sharing', 'required', 'on' => self::SCENARIO_CONFIRM],
[['id_point_sale', 'id_producer_with_sharing', 'id_point_sale_with_sharing', 'status',
'created_by', 'confirmed_by', 'declined_by'], 'integer'],
[['created_at', 'confirmed_at', 'declined_at'], 'safe'],
['id_point_sale', 'exist', 'targetClass' => PointSale::class, 'targetAttribute' => 'id'],
['id_point_sale_with_sharing', 'exist', 'targetClass' => PointSale::class, 'targetAttribute' => 'id'],
['id_producer_with_sharing', 'exist', 'targetClass' => Producer::class, 'targetAttribute' => 'id'],
[['created_by', 'confirmed_by', 'declined_by'], 'exist', 'targetClass' => User::class, 'targetAttribute' => 'id'],
];
}

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',
];
}

/* Get / Set */

public function getId(): ?int
{
return $this->id;
}

public function getPointSale(): PointSale public function getPointSale(): PointSale
{ {
return $this->pointSaleRelation; return $this->pointSaleRelation;


public function getPointSaleWithSharing(): ?PointSale public function getPointSaleWithSharing(): ?PointSale
{ {
return $this->pointSaleWithSharing;
return $this->pointSaleWithSharingRelation;
} }


public function setPointSaleWithSharing(PointSale $pointSaleWithSharing = null): self public function setPointSaleWithSharing(PointSale $pointSaleWithSharing = null): self
return $this; return $this;
} }


public static function tableName()
{
return 'shared_point_sale';
}

public function rules()
{
return [
[['id_point_sale', 'id_producer_with_sharing', 'created_at', 'created_by'], 'required'],
[['id_point_sale', 'id_producer_with_sharing', 'id_point_sale_with_sharing', 'status',
'created_by', 'confirmed_by', 'declined_by'], 'integer'],
[['created_at', 'confirmed_at', 'declined_at'], 'safe'],
['id_point_sale', 'exist', 'targetClass' => PointSale::class, 'targetAttribute' => 'id'],
['id_producer_with_sharing', 'exist', 'targetClass' => Producer::class, 'targetAttribute' => 'id'],
[['created_by', 'confirmed_by', 'declined_by'], 'exist', 'targetClass' => User::class, 'targetAttribute' => 'id'],
];
}

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',
];
}

/* Relations */ /* Relations */


public function getPointSaleRelation() public function getPointSaleRelation()

+ 6
- 0
domain/PointSale/SharedPointSale/SharedPointSaleModule.php View File

SharedPointSaleDefinition::class, SharedPointSaleDefinition::class,
SharedPointSaleBuilder::class, SharedPointSaleBuilder::class,
SharedPointSaleRepository::class, SharedPointSaleRepository::class,
SharedPointSaleResolver::class,
SharedPointSaleManager::class SharedPointSaleManager::class
]; ];
} }
return SharedPointSaleRepository::getInstance(); return SharedPointSaleRepository::getInstance();
} }


public function getResolver(): SharedPointSaleResolver
{
return SharedPointSaleResolver::getInstance();
}

public function getManager(): SharedPointSaleManager public function getManager(): SharedPointSaleManager
{ {
return SharedPointSaleManager::getInstance(); return SharedPointSaleManager::getInstance();

+ 11
- 2
domain/PointSale/SharedPointSale/SharedPointSaleRepository.php View File

namespace domain\PointSale\SharedPointSale; namespace domain\PointSale\SharedPointSale;


use domain\_\AbstractRepository; use domain\_\AbstractRepository;
use domain\PointSale\PointSale\PointSale;


class SharedPointSaleRepository extends AbstractRepository class SharedPointSaleRepository extends AbstractRepository
{ {
{ {
return $this->createQuery() return $this->createQuery()
->filterByProducerOfPointSale($this->getProducerContext()) ->filterByProducerOfPointSale($this->getProducerContext())
->filterIsStatusOnline()
->filterIsRequest()
->find(); ->find();
} }


{ {
return $this->createQuery() return $this->createQuery()
->filterByProducerWithSharing($this->getProducerContext()) ->filterByProducerWithSharing($this->getProducerContext())
->filterIsStatusOnline()
->filterIsRequest()
->find();
}

public function findSharedPointsSaleConfirmedByPointSale(PointSale $pointSale)
{
return $this->createQuery()
->filterByPointSale($pointSale)
->filterIsConfirmed()
->find(); ->find();
} }
} }

+ 28
- 0
domain/PointSale/SharedPointSale/SharedPointSaleRepositoryQuery.php View File



use domain\_\AbstractRepositoryQuery; use domain\_\AbstractRepositoryQuery;
use domain\_\StatusInterface; use domain\_\StatusInterface;
use domain\PointSale\PointSale\PointSale;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;


class SharedPointSaleRepositoryQuery extends AbstractRepositoryQuery class SharedPointSaleRepositoryQuery extends AbstractRepositoryQuery
$this->andWhere(['id_producer_with_sharing' => $producer->id]); $this->andWhere(['id_producer_with_sharing' => $producer->id]);
return $this; return $this;
} }

public function filterByPointSale(PointSale $pointSale)
{
$this->andWhere('id_point_sale = :id_point_sale OR id_point_sale_with_sharing = :id_point_sale')
->addParams(['id_point_sale' => $pointSale->id]);
return $this;
}

public function filterIsRequest()
{
$this->filterIsPointSaleWithSharingIsNull()
->filterIsStatusOnline();
return $this;
}

public function filterIsConfirmed()
{
$this->filterIsStatusOnline();
$this->andWhere('id_point_sale_with_sharing IS NOT NULL AND confirmed_at IS NOT NULL');
return $this;
}

public function filterIsPointSaleWithSharingIsNull(): self
{
$this->andWhere('id_point_sale_with_sharing IS NULL');
return $this;
}
} }

+ 62
- 0
domain/PointSale/SharedPointSale/SharedPointSaleResolver.php View File

<?php

namespace domain\PointSale\SharedPointSale;

use domain\_\AbstractResolver;
use domain\PointSale\PointSale\PointSale;
use domain\PointSale\PointSale\PointSaleRepository;

class SharedPointSaleResolver extends AbstractResolver
{
protected PointSaleRepository $pointSaleRepository;
protected SharedPointSaleRepository $sharedPointSaleRepository;

public function loadDependencies(): void
{
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class);
$this->sharedPointSaleRepository = $this->loadService(SharedPointSaleRepository::class);
}

public function getPointsSaleSharedWithPointSale(PointSale $pointSale): array
{
$pointsSaleSharedWithPointSaleArray = [];
$sharedPointsSaleConfirmedArray = $this->sharedPointSaleRepository->findSharedPointsSaleConfirmedByPointSale($pointSale);

foreach($sharedPointsSaleConfirmedArray as $sharedPointSaleConfirmed) {
if($sharedPointSaleConfirmed->getPointSale()->id != $pointSale->id
&& !in_array($sharedPointSaleConfirmed->getPointSale(), $pointsSaleSharedWithPointSaleArray)) {
$pointsSaleSharedWithPointSaleArray[] = $sharedPointSaleConfirmed->getPointSale();
}
if($sharedPointSaleConfirmed->getPointSaleWithSharing()->id != $pointSale->id
&& !in_array($sharedPointSaleConfirmed->getPointSaleWithSharing(), $pointsSaleSharedWithPointSaleArray)) {
$pointsSaleSharedWithPointSaleArray[] = $sharedPointSaleConfirmed->getPointSaleWithSharing();
}
}

return $pointsSaleSharedWithPointSaleArray;
}

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

public function countPointsSaleShared(): int
{
$count = 0;
$pointsSaleArray = $this->pointSaleRepository->findPointSales();

foreach($pointsSaleArray as $pointSale) {
if($this->hasPointSaleSharedWithPointSale($pointSale)) {
$count ++;
}
}

return $count;
}

public function countSharedPointsSaleRequestsOthers(): int
{
return count($this->sharedPointSaleRepository->findSharedPointsSaleRequestsOthers());
}
}

+ 5
- 0
domain/Producer/Producer/Producer.php View File

]; ];
} }


public function getName(): string
{
return $this->name;
}

/* /*
* Relations * Relations
*/ */

Loading…
Cancel
Save