Browse Source

Refactoring services #885

refactoring
Guillaume Bourgeois 1 year ago
parent
commit
f7c4069400
14 changed files with 97 additions and 61 deletions
  1. +7
    -7
      backend/controllers/DistributionController.php
  2. +7
    -4
      backend/controllers/OrderController.php
  3. +3
    -3
      backend/views/distribution/report-bourlingue.php
  4. +8
    -8
      backend/views/distribution/report.php
  5. +3
    -3
      backend/views/order/report.php
  6. +2
    -0
      backend/views/site/index.php
  7. +7
    -5
      common/logic/Order/Order/Repository/OrderRepository.php
  8. +26
    -0
      common/logic/Order/Order/Service/OrderBuilder.php
  9. +0
    -23
      common/logic/PointSale/PointSale/Service/PointSaleBuilder.php
  10. +12
    -0
      common/logic/User/CreditHistory/Event/CreditHistoryCreateEvent.php
  11. +1
    -1
      common/logic/User/CreditHistory/Model/CreditHistory.php
  12. +7
    -1
      common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php
  13. +6
    -3
      common/logic/User/UserProducer/Service/UserProducerBuilder.php
  14. +8
    -3
      producer/controllers/OrderController.php

+ 7
- 7
backend/controllers/DistributionController.php View File

foreach ($order->creditHistory as $creditHistory) { foreach ($order->creditHistory as $creditHistory) {
$creditHistoryArray[] = [ $creditHistoryArray[] = [
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), 'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)),
'user' => $creditHistory->getUserObject()->getUsername(),
'user' => $userManager->getUsername($creditHistory->getUserObject()),
'user_action' => $creditHistoryManager->getStrUserAction($creditHistory), 'user_action' => $creditHistoryManager->getStrUserAction($creditHistory),
'wording' => $creditHistoryManager->getStrWording($creditHistory), 'wording' => $creditHistoryManager->getStrWording($creditHistory),
'debit' => ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . $creditHistoryManager->getAmount( 'debit' => ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . $creditHistoryManager->getAmount(
$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();
$orderManager = $this->getOrderManager(); $orderManager = $this->getOrderManager();
$productManager = $this->getProductManager(); $productManager = $this->getProductManager();
$pointSaleManager = $this->getPointSaleManager();


if (!\Yii::$app->user->isGuest) { if (!\Yii::$app->user->isGuest) {
$idProducer = GlobalParam::getCurrentProducerId(); $idProducer = GlobalParam::getCurrentProducerId();
]); ]);


foreach ($pointsSaleArray as $pointSale) { foreach ($pointsSaleArray as $pointSale) {
$pointSale->initOrders($ordersArray);
$orderManager->initPointSaleOrders($pointSale, $ordersArray);
} }


// produits // produits
{ {
$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();
$productDistribution = $this->getProductDistributionManager(); $productDistribution = $this->getProductDistributionManager();
$pointSaleManager = $this->getPointSaleManager();
$orderManager = $this->getOrderManager();
$productCategoryManager = $this->getProductCategoryManager(); $productCategoryManager = $this->getProductCategoryManager();


if (!\Yii::$app->user->isGuest) { if (!\Yii::$app->user->isGuest) {
]); ]);


foreach ($pointsSaleArray as $pointSale) { foreach ($pointsSaleArray as $pointSale) {
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray);
$orderManager->initPointSaleOrders($pointSale, $ordersArray);
} }


$ordersByPage = 22; $ordersByPage = 22;
public function actionReportTerredepains($date, $key) public function actionReportTerredepains($date, $key)
{ {
$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();
$productDistributionManager = $this->getProductDistributionManager();
$pointSaleManager = $this->getPointSaleManager();
$orderManager = $this->getOrderManager();
$productManager = $this->getProductManager(); $productManager = $this->getProductManager();


if ($key == 'ef572cc148c001f0180c4a624189ed30') { if ($key == 'ef572cc148c001f0180c4a624189ed30') {
]); ]);


foreach ($pointsSaleArray as $pointSale) { foreach ($pointsSaleArray as $pointSale) {
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray);
$orderManager->initPointSaleOrders($pointSale, $ordersArray);
} }


// produits // produits

+ 7
- 4
backend/controllers/OrderController.php View File

use common\forms\SubscriptionForm; use common\forms\SubscriptionForm;
use common\helpers\CSV; use common\helpers\CSV;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\MeanPayment;
use common\helpers\Price; use common\helpers\Price;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution; use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution;
$orders = $orderManager->findOrdersByDistribution($distribution); $orders = $orderManager->findOrdersByDistribution($distribution);


foreach ($pointsSale as $point) { foreach ($pointsSale as $point) {
$pointSaleManager->initPointSaleOrders($point, $orders);
$orderManager->initPointSaleOrders($point, $orders);


if (isset($_POST['submit_pv']) && $_POST['submit_pv']) { if (isset($_POST['submit_pv']) && $_POST['submit_pv']) {
// modifs // modifs


// init commandes point de vente // init commandes point de vente
foreach ($arrayPointsSale as $pointSale) { foreach ($arrayPointsSale as $pointSale) {
$pointSaleManager->initPointSaleOrders($pointSale, $arrayOrders);
$orderManager->initPointSaleOrders($pointSale, $arrayOrders);


$dataSelectOrders = []; $dataSelectOrders = [];
$dataOptionsOrders = []; $dataOptionsOrders = [];
} }
} }
} }
/** /**
* Retourne l'état du paiement (historique, crédit) d'une commande donnée. * Retourne l'état du paiement (historique, crédit) d'une commande donnée.
*/ */
$amount, $amount,
GlobalParam::getCurrentProducer(), GlobalParam::getCurrentProducer(),
$order->user, $order->user,
GlobalParam::getCurrentUser()
GlobalParam::getCurrentUser(),
MeanPayment::CREDIT,
$order
); );
} }



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

