|
12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
-
- namespace common\logic\Document\DeliveryNote\Service;
-
- use common\logic\Document\DeliveryNote\Model\DeliveryNote;
- use common\logic\Document\Document\Service\DocumentSolver;
- use common\logic\Document\Invoice\Model\Invoice;
- use common\logic\SolverInterface;
-
- class DeliveryNoteSolver extends DocumentSolver implements SolverInterface
- {
- public function getInvoiceId(DeliveryNote $deliveryNote): ?int
- {
- if($deliveryNote->orders && count($deliveryNote->orders) > 0) {
- foreach($deliveryNote->orders as $order) {
- if($order->id_invoice) {
- return $order->id_invoice;
- }
- }
- }
-
- return null;
- }
-
- public function isInvoiced(DeliveryNote $deliveryNote): bool
- {
- return (bool) $this->getInvoiceId($deliveryNote);
- }
-
- public function getInvoice(DeliveryNote $deliveryNote): ?Invoice
- {
- $idInvoice = (int) $this->getInvoiceId($deliveryNote);
- return Invoice::searchOne([
- 'id' => $idInvoice
- ]);
- }
- }
|