Browse Source

[Administration] Bons de livraison : gestion de l'ajout/suppression/ignore de commandes #1235

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
62cfc18b8e
9 changed files with 263 additions and 167 deletions
  1. +63
    -0
      backend/controllers/DocumentController.php
  2. +0
    -51
      backend/controllers/InvoiceController.php
  3. +6
    -102
      backend/views/document/_form.php
  4. +45
    -0
      backend/views/document/form/_orders.php
  5. +71
    -0
      backend/views/document/form/_payment.php
  6. +11
    -8
      backend/web/js/vuejs/document-form.js
  7. +25
    -0
      common/logic/Order/Order/Repository/OrderRepository.php
  8. +16
    -0
      common/logic/Order/Order/Repository/OrderRepositoryQuery.php
  9. +26
    -6
      common/logic/Order/Order/Service/OrderBuilder.php

+ 63
- 0
backend/controllers/DocumentController.php View File

$json['orders_update_array'] = $document ? $this->initOrdersArray($orderManager->findOrdersByUserAndInvoice($user, $document)) : []; $json['orders_update_array'] = $document ? $this->initOrdersArray($orderManager->findOrdersByUserAndInvoice($user, $document)) : [];
} }


if ($classDocument == 'DeliveryNote') {
$json['orders_create_array'] = $this->initOrdersArray($orderManager->findOrdersByUserNotLinkedDeliveryNote($user));
$json['orders_update_array'] = $document ? $this->initOrdersArray($orderManager->findOrdersByUserAndDeliveryNote($user, $document)) : [];
}

return $json; return $json;
} }
} }
return Ajax::responseError('Une erreur est survenue lors de la suppression du produit.'); return Ajax::responseError('Une erreur est survenue lors de la suppression du produit.');
} }


public function actionAjaxAddOrder($idDocument, $classDocument, $idOrder)
{
$documentManager = $this->getDocumentManager();
$orderManager = $this->getOrderManager();

$document = $documentManager->findOneDocumentByIdAndClass($idDocument, $classDocument);
$order = $orderManager->findOneOrderById($idOrder);

if ($document && $documentManager->isStatusDraft($document) && $order) {
$orderManager->updateOrderDocument($order, $document);

return Ajax::responseSuccess("Commande ajoutée à la facture.");
}
else {
return Ajax::responseError("Une erreur est survenue lors de l'ajout de la commande.");
}
}

public function actionAjaxDeleteOrder($idDocument, $classDocument, $idOrder)
{
$documentManager = $this->getDocumentManager();
$orderManager = $this->getOrderManager();

$document = $documentManager->findOneDocumentByIdAndClass($idDocument, $classDocument);
$order = $orderManager->findOneOrderById($idOrder);

if ($document && $documentManager->isStatusDraft($document)) {
if($documentManager->isDocumentDeliveryNote($document)) {
$orderManager->updateOrderDeliveryNote($order, null);
}
elseif($documentManager->isDocumentInvoice($document)) {
$orderManager->updateOrderInvoice($order, null);
}

return Ajax::responseSuccess('Commande supprimée de la facture.');
}
else {
return Ajax::responseError('Une erreur est survenue lors de la suppression de la commande.');
}
}

public function actionAjaxIgnoreOrderWhenInvoicing($idDocument, $classDocument, $idOrder)
{
$documentManager = $this->getDocumentManager();
$orderManager = $this->getOrderManager();

$document = $documentManager->findOneDocumentByIdAndClass($idDocument, $classDocument);
$order = $orderManager->findOneOrderById($idOrder);

if ($document && $documentManager->isStatusDraft($document) && $order) {
$orderManager->updateOrderIgnoreWhenInvoicing($order, true);
return Ajax::responseSuccess("La commande sera maintenant ignorée au moment de la facturation.");
}
else {
return Ajax::responseError("Une erreur est survenue.");
}
}

public function getClass() public function getClass()
{ {
$class = get_class($this); $class = get_class($this);

+ 0
- 51
backend/controllers/InvoiceController.php View File

return Ajax::responseError("Une erreur est survenue lors de l'ajout du bon de livraison."); return Ajax::responseError("Une erreur est survenue lors de l'ajout du bon de livraison.");
} }
} }