$cpt = 0 ; $cpt = 0 ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders, false, $unit);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; $theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ;
$strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />'; $strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />';
$cpt = 0 ; $cpt = 0 ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders, false, $unit);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ; $theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ;
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; $html .= $product->name . ' (' .$quantity .$theUnit.')<br />';
$cpt = 0 ; $cpt = 0 ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderManager->getProductQuantity($product->id, $ordersArray, false, $unit);
$quantity = $orderManager->getProductQuantity($product, $ordersArray, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ; $theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ;
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; $html .= $product->name . ' (' .$quantity .$theUnit.')<br />';

+ 8
- 8
backend/views/distribution/report.php View File

$strUser = ''; $strUser = '';


// username // username
$strUser .= $order->getStrUser() ;
$strUser .= $orderManager->getOrderUsername($order) ;
if(strlen($order->comment_point_sale)) if(strlen($order->comment_point_sale))
{ {
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
if($product->id == $productOrder->id_product) { if($product->id == $productOrder->id_product) {
$unit = ( $productManager->strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($productOrder->unit, 'wording_short', true) ; $unit = ( $productManager->strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($productOrder->unit, 'wording_short', true) ;
$strProducts .= '('.$productOrder->quantity .$unit.') '.$product->getNameExport() . '<br />';
$strProducts .= '('.$productOrder->quantity .$unit.') '.$productManager->getNameExport($product) . '<br />';
$add = true; $add = true;
} }
} }
if($isBig) { if($isBig) {
$html .= '<td></td>' ; $html .= '<td></td>' ;
} }
$html .= '<td>'.$order->getCommentReport().'</td>';
$html .= '<td>'.$orderManager->getCommentReport($order).'</td>';
if($pointSale->credit) { if($pointSale->credit) {
$credit = '' ; $credit = '' ;
$cpt = 0 ; $cpt = 0 ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders, false, $unit);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ; $theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ;
$strProducts .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />';
$strProducts .= '(' .$quantity .$theUnit.') '.$productManager->getNameExport($product) . '<br />';
} }
} }


