diff --git a/src/Qbil/Models/Invoice.php b/src/Qbil/Models/Invoice.php index 4cf4706..63de370 100644 --- a/src/Qbil/Models/Invoice.php +++ b/src/Qbil/Models/Invoice.php @@ -27,6 +27,7 @@ public function __construct(Document $document, bool $includeInvoiceLines = true $this->orderNumber = Util::extract($document->HeaderFields, 'invoiceordernumber'); $this->contract = Util::extract($document->HeaderFields, 'Inkoopcontract'); $this->vat = Util::extract($document->HeaderFields, 'vatCode'); + $this->dieselSurcharge = Util::extract($document->HeaderFields, 'DieselSurcharge'); if ($includeInvoiceLines) { foreach (array_column(Util::extract($document->Tables, 'LineItem', 'TableRows'), 'ItemFields') as $line) { @@ -36,7 +37,11 @@ public function __construct(Document $document, bool $includeInvoiceLines = true Util::extract($line, 'LIT_VatExcludedAmount') ?? 0, Util::extract($line, 'LIT_UnitPriceAmount') ?? 0, Util::extract($line, 'LIT_Inkoopcontract') ?? null, - $document->DocumentSubType + $document->DocumentSubType, + null, + Util::extract($line, 'LIT_qtyPerBox') ?? 0, + Util::extract($line, 'LIT_nrBoxes') ?? 0, + $this ); $this->addInvoiceLine($invoiceLine); @@ -57,6 +62,7 @@ public function __construct(Document $document, bool $includeInvoiceLines = true private $orderNumber; private $contract; private $vat; + private $dieselSurcharge; private $invoiceLines = []; public function addInvoiceLine(InvoiceLineInterface $invoiceLine) @@ -88,14 +94,6 @@ public function getSupplierInvoiceNumber() return $this->supplierInvoiceNumber; } - /** - * @return mixed - */ - public function getAmount() - { - return $this->amount; - } - /** * @return mixed */ @@ -175,4 +173,21 @@ public function getVat() { return $this->vat; } + + /** + * @return mixed + */ + public function getDieselSurcharge() + { + return $this->dieselSurcharge; + } + + public function getAmount() + { + if (!$this->dieselSurcharge || $this->getDieselSurcharge() < 0) { + return $this->amount; + } + + return (($this->dieselSurcharge * $this->amount) / 100) + $this->amount; + } } diff --git a/src/Qbil/Models/InvoiceLine.php b/src/Qbil/Models/InvoiceLine.php index f3fd27d..9861aee 100644 --- a/src/Qbil/Models/InvoiceLine.php +++ b/src/Qbil/Models/InvoiceLine.php @@ -10,7 +10,18 @@ class InvoiceLine implements InvoiceLineInterface { - public function __construct(string $order, float $quantity, float $amount, float $price, string $purchaseContract, string $type, ?string $allocatedInvoice = null) + public function __construct( + string $order, + float $quantity, + float $amount, + float $price, + string $purchaseContract, + string $type, + ?string $allocatedInvoice = null, + ?float $qtyPerBox = 0, + ?int $noOfBoxes = 0, + ?Invoice $invoice = null + ) { $this->order = $order; $this->quantity = $quantity; @@ -19,6 +30,9 @@ public function __construct(string $order, float $quantity, float $amount, float $this->purchaseContract = $purchaseContract; $this->type = $type; $this->allocatedInvoice = $allocatedInvoice; + $this->qtyPerBox = $qtyPerBox; + $this->noOfBoxes = $noOfBoxes; + $this->invoice = $invoice; } private $order; @@ -28,6 +42,9 @@ public function __construct(string $order, float $quantity, float $amount, float private $purchaseContract; private $type; private $allocatedInvoice; + public $qtyPerBox; + public $noOfBoxes; + public $invoice; /** * @return mixed @@ -42,6 +59,10 @@ public function getOrder() */ public function getQuantity() { + if ($this->qtyPerBox > 0 || $this->noOfBoxes > 0) { + return $this->qtyPerBox * $this->qtyPerBox; + } + return $this->quantity; } @@ -50,6 +71,14 @@ public function getQuantity() */ public function getAmount() { + if (!$this->invoice) { + return $this->amount; + } + + if ($this->invoice->getDieselSurcharge() < 0) { + return (($this->invoice->getDieselSurcharge() * $this->amount) / 100) + $this->amount; + } + return $this->amount; } @@ -60,7 +89,11 @@ public function getAmount() */ public function getEstimatedAmount() { - return $this->amount; + if (!$this->invoice || $this->invoice->getDieselSurcharge() < 0) { + return $this->amount; + } + + return (($this->invoice->getDieselSurcharge() * $this->amount) / 100) + $this->amount; } /**