public function actionAjaxAddOrder($idInvoice, $idOrder)
{
$invoiceManager = $this->getInvoiceManager();
$orderManager = $this->getOrderManager();

$invoice = $invoiceManager->findOneInvoiceById($idInvoice);
$order = $orderManager->findOneOrderById($idOrder);

if ($invoice && $invoiceManager->isStatusDraft($invoice) && $order) {
$orderManager->updateOrderInvoice($order, $invoice);
return Ajax::responseSuccess("Commande ajoutée à la facture.");
}
else {
return Ajax::responseError("Une erreur est survenue lors de l'ajout de la commande.");
}
}

public function actionAjaxDeleteOrder($idInvoice, $idOrder)
{
$invoiceManager = $this->getInvoiceManager();
$orderManager = $this->getOrderManager();

$invoice = $invoiceManager->findOneInvoiceById($idInvoice);
$order = $orderManager->findOneOrderById($idOrder);

if ($invoice && $invoiceManager->isStatusDraft($invoice)) {
$orderManager->updateOrderInvoice($order, null);
return Ajax::responseSuccess('Commande supprimée de la facture.');
}
else {
return Ajax::responseError('Une erreur est survenue lors de la suppression de la commande.');
}
}

public function actionAjaxIgnoreOrderWhenInvoicing($idInvoice, $idOrder)
{
$invoiceManager = $this->getInvoiceManager();
$orderManager = $this->getOrderManager();

$invoice = $invoiceManager->findOneInvoiceById($idInvoice);
$order = $orderManager->findOneOrderById($idOrder);

if ($invoice && $invoiceManager->isStatusDraft($invoice) && $order) {
$orderManager->updateOrderIgnoreWhenInvoicing($order, true);
return Ajax::responseSuccess("La commande sera maintenant ignorée au moment de la facturation.");
}
else {
return Ajax::responseError("Une erreur est survenue.");
}
}
} }

+ 6
- 102
backend/views/document/_form.php View File

</div> </div>
<div class="clr"></div> <div class="clr"></div>


<?php if ($action == 'update' && $documentClass == 'DeliveryNote'): ?>
<?= $this->render('form/_orders'); ?>
<?php endif; ?>

<?php if ($action == 'update' && $documentClass == 'Invoice'): ?> <?php if ($action == 'update' && $documentClass == 'Invoice'): ?>


<?php if($documentManager->isStatusValid($model)): ?>
<div>
<div class="panel panel-default">
<div class="panel-heading">
Règlement
</div>
<div class="panel-body">
<?php if($model->payments && count($model->payments) > 0): ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Moyen de paiement</th>
<th>Date transaction</th>
<th>Montant</th>
</tr>
</thead>
<tbody>
<?php foreach($model->payments as $payment): ?>
<tr>
<td><?= $paymentManager->getStrMeanPayment($payment); ?></td>
<td><?= $payment->date_transaction ? date('d/m/Y', strtotime($payment->date_transaction)) : '' ?></td>
<td><?= Price::format($payment->amount); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