$cpt = 0 ; $cpt = 0 ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders, false, $unit);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ; $theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ;
$html .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />';
$html .= '(' .$quantity .$theUnit.') '.$productManager->getNameExport($product) . '<br />';
} }
} }


$cpt = 0 ; $cpt = 0 ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
foreach( Product::$unitsArray as $unit => $dataUnit) { foreach( Product::$unitsArray as $unit => $dataUnit) {
$quantity = $orderManager->getProductQuantity($product->id, $ordersArray, false, $unit);
$quantity = $orderManager->getProductQuantity($product, $ordersArray, false, $unit);
if ($quantity) { if ($quantity) {
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ; $theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : '&nbsp;'. $productManager->strUnit($unit, 'wording_short', true) ;
$html .= '(' .$quantity .$theUnit.') '.$product->name . '<br />'; $html .= '(' .$quantity .$theUnit.') '.$product->name . '<br />';

+ 3
- 3
backend/views/order/report.php View File

$strProducts = ''; $strProducts = '';
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders);
$strQuantity = ''; $strQuantity = '';
if ($quantity) { if ($quantity) {
$strQuantity = $quantity; $strQuantity = $quantity;
{ {
$html .= '<tr><td>'.$pointSale->name.'</td><td>' ; $html .= '<tr><td>'.$pointSale->name.'</td><td>' ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders);
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders);
$strQuantity = ($quantity) ? $quantity : '' ; $strQuantity = ($quantity) ? $quantity : '' ;
if(strlen($strQuantity)) { if(strlen($strQuantity)) {
// total // total
$html .= '<tr><td><strong>Total</strong></td><td>' ; $html .= '<tr><td><strong>Total</strong></td><td>' ;
foreach ($productsArray as $product) { foreach ($productsArray as $product) {
$quantity = $orderManager->getProductQuantity($product->id, $ordersArray);
$quantity = $orderManager->getProductQuantity($product, $ordersArray);
if($quantity) { if($quantity) {
$html .= $quantity . '&nbsp;'.$product->name.', ' ; $html .= $quantity . '&nbsp;'.$product->name.', ' ;
} }

+ 2
- 0
backend/views/site/index.php View File

</thead> </thead>
<tbody> <tbody>
<?php foreach($ordersArray as $order): ?> <?php foreach($ordersArray as $order): ?>
<?php $orderManager->initOrder($order); ?>

<tr class="<?= $orderManager->getHistoryClass($order) ; ?>"> <tr class="<?= $orderManager->getHistoryClass($order) ; ?>">
<td class="infos"><?= $orderManager->getLabelOrigin($order, true); ?></td> <td class="infos"><?= $orderManager->getLabelOrigin($order, true); ?></td>
<td class="date"> <td class="date">

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

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\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderBuilder;
use common\logic\Order\Order\Service\OrderSolver; use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Order\ProductOrder\Repository\ProductOrderRepository; use common\logic\Order\ProductOrder\Repository\ProductOrderRepository;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
// findBy // findBy
public function findOrdersBy(array $params = [], array $options = []) public function findOrdersBy(array $params = [], array $options = [])
{ {
$orderBuilder = OrderBuilder::getInstance();
$orders = Order::searchBy($params, $options); $orders = Order::searchBy($params, $options);


/* /*
* Initialisation des commandes * Initialisation des commandes
*/ */

if (is_array($orders)) { if (is_array($orders)) {
if (count($orders)) { if (count($orders)) {
foreach ($orders as $order) { foreach ($orders as $order) {
if (is_a($order, 'common\logic\Order\Order\Order')) {
$order->init();
if (is_a($order, 'common\logic\Order\Order\Model\Order')) {
$orderBuilder->initOrder($order);
} }
} }
return $orders; return $orders;
} }
} else { } else {
$order = $orders; $order = $orders;
if (is_a($order, 'common\logic\Order\Order\Order')) {
return $order->init();
if (is_a($order, 'common\logic\Order\Order\Model\Order')) {
$orderBuilder->initOrder($order);
return $order;
} // count } // count
else { else {
return $order; return $order;

+ 26
- 0
common/logic/Order/Order/Service/OrderBuilder.php View File

use common\logic\Order\ProductOrder\Model\ProductOrder; use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\Order\ProductOrder\Service\ProductOrderBuilder; use common\logic\Order\ProductOrder\Service\ProductOrderBuilder;
use common\logic\Order\ProductOrder\Service\ProductOrderSolver; use common\logic\Order\ProductOrder\Service\ProductOrderSolver;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Service\PointSaleBuilder; use common\logic\PointSale\PointSale\Service\PointSaleBuilder;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository;
} }
} }


/**
* Initialise les commandes liées au point de vente.
*/
public function initPointSaleOrders(PointSale $pointSale, array $ordersArray): void
{
$pointSale->orders = [];
$pointSale->revenues = 0;
$pointSale->revenues_with_tax = 0;

if ($ordersArray) {
foreach ($ordersArray as $order) {
$this->initOrder($order);

if ($pointSale->id == $order->id_point_sale) {
$pointSale->orders[] = $order;

if (is_null($order->date_delete)) {
$pointSale->revenues += (float) $order->amount;
$pointSale->revenues_with_tax += (float) $order->amount_with_tax;
}
}
}
}
}

} }

+ 0
- 23
common/logic/PointSale/PointSale/Service/PointSaleBuilder.php View File

return $pointSale; return $pointSale;
} }


/**
* Initialise les commandes liées au point de vente.
*/
public function initPointSaleOrders(PointSale $pointSale, array $ordersArray): void
{
$pointSale->orders = [];
$pointSale->revenues = 0;
$pointSale->revenues_with_tax = 0;

if ($ordersArray) {
foreach ($ordersArray as $order) {
if ($pointSale->id == $order->id_point_sale) {
$pointSale->orders[] = $order;

if (is_null($order->date_delete)) {
$pointSale->revenues += (float) $order->amount;
$pointSale->revenues_with_tax += (float) $order->amount_with_tax;
}
}
}
}
}

// resetPointProductions // resetPointProductions
public function resetPointSalePointProductions(Producer $producer): void public function resetPointSalePointProductions(Producer $producer): void
{ {

+ 12
- 0
common/logic/User/CreditHistory/Event/CreditHistoryCreateEvent.php View File

<?php

namespace common\logic\User\CreditHistory\Event;

use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\User\CreditHistory\Model\CreditHistory;
use yii\base\Event;

class CreditHistoryCreateEvent extends Event
{
public CreditHistory $creditHistory;
}

+ 1
- 1
common/logic/User/CreditHistory/Model/CreditHistory.php View File

public function init() public function init()
{ {
$this->on(CreditHistory::EVENT_CREATE, function($event) { $this->on(CreditHistory::EVENT_CREATE, function($event) {
UserProducerEventSubscriber::onCreateCreditHistory($event->creditHistory);
UserProducerEventSubscriber::onCreateCreditHistory($event);
}); });


parent::init(); parent::init();

+ 7
- 1
common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php View File

use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderSolver; use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Producer\Producer\Model\Producer; use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\CreditHistory\Event\CreditHistoryCreateEvent;
use common\logic\User\CreditHistory\Model\CreditHistory; use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
use yii\base\Event; use yii\base\Event;
$creditHistory->setComment($creditHistory->getComment() . $this->orderSolver->getCreditHistoryComment($creditHistory)); $creditHistory->setComment($creditHistory->getComment() . $this->orderSolver->getCreditHistoryComment($creditHistory));
$this->saveCreate($creditHistory); $this->saveCreate($creditHistory);


$creditHistory->trigger(CreditHistory::EVENT_CREATE, new Event(['creditHistory' => $creditHistory]));
$creditHistoryCreateEvent = new CreditHistoryCreateEvent();
$creditHistoryCreateEvent->creditHistory = $creditHistory;
$creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent);

print_r($creditHistory);
die('#'.$creditHistory->id);


return $creditHistory; return $creditHistory;
} }

+ 6
- 3
common/logic/User/UserProducer/Service/UserProducerBuilder.php View File

use common\logic\AbstractBuilder; use common\logic\AbstractBuilder;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Repository\OrderRepository; use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Producer\Producer\Model\Producer; use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository; use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\User\CreditHistory\Model\CreditHistory; use common\logic\User\CreditHistory\Model\CreditHistory;
protected UserProducerRepository $userProducerRepository; protected UserProducerRepository $userProducerRepository;
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;
protected ProducerRepository $producerRepository; protected ProducerRepository $producerRepository;
protected OrderSolver $orderSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->userProducerRepository = $this->loadService(UserProducerRepository::class); $this->userProducerRepository = $this->loadService(UserProducerRepository::class);
$this->orderRepository = $this->loadService(OrderRepository::class); $this->orderRepository = $this->loadService(OrderRepository::class);
$this->producerRepository = $this->loadService(ProducerRepository::class); $this->producerRepository = $this->loadService(ProducerRepository::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
} }


public function instanciateUserProducer(User $user, Producer $producer, int $bookmark = 1) public function instanciateUserProducer(User $user, Producer $producer, int $bookmark = 1)
$order = $this->orderRepository->findOneOrderById((int) $creditHistory->id_order); $order = $this->orderRepository->findOneOrderById((int) $creditHistory->id_order);


if ($order) { if ($order) {
$paymentStatus = $order->getPaymentStatus();
$paymentStatus = $this->orderSolver->getPaymentStatus($order);
if ($paymentStatus == Order::PAYMENT_PAID if ($paymentStatus == Order::PAYMENT_PAID
|| $paymentStatus == Order::PAYMENT_SURPLUS) { || $paymentStatus == Order::PAYMENT_SURPLUS) {




if ($this->isCreditLimitCrossed($oldCredit, $newCredit)) { if ($this->isCreditLimitCrossed($oldCredit, $newCredit)) {


$user = $userRepository->getOneById($creditHistory->id_user);
$producer = $producerRepository->getOneById($creditHistory->id_producer);
$user = $userRepository->findOneUserById($creditHistory->id_user);
$producer = $producerRepository->findOneProducerById($creditHistory->id_producer);


\Yii::$app->mailer->compose( \Yii::$app->mailer->compose(
[ [

+ 8
- 3
producer/controllers/OrderController.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Mailjet; use common\helpers\Mailjet;
use common\helpers\MeanPayment;
use common\helpers\Password; use common\helpers\Password;
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;
$amountRemaining, $amountRemaining,
$producer, $producer,
GlobalParam::getCurrentUser(), GlobalParam::getCurrentUser(),
GlobalParam::getCurrentUser()
GlobalParam::getCurrentUser(),
MeanPayment::CREDIT,
$order
); );
$orderManager->changeOrderStatus($order, 'paid-by-credit', 'user'); $orderManager->changeOrderStatus($order, 'paid-by-credit', 'user');
} else { } else {
$orderManager->changeOrderStatus($order, 'waiting-paiement-on-delivery', 'user'); $orderManager->changeOrderStatus($order, 'waiting-paiement-on-delivery', 'user');
} }
} // surplus à rembourser } // surplus à rembourser
elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) {
elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) {
$amountSurplus = $orderManager->getOrderAmount($order, Order::AMOUNT_SURPLUS); $amountSurplus = $orderManager->getOrderAmount($order, Order::AMOUNT_SURPLUS);
$creditHistoryManager->createCreditHistory( $creditHistoryManager->createCreditHistory(
CreditHistory::TYPE_REFUND, CreditHistory::TYPE_REFUND,
$amountSurplus, $amountSurplus,
$producer, $producer,
GlobalParam::getCurrentUser(), GlobalParam::getCurrentUser(),
GlobalParam::getCurrentUser()
GlobalParam::getCurrentUser(),
MeanPayment::CREDIT,
$order
); );
} }
} else { } else {

Loading…
Cancel
Save