Selaa lähdekoodia

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

feature/souke
Guillaume Bourgeois 1 vuosi sitten
vanhempi
commit
62cfc18b8e
9 muutettua tiedostoa jossa 263 lisäystä ja 167 poistoa
  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 Näytä tiedosto

@@ -463,6 +463,11 @@ class DocumentController extends BackendController
$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;
}
}
@@ -703,6 +708,64 @@ class DocumentController extends BackendController
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()
{
$class = get_class($this);

+ 0
- 51
backend/controllers/InvoiceController.php Näytä tiedosto

@@ -90,55 +90,4 @@ class InvoiceController extends DocumentController
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 Näytä tiedosto

@@ -240,65 +240,13 @@ $documentClass = $documentManager->getClass($model);
</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($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 class="panel panel-default">
@@ -348,51 +296,7 @@ $documentClass = $documentManager->getClass($model);
</div>
</div>
<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 class="clr"></div>
<?php endif; ?>

+ 45
- 0
backend/views/document/form/_orders.php Näytä tiedosto

@@ -0,0 +1,45 @@
<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 Näytä tiedosto

@@ -0,0 +1,71 @@
<?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 Näytä tiedosto

@@ -182,11 +182,12 @@ var app = new Vue({
app.init();
});
},
submitOrderAddToInvoice: function() {
submitOrderAddToDocument: function() {
var app = this;
axios.get(UrlManager.getBaseUrlAbsolute() + "invoice/ajax-add-order", {
axios.get(UrlManager.getBaseUrlAbsolute() + "document/ajax-add-order", {
params: {
idInvoice: this.getDocumentId(),
idDocument: this.getDocumentId(),
classDocument: this.getDocumentClass(),
idOrder: app.orderAddId
}
})
@@ -198,9 +199,10 @@ var app = new Vue({
},
submitOrderIgnoreWhenInvoicing: function() {
var app = this;
axios.get(UrlManager.getBaseUrlAbsolute() + "invoice/ajax-ignore-order-when-invoicing", {
axios.get(UrlManager.getBaseUrlAbsolute() + "document/ajax-ignore-order-when-invoicing", {
params: {
idInvoice: this.getDocumentId(),
idDocument: this.getDocumentId(),
classDocument: this.getDocumentClass(),
idOrder: app.orderAddId
}
})
@@ -210,13 +212,14 @@ var app = new Vue({
app.init();
});
},
deleteOrderFromInvoice: function() {
deleteOrderFromDocument: function() {
var app = this;
var idOrder = event.currentTarget.getAttribute('data-id');

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

+ 25
- 0
common/logic/Order/Order/Repository/OrderRepository.php Näytä tiedosto

@@ -8,6 +8,7 @@ use common\logic\AbstractRepository;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\Distribution\Repository\DistributionRepository;
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\Repository\InvoiceRepository;
use common\logic\Document\Invoice\Service\InvoiceSolver;
@@ -140,6 +141,16 @@ class OrderRepository extends AbstractRepository
->find();
}

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

public function findOrdersByUserNotInvoiced(User $user)
{
return $this
@@ -154,6 +165,20 @@ class OrderRepository extends AbstractRepository
->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)
{
$queryIncoming = clone $this->createDefaultQuery()

+ 16
- 0
common/logic/Order/Order/Repository/OrderRepositoryQuery.php Näytä tiedosto

@@ -3,6 +3,7 @@
namespace common\logic\Order\Order\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Order\Order\Service\OrderDefinition;
use common\logic\User\User\Model\User;
@@ -84,6 +85,14 @@ class OrderRepositoryQuery extends AbstractRepositoryQuery
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
{
$this->andWhere('order.id_invoice IS NULL');
@@ -91,6 +100,13 @@ class OrderRepositoryQuery extends AbstractRepositoryQuery
return $this;
}

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

return $this;
}

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

+ 26
- 6
common/logic/Order/Order/Service/OrderBuilder.php Näytä tiedosto

@@ -13,6 +13,8 @@ use common\logic\Distribution\Distribution\Service\DistributionSolver;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\DeliveryNote\Service\DeliveryNoteBuilder;
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\Order\Order\Event\OrderDeleteEvent;
use common\logic\Order\Order\Model\Order;
@@ -61,6 +63,7 @@ class OrderBuilder extends AbstractBuilder
protected DistributionSolver $distributionSolver;
protected UserRepository $userRepository;
protected DeliveryNoteBuilder $deliveryNoteBuilder;
protected DocumentSolver $documentSolver;

public function loadDependencies(): void
{
@@ -84,6 +87,7 @@ class OrderBuilder extends AbstractBuilder
$this->distributionSolver = $this->loadService(DistributionSolver::class);
$this->userRepository = $this->loadService(UserRepository::class);
$this->deliveryNoteBuilder = $this->loadService(DeliveryNoteBuilder::class);
$this->documentSolver = $this->loadService(DocumentSolver::class);
}

public function instanciateOrder(Distribution $distribution): Order
@@ -558,12 +562,6 @@ class OrderBuilder extends AbstractBuilder
}
}

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

public function assignAllOrdersDeliveryNote(array $idOrders, DeliveryNote $deliveryNote)
{
$this->unassignAllOrdersDeliveryNote($deliveryNote);
@@ -626,6 +624,16 @@ class OrderBuilder extends AbstractBuilder
$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)
{
if($invoice) {
@@ -637,4 +645,16 @@ class OrderBuilder extends AbstractBuilder

$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…
Peruuta
Tallenna