@@ -44,6 +44,7 @@ use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\PointSale\PointSale\Model\PointSale; | |||
use common\logic\Product\Product\Model\Product; | |||
use common\logic\Product\Product\Wrapper\ProductContainer; | |||
use common\logic\User\User\Model\User; | |||
use Yii; | |||
use yii\filters\AccessControl; | |||
@@ -115,84 +116,12 @@ class SiteController extends BackendController | |||
*/ | |||
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', [ | |||
'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() | |||
]); | |||
} | |||
@@ -6,6 +6,8 @@ use common\helpers\GlobalParam; | |||
use common\logic\AbstractRepository; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
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\Subscription\Subscription\Model\Subscription; | |||
use common\logic\Subscription\Subscription\Service\SubscriptionSolver; | |||
@@ -15,12 +17,14 @@ class DistributionRepository extends AbstractRepository | |||
protected DistributionRepositoryQuery $query; | |||
protected DistributionSolver $distributionSolver; | |||
protected SubscriptionSolver $subscriptionSolver; | |||
protected ProducerSolver $producerSolver; | |||
public function loadDependencies(): void | |||
{ | |||
$this->loadQuery(DistributionRepositoryQuery::class); | |||
$this->distributionSolver = $this->loadService(DistributionSolver::class); | |||
$this->subscriptionSolver = $this->loadService(SubscriptionSolver::class); | |||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||
} | |||
public function getDefaultOptionsSearch(): array | |||
@@ -162,4 +166,35 @@ class DistributionRepository extends AbstractRepository | |||
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; | |||
} | |||
} |
@@ -30,4 +30,9 @@ class DistributionContainer extends AbstractContainer | |||
{ | |||
return DistributionDefinition::getInstance(); | |||
} | |||
public function getRepository(): DistributionRepository | |||
{ | |||
return DistributionRepository::getInstance(); | |||
} | |||
} |
@@ -22,6 +22,7 @@ use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | |||
use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\Producer\Producer\Repository\ProducerRepository; | |||
use common\logic\Producer\Producer\Service\ProducerSolver; | |||
use common\logic\Product\Product\Service\ProductSolver; | |||
use common\logic\Subscription\Subscription\Model\Subscription; | |||
use common\logic\User\User\Model\User; | |||
@@ -43,6 +44,7 @@ class OrderRepository extends AbstractRepository | |||
protected InvoiceRepository $invoiceRepository; | |||
protected InvoiceSolver $invoiceSolver; | |||
protected PaymentSolver $paymentSolver; | |||
protected ProducerSolver $producerSolver; | |||
public function loadDependencies(): void | |||
{ | |||
@@ -59,6 +61,7 @@ class OrderRepository extends AbstractRepository | |||
$this->invoiceRepository = $this->loadService(InvoiceRepository::class); | |||
$this->invoiceSolver = $this->loadService(InvoiceSolver::class); | |||
$this->paymentSolver = $this->loadService(PaymentSolver::class); | |||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||
} | |||
public function getDefaultOptionsSearch(): array | |||
@@ -622,4 +625,37 @@ class OrderRepository extends AbstractRepository | |||
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; | |||
} | |||
} |
@@ -254,7 +254,7 @@ class ProducerRepository extends AbstractRepository | |||
} | |||
if ($producer) { | |||
return $producer->$config; | |||
return $this->producerSolver->getConfig($producer, $config); | |||
} | |||
} | |||
@@ -255,4 +255,13 @@ class ProducerSolver extends AbstractService implements SolverInterface | |||
return 'Points de vente'; | |||
} | |||
public function getConfig(string $config, Producer $producer = null): ?string | |||
{ | |||
if(!$producer) { | |||
$producer = $this->getProducerContext(); | |||
} | |||
return $producer->$config; | |||
} | |||
} |
@@ -394,6 +394,9 @@ class OrderController extends ProducerBaseController | |||
$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->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | |||
if(!$isNewOrder) { | |||
$order->date_update = date('Y-m-d H:i:s'); | |||
} | |||
$order->save(); | |||
$orderManager->generateOrderReference($order); | |||
@@ -428,7 +431,7 @@ class OrderController extends ProducerBaseController | |||
} | |||
$productOrder->quantity = $quantity; | |||
$productOrder->price = $productManager->getPrice($product, [ | |||
'user' => GlobalParam::getCurrentUser(), | |||
'user' => $this->getUserCurrent(), | |||
'user_producer' => $userProducer, | |||
'point_sale' => $pointSale, | |||
'quantity' => $quantity |