Просмотр исходного кода

Abonnements > ajout/modification : prendre en compte contrainte de délai et d'heure limite de commande #1079

feature/souke
Guillaume 1 год назад
Родитель
Сommit
9cc6f80056
2 измененных файлов: 27 добавлений и 28 удалений
  1. +5
    -1
      common/logic/Distribution/Distribution/Repository/DistributionRepository.php
  2. +22
    -27
      common/logic/Order/Order/Service/OrderBuilder.php

+ 5
- 1
common/logic/Distribution/Distribution/Repository/DistributionRepository.php Просмотреть файл

@@ -110,7 +110,7 @@ class DistributionRepository extends AbstractRepository
* Recherche les distributions futures où l'abonnement peut s'appliquer.
*/
// searchMatchedIncomingDistributions
public function findDistributionsIncomingMatchWithSubscrtiption(Subscription $subscription): array
public function findDistributionsIncomingMatchWithSubscrtiption(Subscription $subscription, bool $filterByOrderDeadline = false): array
{
$params = [
':date_earliest_order' => date('Y-m-d'),
@@ -141,6 +141,10 @@ class DistributionRepository extends AbstractRepository
}
}

if($filterByOrderDeadline) {
$matchedIncomingDistributionsArray = $this->distributionSolver->filterDistributionsByDateDelay($matchedIncomingDistributionsArray);
}

return $matchedIncomingDistributionsArray;
}


+ 22
- 27
common/logic/Order/Order/Service/OrderBuilder.php Просмотреть файл

@@ -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++;
}
}


Загрузка…
Отмена
Сохранить