<?php if($invoiceManager->isDocumentInvoice($model) && !$invoiceManager->isInvoicePaid($model)): ?>
<div class="row">
<?php $form = ActiveForm::begin(); ?>
<div class="col-md-3">
<?= $form->field($payment, 'mean_payment')->dropDownList(MeanPayment::getAll()); ?>
</div>
<div class="col-md-3">
<?= $form->field($payment, 'date_transaction')->textInput([
'class' => 'datepicker form-control'
]); ?>
</div>
<div class="col-md-3">
<?= $form->field($payment, 'amount', [
'template' => '{label}<div class="input-group">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>{hint}',
])->textInput(); ?>
</div>
<div class="col-md-3">
<div class="form-group">
<br>
<?= Html::submitButton('Ajouter', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
<?= $this->render('form/_payment', ['model' => $model]); ?>


<div v-if="(deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0) || (deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0)"> <div v-if="(deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0) || (deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0)">
<div class="panel panel-default"> <div class="panel panel-default">
</div> </div>
</div> </div>
<div v-else> <div v-else>
<div class="panel panel-default">
<div class="panel-heading">
Commandes
</div>
<div class="panel-body">
<table v-if="ordersUpdateArray && ordersUpdateArray.length > 0" class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th v-if="taxRateProducer != 0">Montant (TTC)</th>
<th v-else>Montant</th>
<th v-if="document.status == 'draft'"></th>
</tr>
</thead>
<tbody>
<tr v-for="order in ordersUpdateArray">
<td>{{ order.name }}</td>
<td>{{ formatPrice(order.amount_with_tax) }}</td>
<td v-if="document.status == 'draft'">
<a class="btn btn-default" href="javascript:void(0);" @click="deleteOrderFromInvoice"
:data-id="order.id">
<span class="glyphicon glyphicon-trash"></span>
</a>
</td>
</tr>
</tbody>
</table>
<div v-else class="alert alert-warning">Aucune commande associée.</div>

<div v-if="document.status == 'draft'" id="order-add">
<div class="col-md-8">
<select class="form-control" v-model="orderAddId">
<option value="0" selected="selected">--</option>
<option v-for="order in ordersCreateArray" :value="order.id">
{{ order.name }}
</option>
</select>
</div>
<div class="col-md-4">
<button class="btn btn-primary" value="Ajouter" @click="submitOrderAddToInvoice">Ajouter</button>
<button class="btn btn-danger" value="Ignorer" @click="submitOrderIgnoreWhenInvoicing">Ignorer</button>
</div>
</div>
</div>
</div>
<?= $this->render('form/_orders'); ?>
</div> </div>
<div class="clr"></div> <div class="clr"></div>
<?php endif; ?> <?php endif; ?>

+ 45
- 0
backend/views/document/form/_orders.php View File

<div class="panel panel-default">
<div class="panel-heading">
Commandes
</div>
<div class="panel-body">
<table v-if="ordersUpdateArray && ordersUpdateArray.length > 0" class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th v-if="taxRateProducer != 0">Montant (TTC)</th>
<th v-else>Montant</th>
<th v-if="document.status == 'draft'"></th>
</tr>
</thead>
<tbody>
<tr v-for="order in ordersUpdateArray">
<td>{{ order.name }}</td>
<td>{{ formatPrice(order.amount_with_tax) }}</td>
<td v-if="document.status == 'draft'">
<a class="btn btn-default" href="javascript:void(0);" @click="deleteOrderFromDocument"
:data-id="order.id">
<span class="glyphicon glyphicon-trash"></span>
</a>
</td>
</tr>
</tbody>
</table>
<div v-else class="alert alert-warning">Aucune commande associée.</div>

<div v-if="document.status == 'draft'" id="order-add">
<div class="col-md-8">
<select class="form-control" v-model="orderAddId">
<option value="0" selected="selected">--</option>
<option v-for="order in ordersCreateArray" :value="order.id">
{{ order.name }}
</option>
</select>
</div>
<div class="col-md-4">
<button class="btn btn-primary" value="Ajouter" @click="submitOrderAddToDocument">Ajouter</button>
<button class="btn btn-danger" value="Ignorer" @click="submitOrderIgnoreWhenInvoicing">Ignorer</button>
</div>
</div>
</div>
</div>

+ 71
- 0
backend/views/document/form/_payment.php View File

<?php

use common\helpers\MeanPayment;
use common\helpers\Price;
use common\logic\Document\Document\Wrapper\DocumentManager;
use common\logic\Document\Invoice\Wrapper\InvoiceManager;
use common\logic\Payment\Wrapper\PaymentManager;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

$documentManager = DocumentManager::getInstance();
$paymentManager = PaymentManager::getInstance();
$invoiceManager = InvoiceManager::getInstance();

if($documentManager->isStatusValid($model)): ?>
<div>
<div class="panel panel-default">
<div class="panel-heading">
Règlement
</div>
<div class="panel-body">
<?php if($model->payments && count($model->payments) > 0): ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Moyen de paiement</th>
<th>Date transaction</th>
<th>Montant</th>
</tr>
</thead>
<tbody>
<?php foreach($model->payments as $payment): ?>
<tr>
<td><?= $paymentManager->getStrMeanPayment($payment); ?></td>
<td><?= $payment->date_transaction ? date('d/m/Y', strtotime($payment->date_transaction)) : '' ?></td>
<td><?= Price::format($payment->amount); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

<?php if($invoiceManager->isDocumentInvoice($model) && !$invoiceManager->isInvoicePaid($model)): ?>
<div class="row">
<?php $form = ActiveForm::begin(); ?>
<div class="col-md-3">
<?= $form->field($payment, 'mean_payment')->dropDownList(MeanPayment::getAll()); ?>
</div>
<div class="col-md-3">
<?= $form->field($payment, 'date_transaction')->textInput([
'class' => 'datepicker form-control'
]); ?>
</div>
<div class="col-md-3">
<?= $form->field($payment, 'amount', [
'template' => '{label}<div class="input-group">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>{hint}',
])->textInput(); ?>
</div>
<div class="col-md-3">
<div class="form-group">
<br>
<?= Html::submitButton('Ajouter', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>

+ 11
- 8
backend/web/js/vuejs/document-form.js View File

app.init(); app.init();
}); });
}, },
submitOrderAddToInvoice: function() {
submitOrderAddToDocument: function() {
var app = this; var app = this;
axios.get(UrlManager.getBaseUrlAbsolute() + "invoice/ajax-add-order", {
axios.get(UrlManager.getBaseUrlAbsolute() + "document/ajax-add-order", {
params: { params: {
idInvoice: this.getDocumentId(),
idDocument: this.getDocumentId(),
classDocument: this.getDocumentClass(),
idOrder: app.orderAddId idOrder: app.orderAddId
} }
}) })
}, },
submitOrderIgnoreWhenInvoicing: function() { submitOrderIgnoreWhenInvoicing: function() {
var app = this; var app = this;
axios.get(UrlManager.getBaseUrlAbsolute() + "invoice/ajax-ignore-order-when-invoicing", {
axios.get(UrlManager.getBaseUrlAbsolute() + "document/ajax-ignore-order-when-invoicing", {
params: { params: {
idInvoice: this.getDocumentId(),
idDocument: this.getDocumentId(),
classDocument: this.getDocumentClass(),
idOrder: app.orderAddId idOrder: app.orderAddId
} }
}) })
app.init(); app.init();
}); });
}, },
deleteOrderFromInvoice: function() {
deleteOrderFromDocument: function() {
var app = this; var app = this;
var idOrder = event.currentTarget.getAttribute('data-id'); var idOrder = event.currentTarget.getAttribute('data-id');


axios.get(UrlManager.getBaseUrlAbsolute() + "invoice/ajax-delete-order", {
axios.get(UrlManager.getBaseUrlAbsolute() + "document/ajax-delete-order", {
params: { params: {
idInvoice: app.getDocumentId(),
idDocument: app.getDocumentId(),
classDocument: this.getDocumentClass(),
idOrder: idOrder idOrder: idOrder
} }
}) })

+ 25
- 0
common/logic/Order/Order/Repository/OrderRepository.php View File

use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\Distribution\Repository\DistributionRepository; use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository; use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\Invoice\Model\Invoice; use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Document\Invoice\Repository\InvoiceRepository; use common\logic\Document\Invoice\Repository\InvoiceRepository;
use common\logic\Document\Invoice\Service\InvoiceSolver; use common\logic\Document\Invoice\Service\InvoiceSolver;
->find(); ->find();
} }


