Browse Source

[Technique] Refactoring UnitModule

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
6a73619cfa
31 changed files with 265 additions and 83 deletions
  1. +3
    -1
      backend/controllers/DistributionController.php
  2. +1
    -1
      backend/controllers/DocumentController.php
  3. +2
    -2
      backend/controllers/ProductController.php
  4. +3
    -1
      backend/controllers/SubscriptionController.php
  5. +2
    -1
      backend/models/MailForm.php
  6. +7
    -4
      backend/views/distribution/report-bourlingue.php
  7. +1
    -1
      backend/views/distribution/report-grid.php
  8. +1
    -1
      backend/views/document/_download_product_line.php
  9. +1
    -1
      backend/views/product/index.php
  10. +7
    -4
      backend/views/product/update/prices/_form.php
  11. +1
    -1
      backend/views/product/update/prices/list.php
  12. +1
    -1
      backend/views/subscription/index.php
  13. +1
    -0
      common/components/BusinessLogic.php
  14. +6
    -0
      common/components/BusinessLogicTrait.php
  15. +3
    -1
      common/forms/SubscriptionForm.php
  16. +1
    -1
      common/helpers/CSV.php
  17. +32
    -0
      common/logic/Config/Unit/Module/UnitModule.php
  18. +66
    -0
      common/logic/Config/Unit/Service/UnitDefinition.php
  19. +65
    -0
      common/logic/Config/Unit/Service/UnitSolver.php
  20. +3
    -3
      common/logic/Distribution/Distribution/Service/DistributionReport2CsvGenerator.php
  21. +2
    -2
      common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php
  22. +4
    -1
      common/logic/Distribution/Distribution/Service/DistributionReportPdfGenerator.php
  23. +1
    -1
      common/logic/Order/Order/Repository/OrderRepository.php
  24. +5
    -8
      common/logic/Order/ProductOrder/Service/ProductOrderSolver.php
  25. +1
    -1
      common/logic/Product/Product/Model/Product.php
  26. +28
    -32
      common/logic/Product/Product/Service/ProductSolver.php
  27. +1
    -1
      common/logic/Subscription/Subscription/Service/SubscriptionSolver.php
  28. +1
    -1
      common/logic/User/User/Service/UsersCreditCsvGenerator.php
  29. +9
    -7
      producer/controllers/OrderController.php
  30. +5
    -4
      producer/controllers/SubscriptionController.php
  31. +1
    -1
      producer/views/site/index.php

+ 3
- 1
backend/controllers/DistributionController.php View File



