|
|
@@ -9,6 +9,7 @@ use common\logic\AbstractBuilder; |
|
|
|
use common\logic\Config\TaxRate\Model\TaxRate; |
|
|
|
use common\logic\Distribution\Distribution\Model\Distribution; |
|
|
|
use common\logic\Distribution\Distribution\Repository\DistributionRepository; |
|
|
|
use common\logic\Distribution\Distribution\Service\DistributionSolver; |
|
|
|
use common\logic\Document\Document\Model\Document; |
|
|
|
use common\logic\Order\Order\Model\Order; |
|
|
|
use common\logic\Order\Order\Repository\OrderRepository; |
|
|
@@ -54,6 +55,7 @@ class OrderBuilder extends AbstractBuilder |
|
|
|
protected SubscriptionRepository $subscriptionRepository; |
|
|
|
protected SubscriptionSolver $subscriptionSolver; |
|
|
|
protected ProductSolver $productSolver; |
|
|
|
protected DistributionSolver $distributionSolver; |
|
|
|
|
|
|
|
public function loadDependencies(): void |
|
|
|
{ |
|
|
@@ -75,6 +77,7 @@ class OrderBuilder extends AbstractBuilder |
|
|
|
$this->subscriptionRepository = $this->loadService(SubscriptionRepository::class); |
|
|
|
$this->subscriptionSolver = $this->loadService(SubscriptionSolver::class); |
|
|
|
$this->productSolver = $this->loadService(ProductSolver::class); |
|
|
|
$this->distributionSolver = $this->loadService(DistributionSolver::class); |
|
|
|
} |
|
|
|
|
|
|
|
public function instanciateOrder(Distribution $distribution): Order |
|
|
@@ -153,7 +156,7 @@ class OrderBuilder extends AbstractBuilder |
|
|
|
public function updateOrdersIncomingDistributionsFromSubscription(Subscription $subscription, $update = false): array |
|
|
|
{ |
|
|
|
$orderArray = []; |
|
|
|
$matchedDistributionsArray = $this->distributionRepository->findDistributionsIncomingMatchWithSubscrtiption($subscription); |
|
|
|
$matchedDistributionsArray = $this->distributionRepository->findDistributionsIncomingMatchWithSubscrtiption($subscription, true); |
|
|
|
|
|
|
|
if ($update) { |
|
|
|
$this->deleteOrdersIncomingDistributionsFromSubscription($subscription); |
|
|
@@ -184,19 +187,10 @@ class OrderBuilder extends AbstractBuilder |
|
|
|
':id_subscription' => $subscription->id |
|
|
|
]; |
|
|
|
|
|
|
|
$orderDeadline = $this->producerRepository->getConfig('order_deadline'); |
|
|
|
$hour = date('G'); |
|
|
|
|
|
|
|
if ($hour >= $orderDeadline) { |
|
|
|
$conditionDistributionDate = 'distribution.date > :date_today'; |
|
|
|
} else { |
|
|
|
$conditionDistributionDate = 'distribution.date >= :date_today'; |
|
|
|
} |
|
|
|
|
|
|
|
$orders = Order::find() |
|
|
|
->joinWith('distribution') |
|
|
|
->where('distribution.id_producer = :id_producer') |
|
|
|
->andWhere($conditionDistributionDate) |
|
|
|
->andWhere('distribution.date >= :date_today') |
|
|
|
->andWhere('distribution.date ' . $comparatorDateStart . ' :date_start') |
|
|
|
->andWhere('order.id_subscription = :id_subscription'); |
|
|
|
|
|
|
@@ -208,25 +202,26 @@ class OrderBuilder extends AbstractBuilder |
|
|
|
$countOrdersDeleted = 0; |
|
|
|
if ($ordersArray && count($ordersArray)) { |
|
|
|
foreach ($ordersArray as $order) { |
|
|
|
if($this->distributionSolver->isDistributionAvailable($order->distribution)) { |
|
|
|
$theOrder = $this->orderRepository->findOneOrderById($order->id); |
|
|
|
$this->initOrder($theOrder); |
|
|
|
|
|
|
|
// remboursement de la commande |
|
|
|
if ($theOrder->id_user && $this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID) && $configCredit) { |
|
|
|
|
|
|
|
$this->creditHistoryBuilder->createCreditHistory( |
|
|
|
CreditHistory::TYPE_REFUND, |
|
|
|
$this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID), |
|
|
|
$theOrder->distribution->producer, |
|
|
|
$theOrder->user, |
|
|
|
GlobalParam::getCurrentUser() |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
$theOrder = $this->orderRepository->findOneOrderById($order->id); |
|
|
|
$this->initOrder($theOrder); |
|
|
|
|
|
|
|
// remboursement de la commande |
|
|
|
if ($theOrder->id_user && $this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID) && $configCredit) { |
|
|
|
$this->deleteOrder($order, true); |
|
|
|
|
|
|
|
$this->creditHistoryBuilder->createCreditHistory( |
|
|
|
CreditHistory::TYPE_REFUND, |
|
|
|
$this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID), |
|
|
|
$theOrder->distribution->producer, |
|
|
|
$theOrder->user, |
|
|
|
GlobalParam::getCurrentUser() |
|
|
|
); |
|
|
|
$countOrdersDeleted++; |
|
|
|
} |
|
|
|
|
|
|
|
$this->deleteOrder($order, true); |
|
|
|
|
|
|
|
$countOrdersDeleted++; |
|
|
|
} |
|
|
|
} |
|
|
|
|