|
|
@@ -1032,8 +1032,7 @@ class DistributionController extends BackendController |
|
|
|
|
|
|
|
public function actionAjaxValidateDeliveryNotes($idOrders) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
$deliveryNoteManager = $this->getDeliveryNoteManager(); |
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
@@ -1041,38 +1040,19 @@ class DistributionController extends BackendController |
|
|
|
|
|
|
|
if (is_array($idOrders) && count($idOrders) > 0) { |
|
|
|
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'); |
|
|
|
} |
|
|
|
} |