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