소스 검색

[Technique] Refactoring UnitModule

feature/souke
Guillaume Bourgeois 1 년 전
부모
커밋
6a73619cfa
31개의 변경된 파일265개의 추가작업 그리고 83개의 파일을 삭제
  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 파일 보기

@@ -301,9 +301,11 @@ class DistributionController extends BackendController

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

if ($ordersArray) {
foreach ($ordersArray as &$order) {
@@ -313,7 +315,7 @@ class DistributionController extends BackendController
$productOrderArray = [];
foreach ($order->productOrder as $productOrder) {
$productOrderArray[$productOrder->id_product] = [
'quantity' => $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'],
'quantity' => $productOrderModule->getSolver()->getQuantityToCoefficientOfUnit($productOrder),
'unit' => $productOrder->unit,
'price' => number_format($productOrder->price, 5),
'invoice_price' => number_format($productOrder->invoice_price, 5),

+ 1
- 1
backend/controllers/DocumentController.php 파일 보기

@@ -618,7 +618,7 @@ class DocumentController extends BackendController
'order',
function ($product) use ($document, $userProducer, $pointSale, $productModule) {
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),
'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value

+ 2
- 2
backend/controllers/ProductController.php 파일 보기

@@ -504,7 +504,7 @@ class ProductController extends BackendController
'',
'',
'',
CSV::formatPrice($product->price)
CSV::formatNumber($product->price)
];

// prix spécifiques
@@ -518,7 +518,7 @@ class ProductController extends BackendController
$productPrice->userGroup ? $productPrice->userGroup->name : '',
$productPrice->pointSale ? $productPrice->pointSale->name : '',
$productPrice->from_quantity ?? '',
CSV::formatPrice($productPrice->price)
CSV::formatNumber($productPrice->price)
];
}
}

+ 3
- 1
backend/controllers/SubscriptionController.php 파일 보기

@@ -39,6 +39,7 @@ namespace backend\controllers;

use common\forms\SubscriptionForm;
use common\helpers\GlobalParam;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Product\Product\Model\Product;
use common\logic\Subscription\Subscription\Model\SubscriptionSearch;
use yii\filters\AccessControl;
@@ -280,6 +281,7 @@ class SubscriptionController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

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

$productsQuery = Product::find()
@@ -296,7 +298,7 @@ class SubscriptionController extends BackendController
$productsArray = $productsQuery->asArray()->orderBy('order ASC')->all();

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])) {
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient'];

+ 2
- 1
backend/models/MailForm.php 파일 보기

@@ -40,6 +40,7 @@ namespace backend\models;

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

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

+ 7
- 4
backend/views/distribution/report-bourlingue.php 파일 보기

@@ -37,11 +37,14 @@ termes.
*/

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\Product\Product\Model\Product;
use common\logic\Product\Product\Module\ProductModule;
use common\logic\User\UserProducer\Model\UserProducer;

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

@@ -108,7 +111,7 @@ foreach ($pointsSaleArray as $pointSale) {
$add = false;
foreach ($order->productOrder as $productOrder) {
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 />';
$add = true;
}
@@ -188,7 +191,7 @@ foreach ($pointsSaleArray as $pointSale) {
foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderModule->getProductQuantity($product, $pointSale->orders, false, $unit);
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 />';
}
}
@@ -237,7 +240,7 @@ foreach ($pointsSaleArray as $pointSale)
foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderModule->getProductQuantity($product, $pointSale->orders, false, $unit);
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 />';
}
}
@@ -264,7 +267,7 @@ foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderModule->getProductQuantity($product, $ordersArray, false, $unit);
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 />';
}
}

+ 1
- 1
backend/views/distribution/report-grid.php 파일 보기

