소스 검색

[Administration] Distributions > Commandes : possibilité de générer un BL pour une commande via le bouton "Action" #1185

feature/souke
Guillaume Bourgeois 1 년 전
부모
커밋
00921b2601
3개의 변경된 파일721개의 추가작업 그리고 681개의 파일을 삭제
  1. +134
    -126
      backend/controllers/DistributionController.php
  2. +2
    -1
      backend/views/distribution/index.php
  3. +585
    -554
      backend/web/js/vuejs/distribution-index.js

+ 134
- 126
backend/controllers/DistributionController.php 파일 보기

@@ -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'
]
];
}
}

+ 2
- 1
backend/views/distribution/index.php 파일 보기

@@ -276,7 +276,7 @@ $this->setPageTitle('Distributions') ;
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a v-if="idActivePointSale > 0" @click="generateDeliveryNote" href="javascript:void(0);" >Générer un bon de livraison pour ce point de vente</a></li>
<li><a v-if="idActivePointSale > 0" @click="generateDeliveryNotePointSale" href="javascript:void(0);" >Générer un bon de livraison pour ce point de vente</a></li>
<li><a @click="generateDeliveryNoteEachUser" href="javascript:void(0);">Générer un bon de livraison pour chaque client</a></li>
<li><a @click="validateDeliveryNotes" href="javascript:void(0);">Valider les bons de livraisons</a></li>
</ul>
@@ -418,6 +418,7 @@ $this->setPageTitle('Distributions') ;
<li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="orderViewClick"><span :class="'glyphicon ' + ((showViewProduct && idOrderView == order.id) ? 'glyphicon-eye-close' : 'glyphicon-eye-open')"></span> Voir</a></li>
<li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="updateOrderClick"><span class="glyphicon glyphicon-pencil"></span> Modifier</a></li>
<li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="deleteOrderClick"><span class="glyphicon glyphicon-trash"></span> Supprimer</a></li>
<li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="generateDeliveryNote"><span class="glyphicon glyphicon-file"></span> Générer un bon de livraison</a></li>
<li v-if="order.id_subscription > 0"><a class="" :href="baseUrl+'/subscription/update?id='+order.id_subscription"><span class="glyphicon glyphicon-repeat"></span> Modifier l'abonnement associé</a></li>
<li v-else><a class="add-subscription" :href="baseUrl+'/subscription/create?idOrder='+order.id"><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-repeat"></span>Créer un abonnement sur cette base</a></li>
</ul>

+ 585
- 554
backend/web/js/vuejs/distribution-index.js
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


Loading…
취소
저장