$documentModule = $this->getDocumentModule(); | $documentModule = $this->getDocumentModule(); | ||||
$orderModule = $this->getOrderModule(); | $orderModule = $this->getOrderModule(); | ||||
$producerModule = $this->getProducerModule(); | $producerModule = $this->getProducerModule(); | ||||
$producerCurrent = $this->getProducerCurrent(); | |||||
$invoiceModule = $this->getInvoiceModule(); | |||||
$deliveryNoteModule = $this->getDeliveryNoteModule(); | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
]; | ]; | ||||
if ($classDocument == 'Invoice') { | if ($classDocument == 'Invoice') { | ||||
$options = [ | |||||
'orderby' => 'distribution.date ASC', | |||||
'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | |||||
]; | |||||
$deliveryNotesCreateArray = DeliveryNote::searchAll([ | $deliveryNotesCreateArray = DeliveryNote::searchAll([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'status' => Document::STATUS_VALID, | 'status' => Document::STATUS_VALID, | ||||
'ignore_when_invoicing' => null | 'ignore_when_invoicing' => null | ||||
], $options); | |||||
$deliveryNotesUpdateArray = DeliveryNote::searchAll([ | |||||
'id_user' => $user->id, | |||||
'status' => Document::STATUS_VALID, | |||||
'order.id_invoice' => $idDocument, | |||||
'ignore_when_invoicing' => null | |||||
], $options); | |||||
], [ | |||||
'orderby' => 'distribution.date ASC', | |||||
'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | |||||
]); | |||||
$invoice = $idDocument ? $invoiceModule->getRepository()->findOneInvoiceById($idDocument) : null; | |||||
$deliveryNotesUpdateArray = $invoice ? $deliveryNoteModule->getRepository()->findDeliveryNotesByInvoice($invoice) : null; | |||||
$json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray); | $json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray); | ||||
$json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray); | $json['delivery_note_update_array'] = $this->initDeliveryNoteArray('update', $deliveryNotesUpdateArray); | ||||
$json['orders_create_array'] = []; | $json['orders_create_array'] = []; | ||||
$json['orders_update_array'] = []; | $json['orders_update_array'] = []; | ||||
if(!$producerModule->getConfig('option_invoice_only_based_on_delivery_notes')) { | if(!$producerModule->getConfig('option_invoice_only_based_on_delivery_notes')) { |
$userModule = $this->getUserModule(); | $userModule = $this->getUserModule(); | ||||
$documentModule = $this->getDocumentModule(); | $documentModule = $this->getDocumentModule(); | ||||
$orderModule = $this->getOrderModule(); | $orderModule = $this->getOrderModule(); | ||||
$deliveryNoteModule = $this->getDeliveryNoteModule(); | |||||
$isDocumentDeliveryNote = $documentModule->getSolver()->isDocumentDeliveryNote($document); | $isDocumentDeliveryNote = $documentModule->getSolver()->isDocumentDeliveryNote($document); | ||||
$displayPrices = !$isDocumentDeliveryNote || ($isDocumentDeliveryNote && $producerModule->getConfig('document_display_prices_delivery_note')); | $displayPrices = !$isDocumentDeliveryNote || ($isDocumentDeliveryNote && $producerModule->getConfig('document_display_prices_delivery_note')); | ||||
<strong>Libellé : </strong> | <strong>Libellé : </strong> | ||||
<?= $document->name; ?> | <?= $document->name; ?> | ||||
</div> | </div> | ||||
<?php if ($documentModule->getSolver()->isDocumentInvoice($document)): ?> | |||||
<?php $deliveryNotesUpdateArray = $deliveryNoteModule->getRepository()->findDeliveryNotesByInvoice($document); ?> | |||||
<?php if($deliveryNotesUpdateArray && count($deliveryNotesUpdateArray)): ?> | |||||
<strong>Bons de livraison : </strong> | |||||
<?php foreach($deliveryNotesUpdateArray as $key => $deliveryNote): ?> | |||||
<?= $deliveryNote->reference ?><?php if ($key !== array_key_last($deliveryNotesUpdateArray)): ?>, <?php endif; ?> | |||||
<?php endforeach; ?> | |||||
<?php endif; ?> | |||||
<?php endif; ?> | |||||
<?php if (strlen($document->comment)): ?> | <?php if (strlen($document->comment)): ?> | ||||
<div class="comment"> | <div class="comment"> | ||||
<br> | <br> |
namespace domain\Document\DeliveryNote; | namespace domain\Document\DeliveryNote; | ||||
use domain\Document\Document\Document; | |||||
use domain\Document\Invoice\Invoice; | |||||
use domain\Order\Order\Order; | use domain\Order\Order\Order; | ||||
use domain\_\AbstractRepository; | use domain\_\AbstractRepository; | ||||
return $deliveryNoteExist; | return $deliveryNoteExist; | ||||
} | } | ||||
public function findDeliveryNotesByInvoice(Invoice $invoice): array | |||||
{ | |||||
return DeliveryNote::searchAll([ | |||||
'id_user' => $invoice->id_user, | |||||
'status' => Document::STATUS_VALID, | |||||
'order.id_invoice' => $invoice->id, | |||||
'ignore_when_invoicing' => null | |||||
], [ | |||||
'orderby' => 'distribution.date ASC', | |||||
'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | |||||
]); | |||||
} | |||||
} | } |
{ | { | ||||
return $this->getInvoiceAmountPaid($invoice) >= Price::numberTwoDecimals($this->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL)); | return $this->getInvoiceAmountPaid($invoice) >= Price::numberTwoDecimals($this->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL)); | ||||
} | } | ||||
} | } |