Skip to content

Commit

Permalink
Merge pull request #3 from QbilSoftware/added-few-fields
Browse files Browse the repository at this point in the history
Added diesel-surcharge, qty per box and no of boxes to invoice and in…
  • Loading branch information
xersion22 authored Oct 1, 2021
2 parents e0dae2f + 36d38fe commit 7d2ba7e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
33 changes: 24 additions & 9 deletions src/Qbil/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -88,14 +94,6 @@ public function getSupplierInvoiceNumber()
return $this->supplierInvoiceNumber;
}

/**
* @return mixed
*/
public function getAmount()
{
return $this->amount;
}

/**
* @return mixed
*/
Expand Down Expand Up @@ -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;
}
}
37 changes: 35 additions & 2 deletions src/Qbil/Models/InvoiceLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 7d2ba7e

Please sign in to comment.