Browse Source

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

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
ab99ef438a
4 changed files with 20 additions and 29 deletions
  1. +8
    -28
      backend/controllers/DistributionController.php
  2. +2
    -0
      common/helpers/Ajax.php
  3. +8
    -0
      common/logic/Document/Document/Service/DocumentBuilder.php
  4. +2
    -1
      composer.json

+ 8
- 28
backend/controllers/DistributionController.php View File



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

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


if (strlen($idOrders)) { if (strlen($idOrders)) {


if (is_array($idOrders) && count($idOrders) > 0) { if (is_array($idOrders) && count($idOrders) > 0) {
foreach ($idOrders as $idOrder) { foreach ($idOrders as $idOrder) {
$order = Order::searchOne([
'id' => (int)$idOrder
]);

if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) {
$deliveryNote = DeliveryNote::searchOne([
'id' => (int)$order->id_delivery_note
]);

if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) {
$deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID);
$deliveryNoteManager->saveUpdate($deliveryNote);
$order = $orderManager->findOneOrderById($idOrder);
if ($order && $orderManager->isOrderFromProducer($order)) {
$deliveryNote = $deliveryNoteManager->findOneDeliveryNoteById((int)$order->id_delivery_note);
if($deliveryNote) {
$deliveryNoteManager->validateDocument($deliveryNote);
} }
} }
} }


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


return [
'return' => 'error',
'alert' => [
'type' => 'danger',
'message' => 'Une erreur est survenue lors de la validation des bons de livraison'
]
];
return Ajax::responseError('Une erreur est survenue lors de la validation des bons de livraison');
} }
} }

+ 2
- 0
common/helpers/Ajax.php View File



private static function response(string $responseType, string $message): array private static function response(string $responseType, string $message): array
{ {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

return [ return [
'return' => $responseType, 'return' => $responseType,
'alert' => [ 'alert' => [

+ 8
- 0
common/logic/Document/Document/Service/DocumentBuilder.php View File

} }
} }


public function validateDocument(Document $document): void
{
if($this->documentSolver->isStatusDraft($document)) {
$this->changeStatus($document, Document::STATUS_VALID);
$this->update($document);
}
}

public function initTaxCalculationMethod(DocumentInterface $document): void public function initTaxCalculationMethod(DocumentInterface $document): void
{ {
$producerTaxCalculationMethod = $this->producerRepository->getConfig('option_tax_calculation_method'); $producerTaxCalculationMethod = $this->producerRepository->getConfig('option_tax_calculation_method');

+ 2
- 1
composer.json View File

"loveorigami/yii2-bootstrap-toggle": "*", "loveorigami/yii2-bootstrap-toggle": "*",
"justcoded/yii2-event-listener": "*", "justcoded/yii2-event-listener": "*",
"ext-pdo": "*", "ext-pdo": "*",
"weluse/yii2-mailjet": "^0.2.0"
"weluse/yii2-mailjet": "^0.2.0",
"ext-json": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-codeception": "*", "yiisoft/yii2-codeception": "*",

Loading…
Cancel
Save