|
|
@@ -40,12 +40,15 @@ namespace producer\controllers; |
|
|
|
|
|
|
|
use common\helpers\GlobalParam; |
|
|
|
use common\helpers\Mailjet; |
|
|
|
use common\logic\Distribution\Distribution\Distribution; |
|
|
|
use common\logic\Order\Order\Order; |
|
|
|
use common\logic\PointSale\PointSale\PointSale; |
|
|
|
use common\logic\Producer\Producer\Producer; |
|
|
|
use common\logic\User\CreditHistory\CreditHistory; |
|
|
|
use common\logic\User\User\User; |
|
|
|
use common\logic\User\UserProducer\UserProducer; |
|
|
|
use DateTime; |
|
|
|
use yii\base\UserException; |
|
|
|
use yii\data\ActiveDataProvider; |
|
|
|
use yii\web\NotFoundHttpException; |
|
|
|
|
|
|
@@ -69,21 +72,13 @@ class OrderController extends ProducerBaseController |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if ($id) { |
|
|
|
$order = $this->getOrderContainer()->getRepository()->getOneById($id); |
|
|
|
if ($order && $this->getOrderContainer()->getSolver()->isStateOpen($order)) { |
|
|
|
$params['order'] = $order; |
|
|
|
} |
|
|
|
$order = $this->getOrderContainer()->getRepository()->getOneById($id); |
|
|
|
if ($order && $this->getOrderContainer()->getSolver()->isStateOpen($order)) { |
|
|
|
$params['order'] = $order; |
|
|
|
} |
|
|
|
|
|
|
|
if (strlen($date)) { |
|
|
|
$distribution = $this->getDistributionContainer()->getRepository()->getOne($producer, $date); |
|
|
|
if ($distribution) { |
|
|
|
$distributionsArray = $this->getDistributionContainer()->getSolver()->filterDistributionsByDateDelay([$distribution]); |
|
|
|
if (count($distributionsArray) == 1) { |
|
|
|
$params['date'] = $date; |
|
|
|
} |
|
|
|
} |
|
|
|
if ($this->getDistributionContainer()->getRepository()->isDateAvailable($producer, $date)) { |
|
|
|
$params['date'] = $date; |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('order', $params); |
|
|
@@ -94,25 +89,13 @@ class OrderController extends ProducerBaseController |
|
|
|
*/ |
|
|
|
public function actionHistory($type = 'incoming') |
|
|
|
{ |
|
|
|
$producer = $this->getProducer(); |
|
|
|
|
|
|
|
$query = Order::find() |
|
|
|
->with('productOrder', 'pointSale', 'creditHistory') |
|
|
|
->joinWith('distribution', 'distribution.producer') |
|
|
|
->where([ |
|
|
|
'id_user' => $this->getUserCurrent()->id, |
|
|
|
'distribution.id_producer' => $producer->id |
|
|
|
]) |
|
|
|
->params([':date_today' => date('Y-m-d')]); |
|
|
|
|
|
|
|
$queryIncoming = clone $query; |
|
|
|
$queryIncoming->andWhere('distribution.date >= :date_today')->orderBy('distribution.date ASC'); |
|
|
|
|
|
|
|
$queryPassed = clone $query; |
|
|
|
$queryPassed->andWhere('distribution.date < :date_today')->orderBy('distribution.date DESC'); |
|
|
|
$queryHistoryArray = $this->getOrderContainer()->getRepository() |
|
|
|
->queryHistory($this->getProducer(), $this->getUserCurrent(), $type); |
|
|
|
$queryHistoryIncoming = $queryHistoryArray['incoming']; |
|
|
|
$queryHistoryPassed = $queryHistoryArray['passed']; |
|
|
|
|
|
|
|
$dataProviderOrders = new ActiveDataProvider([ |
|
|
|
'query' => ($type == 'incoming') ? $queryIncoming : $queryPassed, |
|
|
|
'query' => ($type == 'incoming') ? $queryHistoryIncoming : $queryHistoryPassed, |
|
|
|
'pagination' => [ |
|
|
|
'pageSize' => 10, |
|
|
|
], |
|
|
@@ -123,8 +106,8 @@ class OrderController extends ProducerBaseController |
|
|
|
'orderOk' => \Yii::$app->getRequest()->get('orderOk', false), |
|
|
|
'cancelOk' => \Yii::$app->getRequest()->get('cancelOk', false), |
|
|
|
'type' => $type, |
|
|
|
'countIncoming' => $queryIncoming->count(), |
|
|
|
'countPassed' => $queryPassed->count(), |
|
|
|
'countIncoming' => $queryHistoryIncoming->count(), |
|
|
|
'countPassed' => $queryHistoryPassed->count(), |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@@ -569,75 +552,105 @@ class OrderController extends ProducerBaseController |
|
|
|
|
|
|
|
/** |
|
|
|
* Annule une commande. |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @throws \yii\web\NotFoundHttpException |
|
|
|
* @throws UserException |
|
|
|
*/ |
|
|
|
public function actionCancel($id) |
|
|
|
public function actionCancel(int $id) |
|
|
|
{ |
|
|
|
$order = Order::searchOne([ |
|
|
|
'id' => $id |
|
|
|
]); |
|
|
|
$orderContainer = $this->getOrderContainer(); |
|
|
|
$order = $orderContainer->getRepository()->getOneById($id); |
|
|
|
|
|
|
|
if (!$order) { |
|
|
|
throw new \yii\web\NotFoundHttpException('Commande introuvable'); |
|
|
|
} |
|
|
|
|
|
|
|
if ($order->getState() != Order::STATE_OPEN) { |
|
|
|
if ($orderContainer->getSolver()->isStateOpen($order)) { |
|
|
|
throw new UserException('Vous ne pouvez plus annuler cette commande.'); |
|
|
|
} |
|
|
|
|
|
|
|
if ($order && GlobalParam::getCurrentUserId() == $order->id_user) { |
|
|
|
$order->delete(); |
|
|
|
if ($orderContainer->getSolver()->belongsToUser($order, GlobalParam::getCurrentUser())) { |
|
|
|
$orderContainer->getBuilder()->delete($order); |
|
|
|
\Yii::$app->session->setFlash('success', 'Votre commande a bien été annulée.'); |
|
|
|
} |
|
|
|
|
|
|
|
$this->redirect(\Yii::$app->urlManager->createUrl(['order/history'])); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Page de confirmation de commande. |
|
|
|
*/ |
|
|
|
public function actionConfirm($idOrder, $returnPayment = '') |
|
|
|
{ |
|
|
|
$order = Order::searchOne(['id' => $idOrder]); |
|
|
|
$producer = $this->getProducer(); |
|
|
|
|
|
|
|
if (!$order || ($order->id_user != GlobalParam::getCurrentUserId() && !$producer->option_allow_order_guest)) { |
|
|
|
throw new \yii\base\UserException('Commande introuvable.'); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('confirm', [ |
|
|
|
'order' => $order, |
|
|
|
'returnPayment' => $returnPayment |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Vérifie le code saisi pour un point de vente. |
|
|
|
* |
|
|
|
* @param integer $idPointSale |
|
|
|
* @param string $code |
|
|
|
* @return boolean |
|
|
|
*/ |
|
|
|
public function actionAjaxValidateCodePointSale($idPointSale, $code) |
|
|
|
public function actionAjaxValidateCodePointSale(int $idPointSale, string $code) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
$pointSaleContainer = $this->getPointSaleContainer(); |
|
|
|
$pointSale = $pointSaleContainer->getRepostory()->getOneById($idPointSale); |
|
|
|
|
|
|
|
$pointSale = PointSale::findOne($idPointSale); |
|
|
|
if ($pointSale) { |
|
|
|
if ($pointSale->validateCode($code)) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if ($pointSale && $pointSaleContainer->getSolver()->validateCode($pointSale, $code)) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxInfos($date = '', $pointSaleId = 0) |
|
|
|
public function actionAjaxInfos(string $date = '', int $pointSaleId = 0) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
$user = GlobalParam::getCurrentUser(); |
|
|
|
$producer = $this->getProducer(); |
|
|
|
$pointSale = $this->getPointSaleContainer()->getRepository()->getOneById($pointSaleId); |
|
|
|
$order = $this->getOrderUser($date, $pointSale); |
|
|
|
|
|
|
|
return $this->buildJsonAjaxInfos($date, $producer, $pointSale, $user, $order); |
|
|
|
} |
|
|
|
|
|
|
|
public function buildJsonAjaxInfos( |
|
|
|
string $date, |
|
|
|
Producer $producer, |
|
|
|
PointSale $pointSale = null, |
|
|
|
User $user = null, |
|
|
|
Order $order = null |
|
|
|
) |
|
|
|
{ |
|
|
|
$json = []; |
|
|
|
|
|
|
|
$format = 'Y-m-d'; |
|
|
|
$dateObject = DateTime::createFromFormat($format, $date); |
|
|
|
|
|
|
|
$user = User::getCurrent(); |
|
|
|
$json['producer'] = $this->ajaxInfosProducer($producer); |
|
|
|
$json['distributions'] = $this->ajaxInfosDistributions($producer, $pointSale); |
|
|
|
$json['orders'] = $this->ajaxInfosOrders($producer); |
|
|
|
$json['user'] = $this->ajaxInfosUser($producer); |
|
|
|
$json['points_sale'] = $this->ajaxInfosPointsSale($producer); |
|
|
|
|
|
|
|
// PointSale current |
|
|
|
$pointSaleCurrent = PointSale::findOne($pointSaleId); |
|
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
|
$distribution = $this->getDistributionContainer()->getBuilder()->createIfNotExist($producer, $date); |
|
|
|
$json['distribution'] = $distribution; |
|
|
|
$json['points_sale'] = $this->ajaxInfosPointsSale($producer, $distribution); |
|
|
|
$json['categories'] = $this->ajaxInfosProductCategories($producer); |
|
|
|
$json['products'] = $this->ajaxInfosProducts($producer, $distribution, $pointSale, $user, $order); |
|
|
|
} |
|
|
|
|
|
|
|
// Commande de l'utilisateur |
|
|
|
$orderUser = $this->_getOrderUser($date, $pointSaleId); |
|
|
|
return $json; |
|
|
|
} |
|
|
|
|
|
|
|
// Producteur |
|
|
|
$producer = Producer::searchOne([ |
|
|
|
'id' => $this->getProducer()->id |
|
|
|
]); |
|
|
|
$json['producer'] = [ |
|
|
|
public function ajaxInfosProducer(Producer $producer) |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'order_infos' => $producer->order_infos, |
|
|
|
'credit' => $producer->credit, |
|
|
|
'credit_functioning' => $producer->credit_functioning, |
|
|
@@ -649,8 +662,10 @@ class OrderController extends ProducerBaseController |
|
|
|
'online_payment' => $producer->online_payment, |
|
|
|
'option_online_payment_type' => $producer->online_payment |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
// Distributions |
|
|
|
public function ajaxInfosDistributions(Producer $producer, PointSale $pointSaleCurrent = null) |
|
|
|
{ |
|
|
|
$dateMini = date('Y-m-d'); |
|
|
|
|
|
|
|
$distributionsArray = DistributionModel::searchAll([ |
|
|
@@ -684,12 +699,14 @@ class OrderController extends ProducerBaseController |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$json['distributions'] = $distributionsArrayFilterPointSale; |
|
|
|
return $distributionsArrayFilterPointSale; |
|
|
|
} else { |
|
|
|
$json['distributions'] = $distributionsArray; |
|
|
|
return $distributionsArray; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Commandes de l'utilisateur |
|
|
|
public function ajaxInfosOrders(Producer $producer): array |
|
|
|
{ |
|
|
|
$ordersUserArray = []; |
|
|
|
if (GlobalParam::getCurrentUserId() && !$producer->isOnlinePaymentActiveAndTypeOrder()) { |
|
|
|
$conditionsOrdersUser = [ |
|
|
@@ -720,10 +737,13 @@ class OrderController extends ProducerBaseController |
|
|
|
'pointSale' => $order->pointSale->getAttributes() |
|
|
|
]); |
|
|
|
} |
|
|
|
$json['orders'] = $ordersUserArray; |
|
|
|
} |
|
|
|
|
|
|
|
// User |
|
|
|
return $ordersUserArray; |
|
|
|
} |
|
|
|
|
|
|
|
public function ajaxInfosUser(Producer $producer) |
|
|
|
{ |
|
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
'id_producer' => $producer->id, |
|
|
|
'id_user' => GlobalParam::getCurrentUserId() |
|
|
@@ -733,167 +753,19 @@ class OrderController extends ProducerBaseController |
|
|
|
$userProducer = Producer::addUser($user->id, $producer->id); |
|
|
|
} |
|
|
|
|
|
|
|
$json['user'] = false; |
|
|
|
$jsonUser = false; |
|
|
|
if ($user && $userProducer) { |
|
|
|
$json['user'] = [ |
|
|
|
$jsonUser = [ |
|
|
|
'address' => $user->address, |
|
|
|
'credit' => $userProducer->credit, |
|
|
|
'credit_active' => $userProducer->credit_active, |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
|
// distribution |
|
|
|
$distribution = DistributionModel::initDistribution($date, $producer->id); |
|
|
|
$json['distribution'] = $distribution; |
|
|
|
|
|
|
|
// Points de vente |
|
|
|
$json['points_sale'] = $this->_initPointsSale($producer->id, $distribution); |
|
|
|
|
|
|
|
// Commandes totales |
|
|
|
$ordersArray = Order::searchAll([ |
|
|
|
'distribution.date' => $date, |
|
|
|
]); |
|
|
|
|
|
|
|
// Catégories |
|
|
|
$categoriesArray = ProductCategory::searchAll( |
|
|
|
[], |
|
|
|
[ |
|
|
|
'orderby' => 'product_category.position ASC', |
|
|
|
'as_array' => true |
|
|
|
] |
|
|
|
); |
|
|
|
$countProductsWithoutCategories = Product::searchCount([ |
|
|
|
'id_producer' => $this->getProducer()->id, |
|
|
|
'product.active' => 1, |
|
|
|
'product.id_product_category' => null |
|
|
|
]); |
|
|
|
if ($countProductsWithoutCategories) { |
|
|
|
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']); |
|
|
|
} |
|
|
|
$json['categories'] = $categoriesArray; |
|
|
|
|
|
|
|
// Produits |
|
|
|
$productsArray = Product::find() |
|
|
|
->where([ |
|
|
|
'id_producer' => $this->getProducer()->id, |
|
|
|
'product.active' => 1, |
|
|
|
]); |
|
|
|
|
|
|
|
$productsArray = $productsArray->joinWith([ |
|
|
|
'productDistribution' => function ($query) use ( |
|
|
|
$distribution |
|
|
|
) { |
|
|
|
$query->andOnCondition( |
|
|
|
'product_distribution.id_distribution = ' . $distribution->id |
|
|
|
); |
|
|
|
}, |
|
|
|
/*'productPointSale' => function ($query) use ($pointSaleCurrent) { |
|
|
|
$query->andOnCondition( |
|
|
|
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id |
|
|
|
); |
|
|
|
},*/ |
|
|
|
'productPrice' |
|
|
|
]) |
|
|
|
->orderBy('product_distribution.active DESC, order ASC') |
|
|
|
->all(); |
|
|
|
|
|
|
|
$productsArrayFilter = []; |
|
|
|
|
|
|
|
// filtre sur les points de vente |
|
|
|
foreach ($productsArray as $product) { |
|
|
|
if ($product->isAvailableOnPointSale($pointSaleCurrent)) { |
|
|
|
$productsArrayFilter[] = $product; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$indexProduct = 0; |
|
|
|
foreach ($productsArrayFilter as $key => &$product) { |
|
|
|
$product = array_merge( |
|
|
|
$product->getAttributes(), |
|
|
|
[ |
|
|
|
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], |
|
|
|
'prices' => $product->getPriceArray($user, $pointSaleCurrent), |
|
|
|
'productDistribution' => $product['productDistribution'], |
|
|
|
'productPointSale' => $product['productPointSale'], |
|
|
|
] |
|
|
|
); |
|
|
|
|
|
|
|
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient']; |
|
|
|
|
|
|
|
if (is_null($product['photo'])) { |
|
|
|
$product['photo'] = ''; |
|
|
|
} |
|
|
|
|
|
|
|
$product['quantity_max'] = $product['productDistribution'][0]['quantity_max']; |
|
|
|
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray); |
|
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder; |
|
|
|
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true); |
|
|
|
$product['wording_unit_ref'] = Product::strUnit($product['unit'], 'wording_short', true); |
|
|
|
|
|
|
|
if ($orderUser) { |
|
|
|
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true); |
|
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser; |
|
|
|
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; |
|
|
|
foreach ($orderUser->productOrder as $productOrder) { |
|
|
|
if ($productOrder->id_product == $product['id']) { |
|
|
|
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true); |
|
|
|
$product['step'] = $productOrder->step; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
$product['quantity_form'] = 0; |
|
|
|
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true); |
|
|
|
} |
|
|
|
$product['coefficient_unit'] = $coefficient_unit; |
|
|
|
|
|
|
|
if ($product['quantity_remaining'] < 0) { |
|
|
|
$product['quantity_remaining'] = 0; |
|
|
|
} |
|
|
|
$product['index'] = $indexProduct++; |
|
|
|
} |
|
|
|
|
|
|
|
$json['products'] = $productsArrayFilter; |
|
|
|
} else { |
|
|
|
$json['points_sale'] = $this->_initPointsSale($producer->id); |
|
|
|
} |
|
|
|
|
|
|
|
return $json; |
|
|
|
} |
|
|
|
|
|
|
|
private function _getOrderUser($date, $pointSaleId = false) |
|
|
|
{ |
|
|
|
$orderUser = false; |
|
|
|
if (GlobalParam::getCurrentUserId()) { |
|
|
|
$conditionOrderUser = [ |
|
|
|
'distribution.date' => $date, |
|
|
|
'id_user' => GlobalParam::getCurrentUserId(), |
|
|
|
]; |
|
|
|
|
|
|
|
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; |
|
|
|
return $jsonUser; |
|
|
|
} |
|
|
|
|
|
|
|
private function _initPointsSale($idProducer, $distribution = false) |
|
|
|
private function ajaxInfosPointsSale($idProducer, $distribution = false) |
|
|
|
{ |
|
|
|
$pointsSaleArray = PointSale::find(); |
|
|
|
|
|
|
@@ -983,20 +855,137 @@ class OrderController extends ProducerBaseController |
|
|
|
return $pointsSaleArray; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionConfirm($idOrder, $returnPayment = '') |
|
|
|
public function ajaxInfosProductCategories(Producer $producer) |
|
|
|
{ |
|
|
|
$order = Order::searchOne(['id' => $idOrder]); |
|
|
|
$producer = $this->getProducer(); |
|
|
|
$categoriesArray = $this->getProductCategoryContainer()->getRepository() |
|
|
|
->getAsArray(); |
|
|
|
$countProductsWithoutCategory = $this->getProductContainer()->getRepository() |
|
|
|
->countProductsWithoutCategory($producer); |
|
|
|
|
|
|
|
if (!$order || ($order->id_user != GlobalParam::getCurrentUserId() && !$producer->option_allow_order_guest)) { |
|
|
|
throw new \yii\base\UserException('Commande introuvable.'); |
|
|
|
if ($countProductsWithoutCategory) { |
|
|
|
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('confirm', [ |
|
|
|
'order' => $order, |
|
|
|
'returnPayment' => $returnPayment |
|
|
|
]); |
|
|
|
return $categoriesArray; |
|
|
|
} |
|
|
|
|
|
|
|
public function ajaxInfosProducts( |
|
|
|
Producer $producer, |
|
|
|
Distribution $distribution, |
|
|
|
PointSale $pointSale, |
|
|
|
User $user = null, |
|
|
|
Order $order = null |
|
|
|
) |
|
|
|
{ |
|
|
|
$ordersArray = $this->getOrderContainer()->getRepository()->getByDistribution($distribution); |
|
|
|
|
|
|
|
$productsArray = Product::find() |
|
|
|
->where([ |
|
|
|
'id_producer' => $producer->id, |
|
|
|
'product.active' => 1, |
|
|
|
]); |
|
|
|
|
|
|
|
$productsArray = $productsArray->joinWith([ |
|
|
|
'productDistribution' => function ($query) use ( |
|
|
|
$distribution |
|
|
|
) { |
|
|
|
$query->andOnCondition( |
|
|
|
'product_distribution.id_distribution = ' . $distribution->id |
|
|
|
); |
|
|
|
}, |
|
|
|
'productPrice' |
|
|
|
]) |
|
|
|
->orderBy('product_distribution.active DESC, order ASC') |
|
|
|
->all(); |
|
|
|
|
|
|
|
$productsArrayFilter = []; |
|
|
|
|
|
|
|
// filtre sur les points de vente |
|
|
|
foreach ($productsArray as $product) { |
|
|
|
if ($product->isAvailableOnPointSale($pointSale)) { |
|
|
|
$productsArrayFilter[] = $product; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$indexProduct = 0; |
|
|
|
foreach ($productsArrayFilter as $key => &$product) { |
|
|
|
$product = array_merge( |
|
|
|
$product->getAttributes(), |
|
|
|
[ |
|
|
|
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], |
|
|
|
'prices' => $product->getPriceArray($user, $pointSale), |
|
|
|
'productDistribution' => $product['productDistribution'], |
|
|
|
'productPointSale' => $product['productPointSale'], |
|
|
|
] |
|
|
|
); |
|
|
|
|
|
|
|
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient']; |
|
|
|
|
|
|
|
if (is_null($product['photo'])) { |
|
|
|
$product['photo'] = ''; |
|
|
|
} |
|
|
|
|
|
|
|
$product['quantity_max'] = $product['productDistribution'][0]['quantity_max']; |
|
|
|
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray); |
|
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder; |
|
|
|
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true); |
|
|
|
$product['wording_unit_ref'] = Product::strUnit($product['unit'], 'wording_short', true); |
|
|
|
|
|
|
|
if ($order) { |
|
|
|
$quantityOrderUser = Order::getProductQuantity($product['id'], [$order], true); |
|
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser; |
|
|
|
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; |
|
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
|
if ($productOrder->id_product == $product['id']) { |
|
|
|
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true); |
|
|
|
$product['step'] = $productOrder->step; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
$product['quantity_form'] = 0; |
|
|
|
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true); |
|
|
|
} |
|
|
|
$product['coefficient_unit'] = $coefficient_unit; |
|
|
|
|
|
|
|
if ($product['quantity_remaining'] < 0) { |
|
|
|
$product['quantity_remaining'] = 0; |
|
|
|
} |
|
|
|
$product['index'] = $indexProduct++; |
|
|
|
} |
|
|
|
|
|
|
|
return $productsArrayFilter; |
|
|
|
} |
|
|
|
|
|
|
|
private function getOrderUser(string $date, PointSale $pointSale = null) |
|
|
|
{ |
|
|
|
$orderUser = false; |
|
|
|
if (GlobalParam::getCurrentUserId()) { |
|
|
|
$conditionOrderUser = [ |
|
|
|
'distribution.date' => $date, |
|
|
|
'id_user' => GlobalParam::getCurrentUserId(), |
|
|
|
]; |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|