|
|
@@ -39,23 +39,19 @@ |
|
|
|
namespace backend\controllers; |
|
|
|
|
|
|
|
use common\helpers\Ajax; |
|
|
|
use common\helpers\CSV; |
|
|
|
use common\helpers\GlobalParam; |
|
|
|
use common\helpers\MeanPayment; |
|
|
|
use common\helpers\Password; |
|
|
|
use common\helpers\Price; |
|
|
|
use common\helpers\Tiller; |
|
|
|
use common\logic\Distribution\Distribution\Model\Distribution; |
|
|
|
use common\logic\Document\DeliveryNote\Model\DeliveryNote; |
|
|
|
use common\logic\Document\Document\Model\Document; |
|
|
|
use common\logic\Order\Order\Model\Order; |
|
|
|
use common\logic\PointSale\PointSale\Model\PointSale; |
|
|
|
use common\logic\Producer\Producer\Model\Producer; |
|
|
|
use common\logic\Product\Product\Model\Product; |
|
|
|
use common\logic\User\User\Model\User; |
|
|
|
use common\logic\User\UserProducer\Model\UserProducer; |
|
|
|
use DateTime; |
|
|
|
use kartik\mpdf\Pdf; |
|
|
|
use yii\base\Exception; |
|
|
|
use yii\filters\AccessControl; |
|
|
|
|
|
|
|
class DistributionController extends BackendController |
|
|
@@ -85,27 +81,22 @@ class DistributionController extends BackendController |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionIndex($date = '', $idOrderUpdate = 0) |
|
|
|
public function actionIndex(string $date = '', int $idOrderUpdate = 0) |
|
|
|
{ |
|
|
|
$this->checkProductsPointsSale(); |
|
|
|
|
|
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
|
|
|
|
$format = 'Y-m-d'; |
|
|
|
$theDate = ''; |
|
|
|
$dateObject = DateTime::createFromFormat($format, $date); |
|
|
|
|
|
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
|
$theDate = $date; |
|
|
|
if(!$this->getDistributionModule()->getSolver()->validateDistributionDate($date)) { |
|
|
|
$date = ''; |
|
|
|
} |
|
|
|
|
|
|
|
$orderUpdate = null; |
|
|
|
if ($idOrderUpdate) { |
|
|
|
$orderUpdate = $orderModule->findOneOrderById($idOrderUpdate); |
|
|
|
if($idOrderUpdate) { |
|
|
|
$orderUpdate = $this->getOrderModule()->getRepository() |
|
|
|
->findOneOrderById($idOrderUpdate); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('index', [ |
|
|
|
'date' => $theDate, |
|
|
|
'date' => $date, |
|
|
|
'orderUpdate' => $orderUpdate |
|
|
|
]); |
|
|
|
} |
|
|
@@ -120,16 +111,14 @@ class DistributionController extends BackendController |
|
|
|
$userModule = $this->getUserModule(); |
|
|
|
|
|
|
|
$producer = $this->getProducerCurrent(); |
|
|
|
$format = 'Y-m-d'; |
|
|
|
$dateObject = DateTime::createFromFormat($format, $date); |
|
|
|
|
|
|
|
$dateObject = DateTime::createFromFormat('Y-m-d', $date); |
|
|
|
$json = ['distribution' => [], 'products' => []]; |
|
|
|
$json['means_payment'] = MeanPayment::getAll(); |
|
|
|
$json['producer'] = $this->buildAjaxInfosResponseProducer($producer); |
|
|
|
$json['distributions'] = $this->buildAjaxInfosResponseDistributions($dateObject); |
|
|
|
$json['units'] = Product::$unitsArray; |
|
|
|
|
|
|
|
if ($dateObject && $dateObject->format($format) === $date) { |
|
|
|
if ($distributionModule->getSolver()->validateDistributionDate($date)) { |
|
|
|
$distribution = $distributionModule->createDistributionIfNotExist($date); |
|
|
|
$ordersArray = $orderModule->findOrdersByDistribution($distribution, false); |
|
|
|
$ordersArrayObject = $ordersArray; |
|
|
@@ -927,45 +916,18 @@ class DistributionController extends BackendController |
|
|
|
return $return; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxGenerateDeliveryNote(int $idOrder) |
|
|
|
{ |
|
|
|
$this->generateDeliveryNote($idOrder); |
|
|
|
return Ajax::responseSuccess('Bon de livraison généré'); |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxGenerateDeliveryNotePointSale($idOrders) |
|
|
|
public function actionAjaxGenerateDeliveryNotePointSale(string $idOrders) |
|
|
|
{ |
|
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
$deliveryNoteModule = $this->getDeliveryNoteModule(); |
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
|
|
|
|
if (is_array($idOrders) && count($idOrders) > 0) { |
|
|
|
reset($idOrders); |
|
|
|
$firstOrder = $orderModule->findOneOrderById((int)$idOrders[key($idOrders)]); |
|
|
|
$ordersArray = Order::searchAll(['id' => $idOrders,]); |
|
|
|
$deliveryNote = $deliveryNoteModule->getOneDeliveryNoteExistingFromOrders($ordersArray); |
|
|
|
$isUpdate = (bool) $deliveryNote; |
|
|
|
|
|
|
|
if ($deliveryNote && $deliveryNoteModule->isStatusValid($deliveryNote)) { |
|
|
|
return Ajax::responseError('Vous ne pouvez pas modifier un bon de livraison déjà validé.'); |
|
|
|
} |
|
|
|
|
|
|
|
if(!$deliveryNote && $firstOrder && !$firstOrder->pointSale->id_user) { |
|
|
|
return Ajax::responseError("Vous devez définir un contact de facturation pour ce point de vente."); |
|
|
|
} |
|
|
|
|
|
|
|
if ($firstOrder) { |
|
|
|
if (!$deliveryNote) { |
|
|
|
$deliveryNoteModule->createDeliveryNoteForPointSale( |
|
|
|
$firstOrder->pointSale, |
|
|
|
$firstOrder->distribution, |
|
|
|
$idOrders |
|
|
|
); |
|
|
|
if(is_array($idOrders)) { |
|
|
|
try { |
|
|
|
if($this->getOrderModule()->getDocumentManager()->generateDeliveryNoteForPointSale($idOrders)) { |
|
|
|
return Ajax::responseSuccess("Bon de livraison généré"); |
|
|
|
} |
|
|
|
|
|
|
|
return Ajax::responseSuccess('Bon de livraison ' . ($isUpdate ? 'modifié' : 'généré')); |
|
|
|
} |
|
|
|
catch(Exception $exception) { |
|
|
|
return Ajax::responseError($exception->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -973,52 +935,30 @@ class DistributionController extends BackendController |
|
|
|
return Ajax::responseError('Une erreur est survenue lors de la génération du bon de livraison.'); |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxGenerateDeliveryNoteEachUser($idOrders) |
|
|
|
public function actionAjaxGenerateDeliveryNote(int $idOrder) |
|
|
|
{ |
|
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
$order = $orderModule->getRepository()->findOneOrderById($idOrder); |
|
|
|
$orderModule->getDocumentManager()->generateDeliveryNoteForUser($order); |
|
|
|
return Ajax::responseSuccess('Bon de livraison généré'); |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxGenerateDeliveryNoteEachUser(string $idOrders) |
|
|
|
{ |
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
|
|
|
|
if (is_array($idOrders) && count($idOrders) > 0) { |
|
|
|
foreach ($idOrders as $idOrder) { |
|
|
|
$this->generateDeliveryNote($idOrder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$this->getOrderModule()->getDocumentManager()->generateDeliveryNotesForUser($idOrders); |
|
|
|
return Ajax::responseSuccess('Bon(s) de livraison généré(s)'); |
|
|
|
} |
|
|
|
|
|
|
|
return Ajax::responseError('Une erreur est survenue lors de la génération du bon de livraison.'); |
|
|
|
} |
|
|
|
|
|
|
|
public function generateDeliveryNote(int $idOrder) |
|
|
|
{ |
|
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
$deliveryNoteModule = $this->getDeliveryNoteModule(); |
|
|
|
|
|
|
|
$order = $orderModule->findOneOrderById($idOrder); |
|
|
|
if ($orderModule->isOrderFromProducer($order) && $order->id_user) { |
|
|
|
$deliveryNoteModule->createDeliveryNoteForOrder($order); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxValidateDeliveryNotes($idOrders) |
|
|
|
public function actionAjaxValidateDeliveryNotes(string $idOrders) |
|
|
|
{ |
|
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
$deliveryNoteModule = $this->getDeliveryNoteModule(); |
|
|
|
|
|
|
|
if (strlen($idOrders)) { |
|
|
|
$idOrders = json_decode($idOrders, true); |
|
|
|
if (is_array($idOrders) && count($idOrders) > 0) { |
|
|
|
foreach ($idOrders as $idOrder) { |
|
|
|
$order = $orderModule->findOneOrderById($idOrder); |
|
|
|
if ($orderModule->isOrderFromProducer($order)) { |
|
|
|
$deliveryNote = $deliveryNoteModule->findOneDeliveryNoteById((int) $order->id_delivery_note); |
|
|
|
if($deliveryNote) { |
|
|
|
$deliveryNoteModule->validateDocument($deliveryNote); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if($this->getOrderModule()->getDocumentManager()->validateDeliveryNotes($idOrders)) { |
|
|
|
return Ajax::responseSuccess('Bon(s) de livraison validé(s)'); |
|
|
|
} |
|
|
|
} |