use common\helpers\MeanPayment; | use common\helpers\MeanPayment; | ||||
use domain\Distribution\Distribution\ExportManager; | use domain\Distribution\Distribution\ExportManager; | ||||
use domain\Order\Order\Order; | use domain\Order\Order\Order; | ||||
use domain\Order\Order\OrderRepositoryQuery; | |||||
use domain\Order\OrderStatus\OrderStatus; | use domain\Order\OrderStatus\OrderStatus; | ||||
use domain\User\User\User; | use domain\User\User\User; | ||||
use Yii; | use Yii; | ||||
$arrayOrders = Order::searchAll([ | $arrayOrders = Order::searchAll([ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $producer->id, | 'distribution.id_producer' => $producer->id, | ||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
$configCredit = $producerModule->getConfig('credit'); | $configCredit = $producerModule->getConfig('credit'); | ||||
if (!strlen($forceDate) && $producerModule->getConfig('option_notify_producer_order_summary')) { | if (!strlen($forceDate) && $producerModule->getConfig('option_notify_producer_order_summary')) { | ||||
$arrayOrders = Order::searchAll([ | $arrayOrders = Order::searchAll([ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $producer->id, | |||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
'distribution.id_producer' => $producer->id | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
$mail = Yii::$app->mailerService->getMailer()->compose( | $mail = Yii::$app->mailerService->getMailer()->compose( |
'isCreditFunctioningUser' => $orderModule->getRepository()->isOrderCreditFunctioningUser($order), | 'isCreditFunctioningUser' => $orderModule->getRepository()->isOrderCreditFunctioningUser($order), | ||||
'debitCredit' => false, | 'debitCredit' => false, | ||||
'deliveryNote' => $order->deliveryNote ? $order->deliveryNote->getAttributes() : null, | 'deliveryNote' => $order->deliveryNote ? $order->deliveryNote->getAttributes() : null, | ||||
'labelDeleteAction' => $orderModule->getSolver()->getLabelDeleteAction($order) | |||||
'labelDeleteAction' => $orderModule->getSolver()->getLabelDeleteAction($order), | |||||
'orderStatusHistorySummaryTitleTag' => $orderModule->getSolver()->getOrderStatusHistorySummaryTitleTag($order, "\n"), | |||||
]); | ]); | ||||
} | } | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use domain\Distribution\PointSaleDistribution\PointSaleDistribution; | use domain\Distribution\PointSaleDistribution\PointSaleDistribution; | ||||
use domain\Order\Order\Order; | use domain\Order\Order\Order; | ||||
use domain\Order\Order\OrderRepositoryQuery; | |||||
use domain\Order\OrderStatus\OrderStatus; | use domain\Order\OrderStatus\OrderStatus; | ||||
use domain\PointSale\PointSale\PointSale; | use domain\PointSale\PointSale\PointSale; | ||||
use domain\PointSale\PointSale\PointSaleSearch; | use domain\PointSale\PointSale\PointSaleSearch; | ||||
$ordersArray = Order::searchAll( | $ordersArray = Order::searchAll( | ||||
[ | [ | ||||
'id_point_sale' => $id, | 'id_point_sale' => $id, | ||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
], | ], | ||||
[ | [ | ||||
'conditions' => 'distribution.date > :today', | |||||
'conditions' => [ | |||||
'distribution.date > :today', | |||||
OrderRepositoryQuery::getSqlFilterIsValid() | |||||
], | |||||
'params' => [':today' => date('Y-m-d')] | 'params' => [':today' => date('Y-m-d')] | ||||
] | ] | ||||
); | ); |
use common\helpers\Ajax; | use common\helpers\Ajax; | ||||
use common\helpers\Alwaysdata; | use common\helpers\Alwaysdata; | ||||
use domain\Order\Order\Order; | use domain\Order\Order\Order; | ||||
use domain\Order\Order\OrderRepositoryQuery; | |||||
use domain\Order\OrderStatus\OrderStatus; | use domain\Order\OrderStatus\OrderStatus; | ||||
use domain\Producer\Producer\Producer; | use domain\Producer\Producer\Producer; | ||||
use domain\Product\Product\Product; | use domain\Product\Product\Product; | ||||
$countOrders = Order::searchCount([ | $countOrders = Order::searchCount([ | ||||
'id_user' => $idUser, | 'id_user' => $idUser, | ||||
'distribution.id_producer' => $fromProducerId, | 'distribution.id_producer' => $fromProducerId, | ||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
} | } | ||||
->deleteOrdersIncomingDistributionsFromSubscription($subscription, $this->getUserCurrent()); | ->deleteOrdersIncomingDistributionsFromSubscription($subscription, $this->getUserCurrent()); | ||||
} | } | ||||
foreach ($matchedDistributionsArray as $distribution) { | foreach ($matchedDistributionsArray as $distribution) { | ||||
$subscriptionModule->createOrderFromSubscription($subscription, $distribution->date, $this->getUserCurrent()); | |||||
$orderModule->getManager()->createOrderFromSubscription($subscription, $distribution->date, $this->getUserCurrent()); | |||||
} | } | ||||
$this->setFlash('success', 'Commandes ' . ($update ? 're-' : '') . 'générées dans les distributions futures.'); | $this->setFlash('success', 'Commandes ' . ($update ? 're-' : '') . 'générées dans les distributions futures.'); | ||||
return $this->redirect(['subscription/index']); | return $this->redirect(['subscription/index']); |
<table class="table table-condensed table-bordered"> | <table class="table table-condensed table-bordered"> | ||||
<thead> | <thead> | ||||
<tr> | <tr> | ||||
<th></th> | |||||
<th>Statut</th> | |||||
<th>Origine</th> | |||||
<th>Date</th> | <th>Date</th> | ||||
<th>Client</th> | <th>Client</th> | ||||
<th>Produits</th> | <th>Produits</th> | ||||
<th>Point de vente</th> | <th>Point de vente</th> | ||||
<th>Montant</th> | <th>Montant</th> | ||||
<th>Historique</th> | |||||
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<?php $orderModule->initOrder($order); ?> | <?php $orderModule->initOrder($order); ?> | ||||
<tr class="<?= $orderModule->getHistoryClass($order) ; ?>"> | <tr class="<?= $orderModule->getHistoryClass($order) ; ?>"> | ||||
<td class="infos"><?= $orderModule->getLabelOrigin($order, true); ?></td> | |||||
<td class="history"> | |||||
<?= $orderModule->getSolver()->getLabelOrderStatus($order); ?> | |||||
<?php | |||||
$lastOrderStatusHistory = $orderModule->getSolver()->getLastOrderStatusHistory($order); | |||||
if($lastOrderStatusHistory) { | |||||
echo '<br /><span class="small gray">'.$lastOrderStatusHistory->getDate()->format('d/m/Y à H:i').'</span>'; | |||||
} | |||||
?> | |||||
</td> | |||||
<td class="infos"> | |||||
<?= $orderModule->getSolver()->getLabelOrigin($order, true); ?> | |||||
</td> | |||||
<td class="date"> | <td class="date"> | ||||
<div class="block-date"> | <div class="block-date"> | ||||
<div class="day"><?= strftime('%A', strtotime($order->distribution->date)) ?></div> | <div class="day"><?= strftime('%A', strtotime($order->distribution->date)) ?></div> | ||||
<td><?= $orderModule->getCartSummary($order); ?></td> | <td><?= $orderModule->getCartSummary($order); ?></td> | ||||
<td><?= $orderModule->getPointSaleSummary($order) ; ?></td> | <td><?= $orderModule->getPointSaleSummary($order) ; ?></td> | ||||
<td><?= $orderModule->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true) ; ?></td> | <td><?= $orderModule->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true) ; ?></td> | ||||
<td class="history"><?= $orderModule->getHistorySummary($order) ; ?></td> | |||||
</tr> | </tr> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
</tbody> | </tbody> |
<input type="checkbox" v-model="order.selected" /> | <input type="checkbox" v-model="order.selected" /> | ||||
</td> | </td> | ||||
<td class="column-state"> | <td class="column-state"> | ||||
<span class="label label-danger" v-if="order.order_status_alias == 'canceled'"><span class="glyphicon glyphicon-trash"></span></span> | |||||
<span class="label label-warning" v-if="order.order_status_alias == 'updated'"><span class="glyphicon glyphicon-pencil"></span></span> | |||||
<span class="label label-success" v-if="order.order_status_alias == 'ordered'"><span class="glyphicon glyphicon-check"></span></span> | |||||
<span v-if="order.order_status_alias == 'canceled'" class="label label-danger" :title="order.orderStatusHistorySummaryTitleTag"><span class="glyphicon glyphicon-trash"></span></span> | |||||
<span v-if="order.order_status_alias == 'updated'" class="label label-warning" :title="order.orderStatusHistorySummaryTitleTag"><span class="glyphicon glyphicon-pencil"></span></span> | |||||
<span v-if="order.order_status_alias == 'ordered'" class="label label-success" :title="order.orderStatusHistorySummaryTitleTag"><span class="glyphicon glyphicon-check"></span></span> | |||||
</td> | </td> | ||||
<td class="column-origin"> | <td class="column-origin"> | ||||
<label class="label label-success outline" v-if="order.origin == 'user'">Utilisateur</label> | <label class="label label-success outline" v-if="order.origin == 'user'">Utilisateur</label> | ||||
</div> | </div> | ||||
</td> | </td> | ||||
<td class="column-state-payment"> | <td class="column-state-payment"> | ||||
<template v-if="order.order_status_alias == 'ordered'"> | |||||
<template v-if="order.order_status_alias == 'ordered' || order.order_status_alias == 'updated'"> | |||||
<a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id"> | <a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id"> | ||||
<order-state-payment :order="order" :producer="producer"></order-state-payment> | <order-state-payment :order="order" :producer="producer"></order-state-payment> | ||||
</a> | </a> |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use domain\Order\Order\Order; | use domain\Order\Order\Order; | ||||
use domain\Order\Order\OrderRepositoryQuery; | |||||
use domain\Order\OrderStatus\OrderStatus; | use domain\Order\OrderStatus\OrderStatus; | ||||
use domain\Producer\Producer\ProducerModule; | use domain\Producer\Producer\ProducerModule; | ||||
use domain\User\User\UserModule; | use domain\User\User\UserModule; | ||||
'orders' => function ($url, $model) { | 'orders' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]); | $url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]); | ||||
$countOrders = Order::searchCount([ | $countOrders = Order::searchCount([ | ||||
'id_user' => $model['id'], | |||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
'id_user' => $model['id'] | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
$html = ''; | $html = ''; |
'label' => 'Statut', | 'label' => 'Statut', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($order) use ($orderModule) { | 'value' => function ($order) use ($orderModule) { | ||||
$orderStatusCssClass = $orderModule->getSolver()->getOrderStatusCssClass($order); | |||||
$orderStatusLabel = $orderModule->getSolver()->getOrderStatusLabel($order); | |||||
$orderStatusHistorySummaryTitleTag = $orderModule->getSolver()->getOrderStatusHistorySummaryTitleTag($order); | |||||
return '<span class="label label-'.$orderStatusCssClass.'" title="'.$orderStatusHistorySummaryTitleTag.'">'.$orderStatusLabel.'</span>'; | |||||
return $orderModule->getSolver()->getLabelOrderStatus($order); | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'label' => 'Origine', | 'label' => 'Origine', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($order) { | |||||
if($order->origin == 'user') { | |||||
return '<span class="label label-success outline">Utilisateur</span>'; | |||||
} | |||||
elseif($order->origin == 'auto') { | |||||
return '<span class="label label-default outline">Abonnement</span>'; | |||||
} | |||||
else { | |||||
return '<span class="label label-warning outline">Producteur</span>'; | |||||
} | |||||
'value' => function ($order) use ($orderModule) { | |||||
return $orderModule->getSolver()->getLabelOrigin($order);; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
app.ordersUpdate = JSON.parse(JSON.stringify(response.data.orders)); | app.ordersUpdate = JSON.parse(JSON.stringify(response.data.orders)); | ||||
for (i = 0; i < app.orders.length; i++) { | for (i = 0; i < app.orders.length; i++) { | ||||
if (!app.orders[i].order_status_alias == 'ordered') { | |||||
if (app.orders[i].order_status_alias == 'ordered' || app.orders[i].order_status_alias == 'updated') { | |||||
app.countOrders++; | app.countOrders++; | ||||
} | } | ||||
} | } |
<?php | |||||
use domain\Order\Order\OrderModule; | |||||
use domain\Order\OrderStatus\OrderStatus; | |||||
use domain\Producer\Producer\ProducerModule; | |||||
use domain\User\User\UserModule; | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
/** | |||||
* Class m240528_072445_init_order_status_history | |||||
*/ | |||||
class m240528_072445_init_order_status_history extends Migration | |||||
{ | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeUp() | |||||
{ | |||||
//$this->execute("UPDATE `order` SET order_status_alias = IF(`order`.date_delete IS NULL, 'ordered', 'deleted')"); | |||||
$producerModule = ProducerModule::getInstance(); | |||||
$orderModule = OrderModule::getInstance(); | |||||
$userSystem = UserModule::getInstance()->getRepository()->findOneUserSystem(); | |||||
foreach($producerModule->getRepository()->findProducers() as $producer) { | |||||
Yii::$app->logic->setProducerContext($producer); | |||||
$ordersArray = $orderModule->getRepository()->findOrdersWithOrderStatusAliasNull(); | |||||
echo ($ordersArray ? count($ordersArray) : '0').' : '.$producer->name."\n"; | |||||
while ($ordersArray && count($ordersArray)) { | |||||
foreach ($ordersArray as $order) { | |||||
$orderModule->getManager()->changeOrderStatus( | |||||
$order, | |||||
OrderStatus::ALIAS_ORDERED, | |||||
$userSystem, | |||||
new DateTime($order->date) | |||||
); | |||||
if($order->date_update) { | |||||
$orderModule->getManager()->changeOrderStatus( | |||||
$order, | |||||
OrderStatus::ALIAS_UPDATED, | |||||
$userSystem, | |||||
new DateTime($order->date_update) | |||||
); | |||||
} | |||||
if($order->date_delete) { | |||||
$orderModule->getManager()->changeOrderStatus( | |||||
$order, | |||||
OrderStatus::ALIAS_DELETED, | |||||
$userSystem, | |||||
new DateTime($order->date_delete) | |||||
); | |||||
} | |||||
echo 'Order #'.$order->id."\n"; | |||||
} | |||||
$ordersArray = $orderModule->getRepository()->findOrdersWithOrderStatusAliasNull(); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeDown() | |||||
{ | |||||
} | |||||
} |
return $order; | return $order; | ||||
} | } | ||||
public function initDateUpdate(Order $order) | |||||
{ | |||||
$this->date_update = date('Y-m-d H:i:s');; | |||||
} | |||||
public function addProductOrdersFromSubscription(Order $order, Subscription $subscription): bool | public function addProductOrdersFromSubscription(Order $order, Subscription $subscription): bool | ||||
{ | { | ||||
$productsAdd = false; | $productsAdd = false; |
$orderStatus = $this->orderStatusRepository->getOrderStatusByAlias($orderStatusAlias); | $orderStatus = $this->orderStatusRepository->getOrderStatusByAlias($orderStatusAlias); | ||||
$order->setOrderStatus($orderStatus); | $order->setOrderStatus($orderStatus); | ||||
$this->orderBuilder->initDateUpdate($order); | |||||
$this->orderBuilder->update($order); | $this->orderBuilder->update($order); | ||||
$this->orderStatusHistoryManager->create( | $this->orderStatusHistoryManager->create( |
->where('distribution.id_producer = :id_producer') | ->where('distribution.id_producer = :id_producer') | ||||
->andWhere('distribution.date >= :date_today') | ->andWhere('distribution.date >= :date_today') | ||||
->andWhere('distribution.date ' . $comparatorDateStart . ' :date_start') | ->andWhere('distribution.date ' . $comparatorDateStart . ' :date_start') | ||||
->andWhere('order.id_subscription = :id_subscription'); | |||||
->andWhere('order.id_subscription = :id_subscription') | |||||
->andWhere(OrderRepositoryQuery::getSqlFilterIsValid()); | |||||
$orders->params($params); | $orders->params($params); | ||||
$paramsOrders[':date_start'] = date('Y-m-d 00:00:00'); | $paramsOrders[':date_start'] = date('Y-m-d 00:00:00'); | ||||
} | } | ||||
$conditionsOrders .= ' AND '.OrderRepositoryQuery::getSqlFilterIsOrderStatusNotDeleted(); | |||||
$ordersArray = Order::searchAll([], [ | $ordersArray = Order::searchAll([], [ | ||||
'orderby' => 'IF(ISNULL(date_update), `order`.`date`, `order`.`date_update`) DESC', | '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 order_status_alias LIKE \''.OrderStatus::ALIAS_CANCELED.'\')))', | |||||
'conditions' => $conditionsOrders . ' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND date_update IS NOT NULL))', | |||||
'params' => $paramsOrders, | 'params' => $paramsOrders, | ||||
]); | ]); | ||||
{ | { | ||||
return Order::searchCount([ | return Order::searchCount([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
} | } | ||||
public static function getSqlFilterIsValid(): string | public static function getSqlFilterIsValid(): string | ||||
{ | { | ||||
return "(`order`.order_status_alias = '".OrderStatus::ALIAS_ORDERED."' OR `order`.order_status_alias = '".OrderStatus::ALIAS_UPDATED."')"; | |||||
return " (`order`.order_status_alias = '".OrderStatus::ALIAS_ORDERED."' OR `order`.order_status_alias = '".OrderStatus::ALIAS_UPDATED."') "; | |||||
} | |||||
public static function getSqlFilterIsOrderStatusNotDeleted(): string | |||||
{ | |||||
return " (`order`.order_status_alias != '".OrderStatus::ALIAS_DELETED."') "; | |||||
} | } | ||||
public function filterIsValid(): self | public function filterIsValid(): self |
use domain\Document\Document\Document; | use domain\Document\Document\Document; | ||||
use domain\Document\Document\DocumentSolver; | use domain\Document\Document\DocumentSolver; | ||||
use domain\Order\OrderStatus\OrderStatus; | use domain\Order\OrderStatus\OrderStatus; | ||||
use domain\Order\OrderStatus\OrderStatusSolver; | |||||
use domain\Order\OrderStatusHistory\OrderStatusHistory; | use domain\Order\OrderStatusHistory\OrderStatusHistory; | ||||
use domain\Order\OrderStatusHistory\OrderStatusHistorySolver; | use domain\Order\OrderStatusHistory\OrderStatusHistorySolver; | ||||
use domain\Order\ProductOrder\ProductOrderSolver; | use domain\Order\ProductOrder\ProductOrderSolver; | ||||
protected ProducerSolver $producerSolver; | protected ProducerSolver $producerSolver; | ||||
protected ProductOrderSolver $productOrderSolver; | protected ProductOrderSolver $productOrderSolver; | ||||
protected OrderStatusHistorySolver $orderStatusHistorySolver; | protected OrderStatusHistorySolver $orderStatusHistorySolver; | ||||
protected OrderStatusSolver $orderStatusSolver; | |||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->producerSolver = $this->loadService(ProducerSolver::class); | $this->producerSolver = $this->loadService(ProducerSolver::class); | ||||
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class); | $this->productOrderSolver = $this->loadService(ProductOrderSolver::class); | ||||
$this->orderStatusHistorySolver = $this->loadService(OrderStatusHistorySolver::class); | $this->orderStatusHistorySolver = $this->loadService(OrderStatusHistorySolver::class); | ||||
$this->orderStatusSolver = $this->loadService(OrderStatusSolver::class); | |||||
} | } | ||||
public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string | public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string | ||||
return '<br><span class="payment-detail-remaining-surplus">'.$text.'</span>'; | return '<br><span class="payment-detail-remaining-surplus">'.$text.'</span>'; | ||||
} | } | ||||
public function getLabelOrderStatus(Order $order): string | |||||
{ | |||||
$orderStatusCssClass = $this->getOrderStatusCssClass($order); | |||||
$orderStatusLabel = $this->getOrderStatusLabel($order); | |||||
$orderStatusHistorySummaryTitleTag = $this->getOrderStatusHistorySummaryTitleTag($order); | |||||
return '<span class="label label-'.$orderStatusCssClass.'" title="'.$orderStatusHistorySummaryTitleTag.'">'.$orderStatusLabel.'</span>'; | |||||
} | |||||
/** | /** | ||||
* Retourne l'origine de la commande (client, automatique ou admin) sous forme texte ou HTML. | * Retourne l'origine de la commande (client, automatique ou admin) sous forme texte ou HTML. | ||||
*/ | */ | ||||
// getStrOrigin | |||||
public function getLabelOrigin(Order $order, bool $withLabel = false): string | public function getLabelOrigin(Order $order, bool $withLabel = false): string | ||||
{ | { | ||||
$classLabel = ''; | $classLabel = ''; | ||||
if ($order->origin == Order::ORIGIN_USER) { | if ($order->origin == Order::ORIGIN_USER) { | ||||
$classLabel = 'success'; | $classLabel = 'success'; | ||||
$str = 'Client'; | |||||
$str = 'Utilisateur'; | |||||
} elseif ($order->origin == Order::ORIGIN_AUTO) { | } elseif ($order->origin == Order::ORIGIN_AUTO) { | ||||
$classLabel = 'default'; | $classLabel = 'default'; | ||||
$str = 'Auto'; | |||||
$str = 'Abonnement'; | |||||
} elseif ($order->origin == Order::ORIGIN_ADMIN) { | } elseif ($order->origin == Order::ORIGIN_ADMIN) { | ||||
$classLabel = 'warning'; | $classLabel = 'warning'; | ||||
$str = 'Vous'; | |||||
$str = 'Producteur'; | |||||
} | } | ||||
if ($withLabel) { | if ($withLabel) { | ||||
return '<span class="label label-' . $classLabel . '">' | |||||
. $str . '</span>'; | |||||
return '<span class="label label-' . $classLabel . ' outline">' . $str . '</span>'; | |||||
} else { | } else { | ||||
return $str; | return $str; | ||||
} | } | ||||
public function getOrderStatusLabel(Order $order): string | public function getOrderStatusLabel(Order $order): string | ||||
{ | { | ||||
if($this->isOrderStatusOrdered($order)) { | |||||
return 'Validée'; | |||||
} | |||||
elseif($this->isOrderStatusUpdated($order)) { | |||||
return 'Modifiée'; | |||||
} | |||||
elseif($this->isOrderStatusCanceled($order)) { | |||||
return 'Annulée'; | |||||
} | |||||
elseif($this->isOrderStatusDeleted($order)) { | |||||
return 'Supprimée'; | |||||
} | |||||
return ''; | |||||
return $this->orderStatusSolver->getLabel($order->getOrderStatusAlias()); | |||||
} | } | ||||
public function getOrderStatusHistorySummaryTitleTag(Order $order): string | |||||
public function getOrderStatusHistorySummaryTitleTag(Order $order, string $lineBreak = '
'): string | |||||
{ | { | ||||
$titleTagString = ''; | $titleTagString = ''; | ||||
foreach($order->getOrderStatusHistory() as $orderStatusHistory) { | foreach($order->getOrderStatusHistory() as $orderStatusHistory) { | ||||
$titleTagString .= $this->orderStatusHistorySolver->getOrderStatusHistoryLabel($orderStatusHistory).' ' | $titleTagString .= $this->orderStatusHistorySolver->getOrderStatusHistoryLabel($orderStatusHistory).' ' | ||||
.date('\l\e d/m/Y à H:i:s', $orderStatusHistory->getDate()->getTimestamp()).' ' | |||||
.date('\l\e d/m/Y à H:i', $orderStatusHistory->getDate()->getTimestamp()).' ' | |||||
.' par '.$this->userSolver->getUsername($orderStatusHistory->getUser()).' (#'.$orderStatusHistory->getUser()->getId().')' | .' par '.$this->userSolver->getUsername($orderStatusHistory->getUser()).' (#'.$orderStatusHistory->getUser()->getId().')' | ||||
.'
'; | |||||
.$lineBreak; | |||||
} | } | ||||
return $titleTagString; | return $titleTagString; | ||||
} | } | ||||
public function getLastOrderStatusHistory(Order $order): ?OrderStatusHistory | |||||
{ | |||||
$lastOrderStatusHistory = null; | |||||
foreach($order->getOrderStatusHistory() as $orderStatusHistory) { | |||||
if(!$lastOrderStatusHistory || $orderStatusHistory->date > $lastOrderStatusHistory->date) { | |||||
$lastOrderStatusHistory = $orderStatusHistory; | |||||
} | |||||
} | |||||
return $lastOrderStatusHistory; | |||||
} | |||||
} | } |
$orders = Order::searchAll([ | $orders = Order::searchAll([ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'order.tiller_synchronization' => 1, | 'order.tiller_synchronization' => 1, | ||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
$strDate = date('Y-m-d\T12:i:s+0000', strtotime($date) + 1); | $strDate = date('Y-m-d\T12:i:s+0000', strtotime($date) + 1); | ||||
$ordersOpendistrib = Order::searchAll([ | $ordersOpendistrib = Order::searchAll([ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'order.tiller_synchronization' => 1, | 'order.tiller_synchronization' => 1, | ||||
'order_status_alias' => OrderStatus::ALIAS_ORDERED | |||||
], [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | ]); | ||||
$ordersOpendistribSynchro = []; | $ordersOpendistribSynchro = []; |
{ | { | ||||
return [ | return [ | ||||
OrderStatus::ALIAS_ORDERED => [ | OrderStatus::ALIAS_ORDERED => [ | ||||
'name' => 'Validée' | |||||
'label' => 'Créée' | |||||
], | ], | ||||
OrderStatus::ALIAS_UPDATED => [ | OrderStatus::ALIAS_UPDATED => [ | ||||
'name' => 'Modifiée' | |||||
'label' => 'Modifiée' | |||||
], | ], | ||||
OrderStatus::ALIAS_CANCELED => [ | OrderStatus::ALIAS_CANCELED => [ | ||||
'name' => 'Annulée' | |||||
'label' => 'Annulée' | |||||
], | ], | ||||
OrderStatus::ALIAS_DELETED => [ | OrderStatus::ALIAS_DELETED => [ | ||||
'name' => 'Supprimée' | |||||
'label' => 'Supprimée' | |||||
] | ] | ||||
]; | ]; | ||||
} | } |
{ | { | ||||
return [ | return [ | ||||
OrderStatusDefinition::class, | OrderStatusDefinition::class, | ||||
OrderStatusSolver::class, | |||||
OrderStatusRepository::class, | OrderStatusRepository::class, | ||||
OrderStatusBuilder::class, | OrderStatusBuilder::class, | ||||
]; | ]; | ||||
return OrderStatusDefinition::getInstance(); | return OrderStatusDefinition::getInstance(); | ||||
} | } | ||||
public function getSolver(): OrderStatusSolver | |||||
{ | |||||
return OrderStatusSolver::getInstance(); | |||||
} | |||||
public function getRepository(): OrderStatusRepository | public function getRepository(): OrderStatusRepository | ||||
{ | { | ||||
return OrderStatusRepository::getInstance(); | return OrderStatusRepository::getInstance(); |
if(isset($orderStatusArray[$alias])) { | if(isset($orderStatusArray[$alias])) { | ||||
return OrderStatusBuilder::getInstance()->instanciateOrderStatus( | return OrderStatusBuilder::getInstance()->instanciateOrderStatus( | ||||
$alias, | $alias, | ||||
$orderStatusArray[$alias]['name'] | |||||
$orderStatusArray[$alias]['label'] | |||||
); | ); | ||||
} | } | ||||
else { | else { |
<?php | |||||
namespace domain\Order\OrderStatus; | |||||
use domain\_\AbstractSolver; | |||||
class OrderStatusSolver extends AbstractSolver | |||||
{ | |||||
protected OrderStatusDefinition $orderStatusDefinition; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->orderStatusDefinition = $this->loadService(OrderStatusDefinition::class); | |||||
} | |||||
public function getLabel(string $orderStatusAlias): string | |||||
{ | |||||
$orderStatusArray = $this->orderStatusDefinition->getOrderStatusList(); | |||||
if(isset($orderStatusArray[$orderStatusAlias])) { | |||||
return $orderStatusArray[$orderStatusAlias]['label']; | |||||
} | |||||
else { | |||||
return '?'; | |||||
} | |||||
} | |||||
} |
namespace domain\Order\OrderStatusHistory; | namespace domain\Order\OrderStatusHistory; | ||||
use domain\_\AbstractSolver; | use domain\_\AbstractSolver; | ||||
use domain\Order\OrderStatus\OrderStatus; | |||||
use domain\Order\OrderStatus\OrderStatusSolver; | |||||
class OrderStatusHistorySolver extends AbstractSolver | class OrderStatusHistorySolver extends AbstractSolver | ||||
{ | { | ||||
public function getOrderStatusHistoryLabel(OrderStatusHistory $orderStatusHistory): string | |||||
protected OrderStatusSolver $orderStatusSolver; | |||||
public function loadDependencies(): void | |||||
{ | { | ||||
if($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED) { | |||||
return 'Validée'; | |||||
} | |||||
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_UPDATED) { | |||||
return 'Modifiée'; | |||||
} | |||||
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED) { | |||||
return 'Annulée'; | |||||
} | |||||
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_DELETED) { | |||||
return 'Supprimée'; | |||||
} | |||||
$this->orderStatusSolver = $this->loadService(OrderStatusSolver::class); | |||||
} | |||||
return ''; | |||||
public function getOrderStatusHistoryLabel(OrderStatusHistory $orderStatusHistory): string | |||||
{ | |||||
return $this->orderStatusSolver->getLabel($orderStatusHistory->getOrderStatusAlias()); | |||||
} | } | ||||
} | } |
use domain\Config\Unit\UnitDefinition; | use domain\Config\Unit\UnitDefinition; | ||||
use domain\Distribution\Distribution\Distribution; | use domain\Distribution\Distribution\Distribution; | ||||
use domain\Order\Order\Order; | use domain\Order\Order\Order; | ||||
use domain\Order\Order\OrderRepositoryQuery; | |||||
use domain\Order\OrderStatus\OrderStatus; | use domain\Order\OrderStatus\OrderStatus; | ||||
use domain\Order\ProductOrder\ProductOrder; | use domain\Order\ProductOrder\ProductOrder; | ||||
use domain\PointSale\PointSale\PointSale; | use domain\PointSale\PointSale\PointSale; | ||||
->where('id_distribution = :id_distribution') | ->where('id_distribution = :id_distribution') | ||||
->andWhere('id_user = :id_user') | ->andWhere('id_user = :id_user') | ||||
->andWhere('id_point_sale = :id_point_sale') | ->andWhere('id_point_sale = :id_point_sale') | ||||
->andWhere(OrderRepositoryQuery::getSqlFilterIsValid()) | |||||
->params([ | ->params([ | ||||
':id_distribution' => $posts['Order']['id_distribution'], | ':id_distribution' => $posts['Order']['id_distribution'], | ||||
':id_point_sale' => $posts['Order']['id_point_sale'], | ':id_point_sale' => $posts['Order']['id_point_sale'], | ||||
if ($order && !$order->online_payment_url) { | if ($order && !$order->online_payment_url) { | ||||
if ($order->id_point_sale != $posts['Order']['id_point_sale']) { | if ($order->id_point_sale != $posts['Order']['id_point_sale']) { | ||||
$order->id_point_sale = $posts['Order']['id_point_sale']; | $order->id_point_sale = $posts['Order']['id_point_sale']; | ||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $user); | |||||
} | } | ||||
} else { | } else { | ||||
// gestion user : option_allow_order_guest | // gestion user : option_allow_order_guest | ||||
} | } | ||||
$order->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | $order->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | ||||
if(!$isNewOrder) { | |||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $user); | |||||
} | |||||
$order->save(); | $order->save(); | ||||
$orderModule->generateOrderReference($order); | $orderModule->generateOrderReference($order); | ||||
if($isNewOrder) { | if($isNewOrder) { | ||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_ORDERED, $user); | $orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_ORDERED, $user); | ||||
} | } | ||||
else { | |||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $user); | |||||
} | |||||
$producerModule->addUser($user, $producer); | $producerModule->addUser($user, $producer); | ||||
// suppression de tous les enregistrements ProductOrder | // suppression de tous les enregistrements ProductOrder | ||||
public function ajaxInfosOrders(Producer $producer, PointSale $pointSaleCurrent = null): array | public function ajaxInfosOrders(Producer $producer, PointSale $pointSaleCurrent = null): array | ||||
{ | { | ||||
$producerModule = $this->getProducerModule(); | |||||
$orderModule = $this->getOrderModule(); | $orderModule = $this->getOrderModule(); | ||||
$dateMini = date('Y-m-d'); | $dateMini = date('Y-m-d'); | ||||
$ordersUserArray = []; | $ordersUserArray = []; | ||||
if (GlobalParam::getCurrentUserId()) { | if (GlobalParam::getCurrentUserId()) { | ||||
$paramsOrdersUser[':id_point_sale'] = $pointSaleCurrent->id; | $paramsOrdersUser[':id_point_sale'] = $pointSaleCurrent->id; | ||||
} | } | ||||
$conditionsOrdersUser[] = OrderRepositoryQuery::getSqlFilterIsValid(); | |||||
$ordersUserArray = Order::searchAll([ | $ordersUserArray = Order::searchAll([ | ||||
'id_user' => GlobalParam::getCurrentUserId() | 'id_user' => GlobalParam::getCurrentUserId() | ||||
], [ | ], [ | ||||
if (GlobalParam::getCurrentUserId()) { | if (GlobalParam::getCurrentUserId()) { | ||||
$conditionOrderUser = [ | $conditionOrderUser = [ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'id_user' => GlobalParam::getCurrentUserId(), | |||||
'id_user' => GlobalParam::getCurrentUserId() | |||||
]; | ]; | ||||
if ($pointSale) { | if ($pointSale) { | ||||
$conditionOrderUser['id_point_sale'] = $pointSale; | |||||
$conditionOrderUser['id_point_sale'] = $pointSale->id; | |||||
} | } | ||||
$orderUser = Order::searchOne($conditionOrderUser); | |||||
$orderUser = Order::searchOne($conditionOrderUser, [ | |||||
'conditions' => OrderRepositoryQuery::getSqlFilterIsValid() | |||||
]); | |||||
if ($orderUser && $orderUser->online_payment_url) { | if ($orderUser && $orderUser->online_payment_url) { | ||||
$orderUser = null; | $orderUser = null; |