$producerModule = $this->getProducerModule(); | $producerModule = $this->getProducerModule(); | ||||
$productModule = $this->getProductModule(); | $productModule = $this->getProductModule(); | ||||
$subscriptionManger = $this->getSubscriptionModule(); | $subscriptionManger = $this->getSubscriptionModule(); | ||||
$distributionModule = $this-> getDistributionModule(); | |||||
$distributionModule = $this->getDistributionModule(); | |||||
$model = new SubscriptionForm(); | $model = new SubscriptionForm(); | ||||
$model->isAdmin = true; | $model->isAdmin = true; | ||||
$arrayProductsSubscription = $productSubscriptionModule->findProductSubscriptionsBySubscription($subscription); | $arrayProductsSubscription = $productSubscriptionModule->findProductSubscriptionsBySubscription($subscription); | ||||
foreach ($arrayProductsSubscription as $productSubscription) { | foreach ($arrayProductsSubscription as $productSubscription) { | ||||
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity; | |||||
if($productSubscription->getProduct()) { | |||||
$model->products['product_' . $productSubscription->id_product] = $productSubscription->getQuantity(); | |||||
} | |||||
elseif($productSubscription->getRotating()) { | |||||
$model->rotatings['rotating_' . $productSubscription->id_rotating] = $productSubscription->getQuantity(); | |||||
} | |||||
} | } | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404); | throw new NotFoundHttpException('L\'abonnement est introuvable.', 404); | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$subscription = $idSubscription ? $this->getSubscriptionModule()->getRepository()->findOneSubscriptionById($idSubscription) : null; | |||||
$rotatingModule = $this->getRotatingModule(); | $rotatingModule = $this->getRotatingModule(); | ||||
$unitModule = $this->getUnitModule(); | $unitModule = $this->getUnitModule(); | ||||
}]); | }]); | ||||
} | } | ||||
// Produits | |||||
$productsArray = $productsQuery->asArray()->orderBy('order ASC')->all(); | $productsArray = $productsQuery->asArray()->orderBy('order ASC')->all(); | ||||
foreach ($productsArray as &$theProduct) { | foreach ($productsArray as &$theProduct) { | ||||
$theProduct['wording_unit'] = $unitModule->getSolver()->strUnit($theProduct['unit']); | $theProduct['wording_unit'] = $unitModule->getSolver()->strUnit($theProduct['unit']); | ||||
$rotatingsArrayReturn = []; | $rotatingsArrayReturn = []; | ||||
$rotatingsArray = $rotatingModule->getRepository()->findRotatings(); | $rotatingsArray = $rotatingModule->getRepository()->findRotatings(); | ||||
foreach($rotatingsArray as $rotating) { | foreach($rotatingsArray as $rotating) { | ||||
$productSubscription = $this->getProductSubscriptionModule()->getRepository() | |||||
->findOneProductSubscriptionBySubscriptionAndRotating($subscription, $rotating); | |||||
$rotatingsArrayReturn[] = array_merge($rotating->getAttributes(), [ | $rotatingsArrayReturn[] = array_merge($rotating->getAttributes(), [ | ||||
'quantity' => '' | |||||
'quantity' => $productSubscription ? $productSubscription->getQuantity() : '' | |||||
]); | ]); | ||||
} | } | ||||
use domain\Product\Product\ProductModule; | use domain\Product\Product\ProductModule; | ||||
use domain\Subscription\Subscription\Subscription; | use domain\Subscription\Subscription\Subscription; | ||||
use domain\Subscription\Subscription\SubscriptionModule; | use domain\Subscription\Subscription\SubscriptionModule; | ||||
use domain\Subscription\Subscription\SubscriptionRepository; | |||||
use domain\User\User\UserModule; | use domain\User\User\UserModule; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use yii\helpers\ArrayHelper; | use yii\helpers\ArrayHelper; | ||||
$this->addBreadcrumb($this->getTitle()) ; | $this->addBreadcrumb($this->getTitle()) ; | ||||
$this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ; | $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ; | ||||
$subscriptionsArray = Subscription::searchAll() ; | |||||
?> | ?> | ||||
<div class="subscription-index"> | <div class="subscription-index"> | ||||
<?= GridView::widget([ | <?= GridView::widget([ | ||||
$html = '' ; | $html = '' ; | ||||
foreach($model->productSubscription as $productSubscription) | foreach($model->productSubscription as $productSubscription) | ||||
{ | { | ||||
if(isset($productSubscription->product)) { | |||||
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).' '. $productModule->getSolver()->strUnit($productSubscription->product, 'wording_short').')<br />' ; | |||||
if($productSubscription->getProduct()) { | |||||
$html .= Html::encode($productSubscription->getProduct()->name).' ('.($productSubscription->getQuantity() * Product::$unitsArray[$productSubscription->getProduct()->unit]['coefficient']).' '. $productModule->getSolver()->strUnit($productSubscription->getProduct(), 'wording_short').')<br />' ; | |||||
} | |||||
elseif($productSubscription->getRotating()) { | |||||
$html .= Html::encode($productSubscription->getRotating()->getName()).' ('.($productSubscription->getQuantity()).' p.)<br />' ; | |||||
} | } | ||||
else { | else { | ||||
$html .= 'Produit non défini<br />' ; | $html .= 'Produit non défini<br />' ; |
domain\User\UserProducer\Event\PaymentObserver::class | domain\User\UserProducer\Event\PaymentObserver::class | ||||
], | ], | ||||
Distribution::class => [ | Distribution::class => [ | ||||
// Initialisation de l'ensemble des produits tournants au moment de l'activation d'une distribution | |||||
domain\Product\Rotating\Event\DistributionObserver::class, | |||||
// Subscription : génération des commandes sur base des abonnements | // Subscription : génération des commandes sur base des abonnements | ||||
domain\Subscription\Subscription\Event\DistributionObserver::class, | domain\Subscription\Subscription\Event\DistributionObserver::class, | ||||
// Initialisation de l'ensemble des produits tournants au moment de l'activation d'une distribution | |||||
domain\Product\Rotating\Event\DistributionObserver::class | |||||
], | ], | ||||
DeliveryNote::class => [ | DeliveryNote::class => [ | ||||
// Order : assignation du bon de livraison aux commandes | // Order : assignation du bon de livraison aux commandes |
use domain\Product\Product\Product; | use domain\Product\Product\Product; | ||||
use domain\Product\Product\ProductModule; | use domain\Product\Product\ProductModule; | ||||
use domain\Product\Product\ProductRepository; | |||||
use domain\Product\Rotating\RotatingRepository; | |||||
use domain\Subscription\ProductSubscription\ProductSubscription; | use domain\Subscription\ProductSubscription\ProductSubscription; | ||||
use domain\Subscription\ProductSubscription\ProductSubscriptionManager; | |||||
use domain\Subscription\Subscription\Subscription; | use domain\Subscription\Subscription\Subscription; | ||||
use domain\Subscription\Subscription\SubscriptionModule; | use domain\Subscription\Subscription\SubscriptionModule; | ||||
use domain\User\User\UserModule; | use domain\User\User\UserModule; | ||||
$subscriptionModule = SubscriptionModule::getInstance(); | $subscriptionModule = SubscriptionModule::getInstance(); | ||||
if ($this->id) { | if ($this->id) { | ||||
$subscription = Subscription::searchOne(['id' => $this->id]) ; | |||||
$subscription = Subscription::searchOne(['id' => $this->id]) ; | |||||
$subscription->populateUpdatedBy($userModule->getCurrent()); | $subscription->populateUpdatedBy($userModule->getCurrent()); | ||||
} | } | ||||
else { | else { | ||||
$subscription->save(); | $subscription->save(); | ||||
// produits | |||||
if ($this->id) { | if ($this->id) { | ||||
$productsSubscriptionsArray = ProductSubscription::findAll(['id_subscription' => $this->id]) ; | |||||
ProductSubscription::deleteAll(['id_subscription' => $this->id]); | |||||
ProductSubscription::deleteAll(['id_subscription' => $this->id]); | |||||
} | } | ||||
foreach ($this->products as $nameInput => $quantity) { | foreach ($this->products as $nameInput => $quantity) { | ||||
if ($quantity) { | |||||
$idProduct = (int) str_replace('product_', '', $nameInput); | |||||
$product = Product::findOne($idProduct) ; | |||||
$newProductSubscription = new ProductSubscription; | |||||
$newProductSubscription->id_subscription = $subscription->id; | |||||
$newProductSubscription->id_product = $idProduct; | |||||
$newProductSubscription->quantity = $quantity / $productModule->getSolver()->getUnitCoefficient($product); | |||||
$idProduct = (int) str_replace('product_', '', $nameInput); | |||||
$product = ProductRepository::getInstance()->findOneProductById($idProduct) ; | |||||
if ($quantity && $product) { | |||||
ProductSubscriptionManager::getInstance()->createProductSubscription( | |||||
$subscription, | |||||
$product, | |||||
null, | |||||
$quantity / $productModule->getSolver()->getUnitCoefficient($product) | |||||
); | |||||
} | |||||
} | |||||
$newProductSubscription->save(); | |||||
foreach ($this->rotatings as $nameInput => $quantity) { | |||||
$idRotating = (int) str_replace('rotating_', '', $nameInput); | |||||
$rotating = RotatingRepository::getInstance()->findOneRotatingById($idRotating) ; | |||||
if ($quantity && $rotating) { | |||||
ProductSubscriptionManager::getInstance()->createProductSubscription( | |||||
$subscription, | |||||
null, | |||||
$rotating, | |||||
$quantity | |||||
); | |||||
} | } | ||||
} | } | ||||
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
/** | |||||
* Class m240709_093857_alter_column_product_subscription_id_product | |||||
*/ | |||||
class m240709_093857_alter_column_product_subscription_id_product extends Migration | |||||
{ | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeUp() | |||||
{ | |||||
$this->alterColumn('product_subscription', 'id_product', Schema::TYPE_INTEGER); | |||||
} | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeDown() | |||||
{ | |||||
$this->alterColumn('product_subscription', 'id_product', Schema::TYPE_INTEGER.' NOT NULL'); | |||||
} | |||||
} |
use domain\Product\Product\Product; | use domain\Product\Product\Product; | ||||
use domain\Product\Product\ProductRepository; | use domain\Product\Product\ProductRepository; | ||||
use domain\Product\Product\ProductSolver; | use domain\Product\Product\ProductSolver; | ||||
use domain\Product\Rotating\RotatingResolver; | |||||
use domain\Subscription\Subscription\Subscription; | use domain\Subscription\Subscription\Subscription; | ||||
use domain\Subscription\Subscription\SubscriptionBuilder; | use domain\Subscription\Subscription\SubscriptionBuilder; | ||||
use domain\Subscription\Subscription\SubscriptionRepository; | use domain\Subscription\Subscription\SubscriptionRepository; | ||||
$user = $subscription->user ?? null; | $user = $subscription->user ?? null; | ||||
foreach ($subscription->productSubscription as $productSubscription) { | foreach ($subscription->productSubscription as $productSubscription) { | ||||
if($productSubscription->getProduct()) { | |||||
$product = $productSubscription->getProduct(); | |||||
} | |||||
elseif($productSubscription->getRotating()) { | |||||
$product = RotatingResolver::getInstance()->getProductOfRotatingInDistribution( | |||||
$productSubscription->getRotating(), | |||||
$order->distribution | |||||
); | |||||
} | |||||
$this->productOrderBuilder->createProductOrder( | $this->productOrderBuilder->createProductOrder( | ||||
$order, | $order, | ||||
$productSubscription->product, | |||||
$productSubscription->quantity, | |||||
(float) $this->productSolver->getPrice($productSubscription->product, [ | |||||
$product, | |||||
$productSubscription->getQuantity(), | |||||
(float) $this->productSolver->getPrice($product, [ | |||||
'user' => $user, | 'user' => $user, | ||||
'point_sale' => $subscription->pointSale, | 'point_sale' => $subscription->pointSale, | ||||
'quantity' => $productSubscription->quantity | |||||
'quantity' => $productSubscription->getQuantity() | |||||
]) | ]) | ||||
); | ); | ||||
$productsAdd = true; | $productsAdd = true; |
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['id_producer', 'name', 'day', 'selected_products_ids'], 'required'], | |||||
[['id_producer', 'name', 'day'], 'required'], | |||||
[['name'], 'string', 'max' => 255], | [['name'], 'string', 'max' => 255], | ||||
[['id_producer', 'day', 'status'], 'integer'], | [['id_producer', 'day', 'status'], 'integer'], | ||||
[['selected_products_ids'], 'verifySelectedProductsIds'], | [['selected_products_ids'], 'verifySelectedProductsIds'], |
*/ | */ | ||||
public function initializeRotatingInDistribution(Rotating $rotating, Distribution $distribution) | public function initializeRotatingInDistribution(Rotating $rotating, Distribution $distribution) | ||||
{ | { | ||||
$rotatingProductOfDistribution = $this->rotatingResolver->deductRotatingProductOfDistribution($rotating, $distribution); | |||||
if($rotating->getDay() == $distribution->getDate()->format('N')) { | |||||
$rotatingProductOfDistribution = $this->rotatingResolver->deductRotatingProductOfDistribution($rotating, $distribution); | |||||
$this->distributionRotatingManager->createDistributionRotatingIfNotExist( | |||||
$distribution, | |||||
$rotatingProductOfDistribution | |||||
); | |||||
$this->distributionRotatingManager->createDistributionRotatingIfNotExist( | |||||
$distribution, | |||||
$rotatingProductOfDistribution | |||||
); | |||||
foreach($rotating->getRotatingProducts() as $rotatingProduct) { | |||||
if($rotatingProduct->getId() == $rotatingProductOfDistribution->getId()) { | |||||
$this->productManager->activateProductInDistribution($rotatingProductOfDistribution->getProduct(), $distribution); | |||||
} | |||||
else { | |||||
$this->productManager->deactivateProductInDistribution($rotatingProduct->getProduct(), $distribution); | |||||
foreach($rotating->getRotatingProducts() as $rotatingProduct) { | |||||
if($rotatingProduct->getId() == $rotatingProductOfDistribution->getId()) { | |||||
$this->productManager->activateProductInDistribution($rotatingProductOfDistribution->getProduct(), $distribution); | |||||
} | |||||
else { | |||||
$this->productManager->deactivateProductInDistribution($rotatingProduct->getProduct(), $distribution); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
return $this->getFirstRotatingProduct($rotating); | return $this->getFirstRotatingProduct($rotating); | ||||
} | } | ||||
public function getProductOfRotatingInDistribution(Rotating $rotating, Distribution $distribution): Product | |||||
{ | |||||
$rotatingProduct = $this->distributionRotatingRepository->findOneDistributionRotating($distribution, $rotating); | |||||
return $rotatingProduct->getRotatingProduct()->getProduct(); | |||||
} | |||||
/** | /** | ||||
* @throws ErrorException | * @throws ErrorException | ||||
*/ | */ |
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use domain\Product\Product\Product; | use domain\Product\Product\Product; | ||||
use domain\Product\Rotating\Rotating; | use domain\Product\Rotating\Rotating; | ||||
use domain\Subscription\Subscription\Subscription; | |||||
use yii\db\ActiveQuery; | use yii\db\ActiveQuery; | ||||
/** | |||||
* This is the model class for table "commande_auto_produit". | |||||
*/ | |||||
class ProductSubscription extends ActiveRecordCommon | class ProductSubscription extends ActiveRecordCommon | ||||
{ | { | ||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | public static function tableName() | ||||
{ | { | ||||
return 'product_subscription'; | return 'product_subscription'; | ||||
} | } | ||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
]; | ]; | ||||
} | } | ||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | public function attributeLabels() | ||||
{ | { | ||||
return [ | return [ | ||||
]; | ]; | ||||
} | } | ||||
/* Méthodes */ | |||||
/* Getters / setters */ | /* Getters / setters */ | ||||
public function getRotating(): ?Rotating | public function getRotating(): ?Rotating | ||||
return $this; | return $this; | ||||
} | } | ||||
/* Relations */ | |||||
public function getSubscription(): Subscription | |||||
{ | |||||
return $this->subscriptionRelation; | |||||
} | |||||
public function getRotatingRelation(): ActiveQuery | |||||
public function setSubscription(Subscription $subscription): self | |||||
{ | { | ||||
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']); | |||||
$this->populateFieldObject('id_subscription', 'subscriptionRelation', $subscription); | |||||
return $this; | |||||
} | } | ||||
public function getProduct() | |||||
public function getProduct(): ?Product | |||||
{ | { | ||||
return $this->hasOne(Product::class, ['id' => 'id_product']); | |||||
return $this->productRelation; | |||||
} | } | ||||
public function populateProduct(Product $product): void | |||||
public function setProduct(Product $product): self | |||||
{ | { | ||||
$this->populateFieldObject('id_product', 'product', $product); | $this->populateFieldObject('id_product', 'product', $product); | ||||
return $this; | |||||
} | |||||
public function getQuantity(): float | |||||
{ | |||||
return $this->quantity; | |||||
} | |||||
public function setQuantity(float $quantity): self | |||||
{ | |||||
$this->quantity = $quantity; | |||||
return $this; | |||||
} | |||||
/* Relations */ | |||||
public function getRotatingRelation(): ActiveQuery | |||||
{ | |||||
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']); | |||||
} | |||||
public function getProductRelation(): ActiveQuery | |||||
{ | |||||
return $this->hasOne(Product::class, ['id' => 'id_product']); | |||||
} | } | ||||
} | } |
namespace domain\Subscription\ProductSubscription; | namespace domain\Subscription\ProductSubscription; | ||||
use domain\_\AbstractBuilder; | use domain\_\AbstractBuilder; | ||||
use domain\Subscription\Subscription\Subscription; | |||||
class ProductSubscriptionBuilder extends AbstractBuilder | class ProductSubscriptionBuilder extends AbstractBuilder | ||||
{ | { | ||||
public function instanciateProductSubscription(): ProductSubscription | |||||
public function instanciateProductSubscription(Subscription $subscription): ProductSubscription | |||||
{ | { | ||||
$productSubscription = new ProductSubscription(); | $productSubscription = new ProductSubscription(); | ||||
return $productSubscription; | |||||
} | |||||
public function createProductSubscription(): ProductSubscription | |||||
{ | |||||
$productSubscription = $this->instanciateProductSubscription(); | |||||
$this->saveCreate($productSubscription); | |||||
$productSubscription->setSubscription($subscription); | |||||
return $productSubscription; | return $productSubscription; | ||||
} | } |
<?php | |||||
namespace domain\Subscription\ProductSubscription; | |||||
use domain\_\AbstractManager; | |||||
use domain\Product\Product\Product; | |||||
use domain\Product\Rotating\Rotating; | |||||
use domain\Subscription\Subscription\Subscription; | |||||
use yii\base\ErrorException; | |||||
class ProductSubscriptionManager extends AbstractManager | |||||
{ | |||||
protected ProductSubscriptionBuilder $productSubscriptionBuilder; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->productSubscriptionBuilder = $this->loadService(ProductSubscriptionBuilder::class); | |||||
} | |||||
public function createProductSubscription(Subscription $subscription, Product $product = null, Rotating $rotating = null, float $quantity = null): ProductSubscription | |||||
{ | |||||
if(!$product && !$rotating) { | |||||
throw new ErrorException("Il faut au moins un produit ou un produit tournant pour créer un ProductSubscription"); | |||||
} | |||||
$productSubscription = $this->productSubscriptionBuilder->instanciateProductSubscription($subscription); | |||||
if($product) { | |||||
$productSubscription->setProduct($product); | |||||
} | |||||
if($rotating) { | |||||
$productSubscription->setRotating($rotating); | |||||
} | |||||
$productSubscription->setQuantity($quantity); | |||||
$productSubscription->save(); | |||||
return $productSubscription; | |||||
} | |||||
} |
return [ | return [ | ||||
ProductSubscriptionDefinition::class, | ProductSubscriptionDefinition::class, | ||||
ProductSubscriptionRepository::class, | ProductSubscriptionRepository::class, | ||||
ProductSubscriptionBuilder::class | |||||
ProductSubscriptionBuilder::class, | |||||
ProductSubscriptionManager::class, | |||||
]; | ]; | ||||
} | } | ||||
return ProductSubscriptionRepository::getInstance(); | return ProductSubscriptionRepository::getInstance(); | ||||
} | } | ||||
public function getFactory(): ProductSubscriptionBuilder | |||||
public function getBuilder(): ProductSubscriptionBuilder | |||||
{ | { | ||||
return ProductSubscriptionBuilder::getInstance(); | return ProductSubscriptionBuilder::getInstance(); | ||||
} | } | ||||
public function getManager(): ProductSubscriptionManager | |||||
{ | |||||
return ProductSubscriptionManager::getInstance(); | |||||
} | |||||
} | } |
namespace domain\Subscription\ProductSubscription; | namespace domain\Subscription\ProductSubscription; | ||||
use domain\Product\Rotating\Rotating; | |||||
use domain\Subscription\Subscription\Subscription; | use domain\Subscription\Subscription\Subscription; | ||||
use domain\_\AbstractRepository; | use domain\_\AbstractRepository; | ||||
public function getDefaultOptionsSearch(): array | public function getDefaultOptionsSearch(): array | ||||
{ | { | ||||
return [ | return [ | ||||
self::WITH => ['product'], | |||||
self::WITH => ['productRelation'], | |||||
self::JOIN_WITH => [], | self::JOIN_WITH => [], | ||||
self::ORDER_BY => '', | self::ORDER_BY => '', | ||||
self::ATTRIBUTE_ID_PRODUCER => '' | self::ATTRIBUTE_ID_PRODUCER => '' | ||||
->filterBySubscription($subscription) | ->filterBySubscription($subscription) | ||||
->find(); | ->find(); | ||||
} | } | ||||
public function findOneProductSubscriptionBySubscriptionAndRotating(Subscription $subscription, Rotating $rotating): ?ProductSubscription | |||||
{ | |||||
return $this->createDefaultQuery() | |||||
->filterBySubscription($subscription) | |||||
->filterByRotating($rotating) | |||||
->findOne(); | |||||
} | |||||
} | } |
namespace domain\Subscription\ProductSubscription; | namespace domain\Subscription\ProductSubscription; | ||||
use domain\Product\Rotating\Rotating; | |||||
use domain\Subscription\Subscription\Subscription; | use domain\Subscription\Subscription\Subscription; | ||||
use domain\_\AbstractRepositoryQuery; | use domain\_\AbstractRepositoryQuery; | ||||
$this->andWhere(['id_subscription' => $subscription->id]); | $this->andWhere(['id_subscription' => $subscription->id]); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function filterByRotating(Rotating $rotating): self | |||||
{ | |||||
$this->andWhere(['id_rotating' => $rotating->getId()]); | |||||
return $this; | |||||
} | |||||
} | } |
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'id_user' => 'Utilisateur', | 'id_user' => 'Utilisateur', | ||||
'id_producer' => 'Etablissement', | |||||
'id_producer' => 'Producteur', | |||||
'id_point_sale' => 'Point de vente', | 'id_point_sale' => 'Point de vente', | ||||
'date_begin' => 'Date de début', | 'date_begin' => 'Date de début', | ||||
'date_end' => 'Date de fin', | 'date_end' => 'Date de fin', | ||||
public function getProductSubscription() | public function getProductSubscription() | ||||
{ | { | ||||
return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id']) | return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id']) | ||||
->with('product'); | |||||
->with('productRelation'); | |||||
} | } | ||||
public function getCreatedBy() | public function getCreatedBy() |
{ | { | ||||
return [ | return [ | ||||
self::WITH => ['producer'], | self::WITH => ['producer'], | ||||
self::JOIN_WITH => ['user', 'productSubscription', 'productSubscription.product', 'pointSale'], | |||||
self::JOIN_WITH => ['user', 'productSubscription', 'productSubscription.productRelation', 'pointSale'], | |||||
self::ORDER_BY => 'user.name ASC', | self::ORDER_BY => 'user.name ASC', | ||||
self::ATTRIBUTE_ID_PRODUCER => 'subscription.id_producer' | self::ATTRIBUTE_ID_PRODUCER => 'subscription.id_producer' | ||||
]; | ]; |
]); | ]); | ||||
$query->andFilterWhere(['like', 'product.name', $this->product_name]) ; | $query->andFilterWhere(['like', 'product.name', $this->product_name]) ; | ||||
return $dataProvider; | return $dataProvider; | ||||
} | } | ||||
$html = '' ; | $html = '' ; | ||||
foreach($subscription->productSubscription as $productSubscription) | foreach($subscription->productSubscription as $productSubscription) | ||||
{ | { | ||||
if(isset($productSubscription->product) && $productSubscription->product) { | |||||
$html .= '<strong>'.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . ' '. $this->productSolver->strUnit($productSubscription->product, 'wording_short') . '</strong> ' . Html::encode($productSubscription->product->name). '<br />' ; | |||||
if($productSubscription->getProduct()) { | |||||
$html .= '<strong>'.($productSubscription->getQuantity() * Product::$unitsArray[$productSubscription->getProduct()->unit]['coefficient']) . ' '. $this->productSolver->strUnit($productSubscription->getProduct(), 'wording_short') . '</strong> ' . Html::encode($productSubscription->getProduct()->name). '<br />' ; | |||||
} | } | ||||
else { | else { | ||||
$html .= 'Produit non défini<br />' ; | $html .= 'Produit non défini<br />' ; |
]); | ]); | ||||
foreach ($arrayProductsSubscription as $productSubscription) { | foreach ($arrayProductsSubscription as $productSubscription) { | ||||
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity; | |||||
$model->products['product_' . $productSubscription->id_product] = $productSubscription->getQuantity(); | |||||
} | } | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404); | throw new NotFoundHttpException('L\'abonnement est introuvable.', 404); | ||||
if (isset($arrayProductsSubscription) && count($arrayProductsSubscription)) { | if (isset($arrayProductsSubscription) && count($arrayProductsSubscription)) { | ||||
foreach ($arrayProductsSubscription as $productSubscription) { | foreach ($arrayProductsSubscription as $productSubscription) { | ||||
if ($product->id == $productSubscription->id_product) { | if ($product->id == $productSubscription->id_product) { | ||||
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($productSubscription->product); | |||||
$quantity = $productSubscription->quantity * $coefficientUnit; | |||||
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($productSubscription->getProduct()); | |||||
$quantity = $productSubscription->getQuantity() * $coefficientUnit; | |||||
} | } | ||||
} | } | ||||
} | } |