|
|
|
|
|
|
|
|
|
|
|
|
|
|
use common\helpers\GlobalParam; |
|
|
use common\helpers\GlobalParam; |
|
|
use common\helpers\Mailjet; |
|
|
use common\helpers\Mailjet; |
|
|
|
|
|
use common\helpers\Password; |
|
|
use common\logic\Distribution\Distribution\Distribution; |
|
|
use common\logic\Distribution\Distribution\Distribution; |
|
|
use common\logic\Order\Order\Order; |
|
|
use common\logic\Order\Order\Order; |
|
|
|
|
|
use common\logic\Order\ProductOrder\ProductOrder; |
|
|
use common\logic\PointSale\PointSale\PointSale; |
|
|
use common\logic\PointSale\PointSale\PointSale; |
|
|
use common\logic\Producer\Producer\Producer; |
|
|
use common\logic\Producer\Producer\Producer; |
|
|
|
|
|
use common\logic\Product\Product\Product; |
|
|
use common\logic\User\CreditHistory\CreditHistory; |
|
|
use common\logic\User\CreditHistory\CreditHistory; |
|
|
use common\logic\User\User\User; |
|
|
use common\logic\User\User\User; |
|
|
use common\logic\User\UserProducer\UserProducer; |
|
|
use common\logic\User\UserProducer\UserProducer; |
|
|
|
|
|
|
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$order = $this->getOrderManager()->findOneById($id); |
|
|
|
|
|
|
|
|
$order = $this->getOrderManager()->findOneOrderById($id); |
|
|
if ($order && $this->getOrderManager()->isOrderStateOpen($order)) { |
|
|
if ($order && $this->getOrderManager()->isOrderStateOpen($order)) { |
|
|
$params['order'] = $order; |
|
|
$params['order'] = $order; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionHistory($type = 'incoming') |
|
|
public function actionHistory($type = 'incoming') |
|
|
{ |
|
|
{ |
|
|
$queryHistoryArray = $this->getOrderManager() |
|
|
$queryHistoryArray = $this->getOrderManager() |
|
|
->queryHistory($this->getProducer(), $this->getUserCurrent(), $type); |
|
|
|
|
|
|
|
|
->queryOrdersHistory($this->getProducer(), $this->getUserCurrent(), $type); |
|
|
$queryHistoryIncoming = $queryHistoryArray['incoming']; |
|
|
$queryHistoryIncoming = $queryHistoryArray['incoming']; |
|
|
$queryHistoryPassed = $queryHistoryArray['passed']; |
|
|
$queryHistoryPassed = $queryHistoryArray['passed']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Supprime un producteur. |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionRemoveProducer(int $id = 0) |
|
|
public function actionRemoveProducer(int $id = 0) |
|
|
{ |
|
|
{ |
|
|
$producer = $this->getProducerContainer()->getRepository()->getOneById($id); |
|
|
|
|
|
|
|
|
$producer = $this->getProducerManager()->findOneProducerById($id); |
|
|
|
|
|
|
|
|
$this->getUserProducerContainer()->getBuilder()->updateActive( |
|
|
|
|
|
|
|
|
$this->getUserProducerManager()->updateActive( |
|
|
$this->getUserCurrent(), |
|
|
$this->getUserCurrent(), |
|
|
$producer, |
|
|
$producer, |
|
|
false |
|
|
false |
|
|
|
|
|
|
|
|
public function actionAjaxProcess() |
|
|
public function actionAjaxProcess() |
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
$posts = \Yii::$app->request->post(); |
|
|
|
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$producerManager = $this->getProducerManager(); |
|
|
$redirect = null; |
|
|
$redirect = null; |
|
|
$order = new Order; |
|
|
|
|
|
$producer = $this->getProducer(); |
|
|
$producer = $this->getProducer(); |
|
|
$idProducer = $producer->id; |
|
|
$idProducer = $producer->id; |
|
|
|
|
|
|
|
|
$posts = \Yii::$app->request->post(); |
|
|
|
|
|
|
|
|
$order = $orderManager->instanciateOrder(); |
|
|
|
|
|
|
|
|
if ($idProducer) { |
|
|
if ($idProducer) { |
|
|
$this->_verifyProducerActive($idProducer); |
|
|
$this->_verifyProducerActive($idProducer); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$order = new Order; |
|
|
$order = new Order; |
|
|
$order->load(Yii::$app->request->post()); |
|
|
|
|
|
|
|
|
$order->load(\Yii::$app->request->post()); |
|
|
$order->id_user = $user ? $user->id : null; |
|
|
$order->id_user = $user ? $user->id : null; |
|
|
$order->status = 'tmp-order'; |
|
|
$order->status = 'tmp-order'; |
|
|
$order->date = date('Y-m-d H:i:s'); |
|
|
$order->date = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
return ['status' => 'error', 'errors' => $errors]; |
|
|
return ['status' => 'error', 'errors' => $errors]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($producer->isOnlinePaymentActiveAndTypeOrder()) { |
|
|
|
|
|
$order = Order::searchOne([ |
|
|
|
|
|
'id' => $order->id |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($producerManager->isOnlinePaymentActiveAndTypeOrder($producer)) { |
|
|
|
|
|
$order = $orderManager->findOneOrderById($order->id); |
|
|
\Stripe\Stripe::setApiKey( |
|
|
\Stripe\Stripe::setApiKey( |
|
|
$producer->getPrivateKeyApiStripe() |
|
|
|
|
|
|
|
|
$producerManager->getPrivateKeyApiStripe($producer) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
$lineItems = []; |
|
|
$lineItems = []; |
|
|
|
|
|
|
|
|
'price_data' => [ |
|
|
'price_data' => [ |
|
|
'currency' => 'eur', |
|
|
'currency' => 'eur', |
|
|
'product_data' => [ |
|
|
'product_data' => [ |
|
|
'name' => $product->name . ' (' . $productOrder->quantity . ' ' . Product::strUnit( |
|
|
|
|
|
|
|
|
'name' => $product->name . ' (' . $productOrder->quantity . ' ' . $this->getProductManager()->strUnit( |
|
|
$product->unit, |
|
|
$product->unit, |
|
|
'wording_short', |
|
|
'wording_short', |
|
|
true |
|
|
true |
|
|
|
|
|
|
|
|
'order_id' => $order->id |
|
|
'order_id' => $order->id |
|
|
], |
|
|
], |
|
|
], |
|
|
], |
|
|
'success_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl( |
|
|
|
|
|
|
|
|
'success_url' => $this->getUrlManagerProducer()->createAbsoluteUrl( |
|
|
[ |
|
|
[ |
|
|
'order/confirm', |
|
|
'order/confirm', |
|
|
'idOrder' => $order->id, |
|
|
'idOrder' => $order->id, |
|
|
'returnPayment' => 'success' |
|
|
'returnPayment' => 'success' |
|
|
] |
|
|
] |
|
|
), |
|
|
), |
|
|
'cancel_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl( |
|
|
|
|
|
|
|
|
'cancel_url' => $this->getUrlManagerProducer()->createAbsoluteUrl( |
|
|
[ |
|
|
[ |
|
|
'order/confirm', |
|
|
'order/confirm', |
|
|
'idOrder' => $order->id, |
|
|
'idOrder' => $order->id, |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function _verifyProducerActive($idProducer) |
|
|
public function _verifyProducerActive($idProducer) |
|
|
{ |
|
|
{ |
|
|
$producer = Producer::findOne($idProducer); |
|
|
|
|
|
|
|
|
$producer = $this->getProducerManager()->findOneProducerById($idProducer); |
|
|
if ($producer && !$producer->active) { |
|
|
if ($producer && !$producer->active) { |
|
|
throw new NotFoundHttpException('Ce producteur est actuellement hors ligne.'); |
|
|
throw new NotFoundHttpException('Ce producteur est actuellement hors ligne.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function processForm($order, $user) |
|
|
public function processForm($order, $user) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$pointSaleDistributionManager = $this->getPointSaleDistributionManager(); |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
$userPointSaleManager = $this->getUserPointSaleManager(); |
|
|
|
|
|
$userProducerManager = $this->getUserProducerManager(); |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$producerManager = $this->getProducerManager(); |
|
|
|
|
|
$productOrderManager = $this->getProductOrderManager(); |
|
|
|
|
|
$userManager = $this->getUserManager(); |
|
|
|
|
|
$creditHistoryManager = $this->getCreditHistoryManager(); |
|
|
|
|
|
|
|
|
$posts = \Yii::$app->request->post(); |
|
|
$posts = \Yii::$app->request->post(); |
|
|
$productsArray = []; |
|
|
$productsArray = []; |
|
|
$totalQuantity = 0; |
|
|
$totalQuantity = 0; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach ($posts['products'] as $key => $quantity) { |
|
|
foreach ($posts['products'] as $key => $quantity) { |
|
|
$product = Product::find()->where(['id' => (int)$key])->one(); |
|
|
|
|
|
|
|
|
$product = $productManager->findOneProductById((int)$key); |
|
|
|
|
|
|
|
|
$totalQuantity += $quantity; |
|
|
$totalQuantity += $quantity; |
|
|
if ($product && $quantity) { |
|
|
if ($product && $quantity) { |
|
|
$productsArray[] = $product; |
|
|
$productsArray[] = $product; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// date |
|
|
|
|
|
$errorDate = false; |
|
|
$errorDate = false; |
|
|
if (isset($order->id_distribution)) { |
|
|
if (isset($order->id_distribution)) { |
|
|
// date de commande |
|
|
|
|
|
$distribution = DistributionModel::find()->where(['id' => $order->id_distribution])->one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$distribution = $distributionManager->findOneDistributionById($order->id_distribution); |
|
|
if ($order->getState() != Order::STATE_OPEN) { |
|
|
if ($order->getState() != Order::STATE_OPEN) { |
|
|
$errorDate = true; |
|
|
$errorDate = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// point de vente |
|
|
|
|
|
$errorPointSale = false; |
|
|
$errorPointSale = false; |
|
|
if (isset($distribution) && $distribution) { |
|
|
if (isset($distribution) && $distribution) { |
|
|
$pointSaleDistribution = PointSaleDistributionModel::searchOne([ |
|
|
|
|
|
'id_distribution' => $distribution->id, |
|
|
|
|
|
'id_point_sale' => $posts['Order']['id_point_sale'] |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$pointSale = $pointSaleManager->findOnePointSaleById($posts['Order']['id_point_sale']); |
|
|
|
|
|
$pointSaleDistribution = $pointSaleDistributionManager->findOnePointSaleDistribution($distribution, $pointSale); |
|
|
|
|
|
|
|
|
if (!$pointSaleDistribution || !$pointSaleDistribution->delivery) { |
|
|
if (!$pointSaleDistribution || !$pointSaleDistribution->delivery) { |
|
|
$errorPointSale = true; |
|
|
$errorPointSale = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$pointSale = PointSale::findOne($posts['Order']['id_point_sale']); |
|
|
|
|
|
|
|
|
|
|
|
if ($pointSale) { |
|
|
if ($pointSale) { |
|
|
if (strlen($pointSale->code) && !$pointSale->validateCode($posts['code_point_sale'])) { |
|
|
|
|
|
|
|
|
if (strlen($pointSale->code) && !$pointSaleManager->validateCode($pointSale, $posts['code_point_sale'])) { |
|
|
$errorPointSale = true; |
|
|
$errorPointSale = true; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$errorPointSale = true; |
|
|
$errorPointSale = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$userPointSale = UserPointSale::searchOne([ |
|
|
|
|
|
'id_user' => GlobalParam::getCurrentUserId(), |
|
|
|
|
|
'id_point_sale' => $pointSale->id |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userPointSale = $userPointSaleManager->findOneUserPointSale(GlobalParam::getCurrentUser(), $pointSale); |
|
|
if ($pointSale->restricted_access && !$userPointSale) { |
|
|
if ($pointSale->restricted_access && !$userPointSale) { |
|
|
$errorPointSale = true; |
|
|
$errorPointSale = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$errors = []; |
|
|
$errors = []; |
|
|
|
|
|
|
|
|
if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) { |
|
|
if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) { |
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
|
|
'id_producer' => $order->distribution->id_producer, |
|
|
|
|
|
'id_user' => $user->id |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
// gestion point de vente |
|
|
|
|
|
$pointSale = PointSale::searchOne([ |
|
|
|
|
|
'id' => $order->id_point_sale |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$userProducer = $userProducerManager->findOneUserProducer($user, $producer); |
|
|
|
|
|
$pointSale = $pointSaleManager->findOnePointSaleById($order->id_point_sale); |
|
|
|
|
|
|
|
|
// commentaire point de vente |
|
|
// commentaire point de vente |
|
|
$order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ? |
|
|
$order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ? |
|
|
|
|
|
|
|
|
// sauvegarde de la commande |
|
|
// sauvegarde de la commande |
|
|
$order->save(); |
|
|
$order->save(); |
|
|
|
|
|
|
|
|
$order->initReference(); |
|
|
|
|
|
|
|
|
|
|
|
$order->changeOrderStatus('new-order', 'user'); |
|
|
|
|
|
|
|
|
|
|
|
// ajout de l'utilisateur à l'établissement |
|
|
|
|
|
Producer::addUser($user->id, $distribution->id_producer); |
|
|
|
|
|
|
|
|
$orderManager->generateOrderReference($order); |
|
|
|
|
|
$orderManager->changeOrderStatus($order, 'new-order', 'user'); |
|
|
|
|
|
$producerManager->addUser($user, $producer); |
|
|
|
|
|
|
|
|
// suppression de tous les enregistrements ProductOrder |
|
|
// suppression de tous les enregistrements ProductOrder |
|
|
if (!is_null($order)) { |
|
|
if (!is_null($order)) { |
|
|
ProductOrder::deleteAll(['id_order' => $order->id]); |
|
|
|
|
|
|
|
|
$productOrderManager->deleteProductOrdersByOrder($order); |
|
|
|
|
|
|
|
|
$stepsArray = []; |
|
|
|
|
|
if (isset($order->productOrder)) { |
|
|
if (isset($order->productOrder)) { |
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
$unitsArray[$productOrder->id_product] = $productOrder->unit; |
|
|
$unitsArray[$productOrder->id_product] = $productOrder->unit; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// produits dispos |
|
|
|
|
|
$availableProducts = ProductDistributionModel::searchByDistribution($distribution->id); |
|
|
|
|
|
|
|
|
|
|
|
// sauvegarde des produits |
|
|
|
|
|
|
|
|
$availableProducts = $productManager->findProductsByDistribution($distribution); |
|
|
foreach ($productsArray as $product) { |
|
|
foreach ($productsArray as $product) { |
|
|
if (isset($availableProducts[$product->id])) { |
|
|
if (isset($availableProducts[$product->id])) { |
|
|
$productOrder = new ProductOrder(); |
|
|
$productOrder = new ProductOrder(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
$productOrder->quantity = $quantity; |
|
|
$productOrder->quantity = $quantity; |
|
|
$productOrder->price = $product->getPrice([ |
|
|
$productOrder->price = $product->getPrice([ |
|
|
'user' => User::getCurrent(), |
|
|
|
|
|
|
|
|
'user' => GlobalParam::getCurrentUser(), |
|
|
'user_producer' => $userProducer, |
|
|
'user_producer' => $userProducer, |
|
|
'point_sale' => $pointSale, |
|
|
'point_sale' => $pointSale, |
|
|
'quantity' => $quantity |
|
|
'quantity' => $quantity |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// lien utilisateur / point de vente |
|
|
// lien utilisateur / point de vente |
|
|
$pointSale->linkUser($user->id); |
|
|
|
|
|
|
|
|
$pointSaleManager->addUser($user, $pointSale); |
|
|
|
|
|
|
|
|
// credit |
|
|
// credit |
|
|
$credit = Producer::getConfig('credit'); |
|
|
|
|
|
$creditLimit = Producer::getConfig('credit_limit'); |
|
|
|
|
|
$creditFunctioning = $pointSale->getCreditFunctioning(); |
|
|
|
|
|
$creditUser = $user->getCredit($distribution->id_producer); |
|
|
|
|
|
$order = Order::searchOne([ |
|
|
|
|
|
'id' => $order->id |
|
|
|
|
|
]); |
|
|
|
|
|
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); |
|
|
|
|
|
$amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING); |
|
|
|
|
|
|
|
|
$credit = $producerManager->getConfig('credit'); |
|
|
|
|
|
$creditLimit = $producerManager->getConfig('credit_limit'); |
|
|
|
|
|
$creditFunctioning = $pointSaleManager->getPointSaleCreditFunctioning($pointSale); |
|
|
|
|
|
$creditUser = $userManager->getCredit($user, $producer); |
|
|
|
|
|
$order = $orderManager->findOneOrderById($order->id); |
|
|
|
|
|
$amountRemaining = $orderManager->getAmount($order, Order::AMOUNT_REMAINING); |
|
|
|
|
|
|
|
|
if ($credit && $pointSale->credit && |
|
|
if ($credit && $pointSale->credit && |
|
|
(($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) || |
|
|
(($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) || |
|
|
$creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY || |
|
|
$creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY || |
|
|
($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active) |
|
|
($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active) |
|
|
)) { |
|
|
)) { |
|
|
$order->changeOrderStatus('waiting-paiement-by-credit', 'user'); |
|
|
|
|
|
|
|
|
$orderManager->changeOrderStatus($order, 'waiting-paiement-by-credit', 'user'); |
|
|
|
|
|
|
|
|
// à payer |
|
|
// à payer |
|
|
if ($order->getPaymentStatus() == Order::PAYMENT_UNPAID) { |
|
|
|
|
|
|
|
|
if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) { |
|
|
if (!is_null($creditLimit) && $amountRemaining > $creditUser - $creditLimit) { |
|
|
if (!is_null($creditLimit) && $amountRemaining > $creditUser - $creditLimit) { |
|
|
$amountRemaining = $creditUser - $creditLimit; |
|
|
$amountRemaining = $creditUser - $creditLimit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($amountRemaining > 0) { |
|
|
if ($amountRemaining > 0) { |
|
|
$order->saveCreditHistory( |
|
|
|
|
|
|
|
|
$creditHistoryManager->createCreditHistory( |
|
|
CreditHistory::TYPE_PAYMENT, |
|
|
CreditHistory::TYPE_PAYMENT, |
|
|
$amountRemaining, |
|
|
$amountRemaining, |
|
|
$distribution->id_producer, |
|
|
|
|
|
GlobalParam::getCurrentUserId(), |
|
|
|
|
|
GlobalParam::getCurrentUserId() |
|
|
|
|
|
|
|
|
$producer, |
|
|
|
|
|
GlobalParam::getCurrentUser(), |
|
|
|
|
|
GlobalParam::getCurrentUser() |
|
|
); |
|
|
); |
|
|
$order->changeOrderStatus('paid-by-credit', 'user'); |
|
|
|
|
|
|
|
|
$orderManager->changeOrderStatus($order, 'paid-by-credit', 'user'); |
|
|
} else { |
|
|
} else { |
|
|
$order->changeOrderStatus('waiting-paiement-on-delivery', 'user'); |
|
|
|
|
|
|
|
|
$orderManager->changeOrderStatus($order, 'waiting-paiement-on-delivery', 'user'); |
|
|
} |
|
|
} |
|
|
} // surplus à rembourser |
|
|
} // surplus à rembourser |
|
|
elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) { |
|
|
elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) { |
|
|
$amountSurplus = $order->getAmount(Order::AMOUNT_SURPLUS); |
|
|
|
|
|
$order->saveCreditHistory( |
|
|
|
|
|
|
|
|
$amountSurplus = $orderManager->getAmount($order, Order::AMOUNT_SURPLUS); |
|
|
|
|
|
$creditHistoryManager->createCreditHistory( |
|
|
CreditHistory::TYPE_REFUND, |
|
|
CreditHistory::TYPE_REFUND, |
|
|
$amountSurplus, |
|
|
$amountSurplus, |
|
|
$distribution->id_producer, |
|
|
|
|
|
GlobalParam::getCurrentUserId(), |
|
|
|
|
|
GlobalParam::getCurrentUserId() |
|
|
|
|
|
|
|
|
$producer, |
|
|
|
|
|
GlobalParam::getCurrentUser(), |
|
|
|
|
|
GlobalParam::getCurrentUser() |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$order->changeOrderStatus('waiting-paiement-on-delivery', 'user'); |
|
|
|
|
|
|
|
|
$orderManager->changeOrderStatus($order, 'waiting-paiement-on-delivery', 'user'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$paramsEmail = [ |
|
|
$paramsEmail = [ |
|
|
'from_email' => $producer->getEmailOpendistrib(), |
|
|
|
|
|
|
|
|
'from_email' => $producerManager->getEmailOpendistrib($producer), |
|
|
'from_name' => $producer->name, |
|
|
'from_name' => $producer->name, |
|
|
'to_email' => $user->email, |
|
|
'to_email' => $user->email, |
|
|
'to_name' => $user->getUsername(), |
|
|
|
|
|
|
|
|
'to_name' => $userManager->getUsername($user), |
|
|
'subject' => '[' . $producer->name . '] Confirmation de commande', |
|
|
'subject' => '[' . $producer->name . '] Confirmation de commande', |
|
|
'content_view_text' => '@common/mail/orderConfirm-text.php', |
|
|
'content_view_text' => '@common/mail/orderConfirm-text.php', |
|
|
'content_view_html' => '@common/mail/orderConfirm-html.php', |
|
|
'content_view_html' => '@common/mail/orderConfirm-html.php', |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
if ($isNewOrder) { |
|
|
if ($isNewOrder) { |
|
|
// au client |
|
|
// au client |
|
|
if (Producer::getConfig('option_email_confirm')) { |
|
|
|
|
|
|
|
|
if ($producerManager->getConfig('option_email_confirm')) { |
|
|
Mailjet::sendMail($paramsEmail); |
|
|
Mailjet::sendMail($paramsEmail); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// au producteur |
|
|
// au producteur |
|
|
$contactProducer = $producer->getMainContact(); |
|
|
|
|
|
if (Producer::getConfig('option_email_confirm_producer') && $contactProducer && strlen( |
|
|
|
|
|
|
|
|
$contactProducer = $producerManager->getMainContact($producer); |
|
|
|
|
|
if ($producerManager->getConfig('option_email_confirm_producer') && $contactProducer && strlen( |
|
|
$contactProducer->email |
|
|
$contactProducer->email |
|
|
)) { |
|
|
)) { |
|
|
$paramsEmail['to_email'] = $contactProducer->email; |
|
|
$paramsEmail['to_email'] = $contactProducer->email; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$order->setTillerSynchronization(); |
|
|
|
|
|
|
|
|
$orderManager->setTillerSynchronization($order); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionCancel(int $id) |
|
|
public function actionCancel(int $id) |
|
|
{ |
|
|
{ |
|
|
$order = $this->getOrderManager()->findOneById($id); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$order = $this->getOrderManager()->findOneOrderById($id); |
|
|
|
|
|
|
|
|
if (!$order) { |
|
|
if (!$order) { |
|
|
throw new \yii\web\NotFoundHttpException('Commande introuvable'); |
|
|
throw new \yii\web\NotFoundHttpException('Commande introuvable'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($this->getOrderManager()->isOrderStateOpen($order)) { |
|
|
|
|
|
|
|
|
if ($orderManager->isOrderStateOpen($order)) { |
|
|
throw new UserException('Vous ne pouvez plus annuler cette commande.'); |
|
|
throw new UserException('Vous ne pouvez plus annuler cette commande.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($this->getOrderManager()->isOrderbelongsToUser($order, GlobalParam::getCurrentUser())) { |
|
|
|
|
|
$orderContainer->getBuilder()->delete($order); |
|
|
|
|
|
\Yii::$app->session->setFlash('success', 'Votre commande a bien été annulée.'); |
|
|
|
|
|
|
|
|
if ($orderManager->isOrderbelongsToUser($order, GlobalParam::getCurrentUser())) { |
|
|
|
|
|
$orderManager->deleteOrder($order); |
|
|
|
|
|
$this->setFlash('success', 'Votre commande a bien été annulée.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->redirect(\Yii::$app->urlManager->createUrl(['order/history'])); |
|
|
|
|
|
|
|
|
return $this->redirect($this->getUrlManagerProducer()->createUrl(['order/history'])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionConfirm(int $idOrder, string $returnPayment = '') |
|
|
public function actionConfirm(int $idOrder, string $returnPayment = '') |
|
|
{ |
|
|
{ |
|
|
$order = $this->getOrderManager()->findOneById($idOrder); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
$producer = $this->getProducer(); |
|
|
$producer = $this->getProducer(); |
|
|
|
|
|
|
|
|
if (!$order || (!$this->getOrderManager()->isOrderBelongsToUser($order, GlobalParam::getCurrentUser()) && !$producer->option_allow_order_guest)) { |
|
|
|
|
|
|
|
|
if (!$order || (!$orderManager->isOrderBelongsToUser($order, GlobalParam::getCurrentUser()) && !$producer->option_allow_order_guest)) { |
|
|
throw new \yii\base\UserException('Commande introuvable.'); |
|
|
throw new \yii\base\UserException('Commande introuvable.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function actionAjaxValidateCodePointSale(int $idPointSale, string $code) |
|
|
public function actionAjaxValidateCodePointSale(int $idPointSale, string $code) |
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
$pointSaleContainer = $this->getPointSaleContainer(); |
|
|
|
|
|
$pointSale = $pointSaleContainer->getRepository()->getOneById($idPointSale); |
|
|
|
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale); |
|
|
|
|
|
|
|
|
if ($pointSale && $pointSaleContainer->getSolver()->validateCode($pointSale, $code)) { |
|
|
|
|
|
|
|
|
if ($pointSale && $pointSaleManager->validateCode($pointSale, $code)) { |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
$user = GlobalParam::getCurrentUser(); |
|
|
$user = GlobalParam::getCurrentUser(); |
|
|
$producer = $this->getProducer(); |
|
|
$producer = $this->getProducer(); |
|
|
$pointSale = $this->getPointSaleContainer()->getRepository()->getOneById($pointSaleId); |
|
|
|
|
|
|
|
|
$pointSale = $this->getPointSaleManager()->findOnePointSaleById($pointSaleId); |
|
|
$order = $this->getOrderUser($date, $pointSale); |
|
|
$order = $this->getOrderUser($date, $pointSale); |
|
|
|
|
|
|
|
|
return $this->buildJsonAjaxInfos($date, $producer, $pointSale, $user, $order); |
|
|
return $this->buildJsonAjaxInfos($date, $producer, $pointSale, $user, $order); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function ajaxInfosDistributions(Producer $producer, PointSale $pointSaleCurrent = null) |
|
|
public function ajaxInfosDistributions(Producer $producer, PointSale $pointSaleCurrent = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
$dateMini = date('Y-m-d'); |
|
|
$dateMini = date('Y-m-d'); |
|
|
|
|
|
|
|
|
$distributionsArray = DistributionModel::searchAll([ |
|
|
|
|
|
|
|
|
$distributionsArray = Distribution::searchAll([ |
|
|
'active' => 1, |
|
|
'active' => 1, |
|
|
'id_producer' => $producer->id |
|
|
'id_producer' => $producer->id |
|
|
], [ |
|
|
], [ |
|
|
|
|
|
|
|
|
'params' => [':date' => $dateMini], |
|
|
'params' => [':date' => $dateMini], |
|
|
'join_with' => ['pointSaleDistribution'], |
|
|
'join_with' => ['pointSaleDistribution'], |
|
|
]); |
|
|
]); |
|
|
$distributionsArray = DistributionModel::filterDistributionsByDateDelay($distributionsArray); |
|
|
|
|
|
|
|
|
$distributionsArray = $distributionManager->filterDistributionsByDateDelay($distributionsArray); |
|
|
|
|
|
|
|
|
// Filtre par point de vente |
|
|
// Filtre par point de vente |
|
|
if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { |
|
|
|
|
|
|
|
|
if ($pointSaleCurrent && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { |
|
|
$distributionsArrayFilterPointSale = []; |
|
|
$distributionsArrayFilterPointSale = []; |
|
|
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)) { |
|
|
|
|
|
$countOrders = (int)Order::searchCount([ |
|
|
|
|
|
|
|
|
if ($distributionManager->isPointSaleActive($distribution, $pointSaleCurrent)) { |
|
|
|
|
|
$countOrders = Order::searchCount([ |
|
|
'id_distribution' => $distribution->id, |
|
|
'id_distribution' => $distribution->id, |
|
|
'id_point_sale' => $pointSaleId |
|
|
|
|
|
|
|
|
'id_point_sale' => $pointSaleCurrent->id |
|
|
]); |
|
|
]); |
|
|
$orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId); |
|
|
$orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function ajaxInfosOrders(Producer $producer): array |
|
|
|
|
|
|
|
|
public function ajaxInfosOrders(Producer $producer, PointSale $pointSaleCurrent = null): array |
|
|
{ |
|
|
{ |
|
|
|
|
|
$producerManager = $this->getProducerManager(); |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
|
|
|
|
|
|
$dateMini = date('Y-m-d'); |
|
|
$ordersUserArray = []; |
|
|
$ordersUserArray = []; |
|
|
if (GlobalParam::getCurrentUserId() && !$producer->isOnlinePaymentActiveAndTypeOrder()) { |
|
|
|
|
|
|
|
|
if (GlobalParam::getCurrentUserId() && !$producerManager->isOnlinePaymentActiveAndTypeOrder($producer)) { |
|
|
$conditionsOrdersUser = [ |
|
|
$conditionsOrdersUser = [ |
|
|
'distribution.date > :date' |
|
|
'distribution.date > :date' |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
':date' => $dateMini |
|
|
':date' => $dateMini |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { |
|
|
|
|
|
|
|
|
if ($pointSaleCurrent && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { |
|
|
$conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale'; |
|
|
$conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale'; |
|
|
$paramsOrdersUser[':id_point_sale'] = $pointSaleId; |
|
|
|
|
|
|
|
|
$paramsOrdersUser[':id_point_sale'] = $pointSaleCurrent->id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$ordersUserArray = Order::searchAll([ |
|
|
$ordersUserArray = Order::searchAll([ |
|
|
|
|
|
|
|
|
if (is_array($ordersUserArray) && count($ordersUserArray)) { |
|
|
if (is_array($ordersUserArray) && count($ordersUserArray)) { |
|
|
foreach ($ordersUserArray as &$order) { |
|
|
foreach ($ordersUserArray as &$order) { |
|
|
$order = array_merge($order->getAttributes(), [ |
|
|
$order = array_merge($order->getAttributes(), [ |
|
|
'amount_total' => $order->getAmountWithTax(Order::AMOUNT_TOTAL), |
|
|
|
|
|
|
|
|
'amount_total' => $orderManager->getAmountWithTax($order, Order::AMOUNT_TOTAL), |
|
|
'date_distribution' => $order->distribution->date, |
|
|
'date_distribution' => $order->distribution->date, |
|
|
'pointSale' => $order->pointSale->getAttributes() |
|
|
'pointSale' => $order->pointSale->getAttributes() |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function ajaxInfosUser(Producer $producer) |
|
|
public function ajaxInfosUser(Producer $producer) |
|
|
{ |
|
|
{ |
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
|
|
'id_producer' => $producer->id, |
|
|
|
|
|
'id_user' => GlobalParam::getCurrentUserId() |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$userProducerManager = $this->getUserProducerManager(); |
|
|
|
|
|
$producerManager = $this->getProducerManager(); |
|
|
|
|
|
|
|
|
|
|
|
$user = GlobalParam::getCurrentUser(); |
|
|
|
|
|
$userProducer = $userProducerManager->findOneUserProducer($user, $producer); |
|
|
|
|
|
|
|
|
if ($user && !$userProducer) { |
|
|
if ($user && !$userProducer) { |
|
|
$userProducer = Producer::addUser($user->id, $producer->id); |
|
|
|
|
|
|
|
|
$userProducer = $producerManager->addUser($user, $producer); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$jsonUser = false; |
|
|
$jsonUser = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function ajaxInfosPointsSale($idProducer, $distribution = false) |
|
|
private function ajaxInfosPointsSale($idProducer, $distribution = false) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$userManager = $this->getUserManager(); |
|
|
|
|
|
$producerManager = $this->getProducerManager(); |
|
|
|
|
|
|
|
|
|
|
|
$user = GlobalParam::getCurrentUser(); |
|
|
$pointsSaleArray = PointSale::find(); |
|
|
$pointsSaleArray = PointSale::find(); |
|
|
|
|
|
|
|
|
if ($distribution) { |
|
|
if ($distribution) { |
|
|
|
|
|
|
|
|
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC') |
|
|
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC') |
|
|
->all(); |
|
|
->all(); |
|
|
|
|
|
|
|
|
$creditFunctioningProducer = Producer::getConfig('credit_functioning'); |
|
|
|
|
|
|
|
|
$creditFunctioningProducer = $producerManager->getConfig('credit_functioning'); |
|
|
$position = 0; |
|
|
$position = 0; |
|
|
|
|
|
|
|
|
foreach ($pointsSaleArray as &$pointSale) { |
|
|
foreach ($pointsSaleArray as &$pointSale) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$favoritePointSale = false; |
|
|
$favoritePointSale = false; |
|
|
if (User::getCurrent()) { |
|
|
|
|
|
$favoritePointSale = User::getCurrent()->getFavoritePointSale(); |
|
|
|
|
|
|
|
|
if ($user) { |
|
|
|
|
|
$favoritePointSale = $userManager->getUserFavoritePointSale($user); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($favoritePointSale) { |
|
|
if ($favoritePointSale) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function ajaxInfosProductCategories(Producer $producer) |
|
|
public function ajaxInfosProductCategories(Producer $producer) |
|
|
{ |
|
|
{ |
|
|
$categoriesArray = $this->getProductCategoryContainer()->getRepository() |
|
|
|
|
|
->getAsArray(); |
|
|
|
|
|
$countProductsWithoutCategory = $this->getProductContainer()->getRepository() |
|
|
|
|
|
->countProductsWithoutCategory($producer); |
|
|
|
|
|
|
|
|
$categoriesArray = $this->getProductCategoryManager()->findProductCategoriesAsArray(); |
|
|
|
|
|
$countProductsWithoutCategory = $this->getProductManager()->countProductsWithoutCategory($producer); |
|
|
|
|
|
|
|
|
if ($countProductsWithoutCategory) { |
|
|
if ($countProductsWithoutCategory) { |
|
|
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']); |
|
|
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']); |
|
|
|
|
|
|
|
|
Order $order = null |
|
|
Order $order = null |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
$ordersArray = $this->getOrderManager()->findByDistribution($distribution); |
|
|
|
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$ordersArray = $this->getOrderManager()->findOrdersByDistribution($distribution); |
|
|
|
|
|
|
|
|
$productsArray = Product::find() |
|
|
$productsArray = Product::find() |
|
|
->where([ |
|
|
->where([ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// filtre sur les points de vente |
|
|
// filtre sur les points de vente |
|
|
foreach ($productsArray as $product) { |
|
|
foreach ($productsArray as $product) { |
|
|
if ($product->isAvailableOnPointSale($pointSale)) { |
|
|
|
|
|
|
|
|
if ($productManager->isAvailableOnPointSale($product, $pointSale)) { |
|
|
$productsArrayFilter[] = $product; |
|
|
$productsArrayFilter[] = $product; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$indexProduct = 0; |
|
|
$indexProduct = 0; |
|
|
foreach ($productsArrayFilter as $key => &$product) { |
|
|
foreach ($productsArrayFilter as $key => &$product) { |
|
|
|
|
|
$productObject = $product; |
|
|
$product = array_merge( |
|
|
$product = array_merge( |
|
|
$product->getAttributes(), |
|
|
$product->getAttributes(), |
|
|
[ |
|
|
[ |
|
|
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], |
|
|
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], |
|
|
'prices' => $product->getPriceArray($user, $pointSale), |
|
|
|
|
|
|
|
|
'prices' => $productManager->getPriceArray($product, $user, $pointSale), |
|
|
'productDistribution' => $product['productDistribution'], |
|
|
'productDistribution' => $product['productDistribution'], |
|
|
'productPointSale' => $product['productPointSale'], |
|
|
'productPointSale' => $product['productPointSale'], |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$product['quantity_max'] = $product['productDistribution'][0]['quantity_max']; |
|
|
$product['quantity_max'] = $product['productDistribution'][0]['quantity_max']; |
|
|
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray); |
|
|
|
|
|
|
|
|
$quantityOrder = $orderManager->getProductQuantity($productObject, $ordersArray); |
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $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); |
|
|
|
|
|
|
|
|
$product['wording_unit'] = $productManager->strUnit($product['unit'], 'wording_unit', true); |
|
|
|
|
|
$product['wording_unit_ref'] = $productManager->strUnit($product['unit'], 'wording_short', true); |
|
|
|
|
|
|
|
|
if ($order) { |
|
|
if ($order) { |
|
|
$quantityOrderUser = Order::getProductQuantity($product['id'], [$order], true); |
|
|
|
|
|
|
|
|
$quantityOrderUser = $orderManager->getProductQuantity($productObject, [$order], true); |
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
$product['quantity_ordered'] = $quantityOrder; |
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser; |
|
|
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser; |
|
|
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; |
|
|
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit; |
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
if ($productOrder->id_product == $product['id']) { |
|
|
if ($productOrder->id_product == $product['id']) { |
|
|
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true); |
|
|
|
|
|
|
|
|
$product['wording_unit'] = $productManager->strUnit($productOrder->unit, 'wording_unit', true); |
|
|
$product['step'] = $productOrder->step; |
|
|
$product['step'] = $productOrder->step; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$product['quantity_form'] = 0; |
|
|
$product['quantity_form'] = 0; |
|
|
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true); |
|
|
|
|
|
|
|
|
$product['wording_unit'] = $productManager->strUnit($product['unit'], 'wording_unit', true); |
|
|
} |
|
|
} |
|
|
$product['coefficient_unit'] = $coefficient_unit; |
|
|
$product['coefficient_unit'] = $coefficient_unit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function getOrderUser(string $date, PointSale $pointSale = null) |
|
|
private function getOrderUser(string $date, PointSale $pointSale = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
|
|
|
$orderUser = false; |
|
|
$orderUser = false; |
|
|
if (GlobalParam::getCurrentUserId()) { |
|
|
if (GlobalParam::getCurrentUserId()) { |
|
|
$conditionOrderUser = [ |
|
|
$conditionOrderUser = [ |
|
|
|
|
|
|
|
|
'id_user' => GlobalParam::getCurrentUserId(), |
|
|
'id_user' => GlobalParam::getCurrentUserId(), |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
if ($pointSaleId) { |
|
|
|
|
|
$conditionOrderUser['id_point_sale'] = $pointSaleId; |
|
|
|
|
|
|
|
|
if ($pointSale) { |
|
|
|
|
|
$conditionOrderUser['id_point_sale'] = $pointSale; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$orderUser = Order::searchOne($conditionOrderUser); |
|
|
$orderUser = Order::searchOne($conditionOrderUser); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($orderUser) { |
|
|
if ($orderUser) { |
|
|
$json['order'] = array_merge($orderUser->getAttributes(), [ |
|
|
$json['order'] = array_merge($orderUser->getAttributes(), [ |
|
|
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL), |
|
|
|
|
|
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID), |
|
|
|
|
|
|
|
|
'amount_total' => $orderManager->getAmountWithTax($orderUser, Order::AMOUNT_TOTAL), |
|
|
|
|
|
'amount_paid' => $orderManager->getAmount($orderUser, Order::AMOUNT_PAID), |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|