use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\Product\Product\Model\Product; | use common\logic\Product\Product\Model\Product; | ||||
use common\logic\Product\Product\Wrapper\ProductContainer; | |||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$userManager = $this->getUserManager(); | |||||
$producerManager = $this->getProducerManager(); | |||||
$optionDashboardNumberDistributions = $producerManager->getConfig('option_dashboard_number_distributions'); | |||||
$dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3; | |||||
$optionDashboardDateStart = $producerManager->getConfig('option_dashboard_date_start'); | |||||
$optionDashboardDateEnd = $producerManager->getConfig('option_dashboard_date_end'); | |||||
$queryDistributions = Distribution::find()->with('order'); | |||||
if ($optionDashboardDateStart || $optionDashboardDateEnd) { | |||||
if ($optionDashboardDateStart) { | |||||
$queryDistributions->andWhere(['>=', 'distribution.date', $optionDashboardDateStart]); | |||||
} | |||||
if ($optionDashboardDateEnd) { | |||||
$queryDistributions->andWhere(['<=', 'distribution.date', $optionDashboardDateEnd]); | |||||
} | |||||
} else { | |||||
$queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]); | |||||
} | |||||
$distributionsArray = $queryDistributions->andWhere([ | |||||
'distribution.id_producer' => GlobalParam::getCurrentProducerId(), | |||||
'distribution.active' => 1 | |||||
]) | |||||
->orderBy('date ASC') | |||||
->limit($dashboardNumberDistributions) | |||||
->all(); | |||||
// dernières commandes | |||||
$paramsOrders = []; | |||||
if ($optionDashboardDateStart || $optionDashboardDateEnd) { | |||||
$conditionsOrders = ''; | |||||
if ($optionDashboardDateStart) { | |||||
$conditionsOrders .= 'distribution.date >= :date_start'; | |||||
$paramsOrders[':date_start'] = $optionDashboardDateStart; | |||||
} | |||||
if ($optionDashboardDateEnd) { | |||||
if ($optionDashboardDateStart) { | |||||
$conditionsOrders .= ' AND '; | |||||
} | |||||
$conditionsOrders .= 'distribution.date <= :date_end'; | |||||
$paramsOrders[':date_end'] = $optionDashboardDateEnd; | |||||
} | |||||
} else { | |||||
$conditionsOrders = 'distribution.date >= :date_start'; | |||||
$paramsOrders[':date_start'] = date('Y-m-d 00:00:00'); | |||||
} | |||||
$ordersArray = Order::searchAll([], [ | |||||
'orderby' => 'date DESC', | |||||
'conditions' => $conditionsOrders . ' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))', | |||||
'params' => $paramsOrders, | |||||
]); | |||||
// clients | |||||
$usersArray = $userManager->queryUsersBy() | |||||
->orderBy('created_at DESC') | |||||
->limit(5) | |||||
->all(); | |||||
$usersNegativeCredit = $userManager->queryUsersBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->andWhere('user_producer.credit < 0') | |||||
->all(); | |||||
$producerCurrent = GlobalParam::getCurrentProducer(); | |||||
$productsCount = Product::searchCount(); | |||||
$pointsSaleCount = PointSale::searchCount(); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'distributionsArray' => $distributionsArray, | |||||
'ordersArray' => $ordersArray, | |||||
'usersArray' => $usersArray, | |||||
'usersNegativeCredit' => $usersNegativeCredit, | |||||
'producer' => $producerCurrent, | |||||
'productsCount' => $productsCount, | |||||
'pointsSaleCount' => $pointsSaleCount | |||||
'producer' => $this->getProducerCurrent(), | |||||
'distributionsArray' => $this->getDistributionContainer()->getRepository()->findDistributionsDashboard(), | |||||
'ordersArray' => $this->getOrderContainer()->getRepository()->findOrdersDashboard(), | |||||
'productsCount' => $this->getProductContainer()->getRepository()->countProducts(), | |||||
'pointsSaleCount' => $this->getPointSaleContainer()->getRepository()->countPointSales() | |||||
]); | ]); | ||||
} | } | ||||
use common\logic\AbstractRepository; | use common\logic\AbstractRepository; | ||||
use common\logic\Distribution\Distribution\Model\Distribution; | use common\logic\Distribution\Distribution\Model\Distribution; | ||||
use common\logic\Distribution\Distribution\Service\DistributionSolver; | use common\logic\Distribution\Distribution\Service\DistributionSolver; | ||||
use common\logic\Producer\Producer\Repository\ProducerRepository; | |||||
use common\logic\Producer\Producer\Service\ProducerSolver; | |||||
use common\logic\RepositoryQueryInterface; | use common\logic\RepositoryQueryInterface; | ||||
use common\logic\Subscription\Subscription\Model\Subscription; | use common\logic\Subscription\Subscription\Model\Subscription; | ||||
use common\logic\Subscription\Subscription\Service\SubscriptionSolver; | use common\logic\Subscription\Subscription\Service\SubscriptionSolver; | ||||
protected DistributionRepositoryQuery $query; | protected DistributionRepositoryQuery $query; | ||||
protected DistributionSolver $distributionSolver; | protected DistributionSolver $distributionSolver; | ||||
protected SubscriptionSolver $subscriptionSolver; | protected SubscriptionSolver $subscriptionSolver; | ||||
protected ProducerSolver $producerSolver; | |||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->loadQuery(DistributionRepositoryQuery::class); | $this->loadQuery(DistributionRepositoryQuery::class); | ||||
$this->distributionSolver = $this->loadService(DistributionSolver::class); | $this->distributionSolver = $this->loadService(DistributionSolver::class); | ||||
$this->subscriptionSolver = $this->loadService(SubscriptionSolver::class); | $this->subscriptionSolver = $this->loadService(SubscriptionSolver::class); | ||||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||||
} | } | ||||
public function getDefaultOptionsSearch(): array | public function getDefaultOptionsSearch(): array | ||||
return $oneDistributionWeekActive; | return $oneDistributionWeekActive; | ||||
} | } | ||||
public function findDistributionsDashboard(): array | |||||
{ | |||||
$optionDashboardNumberDistributions = $this->producerSolver->getConfig('option_dashboard_number_distributions'); | |||||
$optionDashboardDateStart = $this->producerSolver->getConfig('option_dashboard_date_start'); | |||||
$optionDashboardDateEnd = $this->producerSolver->getConfig('option_dashboard_date_end'); | |||||
$dashboardNumberDistributions = $optionDashboardNumberDistributions ?: 3; | |||||
$queryDistributions = Distribution::find()->with('order'); | |||||
if ($optionDashboardDateStart || $optionDashboardDateEnd) { | |||||
if ($optionDashboardDateStart) { | |||||
$queryDistributions->andWhere(['>=', 'distribution.date', $optionDashboardDateStart]); | |||||
} | |||||
if ($optionDashboardDateEnd) { | |||||
$queryDistributions->andWhere(['<=', 'distribution.date', $optionDashboardDateEnd]); | |||||
} | |||||
} else { | |||||
$queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]); | |||||
} | |||||
$distributionsArray = $queryDistributions->andWhere([ | |||||
'distribution.id_producer' => $this->getProducerContextId(), | |||||
'distribution.active' => 1 | |||||
]) | |||||
->orderBy('date ASC') | |||||
->limit($dashboardNumberDistributions) | |||||
->all(); | |||||
return $distributionsArray; | |||||
} | |||||
} | } |
{ | { | ||||
return DistributionDefinition::getInstance(); | return DistributionDefinition::getInstance(); | ||||
} | } | ||||
public function getRepository(): DistributionRepository | |||||
{ | |||||
return DistributionRepository::getInstance(); | |||||
} | |||||
} | } |
use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; | use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; | ||||
use common\logic\Producer\Producer\Model\Producer; | use common\logic\Producer\Producer\Model\Producer; | ||||
use common\logic\Producer\Producer\Repository\ProducerRepository; | use common\logic\Producer\Producer\Repository\ProducerRepository; | ||||
use common\logic\Producer\Producer\Service\ProducerSolver; | |||||
use common\logic\Product\Product\Service\ProductSolver; | use common\logic\Product\Product\Service\ProductSolver; | ||||
use common\logic\Subscription\Subscription\Model\Subscription; | use common\logic\Subscription\Subscription\Model\Subscription; | ||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
protected InvoiceRepository $invoiceRepository; | protected InvoiceRepository $invoiceRepository; | ||||
protected InvoiceSolver $invoiceSolver; | protected InvoiceSolver $invoiceSolver; | ||||
protected PaymentSolver $paymentSolver; | protected PaymentSolver $paymentSolver; | ||||
protected ProducerSolver $producerSolver; | |||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->invoiceRepository = $this->loadService(InvoiceRepository::class); | $this->invoiceRepository = $this->loadService(InvoiceRepository::class); | ||||
$this->invoiceSolver = $this->loadService(InvoiceSolver::class); | $this->invoiceSolver = $this->loadService(InvoiceSolver::class); | ||||
$this->paymentSolver = $this->loadService(PaymentSolver::class); | $this->paymentSolver = $this->loadService(PaymentSolver::class); | ||||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||||
} | } | ||||
public function getDefaultOptionsSearch(): array | public function getDefaultOptionsSearch(): array | ||||
return false; | return false; | ||||
} | } | ||||
public function findOrdersDashboard(): array | |||||
{ | |||||
$optionDashboardDateStart = $this->producerSolver->getConfig('option_dashboard_date_start'); | |||||
$optionDashboardDateEnd = $this->producerSolver->getConfig('option_dashboard_date_end'); | |||||
$paramsOrders = []; | |||||
if ($optionDashboardDateStart || $optionDashboardDateEnd) { | |||||
$conditionsOrders = ''; | |||||
if ($optionDashboardDateStart) { | |||||
$conditionsOrders .= 'distribution.date >= :date_start'; | |||||
$paramsOrders[':date_start'] = $optionDashboardDateStart; | |||||
} | |||||
if ($optionDashboardDateEnd) { | |||||
if ($optionDashboardDateStart) { | |||||
$conditionsOrders .= ' AND '; | |||||
} | |||||
$conditionsOrders .= 'distribution.date <= :date_end'; | |||||
$paramsOrders[':date_end'] = $optionDashboardDateEnd; | |||||
} | |||||
} else { | |||||
$conditionsOrders = 'distribution.date >= :date_start'; | |||||
$paramsOrders[':date_start'] = date('Y-m-d 00:00:00'); | |||||
} | |||||
$ordersArray = Order::searchAll([], [ | |||||
'orderby' => 'IF(ISNULL(date_update), `order`.`date`, `order`.`date_update`) DESC', | |||||
'conditions' => $conditionsOrders . ' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))', | |||||
'params' => $paramsOrders, | |||||
]); | |||||
return $ordersArray; | |||||
} | |||||
} | } |
} | } | ||||
if ($producer) { | if ($producer) { | ||||
return $producer->$config; | |||||
return $this->producerSolver->getConfig($producer, $config); | |||||
} | } | ||||
} | } | ||||
return 'Points de vente'; | return 'Points de vente'; | ||||
} | } | ||||
public function getConfig(string $config, Producer $producer = null): ?string | |||||
{ | |||||
if(!$producer) { | |||||
$producer = $this->getProducerContext(); | |||||
} | |||||
return $producer->$config; | |||||
} | |||||
} | } |
$order->delivery_home = isset($posts['Order']['delivery_home']) ? $posts['Order']['delivery_home'] : false; | $order->delivery_home = isset($posts['Order']['delivery_home']) ? $posts['Order']['delivery_home'] : false; | ||||
$order->delivery_address = (isset($posts['Order']['delivery_address']) && $order->delivery_home) ? $posts['Order']['delivery_address'] : null; | $order->delivery_address = (isset($posts['Order']['delivery_address']) && $order->delivery_home) ? $posts['Order']['delivery_address'] : null; | ||||
$order->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | $order->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | ||||
if(!$isNewOrder) { | |||||
$order->date_update = date('Y-m-d H:i:s'); | |||||
} | |||||
$order->save(); | $order->save(); | ||||
$orderManager->generateOrderReference($order); | $orderManager->generateOrderReference($order); | ||||
} | } | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->price = $productManager->getPrice($product, [ | $productOrder->price = $productManager->getPrice($product, [ | ||||
'user' => GlobalParam::getCurrentUser(), | |||||
'user' => $this->getUserCurrent(), | |||||
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
'point_sale' => $pointSale, | 'point_sale' => $pointSale, | ||||
'quantity' => $quantity | 'quantity' => $quantity |