public function buildAjaxInfosResponseOrders(array $ordersArray, array $productsArray) public function buildAjaxInfosResponseOrders(array $ordersArray, array $productsArray)
{ {
$productModule = $this->getProductModule();
$userModule = $this->getUserModule(); $userModule = $this->getUserModule();
$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$paymentManager = $this->getPaymentModule(); $paymentManager = $this->getPaymentModule();
$productOrderModule = $this->getProductOrderModule();


if ($ordersArray) { if ($ordersArray) {
foreach ($ordersArray as &$order) { foreach ($ordersArray as &$order) {
$productOrderArray = []; $productOrderArray = [];
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
$productOrderArray[$productOrder->id_product] = [ $productOrderArray[$productOrder->id_product] = [
'quantity' => $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'],
'quantity' => $productOrderModule->getSolver()->getQuantityToCoefficientOfUnit($productOrder),
'unit' => $productOrder->unit, 'unit' => $productOrder->unit,
'price' => number_format($productOrder->price, 5), 'price' => number_format($productOrder->price, 5),
'invoice_price' => number_format($productOrder->invoice_price, 5), 'invoice_price' => number_format($productOrder->invoice_price, 5),

+ 1
- 1
backend/controllers/DocumentController.php View File

'order', 'order',
function ($product) use ($document, $userProducer, $pointSale, $productModule) { function ($product) use ($document, $userProducer, $pointSale, $productModule) {
return array_merge($product->getAttributes(), [ return array_merge($product->getAttributes(), [
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'unit_coefficient' => $productModule->getSolver()->getUnitCoefficient($product->unit),
'prices' => $productModule->getPriceArray($product, $userProducer->user, $pointSale), 'prices' => $productModule->getPriceArray($product, $userProducer->user, $pointSale),
'wording_unit' => $product->wording_unit, 'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value 'tax_rate' => $product->taxRate->value

+ 2
- 2
backend/controllers/ProductController.php View File

'', '',
'', '',
'', '',
CSV::formatPrice($product->price)
CSV::formatNumber($product->price)
]; ];


// prix spécifiques // prix spécifiques
$productPrice->userGroup ? $productPrice->userGroup->name : '', $productPrice->userGroup ? $productPrice->userGroup->name : '',
$productPrice->pointSale ? $productPrice->pointSale->name : '', $productPrice->pointSale ? $productPrice->pointSale->name : '',
$productPrice->from_quantity ?? '', $productPrice->from_quantity ?? '',
CSV::formatPrice($productPrice->price)
CSV::formatNumber($productPrice->price)
]; ];
} }
} }

+ 3
- 1
backend/controllers/SubscriptionController.php View File



use common\forms\SubscriptionForm; use common\forms\SubscriptionForm;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\Subscription\Subscription\Model\SubscriptionSearch; use common\logic\Subscription\Subscription\Model\SubscriptionSearch;
use yii\filters\AccessControl; use yii\filters\AccessControl;
{ {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;


$unitModule = $this->getUnitModule();
$productModule = $this->getProductModule(); $productModule = $this->getProductModule();


$productsQuery = Product::find() $productsQuery = Product::find()
$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'] = $productModule->strUnit($theProduct['unit'], 'wording_short');
$theProduct['wording_unit'] = $unitModule->getSolver()->strUnit($theProduct['unit']);


if (isset($theProduct['productSubscription'][0])) { if (isset($theProduct['productSubscription'][0])) {
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient']; $theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient'];

+ 2
- 1
backend/models/MailForm.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Mailjet; use common\helpers\Mailjet;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\Distribution\Module\DistributionModule; use common\logic\Distribution\Distribution\Module\DistributionModule;
use common\logic\Producer\Producer\Module\ProducerModule; use common\logic\Producer\Producer\Module\ProducerModule;
} }
if($product->price) { if($product->price) {
$productDescription .= ' / '.Price::format($productModule->getPriceWithTax($product)) ; $productDescription .= ' / '.Price::format($productModule->getPriceWithTax($product)) ;
$productDescription .= ' ('. $productModule->strUnit($product->unit, 'wording_unit').')' ;
$productDescription .= ' ('. $productModule->getSolver()->strUnit($product, UnitDefinition::WORDING_UNIT).')' ;
} }


$messageAutoText .= '- '.$productDescription.' $messageAutoText .= '- '.$productDescription.'

+ 7
- 4
backend/views/distribution/report-bourlingue.php View File

*/ */


use common\helpers\Price; use common\helpers\Price;
use common\logic\Config\Unit\Module\UnitModule;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Order\Order\Module\OrderModule; use common\logic\Order\Order\Module\OrderModule;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Module\ProductModule; use common\logic\Product\Product\Module\ProductModule;
use common\logic\User\UserProducer\Model\UserProducer; use common\logic\User\UserProducer\Model\UserProducer;


$unitModule = UnitModule::getInstance();
$productModule = ProductModule::getInstance(); $productModule = ProductModule::getInstance();
$orderModule = OrderModule::getInstance(); $orderModule = OrderModule::getInstance();


$add = false; $add = false;
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
if($product->id == $productOrder->id_product) { if($product->id == $productOrder->id_product) {
$unit = ( $productModule->strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '. $productModule->strUnit($productOrder->unit, 'wording_short', true) ;
$unit = ( $productModule->getSolver()->strUnit($productOrder->product, UnitDefinition::WORDING_SHORT, true) == 'p.') ? '' : ' '. $productModule->getSolver()->strUnit($productOrder->unit, UnitDefinition::WORDING_SHORT, true) ;
$strProducts .= $product->name . ' (' .$productOrder->quantity .$unit.')<br />'; $strProducts .= $product->name . ' (' .$productOrder->quantity .$unit.')<br />';
$add = true; $add = true;
} }
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderModule->getProductQuantity($product, $pointSale->orders, false, $unit); $quantity = $orderModule->getProductQuantity($product, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productModule->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productModule->strUnit($unit, 'wording_short', true) ;
$theUnit = ( $unitModule->getSolver()->strUnit($unit, UnitDefinition::WORDING_SHORT, true) == 'p.') ? '' : '&nbsp;'. $unitModule->getSolver()->strUnit($unit, UnitDefinition::WORDING_SHORT, true) ;
$strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />'; $strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />';
} }
} }
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderModule->getProductQuantity($product, $pointSale->orders, false, $unit); $quantity = $orderModule->getProductQuantity($product, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productModule->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productModule->strUnit($unit, 'wording_short', true) ;
$theUnit = ( $unitModule->getSolver()->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $unitModule->getSolver()->strUnit($unit, 'wording_short', true) ;
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; $html .= $product->name . ' (' .$quantity .$theUnit.')<br />';
} }
} }
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderModule->getProductQuantity($product, $ordersArray, false, $unit); $quantity = $orderModule->getProductQuantity($product, $ordersArray, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productModule->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productModule->strUnit($unit, 'wording_short', true) ;
$theUnit = ( $unitModule->getSolver()->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $unitModule->getSolver()->strUnit($unit, 'wording_short', true) ;
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; $html .= $product->name . ' (' .$quantity .$theUnit.')<br />';
} }
} }

+ 1
- 1
backend/views/distribution/report-grid.php View File

$quantity = ''; $quantity = '';
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
if ($product->id == $productOrder->id_product) { if ($product->id == $productOrder->id_product) {
$unit = ($productModule->strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;' . $productModule->strUnit($productOrder->unit, 'wording_short', true);
$unit = ($productModule->getSolver()->strUnit($productOrder->product, 'wording_short', true) == 'p.') ? '' : '&nbsp;' . $productModule->getSolver()->strUnit($productOrder->product, 'wording_short', true);


$quantity .= $productOrder->quantity . $unit; $quantity .= $productOrder->quantity . $unit;
if ($productOrder->quantity > 1) { if ($productOrder->quantity > 1) {

+ 1
- 1
backend/views/document/_download_product_line.php View File

<td class="align-center"> <td class="align-center">
<?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?> <?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?>
</td> </td>
<td class="align-center"><?= $productModule->strUnit($productOrder->unit, 'wording') ?></td>
<td class="align-center"><?= $productModule->getSolver()->strUnit($productOrder->product, 'wording') ?></td>
<?php if($displayPrices): ?> <?php if($displayPrices): ?>
<?php if($producer->taxRate->value != 0): ?> <?php if($producer->taxRate->value != 0): ?>
<td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td> <td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td>

+ 1
- 1
backend/views/product/index.php View File

'value' => function ($model) use ($productModule) { 'value' => function ($model) use ($productModule) {
$return = ''; $return = '';
if ($model->price) { if ($model->price) {
$return = Price::format($productModule->getPriceWithTax($model)) . ' (' . $productModule->strUnit($model->unit, 'wording_unit', true) . ')';
$return = Price::format($productModule->getPriceWithTax($model)) . ' (' . $productModule->getSolver()->strUnit($model, 'wording_unit', true) . ')';
} }


return $return; return $return;

+ 7
- 4
backend/views/product/update/prices/_form.php View File

<?php <?php


use common\logic\Config\Unit\Module\UnitModule;
use common\logic\Product\Product\Module\ProductModule;
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;


$unitModule = UnitModule::getInstance();
$userModule = $this->getUserModule(); $userModule = $this->getUserModule();
$userGroupModule = $this->getUserGroupModule(); $userGroupModule = $this->getUserGroupModule();
$pointSaleModule = $this->getPointSaleModule(); $pointSaleModule = $this->getPointSaleModule();
$productModule = $this->getProductModule();
$productModule = ProductModule::getInstance();


?> ?>


<?= $form->field($model, 'id_user')->dropDownList($userModule->populateUserDropdownList()); ?> <?= $form->field($model, 'id_user')->dropDownList($userModule->populateUserDropdownList()); ?>
<?= $form->field($model, 'id_user_group')->dropDownList($userGroupModule->populateUserGroupDropdownList()); ?> <?= $form->field($model, 'id_user_group')->dropDownList($userGroupModule->populateUserGroupDropdownList()); ?>
<?= $form->field($model, 'id_point_sale')->dropDownList($pointSaleModule->populatePointSaleDropdownList()); ?> <?= $form->field($model, 'id_point_sale')->dropDownList($pointSaleModule->populatePointSaleDropdownList()); ?>
<?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('. $productModule->strUnit($productModule->getRefUnit($modelProduct->unit), 'wording').')'); ?>
<?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('. $productModule->getSolver()->strUnit($modelProduct, 'wording', true).')'); ?>


<?php <?php
$producer = GlobalParam::getCurrentProducer(); $producer = GlobalParam::getCurrentProducer();
</div> </div>
</div> </div>
<div class="col-xs-4"> <div class="col-xs-4">
<label for="product-price" class="control-label without-tax">Prix ('. $productModule->strUnit($productModule->getRefUnit($modelProduct->unit), 'wording_unit').') HT</label>
<label for="product-price" class="control-label without-tax">Prix ('. $productModule->getSolver()->strUnit($modelProduct, 'wording_unit', true).') HT</label>
<div class="input-group"> <div class="input-group">
{input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> {input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
</div> </div>
</div> </div>
<div class="col-xs-4"> <div class="col-xs-4">
<label for="productprice-price-with-tax" class="control-label with-tax">Prix ('. $productModule->strUnit($productModule->getRefUnit($modelProduct->unit), 'wording_unit').') TTC</label>
<label for="productprice-price-with-tax" class="control-label with-tax">Prix ('. $productModule->getSolver()->strUnit($modelProduct, 'wording_unit', true).') TTC</label>
<div class="input-group"> <div class="input-group">
<input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'"> <input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'">
<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>

+ 1
- 1
backend/views/product/update/prices/list.php View File

'attribute' => 'from_quantity', 'attribute' => 'from_quantity',
'value' => function ($productPrice) use ($productModule) { 'value' => function ($productPrice) use ($productModule) {
if ($productPrice->from_quantity) { if ($productPrice->from_quantity) {
return $productPrice->from_quantity . ' ' . $productModule->strUnit($productModule->getRefUnit($productPrice->product->unit), 'wording');
return $productPrice->from_quantity . ' ' . $productModule->getSolver()->strUnit($productPrice->product, 'wording', true);
} }


return ''; return '';

+ 1
- 1
backend/views/subscription/index.php View File

foreach($model->productSubscription as $productSubscription) foreach($model->productSubscription as $productSubscription)
{ {
if(isset($productSubscription->product)) { if(isset($productSubscription->product)) {
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).'&nbsp;'. $productModule->strUnit($productSubscription->product->unit, 'wording_short').')<br />' ;
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).'&nbsp;'. $productModule->getSolver()->strUnit($productSubscription->product, 'wording_short').')<br />' ;
} }
else { else {
$html .= 'Produit non défini<br />' ; $html .= 'Produit non défini<br />' ;

+ 1
- 0
common/components/BusinessLogic.php View File

public function getModules() public function getModules()
{ {
return [ return [
$this->getUnitModule(),
$this->getTaxRateModule(), $this->getTaxRateModule(),
$this->getUserUserGroupModule(), $this->getUserUserGroupModule(),
$this->getUserGroupModule(), $this->getUserGroupModule(),

+ 6
- 0
common/components/BusinessLogicTrait.php View File

namespace common\components; namespace common\components;


use common\logic\Config\TaxRate\Module\TaxRateModule; use common\logic\Config\TaxRate\Module\TaxRateModule;
use common\logic\Config\Unit\Module\UnitModule;
use common\logic\Distribution\Distribution\Module\DistributionModule; use common\logic\Distribution\Distribution\Module\DistributionModule;
use common\logic\Distribution\PointSaleDistribution\Module\PointSaleDistributionModule; use common\logic\Distribution\PointSaleDistribution\Module\PointSaleDistributionModule;
use common\logic\Distribution\ProductDistribution\Module\ProductDistributionModule; use common\logic\Distribution\ProductDistribution\Module\ProductDistributionModule;


trait BusinessLogicTrait trait BusinessLogicTrait
{ {
public function getUnitModule(): UnitModule
{
return UnitModule::getInstance();
}

public function getOpinionModule(): OpinionModule public function getOpinionModule(): OpinionModule
{ {
return OpinionModule::getInstance(); return OpinionModule::getInstance();

+ 3
- 1
common/forms/SubscriptionForm.php View File

namespace common\forms; namespace common\forms;


use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Module\ProductModule;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription; use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription; use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\Subscription\Subscription\Module\SubscriptionModule; use common\logic\Subscription\Subscription\Module\SubscriptionModule;
*/ */
public function save() public function save()
{ {
$productModule = ProductModule::getInstance();
$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$subscriptionModule = SubscriptionModule::getInstance(); $subscriptionModule = SubscriptionModule::getInstance();


$newProductSubscription = new ProductSubscription; $newProductSubscription = new ProductSubscription;
$newProductSubscription->id_subscription = $subscription->id; $newProductSubscription->id_subscription = $subscription->id;
$newProductSubscription->id_product = $idProduct; $newProductSubscription->id_product = $idProduct;
$newProductSubscription->quantity = $quantity / Product::$unitsArray[$product->unit]['coefficient'];
$newProductSubscription->quantity = $quantity / $productModule->getSolver()->getUnitCoefficient($product->unit);


$newProductSubscription->save(); $newProductSubscription->save();
} }

+ 1
- 1
common/helpers/CSV.php View File

header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
} }


public static function formatPrice($price): string
public static function formatNumber($price): string
{ {
return str_replace('.', ',', $price); return str_replace('.', ',', $price);
} }

+ 32
- 0
common/logic/Config/Unit/Module/UnitModule.php View File

<?php

namespace common\logic\Config\Unit\Module;

use common\logic\AbstractModule;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Config\Unit\Service\UnitSolver;

/**
* @mixin UnitDefinition
* @mixin UnitSolver
*/
class UnitModule extends AbstractModule
{
public function getServices(): array
{
return [
UnitDefinition::class,
UnitSolver::class
];
}

public function getDefinition(): UnitDefinition
{
return UnitDefinition::getInstance();
}

public function getSolver(): UnitSolver
{
return UnitSolver::getInstance();
}
}

+ 66
- 0
common/logic/Config/Unit/Service/UnitDefinition.php View File

<?php

namespace common\logic\Config\Unit\Service;

use common\logic\AbstractDefinition;

class UnitDefinition extends AbstractDefinition
{
const UNIT_PIECE = 'PIECE';
const UNIT_G = 'g';
const UNIT_KG = 'kg';
const UNIT_ML = 'mL';
const UNIT_L = 'L';

const WORDING_UNIT = 'wording_unit';
const WORDING = 'wording';
const WORDING_SHORT = 'wording_short';

public function getUnits(): array
{
return [
'piece' => [
'unit' => 'piece',
'wording_unit' => 'la pièce',
'wording' => 'pièce(s)',
'wording_short' => 'p.',
'coefficient' => 1
],
'g' => [
'ref_unit' => 'kg',
'unit' => 'g',
'wording_unit' => 'le g',
'wording' => 'g',
'wording_short' => 'g',
'coefficient' => 1000
],
'kg' => [
'unit' => 'kg',
'wording_unit' => 'le kg',
'wording' => 'kg',
'wording_short' => 'kg',
'coefficient' => 1
],
'mL' => [
'ref_unit' => 'L',
'unit' => 'mL',
'wording_unit' => 'le mL',
'wording' => 'mL',
'wording_short' => 'mL',
'coefficient' => 1000
],
'L' => [
'unit' => 'L',
'wording_unit' => 'le litre',
'wording' => 'L',
'wording_short' => 'L',
'coefficient' => 1
],
];
}

public function getEntityFqcn(): string
{
return '';
}
}

+ 65
- 0
common/logic/Config/Unit/Service/UnitSolver.php View File

<?php

namespace common\logic\Config\Unit\Service;

use common\logic\AbstractSolver;

class UnitSolver extends AbstractSolver
{
protected UnitDefinition $unitDefinition;

public function loadDependencies(): void
{
$this->unitDefinition = $this->loadService(UnitDefinition::class);
}

public function getUnit(string $idUnit): ?array
{
$unitsArray = $this->unitDefinition->getUnits();
if(isset($unitsArray[$idUnit])) {
return $unitsArray[$idUnit];
}

return null;
}

// getRefUnit
public function getUnitReference(string $idUnit): string
{
$unit = $this->getUnit($idUnit);

if ($unit && isset($unit['ref_unit'])) {
return $unit['ref_unit'];
}

return $idUnit;
}

public function getUnitCoefficient(string $idUnit): int
{
$unit = $this->getUnit($idUnit);

if($unit) {
return $unit['coefficient'];
}

return 1;
}

/**
* Retourne le libellé d'une unité.
*/
public function strUnit(string $idUnit, $format = UnitDefinition::WORDING_SHORT, bool $unitReference = false): string
{
if ($unitReference) {
$idUnit = $this->getUnitReference($idUnit);
}

$unit = $this->getUnit($idUnit);
if ($unit && isset($unit[$format])) {
return $unit[$format];
}

return '';
}
}

+ 3
- 3
common/logic/Distribution/Distribution/Service/DistributionReport2CsvGenerator.php View File

$datas[] = [ $datas[] = [
$pointSale ? $pointSale->name : '', $pointSale ? $pointSale->name : '',
$this->orderSolver->getOrderUsername($order), $this->orderSolver->getOrderUsername($order),
$this->productOrderSolver->getQuantityPriorityPieces($firstProductOrder),
CSV::formatNumber($this->productOrderSolver->getQuantityPriorityPieces($firstProductOrder)),
$this->productSolver->getNameExport($firstProductOrder->product), $this->productSolver->getNameExport($firstProductOrder->product),
$this->productSolver->getWeightAsString($firstProductOrder->product), $this->productSolver->getWeightAsString($firstProductOrder->product),
$this->orderSolver->hasPhone($order) ? CSV::formatPhone($this->orderSolver->getPhone($order)) : '', $this->orderSolver->hasPhone($order) ? CSV::formatPhone($this->orderSolver->getPhone($order)) : '',
$this->orderRepository->getPaymentLabelPaid($order), $this->orderRepository->getPaymentLabelPaid($order),
CSV::formatPrice($this->orderSolver->getOrderAmountWithTax($order))
CSV::formatNumber($this->orderSolver->getOrderAmountWithTax($order))
]; ];


foreach($order->productOrder as $key => $productOrder) { foreach($order->productOrder as $key => $productOrder) {
$datas[] = [ $datas[] = [
'', '',
'', '',
$this->productOrderSolver->getQuantityPriorityPieces($productOrder),
CSV::formatNumber($this->productOrderSolver->getQuantityPriorityPieces($productOrder)),
$this->productSolver->getNameExport($productOrder->product), $this->productSolver->getNameExport($productOrder->product),
$this->productSolver->getWeightAsString($productOrder->product), $this->productSolver->getWeightAsString($productOrder->product),
]; ];

+ 2
- 2
common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php View File

} }
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; $orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity;
if ($productOrder->product->unit != $productOrder->unit) { if ($productOrder->product->unit != $productOrder->unit) {
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productModule->strUnit(
$productOrder->unit,
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $this->productSolver->strUnit(
$productOrder->product,
'wording_short', 'wording_short',
true true
); );

+ 4
- 1
common/logic/Distribution/Distribution/Service/DistributionReportPdfGenerator.php View File



use common\helpers\Price; use common\helpers\Price;
use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\Config\Unit\Service\UnitSolver;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository; use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository;
use common\logic\Document\Document\Service\DocumentSolver; use common\logic\Document\Document\Service\DocumentSolver;
{ {
const LIMIT_PRODUCTS = 120; const LIMIT_PRODUCTS = 120;


protected UnitSolver $unitSolver;
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;
protected OrderBuilder $orderBuilder; protected OrderBuilder $orderBuilder;
protected ProductRepository $productRepository; protected ProductRepository $productRepository;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->unitSolver = $this->loadService(UnitSolver::class);
$this->orderRepository = $this->loadService(OrderRepository::class); $this->orderRepository = $this->loadService(OrderRepository::class);
$this->orderBuilder = $this->loadService(OrderBuilder::class); $this->orderBuilder = $this->loadService(OrderBuilder::class);
$this->productRepository = $this->loadService(ProductRepository::class); $this->productRepository = $this->loadService(ProductRepository::class);


public function displayOrderProduct(string $quantity, string $unit, Product $product) public function displayOrderProduct(string $quantity, string $unit, Product $product)
{ {
$theUnit = ( $this->productSolver->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $this->productSolver->strUnit($unit, 'wording_short', true) ;
$theUnit = ( $this->unitSolver->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $this->unitSolver->strUnit($unit, 'wording_short', true) ;
return '<strong>'.$quantity. $theUnit.'</strong> '.$this->productSolver->getNameExport($product). '<br />'; return '<strong>'.$quantity. $theUnit.'</strong> '.$this->productSolver->getNameExport($product). '<br />';
} }
} }

+ 1
- 1
common/logic/Order/Order/Repository/OrderRepository.php View File

foreach ($order->productOrder as $p) { foreach ($order->productOrder as $p) {
if (isset($p->product)) { if (isset($p->product)) {
$html .= Html::encode($p->product->name) . ' (' . $p->quantity . '&nbsp;' . $this->productSolver->strUnit( $html .= Html::encode($p->product->name) . ' (' . $p->quantity . '&nbsp;' . $this->productSolver->strUnit(
$p->unit,
$p->product,
'wording_short', 'wording_short',
true true
) . ')'; ) . ')';

+ 5
- 8
common/logic/Order/ProductOrder/Service/ProductOrderSolver.php View File



use common\helpers\Price; use common\helpers\Price;
use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Config\Unit\Service\UnitSolver;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder; use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;
use common\logic\SolverInterface; use common\logic\SolverInterface;


class ProductOrderSolver extends AbstractService implements SolverInterface class ProductOrderSolver extends AbstractService implements SolverInterface
{ {
protected UnitSolver $unitSolver;
protected ProductSolver $productSolver; protected ProductSolver $productSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->unitSolver = $this->loadService(UnitSolver::class);
$this->productSolver = $this->loadService(ProductSolver::class); $this->productSolver = $this->loadService(ProductSolver::class);
} }




public function getQuantityWithUnit(ProductOrder $productOrder): string public function getQuantityWithUnit(ProductOrder $productOrder): string
{ {
return $productOrder->quantity.' '.$this->productSolver->strUnit($productOrder->unit);
return $productOrder->quantity.' '.$this->productSolver->strUnit($productOrder->product);
} }


public function getQuantityPiecesStrict(ProductOrder $productOrder): float public function getQuantityPiecesStrict(ProductOrder $productOrder): float
} }
else { else {
if ($productOrder->product && $productOrder->product->weight > 0) { if ($productOrder->product && $productOrder->product->weight > 0) {
return $this->getQuantityCoefficientBase($productOrder) / $productOrder->product->weight;
return $productOrder->quantity / $this->productSolver->getWeightUnitReference($productOrder->product);
} }
} }


return 0; return 0;
} }


public function getQuantityCoefficientBase(ProductOrder $productOrder): float
{
return $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'];
}

public function getPriceWithTax(ProductOrder $productOrder) public function getPriceWithTax(ProductOrder $productOrder)
{ {
return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value); return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value);

+ 1
- 1
common/logic/Product/Product/Model/Product.php View File

parent::afterFind(); parent::afterFind();


$productSolver = ProductSolver::getInstance(); $productSolver = ProductSolver::getInstance();
$this->wording_unit = $productSolver->strUnit($this->unit);
$this->wording_unit = $productSolver->strUnit($this);
$this->price_with_tax = $productSolver->getPriceWithTax($this); $this->price_with_tax = $productSolver->getPriceWithTax($this);
} }



+ 28
- 32
common/logic/Product/Product/Service/ProductSolver.php View File

use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Price; use common\helpers\Price;
use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Config\Unit\Service\UnitSolver;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Service\PointSaleSolver; use common\logic\PointSale\PointSale\Service\PointSaleSolver;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;


class ProductSolver extends AbstractService implements SolverInterface class ProductSolver extends AbstractService implements SolverInterface
{ {
protected UnitSolver $unitSolver;
protected ProductPriceSolver $productPriceSolver; protected ProductPriceSolver $productPriceSolver;
protected PointSaleSolver $pointSaleSolver; protected PointSaleSolver $pointSaleSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->unitSolver = $this->loadService(UnitSolver::class);
$this->productPriceSolver = $this->loadService(ProductPriceSolver::class); $this->productPriceSolver = $this->loadService(ProductPriceSolver::class);
$this->pointSaleSolver = $this->loadService(PointSaleSolver::class); $this->pointSaleSolver = $this->loadService(PointSaleSolver::class);
} }


public function getUnitCoefficient(Product $product): int
{
return $this->unitSolver->getUnitCoefficient($product->unit);
}

public function getUnitReference(Product $product): string
{
return $this->unitSolver->getUnitReference($product->unit);
}

public function strUnit(Product $product, string $format = UnitDefinition::WORDING_SHORT, bool $unitReference = false): string
{
return $this->unitSolver->strUnit($product->unit, $format, $unitReference);
}

public function getWeightUnitReference(Product $product): float
{
if($product->weight) {
return $product->weight / 1000;
}

return 0;
}

public function getWeightAsString(Product $product): string public function getWeightAsString(Product $product): string
{ {
if ($product->weight) { if ($product->weight) {
return $product->name; return $product->name;
} }


public function getRefUnit(string $unit): string
{
if (isset(Product::$unitsArray[$unit]) && isset(Product::$unitsArray[$unit]['ref_unit'])) {
return Product::$unitsArray[$unit]['ref_unit'];
}

return $unit;
}

/**
* Retourne le libellé d'une unité.
*/
public function strUnit(string $unit, $format = 'wording_short', $unitInDb = false): string
{
$strUnit = '';

if ($unitInDb) {
if ($unit == 'g') {
$unit = 'kg';
}
if ($unit == 'mL') {
$unit = 'L';
}
}

if (isset(Product::$unitsArray[$unit]) && isset(Product::$unitsArray[$unit][$format])) {
$strUnit = Product::$unitsArray[$unit][$format];
}

return $strUnit;
}

public function hasPriceWithQuantityZero(array $priceArray): bool public function hasPriceWithQuantityZero(array $priceArray): bool
{ {
foreach ($priceArray as $price) { foreach ($priceArray as $price) {

+ 1
- 1
common/logic/Subscription/Subscription/Service/SubscriptionSolver.php View File

foreach($subscription->productSubscription as $productSubscription) foreach($subscription->productSubscription as $productSubscription)
{ {
if(isset($productSubscription->product) && $productSubscription->product) { if(isset($productSubscription->product) && $productSubscription->product) {
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . '&nbsp'. $this->productSolver->strUnit($productSubscription->product->unit, 'wording_short').')<br />' ;
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . '&nbsp'. $this->productSolver->strUnit($productSubscription->product, 'wording_short').')<br />' ;
} }
else { else {
$html .= 'Produit non défini<br />' ; $html .= 'Produit non défini<br />' ;

+ 1
- 1
common/logic/User/User/Service/UsersCreditCsvGenerator.php View File

$this->userSolver->getUsernameFromArray($user, true), $this->userSolver->getUsernameFromArray($user, true),
$user['email'], $user['email'],
$user['phone'], $user['phone'],
CSV::formatPrice($user['credit']),
CSV::formatNumber($user['credit']),
]; ];
} }



+ 9
- 7
producer/controllers/OrderController.php View File

use common\helpers\Mailjet; use common\helpers\Mailjet;
use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\helpers\Password; use common\helpers\Password;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder; use common\logic\Order\ProductOrder\Model\ProductOrder;
'price_data' => [ 'price_data' => [
'currency' => 'eur', 'currency' => 'eur',
'product_data' => [ 'product_data' => [
'name' => $product->name . ' (' . $productOrder->quantity . ' ' . $this->getProductModule()->strUnit(
$product->unit,
'wording_short',
'name' => $product->name . ' (' . $productOrder->quantity . ' ' . $this->getProductModule()->getSolver()->strUnit(
$product,
UnitDefinition::WORDING_SHORT,
true true
) . ')', ) . ')',
], ],
Order $order = null Order $order = null
) )
{ {
$unitModule = $this->getUnitModule();
$productModule = $this->getProductModule(); $productModule = $this->getProductModule();
$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$ordersArray = $this->getOrderModule()->findOrdersByDistribution($distribution); $ordersArray = $this->getOrderModule()->findOrdersByDistribution($distribution);
$quantityOrder = $orderModule->getProductQuantity($productObject, $ordersArray); $quantityOrder = $orderModule->getProductQuantity($productObject, $ordersArray);
$product['quantity_ordered'] = $quantityOrder; $product['quantity_ordered'] = $quantityOrder;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder; $product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder;
$product['wording_unit'] = $productModule->strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit_ref'] = $productModule->strUnit($product['unit'], 'wording_short', true);
$product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], UnitDefinition::WORDING_UNIT, true);
$product['wording_unit_ref'] = $unitModule->getSolver()->strUnit($product['unit'], UnitDefinition::WORDING_SHORT, true);


if ($order) { if ($order) {
$quantityOrderUser = $orderModule->getProductQuantity($productObject, [$order], true); $quantityOrderUser = $orderModule->getProductQuantity($productObject, [$order], true);
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; $product['quantity_form'] = $quantityOrderUser * $coefficient_unit;
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
if ($productOrder->id_product == $product['id']) { if ($productOrder->id_product == $product['id']) {
$product['wording_unit'] = $productModule->strUnit($productOrder->unit, 'wording_unit', true);
$product['wording_unit'] = $productModule->getSolver()->strUnit($productOrder->product, 'wording_unit', true);
$product['step'] = $productOrder->step; $product['step'] = $productOrder->step;
} }
} }
} else { } else {
$product['quantity_form'] = 0; $product['quantity_form'] = 0;
$product['wording_unit'] = $productModule->strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit'] = $unitModule->getSolver()->strUnit($product['unit'], 'wording_unit', true);
} }
$product['coefficient_unit'] = $coefficient_unit; $product['coefficient_unit'] = $coefficient_unit;



+ 5
- 4
producer/controllers/SubscriptionController.php View File



use common\forms\SubscriptionForm; use common\forms\SubscriptionForm;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription; use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription; use common\logic\Subscription\Subscription\Model\Subscription;
$indexProduct = 0; $indexProduct = 0;
foreach ($productsArray as &$product) { foreach ($productsArray as &$product) {
$quantity = 0; $quantity = 0;
$coefficientUnit = Product::$unitsArray[$product->unit]['coefficient'];
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($product->unit);
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 = Product::$unitsArray[$productSubscription->product->unit]['coefficient'];
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($productSubscription->product->unit);
$quantity = $productSubscription->quantity * $coefficientUnit; $quantity = $productSubscription->quantity * $coefficientUnit;
} }
} }
'index' => $indexProduct++, 'index' => $indexProduct++,
'quantity_form' => $quantity, 'quantity_form' => $quantity,
'coefficient_unit' => $coefficientUnit, 'coefficient_unit' => $coefficientUnit,
'wording_unit' => $productModule->strUnit($product->unit, 'wording_unit', true),
'wording_short' => $productModule->strUnit($product->unit, 'wording_short'),
'wording_unit' => $productModule->getSolver()->strUnit($product, UnitDefinition::WORDING_UNIT, true),
'wording_short' => $productModule->getSolver()->strUnit($product),
'price_with_tax' => $productModule->getPriceWithTax($product, [ 'price_with_tax' => $productModule->getPriceWithTax($product, [
'user' => $user, 'user' => $user,
'user_producer' => $userProducer, 'user_producer' => $userProducer,

+ 1
- 1
producer/views/site/index.php View File

'attribute' => 'price', 'attribute' => 'price',
'value' => function ($model) use ($productModule) { 'value' => function ($model) use ($productModule) {
if ($model->price) { if ($model->price) {
return Price::format($productModule->getPriceWithTax($model)) . ' (' . $productModule->strUnit($model->unit, 'wording_unit', true) . ')';
return Price::format($productModule->getPriceWithTax($model)) . ' (' . $productModule->getSolver()->strUnit($model, 'wording_unit', true) . ')';
} }
return ''; return '';
} }

Loading…
Cancel
Save