Browse Source

[Producer] Commande : correctif filtre jours de distributions (point sale maximum orders)

refactoring
Guillaume 3 years ago
parent
commit
46439add24
1 changed files with 45 additions and 27 deletions
  1. +45
    -27
      producer/controllers/OrderController.php

+ 45
- 27
producer/controllers/OrderController.php View File

@@ -661,6 +661,9 @@ class OrderController extends ProducerBaseController
// PointSale current
$pointSaleCurrent = PointSale::findOne($pointSaleId);

// Commande de l'utilisateur
$orderUser = $this->_getOrderUser($date, $pointSaleId);

// Producteur
$producer = Producer::searchOne([
'id' => $this->getProducer()->id
@@ -697,7 +700,19 @@ class OrderController extends ProducerBaseController
for ($i = 0; $i < count($distributionsArray); $i++) {
$distribution = $distributionsArray[$i];
if (Distribution::isPointSaleActive($distribution, $pointSaleId)) {
$distributionsArrayFilterPointSale[] = $distribution;

$countOrders = (int) Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSaleId
]);
$orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId);

if(!$pointSaleCurrent->maximum_number_orders
|| ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId)
|| ($pointSaleCurrent->maximum_number_orders &&
($countOrders < $pointSaleCurrent->maximum_number_orders))) {
$distributionsArrayFilterPointSale[] = $distribution;
}
}
}

@@ -757,32 +772,6 @@ class OrderController extends ProducerBaseController
}

if ($dateObject && $dateObject->format($format) === $date) {
// Commande de l'utilisateur
$orderUser = false;
if (User::getCurrentId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => User::getCurrentId(),
];

if ($pointSaleId) {
$conditionOrderUser['id_point_sale'] = $pointSaleId;
}

$orderUser = Order::searchOne($conditionOrderUser);

if ($orderUser && $orderUser->online_payment_url) {
$orderUser = false;
}
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

// distribution
$distribution = Distribution::initDistribution($date, $producer->id);
$json['distribution'] = $distribution;
@@ -889,6 +878,35 @@ class OrderController extends ProducerBaseController
return $json;
}

private function _getOrderUser($date, $pointSaleId = false) {
$orderUser = false;
if (User::getCurrentId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => User::getCurrentId(),
];

if ($pointSaleId) {
$conditionOrderUser['id_point_sale'] = $pointSaleId;
}

$orderUser = Order::searchOne($conditionOrderUser);

if ($orderUser && $orderUser->online_payment_url) {
$orderUser = false;
}
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

return $orderUser;
}

private function _initPointsSale($idProducer, $distribution = false)
{
$pointsSaleArray = PointSale::find();

Loading…
Cancel
Save