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), |
'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 |
'', | '', | ||||
'', | '', | ||||
'', | '', | ||||
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) | |||||
]; | ]; | ||||
} | } | ||||
} | } |
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']; |
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.' |
*/ | */ | ||||
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.') ? '' : ' '. $productModule->strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( $unitModule->getSolver()->strUnit($unit, UnitDefinition::WORDING_SHORT, true) == 'p.') ? '' : ' '. $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.') ? '' : ' '. $productModule->strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( $unitModule->getSolver()->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $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.') ? '' : ' '. $productModule->strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( $unitModule->getSolver()->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $unitModule->getSolver()->strUnit($unit, 'wording_short', true) ; | |||||
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | $html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | ||||
} | } | ||||
} | } |
$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.') ? '' : ' ' . $productModule->strUnit($productOrder->unit, 'wording_short', true); | |||||
$unit = ($productModule->getSolver()->strUnit($productOrder->product, 'wording_short', true) == 'p.') ? '' : ' ' . $productModule->getSolver()->strUnit($productOrder->product, 'wording_short', true); | |||||
$quantity .= $productOrder->quantity . $unit; | $quantity .= $productOrder->quantity . $unit; | ||||
if ($productOrder->quantity > 1) { | if ($productOrder->quantity > 1) { |
<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> |
'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; |
<?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> |
'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 ''; |
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']).' '. $productModule->strUnit($productSubscription->product->unit, 'wording_short').')<br />' ; | |||||
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).' '. $productModule->getSolver()->strUnit($productSubscription->product, 'wording_short').')<br />' ; | |||||
} | } | ||||
else { | else { | ||||
$html .= 'Produit non défini<br />' ; | $html .= 'Produit non défini<br />' ; |
public function getModules() | public function getModules() | ||||
{ | { | ||||
return [ | return [ | ||||
$this->getUnitModule(), | |||||
$this->getTaxRateModule(), | $this->getTaxRateModule(), | ||||
$this->getUserUserGroupModule(), | $this->getUserUserGroupModule(), | ||||
$this->getUserGroupModule(), | $this->getUserGroupModule(), |
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(); |
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(); | ||||
} | } |
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); | ||||
} | } |
<?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(); | |||||
} | |||||
} |
<?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 ''; | |||||
} | |||||
} |
<?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 ''; | |||||
} | |||||
} |
$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), | ||||
]; | ]; |
} | } | ||||
$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 | ||||
); | ); |
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.') ? '' : ' '. $this->productSolver->strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( $this->unitSolver->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $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 />'; | ||||
} | } | ||||
} | } |
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 . ' ' . $this->productSolver->strUnit( | $html .= Html::encode($p->product->name) . ' (' . $p->quantity . ' ' . $this->productSolver->strUnit( | ||||
$p->unit, | |||||
$p->product, | |||||
'wording_short', | 'wording_short', | ||||
true | true | ||||
) . ')'; | ) . ')'; |
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); |
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); | ||||
} | } | ||||
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) { |
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']) . ' '. $this->productSolver->strUnit($productSubscription->product->unit, 'wording_short').')<br />' ; | |||||
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . ' '. $this->productSolver->strUnit($productSubscription->product, 'wording_short').')<br />' ; | |||||
} | } | ||||
else { | else { | ||||
$html .= 'Produit non défini<br />' ; | $html .= 'Produit non défini<br />' ; |
$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']), | |||||
]; | ]; | ||||
} | } | ||||
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; | ||||
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, |
'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 ''; | ||||
} | } |