public function findOrdersByUserAndDeliveryNote(User $user, DeliveryNote $deliveryNote)
{
return $this
->createDefaultQuery()
->filterByUser($user)
->filterIsLinkedDeliveryNote($deliveryNote)
->filterIsValid()
->find();
}

public function findOrdersByUserNotInvoiced(User $user) public function findOrdersByUserNotInvoiced(User $user)
{ {
return $this return $this
->find(); ->find();
} }


public function findOrdersByUserNotLinkedDeliveryNote(User $user)
{
return $this
->createDefaultQuery()
->filterByUser($user)
->filterIsNotLinkedDeliveryNote()
->filterIsPassed()
->filterIsValid()
->filterIsNotIgnoreWhenInvoicing()
->orderByDistributionDate('DESC')
->limit(20)
->find();
}

public function queryOrdersHistory(Producer $producer, User $user) public function queryOrdersHistory(Producer $producer, User $user)
{ {
$queryIncoming = clone $this->createDefaultQuery() $queryIncoming = clone $this->createDefaultQuery()

+ 16
- 0
common/logic/Order/Order/Repository/OrderRepositoryQuery.php View File

namespace common\logic\Order\Order\Repository; namespace common\logic\Order\Order\Repository;


use common\logic\AbstractRepositoryQuery; use common\logic\AbstractRepositoryQuery;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\Invoice\Model\Invoice; use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Order\Order\Service\OrderDefinition; use common\logic\Order\Order\Service\OrderDefinition;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
return $this; return $this;
} }


