|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace backend\controllers; |
|
|
namespace backend\controllers; |
|
|
|
|
|
|
|
|
|
|
|
use common\forms\SubscriptionForm; |
|
|
|
|
|
use common\helpers\CSV; |
|
|
use common\helpers\GlobalParam; |
|
|
use common\helpers\GlobalParam; |
|
|
|
|
|
use common\logic\Distribution\Distribution\Distribution; |
|
|
|
|
|
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; |
|
|
|
|
|
use common\logic\Distribution\ProductDistribution\ProductDistribution; |
|
|
|
|
|
use common\logic\Order\Order\Order; |
|
|
|
|
|
use common\logic\Order\ProductOrder\ProductOrder; |
|
|
|
|
|
use common\logic\PointSale\PointSale\PointSale; |
|
|
|
|
|
use common\logic\Product\Product\Product; |
|
|
|
|
|
use common\logic\User\CreditHistory\CreditHistory; |
|
|
|
|
|
use common\logic\User\User\User; |
|
|
|
|
|
use common\logic\User\UserProducer\UserProducer; |
|
|
|
|
|
use yii\filters\AccessControl; |
|
|
|
|
|
use yii\helpers\Html; |
|
|
|
|
|
|
|
|
class OrderController extends BackendController |
|
|
class OrderController extends BackendController |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
'allow' => true, |
|
|
'allow' => true, |
|
|
'roles' => ['@'], |
|
|
'roles' => ['@'], |
|
|
'matchCallback' => function ($rule, $action) { |
|
|
'matchCallback' => function ($rule, $action) { |
|
|
return User::getCurrentStatus() == User::STATUS_ADMIN |
|
|
|
|
|
|| User::getCurrentStatus() == User::STATUS_PRODUCER; |
|
|
|
|
|
|
|
|
return $this->getUserManager()->isCurrentProducer() |
|
|
|
|
|
|| $this->getUserManager()->isCurrentAdmin(); |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
], |
|
|
], |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Traite le formulaire d'ajout/modification de commande. |
|
|
* Traite le formulaire d'ajout/modification de commande. |
|
|
* |
|
|
|
|
|
* @param Distribution $distribution |
|
|
|
|
|
* @param string $date |
|
|
|
|
|
* @param array $points_vente |
|
|
|
|
|
* @param array $produits |
|
|
|
|
|
* @param array $users |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function processOrderForm( |
|
|
public function processOrderForm( |
|
|
$distribution, $date, $pointsSale, $products, $users) |
|
|
|
|
|
|
|
|
Distribution $distribution, |
|
|
|
|
|
string $date, |
|
|
|
|
|
array $pointsSale, |
|
|
|
|
|
array $products, |
|
|
|
|
|
array $users |
|
|
|
|
|
) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
|
|
|
if ($date != '') { |
|
|
if ($date != '') { |
|
|
// commandes |
|
|
|
|
|
$orders = Order::searchAll([ |
|
|
|
|
|
'distribution.date' => $date |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$orders = $orderManager->findOrdersByDistribution($distribution); |
|
|
|
|
|
|
|
|
foreach ($pointsSale as $point) { |
|
|
foreach ($pointsSale as $point) { |
|
|
$point->initOrders($orders); |
|
|
|
|
|
|
|
|
$pointSaleManager->initPointSaleOrders($point, $orders); |
|
|
|
|
|
|
|
|
if (isset($_POST['submit_pv']) && $_POST['submit_pv']) { |
|
|
if (isset($_POST['submit_pv']) && $_POST['submit_pv']) { |
|
|
// modifs |
|
|
// modifs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// création des commande_produit modifiés |
|
|
// création des commande_produit modifiés |
|
|
foreach ($products as $product) { |
|
|
foreach ($products as $product) { |
|
|
$quantity = Yii::$app->getRequest()->post('product_' . $point->id . '_' . $product->id, 0); |
|
|
|
|
|
|
|
|
$quantity = \Yii::$app->getRequest()->post('product_' . $point->id . '_' . $product->id, 0); |
|
|
if ($quantity) { |
|
|
if ($quantity) { |
|
|
$productOrder = new ProductOrder; |
|
|
$productOrder = new ProductOrder; |
|
|
$productOrder->id_order = $order->id; |
|
|
$productOrder->id_order = $order->id; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$username = Yii::$app->getRequest()->post('username_point_sale_' . $point->id, 0); |
|
|
|
|
|
$date = Yii::$app->getRequest()->post('date_order_point_sale_' . $point->id, 0); |
|
|
|
|
|
|
|
|
$username = \Yii::$app->getRequest()->post('username_point_sale_' . $point->id, 0); |
|
|
|
|
|
$date = \Yii::$app->getRequest()->post('date_order_point_sale_' . $point->id, 0); |
|
|
$oneProduct = false; |
|
|
$oneProduct = false; |
|
|
foreach ($products as $product) { |
|
|
foreach ($products as $product) { |
|
|
$quantity = Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0); |
|
|
$quantity = Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (strlen($username) && $date && $oneProduct) { |
|
|
if (strlen($username) && $date && $oneProduct) { |
|
|
$order = new Order; |
|
|
|
|
|
|
|
|
$order = new Order(); |
|
|
$order->id_point_sale = $point->id; |
|
|
$order->id_point_sale = $point->id; |
|
|
$order->id_production = $distribution->id; |
|
|
$order->id_production = $distribution->id; |
|
|
$order->id_user = 0; |
|
|
$order->id_user = 0; |
|
|
|
|
|
|
|
|
$order->save(); |
|
|
$order->save(); |
|
|
|
|
|
|
|
|
foreach ($products as $product) { |
|
|
foreach ($products as $product) { |
|
|
$quantity = Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0); |
|
|
|
|
|
|
|
|
$quantity = \Yii::$app->getRequest()->post('product_point_sale_' . $point->id . '_' . $product->id, 0); |
|
|
if ($quantity) { |
|
|
if ($quantity) { |
|
|
$productOrder = new ProductOrder; |
|
|
$productOrder = new ProductOrder; |
|
|
$productOrder->id_order = $order->id; |
|
|
$productOrder->id_order = $order->id; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$order->initReference(); |
|
|
|
|
|
|
|
|
$orderManager->generateOrderReference($order); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Page principale de la gestion des commandes. |
|
|
* Page principale de la gestion des commandes. |
|
|
* |
|
|
|
|
|
* @param string $date |
|
|
|
|
|
* @param boolean $returnData |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionIndex($date = '', $returnData = false) |
|
|
public function actionIndex($date = '', $returnData = false) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$productDistributionManager = $this->getProductDistributionManager(); |
|
|
|
|
|
|
|
|
if (!Product::searchCount() || !PointSale::searchCount()) { |
|
|
if (!Product::searchCount() || !PointSale::searchCount()) { |
|
|
$this->redirect(['site/index', 'error_products_points_sale' => 1]); |
|
|
$this->redirect(['site/index', 'error_products_points_sale' => 1]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$arrayUsers[$user->id] = $user->name . ' ' . $user->lastname; |
|
|
$arrayUsers[$user->id] = $user->name . ' ' . $user->lastname; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// création du jour de distribution |
|
|
|
|
|
$distribution = DistributionModel::initDistribution($date); |
|
|
|
|
|
|
|
|
$distribution = $distributionManager->createDistributionIfNotExist($this->getProducerCurrent(), $date); |
|
|
|
|
|
|
|
|
// points de vente |
|
|
|
|
|
if ($distribution) { |
|
|
if ($distribution) { |
|
|
$arrayPointsSale = PointSale::find() |
|
|
$arrayPointsSale = PointSale::find() |
|
|
->joinWith(['pointSaleDistribution' => function ($q) use ($distribution) { |
|
|
->joinWith(['pointSaleDistribution' => function ($q) use ($distribution) { |
|
|
|
|
|
|
|
|
]) |
|
|
]) |
|
|
->all(); |
|
|
->all(); |
|
|
} else { |
|
|
} else { |
|
|
$arrayPointsSale = PointSale::searchAll(); |
|
|
|
|
|
|
|
|
$arrayPointsSale = $pointSaleManager->findPointSales(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// produits |
|
|
|
|
|
$arrayProducts = Product::searchAll(); |
|
|
|
|
|
|
|
|
$arrayProducts = $productManager->findProducts(); |
|
|
|
|
|
|
|
|
// gestion des commandes |
|
|
|
|
|
$this->processOrderForm($distribution, $date, $arrayPointsSale, $arrayProducts, $users); |
|
|
$this->processOrderForm($distribution, $date, $arrayPointsSale, $arrayProducts, $users); |
|
|
|
|
|
|
|
|
// commandes |
|
|
// commandes |
|
|
$arrayOrders = Order::searchAll([ |
|
|
|
|
|
'distribution.date' => $date, |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$arrayOrders = $orderManager->findOrdersByDistribution($distribution); |
|
|
$revenues = 0; |
|
|
$revenues = 0; |
|
|
$weight = 0; |
|
|
$weight = 0; |
|
|
$revenuesDelivered = 0; |
|
|
$revenuesDelivered = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init commandes point de vente |
|
|
// init commandes point de vente |
|
|
foreach ($arrayPointsSale as $pointSale) { |
|
|
foreach ($arrayPointsSale as $pointSale) { |
|
|
$pointSale->initOrders($arrayOrders); |
|
|
|
|
|
|
|
|
$pointSaleManager->initPointSaleOrders($pointSale, $arrayOrders); |
|
|
|
|
|
|
|
|
$dataSelectOrders = []; |
|
|
$dataSelectOrders = []; |
|
|
$dataOptionsOrders = []; |
|
|
$dataOptionsOrders = []; |
|
|
|
|
|
|
|
|
if (isset($_POST['Product'])) { |
|
|
if (isset($_POST['Product'])) { |
|
|
|
|
|
|
|
|
foreach ($arrayProducts as $product) { |
|
|
foreach ($arrayProducts as $product) { |
|
|
$productDistribution = ProductDistributionModel::searchOne([ |
|
|
|
|
|
'id_distribution' => $distribution->id, |
|
|
|
|
|
'id_product' => $product->id |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$productDistribution = $productDistributionManager->findOneProductDistribution($distribution, $product); |
|
|
|
|
|
|
|
|
if (!$productDistribution) { |
|
|
if (!$productDistribution) { |
|
|
$productDistribution = new ProductDistribution(); |
|
|
$productDistribution = new ProductDistribution(); |
|
|
|
|
|
|
|
|
$productDistribution->quantity_max = null; |
|
|
$productDistribution->quantity_max = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$productDistribution->save(); |
|
|
|
|
|
|
|
|
$productDistributionManager->saveCreate($productDistribution); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($_POST['Product'][$product->id]['active'])) { |
|
|
if (isset($_POST['Product'][$product->id]['active'])) { |
|
|
|
|
|
|
|
|
$productDistribution->quantity_max = null; |
|
|
$productDistribution->quantity_max = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$productDistribution->save(); |
|
|
|
|
|
|
|
|
$productDistributionManager->saveUpdate($productDistribution); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$arrayProductsSelected = []; |
|
|
$arrayProductsSelected = []; |
|
|
if ($distribution) { |
|
|
if ($distribution) { |
|
|
// produits selec pour production |
|
|
|
|
|
$arrayProductsSelected = ProductDistributionModel::searchByDistribution($distribution->id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// produits |
|
|
|
|
|
if ($distribution) { |
|
|
|
|
|
$arrayProducts = Product::searchByDistribution($distribution->id); |
|
|
|
|
|
|
|
|
$arrayProductsSelected = $productDistributionManager->findProductDistributionsByDistribution($distribution); |
|
|
|
|
|
$arrayProducts = $productManager->findProductsByDistribution($distribution); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// poids total de la production et CA potentiel |
|
|
// poids total de la production et CA potentiel |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// jours de distribution |
|
|
|
|
|
$arrayDistributionDays = DistributionModel::searchAll([ |
|
|
|
|
|
'active' => 1 |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$arrayDistributionDays = $distributionManager->findDistributionsActive(); |
|
|
|
|
|
|
|
|
// commandes auto |
|
|
// commandes auto |
|
|
$subscriptionForm = new SubscriptionForm; |
|
|
|
|
|
|
|
|
$subscriptionForm = new SubscriptionForm(); |
|
|
|
|
|
|
|
|
// productions point vente |
|
|
// productions point vente |
|
|
$pointSaleDistribution = new PointSaleDistribution; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pointSaleDistribution = new PointSaleDistribution(); |
|
|
$oointsSaleDistribution = []; |
|
|
$oointsSaleDistribution = []; |
|
|
|
|
|
|
|
|
if ($distribution) { |
|
|
if ($distribution) { |
|
|
$pointsSaleDistribution = PointSaleDistributionModel::searchAll([ |
|
|
|
|
|
|
|
|
$pointsSaleDistribution = PointSaleDistribution::searchAll([ |
|
|
'id_distribution' => $distribution->id |
|
|
'id_distribution' => $distribution->id |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); |
|
|
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); |
|
|
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); |
|
|
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); |
|
|
|
|
|
|
|
|
$weekDistribution = DistributionModel::find() |
|
|
|
|
|
|
|
|
$weekDistribution = Distribution::find() |
|
|
->andWhere([ |
|
|
->andWhere([ |
|
|
'id_producer' => GlobalParam::getCurrentProducerId(), |
|
|
'id_producer' => GlobalParam::getCurrentProducerId(), |
|
|
'active' => 1, |
|
|
'active' => 1, |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionDownload($date = '', $idPointSale = 0, $global = 0) |
|
|
public function actionDownload($date = '', $idPointSale = 0, $global = 0) |
|
|
{ |
|
|
{ |
|
|
// commandes |
|
|
|
|
|
$ordersArray = Order::searchAll([ |
|
|
|
|
|
'distribution.date' => $date |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
// points de vente |
|
|
|
|
|
$pointsSaleArray = PointSale::searchAll(); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
|
|
|
$productDistributionManager = $this->getProductDistributionManager(); |
|
|
|
|
|
|
|
|
|
|
|
$distribution = $distributionManager->findOneDistributionByDate($date); |
|
|
|
|
|
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution); |
|
|
|
|
|
$productsArray = $productManager->findProducts(); |
|
|
|
|
|
$ordersArray = $orderManager->findOrdersByDate($date); |
|
|
|
|
|
|
|
|
|
|
|
$pointsSaleArray = $pointSaleManager->findPointSales(); |
|
|
foreach ($pointsSaleArray as $pointSale) { |
|
|
foreach ($pointsSaleArray as $pointSale) { |
|
|
$pv->initOrders($ordersArray); |
|
|
|
|
|
|
|
|
$pointSaleManager->initOrders($pointSale, $ordersArray); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// produits |
|
|
|
|
|
$productsArray = Product::find()->orderBy('order ASC')->all(); |
|
|
|
|
|
|
|
|
|
|
|
$distribution = DistributionModel::find() |
|
|
|
|
|
->where('date LIKE \':date\'') |
|
|
|
|
|
->params([':date' => $date]) |
|
|
|
|
|
->one(); |
|
|
|
|
|
|
|
|
|
|
|
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* export global |
|
|
* export global |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
$strProducts = ''; |
|
|
$strProducts = ''; |
|
|
foreach ($productsArray as $product) { |
|
|
foreach ($productsArray as $product) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
$quantity = Order::getProductQuantity($product->id, $pointSale->orders); |
|
|
|
|
|
|
|
|
$quantity = $orderManager->getProductQuantity($product, $pointSale->orders); |
|
|
$strQuantity = ''; |
|
|
$strQuantity = ''; |
|
|
if ($quantity) { |
|
|
if ($quantity) { |
|
|
$strQuantity = $quantity; |
|
|
$strQuantity = $quantity; |
|
|
|
|
|
|
|
|
$strProducts = ''; |
|
|
$strProducts = ''; |
|
|
foreach ($productsArray as $product) { |
|
|
foreach ($productsArray as $product) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
$quantity = Order::getProductQuantity($product->id, $ordersArray); |
|
|
|
|
|
|
|
|
$quantity = $orderManager->getProductQuantity($product, $ordersArray); |
|
|
$strQuantity = ''; |
|
|
$strQuantity = ''; |
|
|
if ($quantity) { |
|
|
if ($quantity) { |
|
|
$strQuantity = $quantity; |
|
|
$strQuantity = $quantity; |
|
|
|
|
|
|
|
|
* @return array |
|
|
* @return array |
|
|
* @see OrderController::actionDownload() |
|
|
* @see OrderController::actionDownload() |
|
|
*/ |
|
|
*/ |
|
|
public function contentRecapCSV($date, $products, $pointsSale, $orders) |
|
|
|
|
|
|
|
|
public function contentRecapCSV(string $date, array $products, array $pointsSale, array $orders) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$productDistributionManager = $this->getProductDistributionManager(); |
|
|
|
|
|
|
|
|
$data = []; |
|
|
$data = []; |
|
|
$filename = 'summary_' . $date; |
|
|
$filename = 'summary_' . $date; |
|
|
|
|
|
|
|
|
$distribution = DistributionModel::find() |
|
|
|
|
|
->where('date LIKE \':date\'') |
|
|
|
|
|
->params([':date' => $date]) |
|
|
|
|
|
->one(); |
|
|
|
|
|
|
|
|
|
|
|
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); |
|
|
|
|
|
|
|
|
$distribution = $distributionManager->findOneDistributionByDate($date); |
|
|
|
|
|
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution); |
|
|
|
|
|
|
|
|
// head |
|
|
// head |
|
|
$data[0] = ['Lieu']; |
|
|
$data[0] = ['Lieu']; |
|
|
|
|
|
|
|
|
$dataAdd = [$pointSale->name]; |
|
|
$dataAdd = [$pointSale->name]; |
|
|
foreach ($products as $product) { |
|
|
foreach ($products as $product) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
$dataAdd[] = Order::getProductQuantity($product->id, $pointSale->orders); |
|
|
|
|
|
|
|
|
$dataAdd[] = $orderManager->getProductQuantity($product, $pointSale->orders); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$data[] = $dataAdd; |
|
|
$data[] = $dataAdd; |
|
|
|
|
|
|
|
|
$dataAdd = ['Total']; |
|
|
$dataAdd = ['Total']; |
|
|
foreach ($products as $product) { |
|
|
foreach ($products as $product) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { |
|
|
$dataAdd[] = Order::getProductQuantity($product->id, $orders); |
|
|
|
|
|
|
|
|
$dataAdd[] = $orderManager->getProductQuantity($product, $orders); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$data[] = $dataAdd; |
|
|
$data[] = $dataAdd; |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function contentPointSaleCSV($date, $products, $pointsSale, $idPointSale) |
|
|
public function contentPointSaleCSV($date, $products, $pointsSale, $idPointSale) |
|
|
{ |
|
|
{ |
|
|
$data = []; |
|
|
|
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$productDistributionManager = $this->getProductDistributionManager(); |
|
|
|
|
|
|
|
|
$distribution = DistributionModel::find()->where('date LIKE \':date\'')->params([':date' => $date])->one(); |
|
|
|
|
|
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); |
|
|
|
|
|
|
|
|
$data = []; |
|
|
|
|
|
$distribution = $distributionManager->findOneDistributionByDate($date); |
|
|
|
|
|
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution); |
|
|
|
|
|
|
|
|
// datas |
|
|
// datas |
|
|
foreach ($pointsSale as $pointSale) { |
|
|
foreach ($pointsSale as $pointSale) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Change l'état d'un jour de production (activé, désactivé). |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $date |
|
|
|
|
|
* @param integer $actif |
|
|
|
|
|
* @param boolean $redirect |
|
|
|
|
|
|
|
|
* Change l'état d'un jour de distribution (activé, désactivé). |
|
|
*/ |
|
|
*/ |
|
|
public function actionChangeState($date, $active, $redirect = true) |
|
|
|
|
|
|
|
|
public function actionChangeState(string $date, bool $active, bool $redirect = true) |
|
|
{ |
|
|
{ |
|
|
// changement état |
|
|
|
|
|
$distribution = DistributionModel::initDistribution($date); |
|
|
|
|
|
$distribution->active = $active; |
|
|
|
|
|
$distribution->save(); |
|
|
|
|
|
|
|
|
|
|
|
if ($active) { |
|
|
|
|
|
// add commandes automatiques |
|
|
|
|
|
Subscription::addAll($date); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$distribution = $distributionManager->createDistributionIfNotExist($this->getProducerCurrent(), $date); |
|
|
|
|
|
$distributionManager->activeDistribution($distribution, $active); |
|
|
|
|
|
|
|
|
if ($redirect) { |
|
|
if ($redirect) { |
|
|
$this->redirect(['index', 'date' => $date]); |
|
|
$this->redirect(['index', 'date' => $date]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Change l'état d'une semaine de production (activé, désactivé). |
|
|
* Change l'état d'une semaine de production (activé, désactivé). |
|
|
* |
|
|
|
|
|
* @param string $date |
|
|
|
|
|
* @param integer $actif |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionChangeStateWeek($date, $active) |
|
|
|
|
|
|
|
|
public function actionChangeStateWeek(string $date, bool $active) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
|
|
|
|
|
|
$pointsSaleArray = $pointSaleManager->findPointSales(); |
|
|
|
|
|
|
|
|
$week = sprintf('%02d', date('W', strtotime($date))); |
|
|
$week = sprintf('%02d', date('W', strtotime($date))); |
|
|
$start = strtotime(date('Y', strtotime($date)) . 'W' . $week); |
|
|
$start = strtotime(date('Y', strtotime($date)) . 'W' . $week); |
|
|
$dateMonday = date('Y-m-d', strtotime('Monday', $start)); |
|
|
$dateMonday = date('Y-m-d', strtotime('Monday', $start)); |
|
|
|
|
|
|
|
|
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); |
|
|
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); |
|
|
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); |
|
|
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); |
|
|
|
|
|
|
|
|
$pointsSaleArray = PointSale::searchAll(); |
|
|
|
|
|
|
|
|
|
|
|
$activeMonday = false; |
|
|
$activeMonday = false; |
|
|
$activeTuesday = false; |
|
|
$activeTuesday = false; |
|
|
$activeWednesday = false; |
|
|
$activeWednesday = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Supprime une commande via une requête AJAX. |
|
|
* Supprime une commande via une requête AJAX. |
|
|
* |
|
|
|
|
|
* @param string $date |
|
|
|
|
|
* @param integer $idOrder |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionAjaxDelete($idOrder) |
|
|
|
|
|
|
|
|
public function actionAjaxDelete(int $idOrder) |
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
|
$order = Order::searchOne([ |
|
|
|
|
|
'id' => $idOrder |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
|
|
|
// delete |
|
|
|
|
|
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
if ($order) { |
|
|
if ($order) { |
|
|
$order->delete(); |
|
|
|
|
|
|
|
|
$orderManager->deleteOrder($order); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ['success']; |
|
|
return ['success']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Supprime une commande. |
|
|
* Supprime une commande. |
|
|
* |
|
|
|
|
|
* @param string $date |
|
|
|
|
|
* @param integer $idOrder |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionDelete($date, $idOrder) |
|
|
|
|
|
|
|
|
public function actionDelete(string $date, int $idOrder) |
|
|
{ |
|
|
{ |
|
|
$order = Order::searchOne(['id' => $idOrder]); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
|
|
|
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
if ($order) { |
|
|
if ($order) { |
|
|
|
|
|
|
|
|
// remboursement de la commande |
|
|
|
|
|
if ($order->id_user && $order->getAmount(Order::AMOUNT_PAID) && Producer::getConfig('credit')) { |
|
|
|
|
|
$order->saveCreditHistory( |
|
|
|
|
|
CreditHistory::TYPE_REFUND, |
|
|
|
|
|
$order->getAmount(Order::AMOUNT_PAID), |
|
|
|
|
|
$order->distribution->id_producer, |
|
|
|
|
|
$order->id_user, |
|
|
|
|
|
GlobalParam::getCurrentUserId() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$order->delete(); |
|
|
|
|
|
ProductOrder::deleteAll(['id_order' => $idOrder]); |
|
|
|
|
|
|
|
|
$orderManager->deleteOrder($order); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->redirect(['index', 'date' => $date]); |
|
|
$this->redirect(['index', 'date' => $date]); |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
|
|
|
|
$distributionManager = $this->getDistributionManager(); |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
$userPointSaleManager = $this->getUserPointSaleManager(); |
|
|
|
|
|
$userManager = $this->getUserManager(); |
|
|
|
|
|
$userProducerManager = $this->getUserProducerManager(); |
|
|
|
|
|
$producerManager = $this->getProducerManager(); |
|
|
|
|
|
$productManager = $this->getProductManager(); |
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
|
|
|
$products = json_decode($products); |
|
|
$products = json_decode($products); |
|
|
$pointSale = PointSale::findOne($idPointSale); |
|
|
|
|
|
$distribution = DistributionModel::searchOne([ |
|
|
|
|
|
'date' => $date |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale); |
|
|
|
|
|
$distribution = $distributionManager->findOneDistributionByDate($date); |
|
|
|
|
|
|
|
|
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date) && |
|
|
|
|
|
($idUser || strlen($username)) && |
|
|
|
|
|
$pointSale && |
|
|
|
|
|
count(get_object_vars($products)) && |
|
|
|
|
|
$distribution) { |
|
|
|
|
|
|
|
|
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date) |
|
|
|
|
|
&& ($idUser || strlen($username)) |
|
|
|
|
|
&& $pointSale |
|
|
|
|
|
&& count(get_object_vars($products)) |
|
|
|
|
|
&& $distribution) { |
|
|
|
|
|
|
|
|
$order = new Order; |
|
|
$order = new Order; |
|
|
$order->date = date('Y-m-d H:i:s'); |
|
|
$order->date = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
$order->id_user = $idUser; |
|
|
$order->id_user = $idUser; |
|
|
|
|
|
|
|
|
// commentaire du point de vente |
|
|
// commentaire du point de vente |
|
|
$userPointSale = UserPointSale::searchOne([ |
|
|
|
|
|
'id_point_sale' => $idPointSale, |
|
|
|
|
|
'id_user' => $idUser |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$userPointSale = $userPointSaleManager->findOneUserPointSale($userManager->findOneUserById($idUser), $pointSale); |
|
|
|
|
|
|
|
|
if ($userPointSale && strlen($userPointSale->comment)) { |
|
|
if ($userPointSale && strlen($userPointSale->comment)) { |
|
|
$order->comment_point_sale = $userPointSale->comment; |
|
|
$order->comment_point_sale = $userPointSale->comment; |
|
|
|
|
|
|
|
|
$userProducer = false; |
|
|
$userProducer = false; |
|
|
if (isset($order->user) && $order->user) { |
|
|
if (isset($order->user) && $order->user) { |
|
|
$user = $order->user; |
|
|
$user = $order->user; |
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
|
|
'id_user' => $user->id, |
|
|
|
|
|
'id_producer' => $order->distribution->id_producer |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userProducer = $userProducerManager->findOneUserProducer( |
|
|
|
|
|
$user, |
|
|
|
|
|
$producerManager->findOneProducerById($order->distribution->id_producer) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach ($products as $key => $dataProductOrder) { |
|
|
foreach ($products as $key => $dataProductOrder) { |
|
|
$product = Product::findOne($key); |
|
|
|
|
|
|
|
|
$product = $productManager->findOneProductById($key); |
|
|
$quantity = $dataProductOrder->quantity / Product::$unitsArray[$dataProductOrder->unit]['coefficient']; |
|
|
$quantity = $dataProductOrder->quantity / Product::$unitsArray[$dataProductOrder->unit]['coefficient']; |
|
|
if ($product && $quantity) { |
|
|
if ($product && $quantity) { |
|
|
$productOrder = new ProductOrder; |
|
|
$productOrder = new ProductOrder; |
|
|
|
|
|
|
|
|
if ($dataProductOrder->price) { |
|
|
if ($dataProductOrder->price) { |
|
|
$productOrder->price = $dataProductOrder->price; |
|
|
$productOrder->price = $dataProductOrder->price; |
|
|
} else { |
|
|
} else { |
|
|
$productOrder->price = $product->getPrice([ |
|
|
|
|
|
|
|
|
$productOrder->price = $productManager->getPrice($product, [ |
|
|
'user' => $user, |
|
|
'user' => $user, |
|
|
'user_producer' => $userProducer, |
|
|
'user_producer' => $userProducer, |
|
|
'point_sale' => $order->pointSale, |
|
|
'point_sale' => $order->pointSale, |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$order = Order::searchOne(['id' => $order->id]); |
|
|
|
|
|
|
|
|
$order = $orderManager->findOneOrderById($order); |
|
|
if ($order && $processCredit) { |
|
|
if ($order && $processCredit) { |
|
|
$order->processCredit(); |
|
|
|
|
|
|
|
|
$orderManager->processCredit($order); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($order) { |
|
|
if ($order) { |
|
|
$order->initReference(); |
|
|
|
|
|
$order->setTillerSynchronization(); |
|
|
|
|
|
|
|
|
$orderManager->generateOrderReference($order); |
|
|
|
|
|
$orderManager->updateOrderTillerSynchronization($order); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// lien utilisateur / point de vente |
|
|
// lien utilisateur / point de vente |
|
|
if ($idUser && $pointSale) { |
|
|
if ($idUser && $pointSale) { |
|
|
$pointSale->linkUser($idUser); |
|
|
|
|
|
|
|
|
$pointSaleManager->addUser($pointSale, $user); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionAjaxUpdate() |
|
|
public function actionAjaxUpdate() |
|
|
{ |
|
|
{ |
|
|
$request = Yii::$app->request; |
|
|
|
|
|
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$userManager = $this->getUserManager(); |
|
|
|
|
|
$pointSaleManager = $this->getPointSaleManager(); |
|
|
|
|
|
$userPointSaleManager = $this->getUserPointSaleManager(); |
|
|
|
|
|
|
|
|
|
|
|
$request = \Yii::$app->request; |
|
|
$date = $request->post('date'); |
|
|
$date = $request->post('date'); |
|
|
$idOrder = $request->post('idOrder'); |
|
|
$idOrder = $request->post('idOrder'); |
|
|
$idPointSale = $request->post('idPointSale'); |
|
|
$idPointSale = $request->post('idPointSale'); |
|
|
|
|
|
|
|
|
$comment = $request->post('comment'); |
|
|
$comment = $request->post('comment'); |
|
|
$processCredit = $request->post('processCredit'); |
|
|
$processCredit = $request->post('processCredit'); |
|
|
|
|
|
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
|
|
|
$user = $userManager->findOneUserById($idUser); |
|
|
|
|
|
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale); |
|
|
|
|
|
|
|
|
$order = Order::searchOne(['id' => $idOrder]); |
|
|
|
|
|
|
|
|
|
|
|
if ($order && |
|
|
|
|
|
$order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { |
|
|
|
|
|
|
|
|
if ($order |
|
|
|
|
|
&& $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { |
|
|
|
|
|
|
|
|
$oldIdUser = $order->id_user; |
|
|
$oldIdUser = $order->id_user; |
|
|
if ($idUser) { |
|
|
if ($idUser) { |
|
|
|
|
|
|
|
|
$order->id_user = $idUser; |
|
|
$order->id_user = $idUser; |
|
|
|
|
|
|
|
|
// commentaire du point de vente |
|
|
// commentaire du point de vente |
|
|
$userPointSale = UserPointSale::searchOne([ |
|
|
|
|
|
'id_point_sale' => $order->id_point_sale, |
|
|
|
|
|
'id_user' => $idUser |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userPointSale = $userPointSaleManager->findOneUserPointSale($user, $pointSale); |
|
|
if ($userPointSale && strlen($userPointSale->comment)) { |
|
|
if ($userPointSale && strlen($userPointSale->comment)) { |
|
|
$order->comment_point_sale = $userPointSale->comment; |
|
|
$order->comment_point_sale = $userPointSale->comment; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Retourne l'état du paiement (historique, crédit) d'une commande donnée. |
|
|
* Retourne l'état du paiement (historique, crédit) d'une commande donnée. |
|
|
* |
|
|
|
|
|
* @param integer $idOrder |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionPaymentStatus($idOrder) |
|
|
|
|
|
|
|
|
public function actionPaymentStatus(int $idOrder) |
|
|
{ |
|
|
{ |
|
|
$creditHistoryManager = $this->getCreditHistoryManager(); |
|
|
$creditHistoryManager = $this->getCreditHistoryManager(); |
|
|
$order = Order::searchOne(['id' => $idOrder]); |
|
|
$order = Order::searchOne(['id' => $idOrder]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Effectue le paiement/remboursement d'une commande. |
|
|
* Effectue le paiement/remboursement d'une commande. |
|
|
* |
|
|
|
|
|
* @param integer $idOrder |
|
|
|
|
|
* @param string $type |
|
|
|
|
|
* @param float $amount |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionAjaxPayment($idOrder, $type, $amount) |
|
|
|
|
|
|
|
|
public function actionAjaxPayment(int $idOrder, string $type, float $amount): array |
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
|
$order = Order::searchOne([ |
|
|
|
|
|
'id' => $idOrder |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
$creditHistoryManager = $this->getCreditHistoryManager(); |
|
|
|
|
|
|
|
|
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
|
|
|
|
|
|
if ($order) { |
|
|
if ($order) { |
|
|
$order->saveCreditHistory( |
|
|
|
|
|
|
|
|
$creditHistoryManager->createCreditHistory( |
|
|
$type, |
|
|
$type, |
|
|
$amount, |
|
|
$amount, |
|
|
GlobalParam::getCurrentProducerId(), |
|
|
|
|
|
$order->id_user, |
|
|
|
|
|
GlobalParam::getCurrentUserId() |
|
|
|
|
|
|
|
|
GlobalParam::getCurrentProducer(), |
|
|
|
|
|
$order->user, |
|
|
|
|
|
GlobalParam::getCurrentUser() |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Modifie l'état de la synchronisation Tiller d'une commande. |
|
|
* Modifie l'état de la synchronisation Tiller d'une commande. |
|
|
* |
|
|
|
|
|
* @param int $idOrder |
|
|
|
|
|
* @param boolean $boolSynchroTiller |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function actionAjaxChangeSynchroTiller($idOrder, $boolSynchroTiller) |
|
|
|
|
|
|
|
|
public function actionAjaxChangeSynchroTiller(int $idOrder, bool $boolSynchroTiller): array |
|
|
{ |
|
|
{ |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
|
$order = Order::searchOne([ |
|
|
|
|
|
'id' => (int)$idOrder |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
|
|
|
|
|
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
if ($order) { |
|
|
if ($order) { |
|
|
$order->tiller_synchronization = (int)$boolSynchroTiller; |
|
|
|
|
|
$res = $order->save(); |
|
|
|
|
|
|
|
|
$orderManager->updateOrderTillerSynchronization($order, (int) $boolSynchroTiller); |
|
|
return ['success']; |
|
|
return ['success']; |
|
|
} |
|
|
} |
|
|
|
|
|
|