@@ -282,7 +282,7 @@ class DistributionController extends BackendController | |||
foreach ($order->creditHistory as $creditHistory) { | |||
$creditHistoryArray[] = [ | |||
'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), | |||
'wording' => $creditHistoryManager->getStrWording($creditHistory), | |||
'debit' => ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . $creditHistoryManager->getAmount( | |||
@@ -593,6 +593,7 @@ class DistributionController extends BackendController | |||
$producerManager = $this->getProducerManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$productManager = $this->getProductManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
if (!\Yii::$app->user->isGuest) { | |||
$idProducer = GlobalParam::getCurrentProducerId(); | |||
@@ -623,7 +624,7 @@ class DistributionController extends BackendController | |||
]); | |||
foreach ($pointsSaleArray as $pointSale) { | |||
$pointSale->initOrders($ordersArray); | |||
$orderManager->initPointSaleOrders($pointSale, $ordersArray); | |||
} | |||
// produits | |||
@@ -851,7 +852,7 @@ class DistributionController extends BackendController | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$productDistribution = $this->getProductDistributionManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$productCategoryManager = $this->getProductCategoryManager(); | |||
if (!\Yii::$app->user->isGuest) { | |||
@@ -883,7 +884,7 @@ class DistributionController extends BackendController | |||
]); | |||
foreach ($pointsSaleArray as $pointSale) { | |||
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray); | |||
$orderManager->initPointSaleOrders($pointSale, $ordersArray); | |||
} | |||
$ordersByPage = 22; | |||
@@ -1043,8 +1044,7 @@ class DistributionController extends BackendController | |||
public function actionReportTerredepains($date, $key) | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$productDistributionManager = $this->getProductDistributionManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$productManager = $this->getProductManager(); | |||
if ($key == 'ef572cc148c001f0180c4a624189ed30') { | |||
@@ -1077,7 +1077,7 @@ class DistributionController extends BackendController | |||
]); | |||
foreach ($pointsSaleArray as $pointSale) { | |||
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray); | |||
$orderManager->initPointSaleOrders($pointSale, $ordersArray); | |||
} | |||
// produits |
@@ -41,6 +41,7 @@ namespace backend\controllers; | |||
use common\forms\SubscriptionForm; | |||
use common\helpers\CSV; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Price; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution; | |||
@@ -96,7 +97,7 @@ class OrderController extends BackendController | |||
$orders = $orderManager->findOrdersByDistribution($distribution); | |||
foreach ($pointsSale as $point) { | |||
$pointSaleManager->initPointSaleOrders($point, $orders); | |||
$orderManager->initPointSaleOrders($point, $orders); | |||
if (isset($_POST['submit_pv']) && $_POST['submit_pv']) { | |||
// modifs | |||
@@ -230,7 +231,7 @@ class OrderController extends BackendController | |||
// init commandes point de vente | |||
foreach ($arrayPointsSale as $pointSale) { | |||
$pointSaleManager->initPointSaleOrders($pointSale, $arrayOrders); | |||
$orderManager->initPointSaleOrders($pointSale, $arrayOrders); | |||
$dataSelectOrders = []; | |||
$dataOptionsOrders = []; | |||
@@ -1004,7 +1005,7 @@ class OrderController extends BackendController | |||
} | |||
} | |||
} | |||
/** | |||
* Retourne l'état du paiement (historique, crédit) d'une commande donnée. | |||
*/ | |||
@@ -1102,7 +1103,9 @@ class OrderController extends BackendController | |||
$amount, | |||
GlobalParam::getCurrentProducer(), | |||
$order->user, | |||
GlobalParam::getCurrentUser() | |||
GlobalParam::getCurrentUser(), | |||
MeanPayment::CREDIT, | |||
$order | |||
); | |||
} | |||
@@ -186,7 +186,7 @@ foreach ($pointsSaleArray as $pointSale) { | |||
$cpt = 0 ; | |||
foreach ($productsArray as $product) { | |||
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) { | |||
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; | |||
$strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | |||
@@ -235,7 +235,7 @@ foreach ($pointsSaleArray as $pointSale) | |||
$cpt = 0 ; | |||
foreach ($productsArray as $product) { | |||
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) { | |||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; | |||
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | |||
@@ -262,7 +262,7 @@ $html .= '<tr><td><strong>Total</strong></td><td>' ; | |||
$cpt = 0 ; | |||
foreach ($productsArray as $product) { | |||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||
$quantity = $orderManager->getProductQuantity($product->id, $ordersArray, false, $unit); | |||
$quantity = $orderManager->getProductQuantity($product, $ordersArray, false, $unit); | |||
if ($quantity) { | |||
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; | |||
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; |
@@ -80,7 +80,7 @@ foreach ($pointsSaleArray as $pointSale) { | |||
$strUser = ''; | |||
// username | |||
$strUser .= $order->getStrUser() ; | |||
$strUser .= $orderManager->getOrderUsername($order) ; | |||
if(strlen($order->comment_point_sale)) | |||
{ | |||
@@ -106,7 +106,7 @@ foreach ($pointsSaleArray as $pointSale) { | |||
foreach ($order->productOrder as $productOrder) { | |||
if($product->id == $productOrder->id_product) { | |||
$unit = ( $productManager->strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($productOrder->unit, 'wording_short', true) ; | |||
$strProducts .= '('.$productOrder->quantity .$unit.') '.$product->getNameExport() . '<br />'; | |||
$strProducts .= '('.$productOrder->quantity .$unit.') '.$productManager->getNameExport($product) . '<br />'; | |||
$add = true; | |||
} | |||
} | |||
@@ -116,7 +116,7 @@ foreach ($pointsSaleArray as $pointSale) { | |||
if($isBig) { | |||
$html .= '<td></td>' ; | |||
} | |||
$html .= '<td>'.$order->getCommentReport().'</td>'; | |||
$html .= '<td>'.$orderManager->getCommentReport($order).'</td>'; | |||
if($pointSale->credit) { | |||
$credit = '' ; | |||
@@ -161,10 +161,10 @@ foreach ($pointsSaleArray as $pointSale) { | |||
$cpt = 0 ; | |||
foreach ($productsArray as $product) { | |||
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) { | |||
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; | |||
$strProducts .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />'; | |||
$strProducts .= '(' .$quantity .$theUnit.') '.$productManager->getNameExport($product) . '<br />'; | |||
} | |||
} | |||
@@ -208,10 +208,10 @@ foreach ($pointsSaleArray as $pointSale) | |||
$cpt = 0 ; | |||
foreach ($productsArray as $product) { | |||
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) { | |||
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; | |||
$html .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />'; | |||
$html .= '(' .$quantity .$theUnit.') '.$productManager->getNameExport($product) . '<br />'; | |||
} | |||
} | |||
@@ -235,7 +235,7 @@ $html .= '<tr><td><strong>Total</strong></td><td>' ; | |||
$cpt = 0 ; | |||
foreach ($productsArray as $product) { | |||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||
$quantity = $orderManager->getProductQuantity($product->id, $ordersArray, false, $unit); | |||
$quantity = $orderManager->getProductQuantity($product, $ordersArray, false, $unit); | |||
if ($quantity) { | |||
$theUnit = ( $productManager->strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. $productManager->strUnit($unit, 'wording_short', true) ; | |||
$html .= '(' .$quantity .$theUnit.') '.$product->name . '<br />'; |
@@ -136,7 +136,7 @@ foreach ($pointsSaleArray as $pointSale) { | |||
$strProducts = ''; | |||
foreach ($productsArray as $product) { | |||
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders); | |||
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders); | |||
$strQuantity = ''; | |||
if ($quantity) { | |||
$strQuantity = $quantity; | |||
@@ -174,7 +174,7 @@ foreach ($pointsSaleArray as $pointSale) | |||
{ | |||
$html .= '<tr><td>'.$pointSale->name.'</td><td>' ; | |||
foreach ($productsArray as $product) { | |||
$quantity = $orderManager->getProductQuantity($product->id, $pointSale->orders); | |||
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders); | |||
$strQuantity = ($quantity) ? $quantity : '' ; | |||
if(strlen($strQuantity)) { | |||
@@ -193,7 +193,7 @@ foreach ($pointsSaleArray as $pointSale) | |||
// total | |||
$html .= '<tr><td><strong>Total</strong></td><td>' ; | |||
foreach ($productsArray as $product) { | |||
$quantity = $orderManager->getProductQuantity($product->id, $ordersArray); | |||
$quantity = $orderManager->getProductQuantity($product, $ordersArray); | |||
if($quantity) { | |||
$html .= $quantity . ' '.$product->name.', ' ; | |||
} |
@@ -149,6 +149,8 @@ $this->setTitle('Tableau de bord'); | |||
</thead> | |||
<tbody> | |||
<?php foreach($ordersArray as $order): ?> | |||
<?php $orderManager->initOrder($order); ?> | |||
<tr class="<?= $orderManager->getHistoryClass($order) ; ?>"> | |||
<td class="infos"><?= $orderManager->getLabelOrigin($order, true); ?></td> | |||
<td class="date"> |
@@ -6,6 +6,7 @@ use common\logic\AbstractRepository; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository; | |||
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\ProductOrder\Repository\ProductOrderRepository; | |||
use common\logic\PointSale\PointSale\Model\PointSale; | |||
@@ -71,25 +72,26 @@ class OrderRepository extends AbstractRepository | |||
// findBy | |||
public function findOrdersBy(array $params = [], array $options = []) | |||
{ | |||
$orderBuilder = OrderBuilder::getInstance(); | |||
$orders = Order::searchBy($params, $options); | |||
/* | |||
* Initialisation des commandes | |||
*/ | |||
if (is_array($orders)) { | |||
if (count($orders)) { | |||
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; | |||
} | |||
} else { | |||
$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 | |||
else { | |||
return $order; |
@@ -16,6 +16,7 @@ use common\logic\Order\OrderStatusHistory\Service\OrderStatusHistoryBuilder; | |||
use common\logic\Order\ProductOrder\Model\ProductOrder; | |||
use common\logic\Order\ProductOrder\Service\ProductOrderBuilder; | |||
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\Repository\PointSaleRepository; | |||
use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; | |||
@@ -593,4 +594,29 @@ class OrderBuilder extends AbstractBuilder | |||
} | |||
} | |||
/** | |||
* 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; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -39,29 +39,6 @@ class PointSaleBuilder extends AbstractBuilder | |||
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 | |||
public function resetPointSalePointProductions(Producer $producer): void | |||
{ |
@@ -0,0 +1,12 @@ | |||
<?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; | |||
} |
@@ -100,7 +100,7 @@ class CreditHistory extends ActiveRecordCommon | |||
public function init() | |||
{ | |||
$this->on(CreditHistory::EVENT_CREATE, function($event) { | |||
UserProducerEventSubscriber::onCreateCreditHistory($event->creditHistory); | |||
UserProducerEventSubscriber::onCreateCreditHistory($event); | |||
}); | |||
parent::init(); |
@@ -6,6 +6,7 @@ use common\logic\AbstractBuilder; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\Order\Order\Service\OrderSolver; | |||
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\User\Model\User; | |||
use yii\base\Event; | |||
@@ -69,7 +70,12 @@ class CreditHistoryBuilder extends AbstractBuilder | |||
$creditHistory->setComment($creditHistory->getComment() . $this->orderSolver->getCreditHistoryComment($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; | |||
} |
@@ -6,6 +6,7 @@ use common\helpers\MeanPayment; | |||
use common\logic\AbstractBuilder; | |||
use common\logic\Order\Order\Model\Order; | |||
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\Repository\ProducerRepository; | |||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||
@@ -20,6 +21,7 @@ class UserProducerBuilder extends AbstractBuilder | |||
protected UserProducerRepository $userProducerRepository; | |||
protected OrderRepository $orderRepository; | |||
protected ProducerRepository $producerRepository; | |||
protected OrderSolver $orderSolver; | |||
public function loadDependencies(): void | |||
{ | |||
@@ -27,6 +29,7 @@ class UserProducerBuilder extends AbstractBuilder | |||
$this->userProducerRepository = $this->loadService(UserProducerRepository::class); | |||
$this->orderRepository = $this->loadService(OrderRepository::class); | |||
$this->producerRepository = $this->loadService(ProducerRepository::class); | |||
$this->orderSolver = $this->loadService(OrderSolver::class); | |||
} | |||
public function instanciateUserProducer(User $user, Producer $producer, int $bookmark = 1) | |||
@@ -85,7 +88,7 @@ class UserProducerBuilder extends AbstractBuilder | |||
$order = $this->orderRepository->findOneOrderById((int) $creditHistory->id_order); | |||
if ($order) { | |||
$paymentStatus = $order->getPaymentStatus(); | |||
$paymentStatus = $this->orderSolver->getPaymentStatus($order); | |||
if ($paymentStatus == Order::PAYMENT_PAID | |||
|| $paymentStatus == Order::PAYMENT_SURPLUS) { | |||
@@ -105,8 +108,8 @@ class UserProducerBuilder extends AbstractBuilder | |||
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( | |||
[ |
@@ -40,6 +40,7 @@ namespace producer\controllers; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\Mailjet; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Password; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Model\Order; | |||
@@ -455,21 +456,25 @@ class OrderController extends ProducerBaseController | |||
$amountRemaining, | |||
$producer, | |||
GlobalParam::getCurrentUser(), | |||
GlobalParam::getCurrentUser() | |||
GlobalParam::getCurrentUser(), | |||
MeanPayment::CREDIT, | |||
$order | |||
); | |||
$orderManager->changeOrderStatus($order, 'paid-by-credit', 'user'); | |||
} else { | |||
$orderManager->changeOrderStatus($order, 'waiting-paiement-on-delivery', 'user'); | |||
} | |||
} // surplus à rembourser | |||
elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) { | |||
elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) { | |||
$amountSurplus = $orderManager->getOrderAmount($order, Order::AMOUNT_SURPLUS); | |||
$creditHistoryManager->createCreditHistory( | |||
CreditHistory::TYPE_REFUND, | |||
$amountSurplus, | |||
$producer, | |||
GlobalParam::getCurrentUser(), | |||
GlobalParam::getCurrentUser() | |||
GlobalParam::getCurrentUser(), | |||
MeanPayment::CREDIT, | |||
$order | |||
); | |||
} | |||
} else { |