public function filterIsLinkedDeliveryNote(DeliveryNote $deliveryNote): self
{
$this->andWhere('order.id_delivery_note IS NOT NULL AND order.id_delivery_note = :id_delivery_note')
->params([':id_delivery_note' => $deliveryNote->id]);

return $this;
}

public function filterIsNotInvoiced(): self public function filterIsNotInvoiced(): self
{ {
$this->andWhere('order.id_invoice IS NULL'); $this->andWhere('order.id_invoice IS NULL');
return $this; return $this;
} }


public function filterIsNotLinkedDeliveryNote(): self
{
$this->andWhere('order.id_delivery_note IS NULL');

return $this;
}

public function filterIsNotIgnoreWhenInvoicing(): self public function filterIsNotIgnoreWhenInvoicing(): self
{ {
$this->andWhere('order.ignore_when_invoicing IS NULL'); $this->andWhere('order.ignore_when_invoicing IS NULL');

+ 26
- 6
common/logic/Order/Order/Service/OrderBuilder.php View File

use common\logic\Document\DeliveryNote\Model\DeliveryNote; use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\DeliveryNote\Service\DeliveryNoteBuilder; use common\logic\Document\DeliveryNote\Service\DeliveryNoteBuilder;
use common\logic\Document\Document\Model\Document; use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Model\DocumentInterface;
use common\logic\Document\Document\Service\DocumentSolver;
use common\logic\Document\Invoice\Model\Invoice; use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Order\Order\Event\OrderDeleteEvent; use common\logic\Order\Order\Event\OrderDeleteEvent;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
protected DistributionSolver $distributionSolver; protected DistributionSolver $distributionSolver;
protected UserRepository $userRepository; protected UserRepository $userRepository;
protected DeliveryNoteBuilder $deliveryNoteBuilder; protected DeliveryNoteBuilder $deliveryNoteBuilder;
protected DocumentSolver $documentSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->distributionSolver = $this->loadService(DistributionSolver::class); $this->distributionSolver = $this->loadService(DistributionSolver::class);
$this->userRepository = $this->loadService(UserRepository::class); $this->userRepository = $this->loadService(UserRepository::class);
$this->deliveryNoteBuilder = $this->loadService(DeliveryNoteBuilder::class); $this->deliveryNoteBuilder = $this->loadService(DeliveryNoteBuilder::class);
$this->documentSolver = $this->loadService(DocumentSolver::class);
} }


public function instanciateOrder(Distribution $distribution): Order public function instanciateOrder(Distribution $distribution): Order
} }
} }


public function updateOrderDeliveryNote(Order $order, DeliveryNote $deliveryNote): bool
{
$order->id_delivery_note = $deliveryNote->id;
return $order->save();
}

public function assignAllOrdersDeliveryNote(array $idOrders, DeliveryNote $deliveryNote) public function assignAllOrdersDeliveryNote(array $idOrders, DeliveryNote $deliveryNote)
{ {
$this->unassignAllOrdersDeliveryNote($deliveryNote); $this->unassignAllOrdersDeliveryNote($deliveryNote);
$this->update($order); $this->update($order);
} }


public function updateOrderDocument(Order $order, DocumentInterface $document = null)
{
if($this->documentSolver->isDocumentInvoice($document)) {
$this->updateOrderInvoice($order, $document);
}
elseif($this->documentSolver->isDocumentDeliveryNote($document)) {
$this->updateOrderDeliveryNote($order, $document);
}
}

public function updateOrderInvoice(Order $order, Invoice $invoice = null) public function updateOrderInvoice(Order $order, Invoice $invoice = null)
{ {
if($invoice) { if($invoice) {


$this->update($order); $this->update($order);
} }

public function updateOrderDeliveryNote(Order $order, DeliveryNote $deliveryNote = null)
{
if($deliveryNote) {
$order->populateDeliveryNote($deliveryNote);
}
else {
$order->id_delivery_note = null;
}

$this->update($order);
}
} }

Loading…
Cancel
Save