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

@@ -999,12 +999,13 @@ class OrderController extends BackendController
}

$order->id_point_sale = $idPointSale;
$order->date_update = date('Y-m-d H:i:s');
$order->mean_payment = $meanPayment;
$order->comment = $comment;

$order->save();

$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $this->getUserCurrent());

$order = Order::searchOne(['id' => $order->id]);
$orderModule->initOrder($order);
if ($order && $orderModule->isCreditAutoPayment($order, $debitCredit)) {

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

@@ -375,8 +375,8 @@ $this->setPageTitle('Distributions') ;
</td>
<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 == '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 class="column-origin">
<label class="label label-success outline" v-if="order.origin == 'user'">Utilisateur</label>

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

@@ -0,0 +1,65 @@
<?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

@@ -1,5 +1,9 @@
<?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;

@@ -13,7 +17,49 @@ class m240528_072445_init_order_status_history extends Migration
*/
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

@@ -265,6 +265,6 @@ class Order extends ActiveRecordCommon
public function getOrderStatusHistoryRelation()
{
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

@@ -46,7 +46,7 @@ class OrderManager extends AbstractService implements ManagerInterface
$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);

@@ -56,7 +56,7 @@ class OrderManager extends AbstractService implements ManagerInterface
$this->orderStatusHistoryManager->create(
$order,
$orderStatus,
new \DateTime(),
is_null($date) ? new \DateTime() : $date,
$user
);
}

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

@@ -98,6 +98,17 @@ class OrderRepository extends AbstractRepository
$this->query->filterIsOrderStatusNotDeleted();
}

public function findOrdersWithOrderStatusAliasNull()
{
$this->createQuery();
$this->defaultFilterProducerContext();

return $this->query
->filterIsOrderStatusAliasNull()
//->limit(100)
->find();
}

public function findOneOrderById(int $id)
{
return $this->createDefaultQuery()
@@ -107,7 +118,6 @@ class OrderRepository extends AbstractRepository

public function countGlobalOrdersByDateAndOrigin(\DateTime $date, string $origin = Order::ORIGIN_USER)
{
// @TODO : pourquoi on utilise pas createDefaultQuery() ?
return $this->createQuery()
->filterIsOrderStatusNotDeleted()
->filterByDate($date)

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

@@ -58,17 +58,17 @@ class OrderRepositoryQuery extends AbstractRepositoryQuery

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
{
$this->andWhere(['order_status_alias' => OrderStatus::ALIAS_ORDERED]);
$this->andWhere(self::getSqlFilterIsValid());

return $this;
}

public function filterIsOrderStatusNotDeleted()
public function filterIsOrderStatusNotDeleted(): self
{
$this->andWhere('order_status_alias != :status_deleted')
->params([':status_deleted' => OrderStatus::ALIAS_DELETED]);
@@ -76,6 +76,12 @@ class OrderRepositoryQuery extends AbstractRepositoryQuery
return $this;
}

public function filterIsOrderStatusAliasNull(): self
{
$this->andWhere('order_status_alias IS NULL');
return $this;
}

public function filterByUser(User $user): self
{
$this->andWhere(['order.id_user' => $user->id]);

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

@@ -556,18 +556,20 @@ class OrderSolver extends AbstractService implements SolverInterface

public function getOrderStatusHistoryByOrderStatusAlias(Order $order, string $orderStatusAlias): ?OrderStatusHistory
{
$orderStatusHistoryReturn = null;
foreach($order->getOrderStatusHistory() as $orderStatusHistory) {
if($orderStatusHistory->getOrderStatusAlias() == $orderStatusAlias) {
return $orderStatusHistory;
$orderStatusHistoryReturn = $orderStatusHistory;
}
}

return null;
return $orderStatusHistoryReturn;
}

public function isOrderStatusValid(Order $order): bool
{
return $this->isOrderStatusOrdered($order);
return $this->isOrderStatusOrdered($order)
|| $this->isOrderStatusUpdated($order);
}

public function isOrderStatusCanceledOrDeleted(Order $order): bool
@@ -581,6 +583,11 @@ class OrderSolver extends AbstractService implements SolverInterface
return $order->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED;
}

public function isOrderStatusUpdated(Order $order): bool
{
return $order->getOrderStatusAlias() == OrderStatus::ALIAS_UPDATED;
}

public function isOrderStatusCanceled(Order $order): bool
{
return $order->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED;
@@ -605,12 +612,10 @@ class OrderSolver extends AbstractService implements SolverInterface
public function getOrderStatusCssClass(Order $order): string
{
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)) {
return 'danger';
@@ -625,12 +630,10 @@ class OrderSolver extends AbstractService implements SolverInterface
public function getOrderStatusLabel(Order $order): string
{
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)) {
return 'Annulée';
@@ -648,7 +651,9 @@ class OrderSolver extends AbstractService implements SolverInterface

foreach($order->getOrderStatusHistory() as $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;

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

@@ -5,6 +5,7 @@ namespace domain\Order\OrderStatus;
class OrderStatus
{
const ALIAS_ORDERED = 'ordered';
const ALIAS_UPDATED = 'updated';
const ALIAS_CANCELED = 'canceled';
const ALIAS_DELETED = 'deleted';


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

@@ -15,7 +15,10 @@ class OrderStatusDefinition extends AbstractDefinition
{
return [
OrderStatus::ALIAS_ORDERED => [
'name' => 'Commandée'
'name' => 'Validée'
],
OrderStatus::ALIAS_UPDATED => [
'name' => 'Modifiée'
],
OrderStatus::ALIAS_CANCELED => [
'name' => 'Annulée'

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

@@ -95,12 +95,12 @@ class OrderStatusHistory extends ActiveRecordCommon

/* Relations */

private function getOrderRelation()
protected function getOrderRelation()
{
return $this->hasOne(Order::class, ['id' => 'id_order']);
}

private function getUserRelation()
protected function getUserRelation()
{
return $this->hasOne(User::class, ['id' => 'id_user']);
}

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

@@ -12,6 +12,9 @@ class OrderStatusHistorySolver extends AbstractSolver
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';
}

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

@@ -185,7 +185,8 @@ class OrderController extends ProducerBaseController
if ($order && !$order->online_payment_url) {
if ($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 {
// gestion user : option_allow_order_guest
@@ -392,7 +393,7 @@ class OrderController extends ProducerBaseController

// une commande annulée est automatiquement réactivée lors d'une modification
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;
@@ -406,12 +407,14 @@ class OrderController extends ProducerBaseController

$order->comment = isset($posts['Order']['comment']) ? $posts['Order']['comment'] : null;
if(!$isNewOrder) {
$order->date_update = date('Y-m-d H:i:s');
$orderModule->getManager()->changeOrderStatus($order, OrderStatus::ALIAS_UPDATED, $user);
}
$order->save();

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

// suppression de tous les enregistrements ProductOrder

Loading…
Cancel
Save