Browse Source

[Administration] Distributions : refactoring gestion des bons de livraisons #1195

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
88a0241e06
4 changed files with 18 additions and 35 deletions
  1. +10
    -31
      backend/controllers/DistributionController.php
  2. +1
    -0
      backend/web/js/vuejs/distribution-index.js
  3. +1
    -1
      common/helpers/Ajax.php
  4. +6
    -3
      common/logic/Order/Order/Service/OrderBuilder.php

+ 10
- 31
backend/controllers/DistributionController.php View File

@@ -759,9 +759,13 @@ class DistributionController extends BackendController
*/
public function actionAjaxProcessAddSubscriptions($date)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$this->getOrderManager()->createAllOrdersFromSubscriptions($date, true);
return ['success'];
$ordersArray = $this->getOrderManager()->createAllOrdersFromSubscriptions($date, true);

if($ordersArray && count($ordersArray)) {
return Ajax::responseSuccess('Les abonnements ont bien été importés.');
}

return Ajax::responseError('Aucun abonnement à importer.');
}

/**
@@ -860,23 +864,12 @@ class DistributionController extends BackendController

public function actionAjaxGenerateDeliveryNote(int $idOrder)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$this->generateDeliveryNote($idOrder);

return [
'return' => 'success',
'alert' => [
'type' => 'success',
'message' => 'Bon de livraison généré'
]
];
return Ajax::responseSuccess('Bon de livraison généré');
}

public function actionAjaxGenerateDeliveryNotePointSale($idOrders)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$orderManager = $this->getOrderManager();
$deliveryNoteManager = $this->getDeliveryNoteManager();

@@ -949,8 +942,6 @@ class DistributionController extends BackendController

public function actionAjaxGenerateDeliveryNoteEachUser($idOrders)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

if (strlen($idOrders)) {
$idOrders = json_decode($idOrders, true);

@@ -960,22 +951,10 @@ class DistributionController extends BackendController
}
}

return [
'return' => 'success',
'alert' => [
'type' => 'success',
'message' => 'Bon(s) de livraison généré(s)'
]
];
return Ajax::responseSuccess('Bon(s) de livraison généré(s)');
}

return [
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la génération du bon de livraison.'
]
];
return Ajax::responseError('Une erreur est survenue lors de la génération du bon de livraison.');
}

public function generateDeliveryNote(int $idOrder)

+ 1
- 0
backend/web/js/vuejs/distribution-index.js View File

@@ -549,6 +549,7 @@ var app = new Vue({
})
.then(function (response) {
app.init(app.idActivePointSale);
appAlerts.alertResponse(response);
});
},
synchroTiller: function () {

+ 1
- 1
common/helpers/Ajax.php View File

@@ -25,7 +25,7 @@ class Ajax
'return' => $responseType,
'alert' => [
'type' => self::getAlertClass($responseType),
'message' => 'Vous ne pouvez pas modifier un bon de livraison déjà validé.'
'message' => $message
]
];
}

+ 6
- 3
common/logic/Order/Order/Service/OrderBuilder.php View File

@@ -134,7 +134,7 @@ class OrderBuilder extends AbstractBuilder
*/
public function createAllOrdersFromSubscriptions(string $date, bool $force = false): array
{
$orderArray = [];
$ordersSubscriptionsArray = [];
$distribution = $this->distributionRepository->findOneDistribution(date('Y-m-d', strtotime($date)));

if ($distribution) {
@@ -142,12 +142,15 @@ class OrderBuilder extends AbstractBuilder
$subscriptionArray = $this->subscriptionRepository->findSubscriptionsByDate($date);
foreach ($subscriptionArray as $subscription) {
if (!$this->subscriptionSolver->hasOrderAlreadyExist($subscription, $orderArray)) {
$this->createOrderFromSubscription($subscription, $date, $force);
$order = $this->createOrderFromSubscription($subscription, $date, $force);
if($order) {
$ordersSubscriptionsArray[] = $order;
}
}
}
}

return $orderArray;
return $ordersSubscriptionsArray;
}

public function updateOrdersIncomingDistributionsFromSubscription(Subscription $subscription, $update = false): array

Loading…
Cancel
Save