|
|
@@ -857,53 +857,22 @@ class DistributionController extends BackendController |
|
|
|
return $return; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxValidateDeliveryNotes($idOrders) |
|
|
|
public function actionAjaxGenerateDeliveryNote(int $idOrder) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
$deliveryNoteManager = $this->getDeliveryNoteManager(); |
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return [ |
|
|
|
'return' => 'success', |
|
|
|
'alert' => [ |
|
|
|
'type' => 'success', |
|
|
|
'message' => 'Bon(s) de livraison validé(s)' |
|
|
|
] |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
$this->generateDeliveryNote($idOrder); |
|
|
|
|
|
|
|
return [ |
|
|
|
'return' => 'error', |
|
|
|
'return' => 'success', |
|
|
|
'alert' => [ |
|
|
|
'type' => 'danger', |
|
|
|
'message' => 'Une erreur est survenue lors de la validation des bons de livraison' |
|
|
|
'type' => 'success', |
|
|
|
'message' => 'Bon de livraison généré' |
|
|
|
] |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxGenerateDeliveryNoteEachUser($idOrders) |
|
|
|
public function actionAjaxGenerateDeliveryNotePointSale($idOrders) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
@@ -912,95 +881,6 @@ class DistributionController extends BackendController |
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
$deliveryNoteManager = $this->getDeliveryNoteManager(); |
|
|
|
|
|
|
|
$producerCurrent = $this->getProducerCurrent(); |
|
|
|
|
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
|
|
|
|
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() && $order->id_user) { |
|
|
|
|
|
|
|
$deliveryNote = null; |
|
|
|
$idDeliveryNote = $order->id_delivery_note; |
|
|
|
if ($idDeliveryNote) { |
|
|
|
$deliveryNote = DeliveryNote::searchOne([ |
|
|
|
'id' => (int)$idDeliveryNote |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
// on regénére le document si c'est un brouillon |
|
|
|
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) { |
|
|
|
$deliveryNote->delete(); |
|
|
|
$deliveryNote = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (!$deliveryNote) { |
|
|
|
$deliveryNote = new DeliveryNote(); |
|
|
|
$deliveryNoteManager->initTaxCalculationMethod($deliveryNote); |
|
|
|
$deliveryNote->id_producer = GlobalParam::getCurrentProducerId(); |
|
|
|
$deliveryNote->id_user = $order->id_user; |
|
|
|
$deliveryNote->name = 'Bon de livraison ' . $orderManager->getOrderUsername($order) . ' (' . date( |
|
|
|
'd/m/Y', |
|
|
|
strtotime( |
|
|
|
$order->distribution->date |
|
|
|
) |
|
|
|
) . ')'; |
|
|
|
$deliveryNote->address = $userManager->getFullAddress($order->user); |
|
|
|
$deliveryNote->save(); |
|
|
|
} |
|
|
|
|
|
|
|
if ($deliveryNote) { |
|
|
|
$order->id_delivery_note = $deliveryNote->id; |
|
|
|
$order->save(); |
|
|
|
|
|
|
|
// init invoice prices |
|
|
|
$user = $userManager->findOneUserById($deliveryNote->id_user); |
|
|
|
$userProducer = $userProducerManager->findOneUserProducer($user); |
|
|
|
$orderManager->updateOrderInvoicePrices($order, [ |
|
|
|
'user' => $user, |
|
|
|
'user_producer' => $userProducer, |
|
|
|
'point_sale' => $order->pointSale |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return [ |
|
|
|
'return' => 'success', |
|
|
|
'alert' => [ |
|
|
|
'type' => 'success', |
|
|
|
'message' => '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.' |
|
|
|
] |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxGenerateDeliveryNote($idOrders) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
$userManager = $this->getUserManager(); |
|
|
|
$userProducerManager = $this->getUserProducerManager(); |
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
$deliveryNoteManager = $this->getDeliveryNoteManager(); |
|
|
|
|
|
|
|
$producerCurrent = $this->getProducerCurrent(); |
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
|
|
|
@@ -1139,4 +1019,132 @@ 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); |
|
|
|
|
|
|
|
if (is_array($idOrders) && count($idOrders) > 0) { |
|
|
|
foreach ($idOrders as $idOrder) { |
|
|
|
$this->generateDeliveryNote($idOrder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return [ |
|
|
|
'return' => 'success', |
|
|
|
'alert' => [ |
|
|
|
'type' => 'success', |
|
|
|
'message' => '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.' |
|
|
|
] |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function generateDeliveryNote(int $idOrder) |
|
|
|
{ |
|
|
|
$userManager = $this->getUserManager(); |
|
|
|
$userProducerManager = $this->getUserProducerManager(); |
|
|
|
$orderManager = $this->getOrderManager(); |
|
|
|
$deliveryNoteManager = $this->getDeliveryNoteManager(); |
|
|
|
$order = $orderManager->findOneOrderById($idOrder); |
|
|
|
|
|
|
|
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId() && $order->id_user) { |
|
|
|
|
|
|
|
$deliveryNote = null; |
|
|
|
$idDeliveryNote = $order->id_delivery_note; |
|
|
|
if ($idDeliveryNote) { |
|
|
|
$deliveryNote = $deliveryNoteManager->findOneDeliveryNoteById($idDeliveryNote); |
|
|
|
} |
|
|
|
|
|
|
|
// on regénére le document si c'est un brouillon |
|
|
|
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) { |
|
|
|
$deliveryNote->delete(); |
|
|
|
$deliveryNote = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (!$deliveryNote) { |
|
|
|
$deliveryNote = $deliveryNoteManager->instanciateDeliveryNote(); |
|
|
|
$deliveryNoteManager->initTaxCalculationMethod($deliveryNote); |
|
|
|
$deliveryNote->id_producer = GlobalParam::getCurrentProducerId(); |
|
|
|
$deliveryNote->id_user = $order->id_user; |
|
|
|
$deliveryNote->name = 'Bon de livraison ' . $orderManager->getOrderUsername($order) . ' (' . date( |
|
|
|
'd/m/Y', |
|
|
|
strtotime( |
|
|
|
$order->distribution->date |
|
|
|
) |
|
|
|
) . ')'; |
|
|
|
$deliveryNote->address = $userManager->getFullAddress($order->user); |
|
|
|
$deliveryNote->save(); |
|
|
|
} |
|
|
|
|
|
|
|
if ($deliveryNote) { |
|
|
|
$order->id_delivery_note = $deliveryNote->id; |
|
|
|
$order->save(); |
|
|
|
|
|
|
|
$user = $userManager->findOneUserById($deliveryNote->id_user); |
|
|
|
$userProducer = $userProducerManager->findOneUserProducer($user); |
|
|
|
$orderManager->updateOrderInvoicePrices($order, [ |
|
|
|
'user' => $user, |
|
|
|
'user_producer' => $userProducer, |
|
|
|
'point_sale' => $order->pointSale |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxValidateDeliveryNotes($idOrders) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
|
|
|
$deliveryNoteManager = $this->getDeliveryNoteManager(); |
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return [ |
|
|
|
'return' => 'success', |
|
|
|
'alert' => [ |
|
|
|
'type' => 'success', |
|
|
|
'message' => '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' |
|
|
|
] |
|
|
|
]; |
|
|
|
} |
|
|
|
} |