Documentation InvoiceCalc Class

This commit is contained in:
David Bomba 2019-04-08 14:28:28 +10:00
parent bbaf4e9cf6
commit 0a1965b598

View File

@ -6,6 +6,9 @@ use App\Helpers\Invoice\InvoiceItemCalc;
use App\Models\Invoice; use App\Models\Invoice;
use App\Utils\Traits\NumberFormatter; use App\Utils\Traits\NumberFormatter;
/**
* Class for invoice calculations.
*/
class InvoiceCalc class InvoiceCalc
{ {
@ -13,36 +16,53 @@ class InvoiceCalc
protected $invoice; protected $invoice;
protected $balance;
protected $paid_to_date;
protected $amount;
protected $line_items;
protected $settings; protected $settings;
protected $invoice_total; private $balance;
protected $tax_map; private $paid_to_date;
protected $total_taxes; private $amount;
protected $total_discount; private $sub_total;
private $line_items;
private $invoice_total;
private $tax_map;
private $total_taxes;
private $total_discount;
/**
* Constructs the object with Invoice and Settings object
*
* @param \App\Models\Invoice $invoice The invoice
* @param \stdClass $settings The settings
*/
public function __construct(Invoice $invoice, \stdClass $settings) public function __construct(Invoice $invoice, \stdClass $settings)
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
$this->settings = $settings; $this->settings = $settings;
} }
/**
* Builds the invoice values
*/
public function build() public function build()
{ {
$this->calcLineItems(); $this->calcLineItems();
} }
/**
* Calculates the line items.
*
* @return self The line items.
*/
private function calcLineItems() private function calcLineItems()
{ {
@ -64,6 +84,9 @@ class InvoiceCalc
//set running total of discounts //set running total of discounts
$this->total_discount += $item_calc->getTotalDiscounts(); $this->total_discount += $item_calc->getTotalDiscounts();
//set running subtotal
$this->sub_total += $item_calc->getLineTotal();
} }
@ -73,17 +96,52 @@ class InvoiceCalc
} }
/** /**
* Getters and Setters * Getters and Setters
*/ */
/**
* Gets the sub total.
*
* @return float The sub total.
*/
private function getSubTotal()
{
return $this->subtotal;
}
/**
* Sets the sub total.
*
* @param float $value The value
*
* @return self $this
*/
private function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
/**
* Gets the tax map.
*
* @return Collection The tax map.
*/
private function getTaxMap() private function getTaxMap()
{ {
return $this->tax_map; return $this->tax_map;
} }
/**
* Sets the tax map.
*
* @param Collection $value Collection of mapped taxes
*
* @return self $this
*/
private function setTaxMap($value) private function setTaxMap($value)
{ {
$htis->tax_map = $value; $htis->tax_map = $value;
@ -91,11 +149,23 @@ class InvoiceCalc
return $this; return $this;
} }
/**
* Gets the total discount.
*
* @return float The total discount.
*/
private function getTotalDiscount() private function getTotalDiscount()
{ {
return $this->total_discount; return $this->total_discount;
} }
/**
* Sets the total discount.
*
* @param float $value The value
*
* @return self $this
*/
private function setTotalDiscount($value) private function setTotalDiscount($value)
{ {
$this->total_discount = $value; $this->total_discount = $value;
@ -103,17 +173,31 @@ class InvoiceCalc
return $this; return $this;
} }
/**
* Gets the total taxes.
*
* @return float The total taxes.
*/
private function getTotalTaxes() private function getTotalTaxes()
{ {
return $this->total_taxes; return $this->total_taxes;
} }
/**
* Sets the total taxes.
*
* @param float $value The value
*
* @return self ( $this )
*/
private function setTotalTaxes($value) private function setTotalTaxes($value)
{ {
$this->total_taxes = $value; $this->total_taxes = $value;
return $this; return $this;
} }
/* /*
private function setDiscount($amount, $discount, $is_amount_discount) private function setDiscount($amount, $discount, $is_amount_discount)
{ {