@@ -101,7 +101,7 @@ function line_product($product, $orders)
$quantity = '';
foreach ($order->productOrder as $productOrder) {
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;
if ($productOrder->quantity > 1) {

+ 1
- 1
backend/views/document/_download_product_line.php 파일 보기

@@ -37,7 +37,7 @@ $productModule = $this->getProductModule();
<td class="align-center">
<?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?>
</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($producer->taxRate->value != 0): ?>
<td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td>

+ 1
- 1
backend/views/product/index.php 파일 보기

@@ -128,7 +128,7 @@ $this->addButton(['label' => 'Nouveau produit <span class="glyphicon glyphicon-p
'value' => function ($model) use ($productModule) {
$return = '';
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;

+ 7
- 4
backend/views/product/update/prices/_form.php 파일 보기

@@ -1,13 +1,16 @@
<?php

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

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

?>

@@ -27,7 +30,7 @@ $productModule = $this->getProductModule();
<?= $form->field($model, 'id_user')->dropDownList($userModule->populateUserDropdownList()); ?>
<?= $form->field($model, 'id_user_group')->dropDownList($userGroupModule->populateUserGroupDropdownList()); ?>
<?= $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
$producer = GlobalParam::getCurrentProducer();
@@ -48,13 +51,13 @@ $productModule = $this->getProductModule();
</div>
</div>
<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">
{input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
</div>
</div>
<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">
<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>

+ 1
- 1
backend/views/product/update/prices/list.php 파일 보기

@@ -112,7 +112,7 @@ $this->render('../_nav', [
'attribute' => 'from_quantity',
'value' => function ($productPrice) use ($productModule) {
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 '';

+ 1
- 1
backend/views/subscription/index.php 파일 보기

@@ -90,7 +90,7 @@ $subscriptionsArray = Subscription::searchAll() ;
foreach($model->productSubscription as $productSubscription)
{
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 {
$html .= 'Produit non défini<br />' ;

+ 1
- 0
common/components/BusinessLogic.php 파일 보기

@@ -12,6 +12,7 @@ class BusinessLogic
public function getModules()
{
return [
$this->getUnitModule(),
$this->getTaxRateModule(),
$this->getUserUserGroupModule(),
$this->getUserGroupModule(),

+ 6
- 0
common/components/BusinessLogicTrait.php 파일 보기

@@ -3,6 +3,7 @@
namespace common\components;

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\PointSaleDistribution\Module\PointSaleDistributionModule;
use common\logic\Distribution\ProductDistribution\Module\ProductDistributionModule;
@@ -34,6 +35,11 @@ use common\logic\User\UserUserGroup\Module\UserUserGroupModule;

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

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

+ 3
- 1
common/forms/SubscriptionForm.php 파일 보기

@@ -39,6 +39,7 @@ termes.
namespace common\forms;

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\Subscription\Model\Subscription;
use common\logic\Subscription\Subscription\Module\SubscriptionModule;
@@ -117,6 +118,7 @@ class SubscriptionForm extends Model
*/
public function save()
{
$productModule = ProductModule::getInstance();
$userModule = UserModule::getInstance();
$subscriptionModule = SubscriptionModule::getInstance();

@@ -175,7 +177,7 @@ class SubscriptionForm extends Model
$newProductSubscription = new ProductSubscription;
$newProductSubscription->id_subscription = $subscription->id;
$newProductSubscription->id_product = $idProduct;
$newProductSubscription->quantity = $quantity / Product::$unitsArray[$product->unit]['coefficient'];
$newProductSubscription->quantity = $quantity / $productModule->getSolver()->getUnitCoefficient($product->unit);

$newProductSubscription->save();
}

+ 1
- 1
common/helpers/CSV.php 파일 보기

@@ -110,7 +110,7 @@ class CSV
header("Content-Transfer-Encoding: binary");
}

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

+ 32
- 0
common/logic/Config/Unit/Module/UnitModule.php 파일 보기

@@ -0,0 +1,32 @@
<?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 파일 보기

@@ -0,0 +1,66 @@
<?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 파일 보기

@@ -0,0 +1,65 @@
<?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 파일 보기

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

foreach($order->productOrder as $key => $productOrder) {
@@ -85,7 +85,7 @@ class DistributionReport2CsvGenerator extends AbstractGenerator
$datas[] = [
'',
'',
$this->productOrderSolver->getQuantityPriorityPieces($productOrder),
CSV::formatNumber($this->productOrderSolver->getQuantityPriorityPieces($productOrder)),
$this->productSolver->getNameExport($productOrder->product),
$this->productSolver->getWeightAsString($productOrder->product),
];

+ 2
- 2
common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php 파일 보기

@@ -106,8 +106,8 @@ class DistributionReportCsvGenerator extends AbstractGenerator
}
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity;
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',
true
);

+ 4
- 1
common/logic/Distribution/Distribution/Service/DistributionReportPdfGenerator.php 파일 보기

@@ -4,6 +4,7 @@ namespace common\logic\Distribution\Distribution\Service;

use common\helpers\Price;
use common\logic\AbstractGenerator;
use common\logic\Config\Unit\Service\UnitSolver;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository;
use common\logic\Document\Document\Service\DocumentSolver;
@@ -24,6 +25,7 @@ class DistributionReportPdfGenerator extends AbstractGenerator
{
const LIMIT_PRODUCTS = 120;

protected UnitSolver $unitSolver;
protected OrderRepository $orderRepository;
protected OrderBuilder $orderBuilder;
protected ProductRepository $productRepository;
@@ -36,6 +38,7 @@ class DistributionReportPdfGenerator extends AbstractGenerator

public function loadDependencies(): void
{
$this->unitSolver = $this->loadService(UnitSolver::class);
$this->orderRepository = $this->loadService(OrderRepository::class);
$this->orderBuilder = $this->loadService(OrderBuilder::class);
$this->productRepository = $this->loadService(ProductRepository::class);
@@ -380,7 +383,7 @@ class DistributionReportPdfGenerator extends AbstractGenerator

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 />';
}
}

+ 1
- 1
common/logic/Order/Order/Repository/OrderRepository.php 파일 보기

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

+ 5
- 8
common/logic/Order/ProductOrder/Service/ProductOrderSolver.php 파일 보기

@@ -4,18 +4,20 @@ namespace common\logic\Order\ProductOrder\Service;

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

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

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

@@ -32,7 +34,7 @@ class ProductOrderSolver extends AbstractService implements SolverInterface

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
@@ -42,18 +44,13 @@ class ProductOrderSolver extends AbstractService implements SolverInterface
}
else {
if ($productOrder->product && $productOrder->product->weight > 0) {
return $this->getQuantityCoefficientBase($productOrder) / $productOrder->product->weight;
return $productOrder->quantity / $this->productSolver->getWeightUnitReference($productOrder->product);
}
}

return 0;
}

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

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

+ 1
- 1
common/logic/Product/Product/Model/Product.php 파일 보기

@@ -198,7 +198,7 @@ class Product extends ActiveRecordCommon implements StatusInterface
parent::afterFind();

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


+ 28
- 32
common/logic/Product/Product/Service/ProductSolver.php 파일 보기

@@ -5,6 +5,8 @@ namespace common\logic\Product\Product\Service;
use common\helpers\GlobalParam;
use common\helpers\Price;
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\Service\PointSaleSolver;
use common\logic\Product\Product\Model\Product;
@@ -13,15 +15,41 @@ use common\logic\SolverInterface;

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

public function loadDependencies(): void
{
$this->unitSolver = $this->loadService(UnitSolver::class);
$this->productPriceSolver = $this->loadService(ProductPriceSolver::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
{
if ($product->weight) {
@@ -131,38 +159,6 @@ class ProductSolver extends AbstractService implements SolverInterface
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
{
foreach ($priceArray as $price) {

+ 1
- 1
common/logic/Subscription/Subscription/Service/SubscriptionSolver.php 파일 보기

@@ -81,7 +81,7 @@ class SubscriptionSolver extends AbstractService implements SolverInterface
foreach($subscription->productSubscription as $productSubscription)
{
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 {
$html .= 'Produit non défini<br />' ;

+ 1
- 1
common/logic/User/User/Service/UsersCreditCsvGenerator.php 파일 보기

@@ -41,7 +41,7 @@ class UsersCreditCsvGenerator extends AbstractGenerator
$this->userSolver->getUsernameFromArray($user, true),
$user['email'],
$user['phone'],
CSV::formatPrice($user['credit']),
CSV::formatNumber($user['credit']),
];
}


+ 9
- 7
producer/controllers/OrderController.php 파일 보기

@@ -43,6 +43,7 @@ use common\helpers\Image;
use common\helpers\Mailjet;
use common\helpers\MeanPayment;
use common\helpers\Password;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder;
@@ -253,9 +254,9 @@ class OrderController extends ProducerBaseController
'price_data' => [
'currency' => 'eur',
'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
) . ')',
],
@@ -882,6 +883,7 @@ class OrderController extends ProducerBaseController
Order $order = null
)
{
$unitModule = $this->getUnitModule();
$productModule = $this->getProductModule();
$orderModule = $this->getOrderModule();
$ordersArray = $this->getOrderModule()->findOrdersByDistribution($distribution);
@@ -933,8 +935,8 @@ class OrderController extends ProducerBaseController
$quantityOrder = $orderModule->getProductQuantity($productObject, $ordersArray);
$product['quantity_ordered'] = $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) {
$quantityOrderUser = $orderModule->getProductQuantity($productObject, [$order], true);
@@ -943,13 +945,13 @@ class OrderController extends ProducerBaseController
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit;
foreach ($order->productOrder as $productOrder) {
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;
}
}
} else {
$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;


+ 5
- 4
producer/controllers/SubscriptionController.php 파일 보기

@@ -40,6 +40,7 @@ namespace producer\controllers;

use common\forms\SubscriptionForm;
use common\helpers\GlobalParam;
use common\logic\Config\Unit\Service\UnitDefinition;
use common\logic\Product\Product\Model\Product;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription;
@@ -264,11 +265,11 @@ class SubscriptionController extends ProducerBaseController
$indexProduct = 0;
foreach ($productsArray as &$product) {
$quantity = 0;
$coefficientUnit = Product::$unitsArray[$product->unit]['coefficient'];
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($product->unit);
if (isset($arrayProductsSubscription) && count($arrayProductsSubscription)) {
foreach ($arrayProductsSubscription as $productSubscription) {
if ($product->id == $productSubscription->id_product) {
$coefficientUnit = Product::$unitsArray[$productSubscription->product->unit]['coefficient'];
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($productSubscription->product->unit);
$quantity = $productSubscription->quantity * $coefficientUnit;
}
}
@@ -285,8 +286,8 @@ class SubscriptionController extends ProducerBaseController
'index' => $indexProduct++,
'quantity_form' => $quantity,
'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, [
'user' => $user,
'user_producer' => $userProducer,

+ 1
- 1
producer/views/site/index.php 파일 보기

@@ -197,7 +197,7 @@ $this->setPageTitle(Html::encode($producer->type . ' à ' . $producer->city));
'attribute' => 'price',
'value' => function ($model) use ($productModule) {
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 '';
}

Loading…
취소
저장