|
|
|
|
|
|
|
|
// PointSale current |
|
|
// PointSale current |
|
|
$pointSaleCurrent = PointSale::findOne($pointSaleId); |
|
|
$pointSaleCurrent = PointSale::findOne($pointSaleId); |
|
|
|
|
|
|
|
|
|
|
|
// Commande de l'utilisateur |
|
|
|
|
|
$orderUser = $this->_getOrderUser($date, $pointSaleId); |
|
|
|
|
|
|
|
|
// Producteur |
|
|
// Producteur |
|
|
$producer = Producer::searchOne([ |
|
|
$producer = Producer::searchOne([ |
|
|
'id' => $this->getProducer()->id |
|
|
'id' => $this->getProducer()->id |
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($distributionsArray); $i++) { |
|
|
for ($i = 0; $i < count($distributionsArray); $i++) { |
|
|
$distribution = $distributionsArray[$i]; |
|
|
$distribution = $distributionsArray[$i]; |
|
|
if (Distribution::isPointSaleActive($distribution, $pointSaleId)) { |
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
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 = Distribution::initDistribution($date, $producer->id); |
|
|
$distribution = Distribution::initDistribution($date, $producer->id); |
|
|
$json['distribution'] = $distribution; |
|
|
$json['distribution'] = $distribution; |
|
|
|
|
|
|
|
|
return $json; |
|
|
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) |
|
|
private function _initPointsSale($idProducer, $distribution = false) |
|
|
{ |
|
|
{ |
|
|
$pointsSaleArray = PointSale::find(); |
|
|
$pointsSaleArray = PointSale::find(); |