Browse Source

Commandes : système de statut de commande

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
9fd46b0e44
14 changed files with 177 additions and 34 deletions
  1. +2
    -1
      backend/controllers/OrderController.php
  2. +2
    -2
      backend/views/distribution/index.php
  3. +65
    -0
      console/commands/InitOrderStatusHistoryController.php
  4. +47
    -1
      console/migrations/m240528_072445_init_order_status_history.php
  5. +1
    -1
      domain/Order/Order/Order.php
  6. +2
    -2
      domain/Order/Order/OrderManager.php
  7. +11
    -1
      domain/Order/Order/OrderRepository.php
  8. +9
    -3
      domain/Order/Order/OrderRepositoryQuery.php
  9. +21
    -16
      domain/Order/Order/OrderSolver.php
  10. +1
    -0
      domain/Order/OrderStatus/OrderStatus.php
  11. +4
    -1
      domain/Order/OrderStatus/OrderStatusDefinition.php
  12. +2
    -2
      domain/Order/OrderStatusHistory/OrderStatusHistory.php
  13. +3
    -0
      domain/Order/OrderStatusHistory/OrderStatusHistorySolver.php
  14. +7
    -4
      producer/controllers/OrderController.php

+ 2
- 1
backend/controllers/OrderController.php View File

} }


$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)) {

+ 2
- 2
backend/views/distribution/index.php View File

</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>

+ 65
- 0
console/commands/InitOrderStatusHistoryController.php View File

<?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();
}
}
}
}

+ 47
- 1
console/migrations/m240528_072445_init_order_status_history.php View File

<?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();
}
}
} }


/** /**

+ 1
- 1
domain/Order/Order/Order.php View File

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]);
} }
} }

+ 2
- 2
domain/Order/Order/OrderManager.php View File

$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
); );
} }

+ 11
- 1
domain/Order/Order/OrderRepository.php View File

$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)

+ 9
- 3
domain/Order/Order/OrderRepositoryQuery.php View File



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]);

+ 21
- 16
domain/Order/Order/OrderSolver.php View File



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()).'&#013;';
.date('\l\e d/m/Y à H:i:s', $orderStatusHistory->getDate()->getTimestamp()).' '
.' par '.$this->userSolver->getUsername($orderStatusHistory->getUser()).' (#'.$orderStatusHistory->getUser()->getId().')'
.'&#013;';
} }


return $titleTagString; return $titleTagString;

+ 1
- 0
domain/Order/OrderStatus/OrderStatus.php View File

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';



+ 4
- 1
domain/Order/OrderStatus/OrderStatusDefinition.php View File

{ {
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'

+ 2
- 2
domain/Order/OrderStatusHistory/OrderStatusHistory.php View File



/* 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']);
} }

+ 3
- 0
domain/Order/OrderStatusHistory/OrderStatusHistorySolver.php View File

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';
} }

+ 7
- 4
producer/controllers/OrderController.php View File

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

Loading…
Cancel
Save