} | } | ||||
$order->id_point_sale = $idPointSale; | $order->id_point_sale = $idPointSale; | ||||
$order->date_update = date('Y-m-d H:i:s'); | |||||
$order->mean_payment = $meanPayment; | $order->mean_payment = $meanPayment; | ||||
$order->comment = $comment; | $order->comment = $comment; | ||||
$order->save(); | $order->save(); | ||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $this->getUserCurrent()); | |||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
$orderModule->initOrder($order); | $orderModule->initOrder($order); | ||||
if ($order && $orderModule->isCreditAutoPayment($order, $debitCredit)) { | if ($order && $orderModule->isCreditAutoPayment($order, $debitCredit)) { |
</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-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 == 'ordered' && order.date_update"><span class="glyphicon glyphicon-pencil"></span></span> | |||||
<span class="label label-success" v-if="order.order_status_alias == 'ordered' && !order.date_update"><span class="glyphicon glyphicon-check"></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> | |||||
</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> |
<?php | |||||
namespace console\commands; | |||||
use domain\Order\Order\OrderModule; | |||||
use domain\Order\OrderStatus\OrderStatus; | |||||
use domain\Producer\Producer\ProducerModule; | |||||
use domain\User\User\UserModule; | |||||
use yii\console\Controller; | |||||
class InitOrderStatusHistoryController extends Controller | |||||
{ | |||||
// ./yii init-order-status-history/index | |||||
public function actionIndex() | |||||
{ | |||||
/* | |||||
Remettre à zéro : | |||||
----------------- | |||||
DELETE FROM `order_status_history`; | |||||
UPDATE `order` SET `order`.order_status_alias = NULL; | |||||
*/ | |||||
$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(); | |||||
} | |||||
} | |||||
} | |||||
} |
<?php | <?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\Migration; | ||||
use yii\db\Schema; | use yii\db\Schema; | ||||
*/ | */ | ||||
public function safeUp() | public function safeUp() | ||||
{ | { | ||||
$this->execute("UPDATE `order` SET order_status_alias = IF(`order`.date_delete IS NULL, 'ordered', 'deleted')"); | |||||
//$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(); | |||||
} | |||||
} | |||||
} | } | ||||
/** | /** |
public function getOrderStatusHistoryRelation() | public function getOrderStatusHistoryRelation() | ||||
{ | { | ||||
return $this->hasMany(OrderStatusHistory::class, ['id_order' => 'id']) | return $this->hasMany(OrderStatusHistory::class, ['id_order' => 'id']) | ||||
->orderBy(['order_status_history.id' => SORT_ASC]); | |||||
->orderBy(['order_status_history.date' => SORT_ASC]); | |||||
} | } | ||||
} | } |
$this->subscriptionRepository = $this->loadService(SubscriptionRepository::class); | $this->subscriptionRepository = $this->loadService(SubscriptionRepository::class); | ||||
} | } | ||||
public function changeOrderStatus(Order $order, string $orderStatusAlias, User $user) | |||||
public function changeOrderStatus(Order $order, string $orderStatusAlias, User $user, \DateTime $date = null) | |||||
{ | { | ||||
$orderStatus = $this->orderStatusRepository->getOrderStatusByAlias($orderStatusAlias); | $orderStatus = $this->orderStatusRepository->getOrderStatusByAlias($orderStatusAlias); | ||||
$this->orderStatusHistoryManager->create( | $this->orderStatusHistoryManager->create( | ||||
$order, | $order, | ||||
$orderStatus, | $orderStatus, | ||||
new \DateTime(), | |||||
is_null($date) ? new \DateTime() : $date, | |||||
$user | $user | ||||
); | ); | ||||
} | } |
$this->query->filterIsOrderStatusNotDeleted(); | $this->query->filterIsOrderStatusNotDeleted(); | ||||
} | } | ||||
public function findOrdersWithOrderStatusAliasNull() | |||||
{ | |||||
$this->createQuery(); | |||||
$this->defaultFilterProducerContext(); | |||||
return $this->query | |||||
->filterIsOrderStatusAliasNull() | |||||
//->limit(100) | |||||
->find(); | |||||
} | |||||
public function findOneOrderById(int $id) | public function findOneOrderById(int $id) | ||||
{ | { | ||||
return $this->createDefaultQuery() | return $this->createDefaultQuery() | ||||
public function countGlobalOrdersByDateAndOrigin(\DateTime $date, string $origin = Order::ORIGIN_USER) | public function countGlobalOrdersByDateAndOrigin(\DateTime $date, string $origin = Order::ORIGIN_USER) | ||||
{ | { | ||||
// @TODO : pourquoi on utilise pas createDefaultQuery() ? | |||||
return $this->createQuery() | return $this->createQuery() | ||||
->filterIsOrderStatusNotDeleted() | ->filterIsOrderStatusNotDeleted() | ||||
->filterByDate($date) | ->filterByDate($date) |
public static function getSqlFilterIsValid(): string | public static function getSqlFilterIsValid(): string | ||||
{ | { | ||||
return "`order`.order_status_alias LIKE '".OrderStatus::ALIAS_ORDERED."'"; | |||||
return "`order`.order_status_alias = '".OrderStatus::ALIAS_ORDERED."' OR `order`.order_status_alias = '".OrderStatus::ALIAS_UPDATED."'"; | |||||
} | } | ||||
public function filterIsValid(): self | public function filterIsValid(): self | ||||
{ | { | ||||
$this->andWhere(['order_status_alias' => OrderStatus::ALIAS_ORDERED]); | |||||
$this->andWhere(self::getSqlFilterIsValid()); | |||||
return $this; | return $this; | ||||
} | } | ||||
public function filterIsOrderStatusNotDeleted() | |||||
public function filterIsOrderStatusNotDeleted(): self | |||||
{ | { | ||||
$this->andWhere('order_status_alias != :status_deleted') | $this->andWhere('order_status_alias != :status_deleted') | ||||
->params([':status_deleted' => OrderStatus::ALIAS_DELETED]); | ->params([':status_deleted' => OrderStatus::ALIAS_DELETED]); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function filterIsOrderStatusAliasNull(): self | |||||
{ | |||||
$this->andWhere('order_status_alias IS NULL'); | |||||
return $this; | |||||
} | |||||
public function filterByUser(User $user): self | public function filterByUser(User $user): self | ||||
{ | { | ||||
$this->andWhere(['order.id_user' => $user->id]); | $this->andWhere(['order.id_user' => $user->id]); |
public function getOrderStatusHistoryByOrderStatusAlias(Order $order, string $orderStatusAlias): ?OrderStatusHistory | public function getOrderStatusHistoryByOrderStatusAlias(Order $order, string $orderStatusAlias): ?OrderStatusHistory | ||||
{ | { | ||||
$orderStatusHistoryReturn = null; | |||||
foreach($order->getOrderStatusHistory() as $orderStatusHistory) { | foreach($order->getOrderStatusHistory() as $orderStatusHistory) { | ||||
if($orderStatusHistory->getOrderStatusAlias() == $orderStatusAlias) { | if($orderStatusHistory->getOrderStatusAlias() == $orderStatusAlias) { | ||||
return $orderStatusHistory; | |||||
$orderStatusHistoryReturn = $orderStatusHistory; | |||||
} | } | ||||
} | } | ||||
return null; | |||||
return $orderStatusHistoryReturn; | |||||
} | } | ||||
public function isOrderStatusValid(Order $order): bool | public function isOrderStatusValid(Order $order): bool | ||||
{ | { | ||||
return $this->isOrderStatusOrdered($order); | |||||
return $this->isOrderStatusOrdered($order) | |||||
|| $this->isOrderStatusUpdated($order); | |||||
} | } | ||||
public function isOrderStatusCanceledOrDeleted(Order $order): bool | public function isOrderStatusCanceledOrDeleted(Order $order): bool | ||||
return $order->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED; | return $order->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED; | ||||
} | } | ||||
public function isOrderStatusUpdated(Order $order): bool | |||||
{ | |||||
return $order->getOrderStatusAlias() == OrderStatus::ALIAS_UPDATED; | |||||
} | |||||
public function isOrderStatusCanceled(Order $order): bool | public function isOrderStatusCanceled(Order $order): bool | ||||
{ | { | ||||
return $order->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED; | return $order->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED; | ||||
public function getOrderStatusCssClass(Order $order): string | public function getOrderStatusCssClass(Order $order): string | ||||
{ | { | ||||
if($this->isOrderStatusOrdered($order)) { | if($this->isOrderStatusOrdered($order)) { | ||||
if($order->date_update) { | |||||
return 'warning'; | |||||
} | |||||
else { | |||||
return 'success'; | |||||
} | |||||
return 'success'; | |||||
} | |||||
elseif($this->isOrderStatusUpdated($order)) { | |||||
return 'warning'; | |||||
} | } | ||||
elseif($this->isOrderStatusCanceled($order)) { | elseif($this->isOrderStatusCanceled($order)) { | ||||
return 'danger'; | return 'danger'; | ||||
public function getOrderStatusLabel(Order $order): string | public function getOrderStatusLabel(Order $order): string | ||||
{ | { | ||||
if($this->isOrderStatusOrdered($order)) { | if($this->isOrderStatusOrdered($order)) { | ||||
if($order->date_update) { | |||||
return 'Modifiée'; | |||||
} | |||||
else { | |||||
return 'Validée'; | |||||
} | |||||
return 'Validée'; | |||||
} | |||||
elseif($this->isOrderStatusUpdated($order)) { | |||||
return 'Modifiée'; | |||||
} | } | ||||
elseif($this->isOrderStatusCanceled($order)) { | elseif($this->isOrderStatusCanceled($order)) { | ||||
return 'Annulée'; | return 'Annulée'; | ||||
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:s', $orderStatusHistory->getDate()->getTimestamp()).' ' | |||||
.' par '.$this->userSolver->getUsername($orderStatusHistory->getUser()).' (#'.$orderStatusHistory->getUser()->getId().')' | |||||
.'
'; | |||||
} | } | ||||
return $titleTagString; | return $titleTagString; |
class OrderStatus | class OrderStatus | ||||
{ | { | ||||
const ALIAS_ORDERED = 'ordered'; | const ALIAS_ORDERED = 'ordered'; | ||||
const ALIAS_UPDATED = 'updated'; | |||||
const ALIAS_CANCELED = 'canceled'; | const ALIAS_CANCELED = 'canceled'; | ||||
const ALIAS_DELETED = 'deleted'; | const ALIAS_DELETED = 'deleted'; | ||||
{ | { | ||||
return [ | return [ | ||||
OrderStatus::ALIAS_ORDERED => [ | OrderStatus::ALIAS_ORDERED => [ | ||||
'name' => 'Commandée' | |||||
'name' => 'Validée' | |||||
], | |||||
OrderStatus::ALIAS_UPDATED => [ | |||||
'name' => 'Modifiée' | |||||
], | ], | ||||
OrderStatus::ALIAS_CANCELED => [ | OrderStatus::ALIAS_CANCELED => [ | ||||
'name' => 'Annulée' | 'name' => 'Annulée' |
/* Relations */ | /* Relations */ | ||||
private function getOrderRelation() | |||||
protected function getOrderRelation() | |||||
{ | { | ||||
return $this->hasOne(Order::class, ['id' => 'id_order']); | return $this->hasOne(Order::class, ['id' => 'id_order']); | ||||
} | } | ||||
private function getUserRelation() | |||||
protected function getUserRelation() | |||||
{ | { | ||||
return $this->hasOne(User::class, ['id' => 'id_user']); | return $this->hasOne(User::class, ['id' => 'id_user']); | ||||
} | } |
if($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED) { | if($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED) { | ||||
return 'Validée'; | return 'Validée'; | ||||
} | } | ||||
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_UPDATED) { | |||||
return 'Modifiée'; | |||||
} | |||||
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED) { | elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED) { | ||||
return 'Annulée'; | return 'Annulée'; | ||||
} | } |
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']; | ||||
$order->date_update = date('Y-m-d H:i:s'); | |||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $user); | |||||
} | } | ||||
} else { | } else { | ||||
// gestion user : option_allow_order_guest | // gestion user : option_allow_order_guest | ||||
// une commande annulée est automatiquement réactivée lors d'une modification | // une commande annulée est automatiquement réactivée lors d'une modification | ||||
if($orderModule->getSolver()->isOrderStatusCanceled($order)) { | if($orderModule->getSolver()->isOrderStatusCanceled($order)) { | ||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_ORDERED, $this->getUserCurrent()); | |||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $this->getUserCurrent()); | |||||
} | } | ||||
$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->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | $order->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null; | ||||
if(!$isNewOrder) { | if(!$isNewOrder) { | ||||
$order->date_update = date('Y-m-d H:i:s'); | |||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $user); | |||||
} | } | ||||
$order->save(); | $order->save(); | ||||
$orderModule->generateOrderReference($order); | $orderModule->generateOrderReference($order); | ||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_ORDERED, $user); | |||||
if($isNewOrder) { | |||||
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_ORDERED, $user); | |||||
} | |||||
$producerModule->addUser($user, $producer); | $producerModule->addUser($user, $producer); | ||||
// suppression de tous les enregistrements ProductOrder | // suppression de tous les enregistrements ProductOrder |