| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- class Invoice {
- private $lineItems = [];
- private $taxRate = 0.2;
- private $reference = "";
- public function addLineItem(InvoiceLineItem $item): void {
- $this->lineItems[] = $item;
- }
- public function addLineItems(array $items): void {
- foreach($items as $item) {
- $this->addLineItem($item);
- }
- }
- /**
- * @return InvoiceLineItem[]
- */
- public function getLineItems(): array {
- return $this->lineItems;
- }
- public function getTotal() {
- $total = 0;
- foreach($this->lineItems as $item) {
- $total += $item->getTotal();
- }
- return $total;
- }
- public function getTaxRate(): float {
- return $this->taxRate;
- }
- public function setTaxRate(float $tax_rate): void {
- $this->taxRate = $tax_rate;
- }
- public function getTax(): float {
- return round($this->getTotal() * $this->taxRate, 2);
- }
- public function getTotalIncTax(): float {
- return $this->getTotal() + $this->getTax();
- }
- public function setReference(string $reference): void {
- $this->reference = $reference;
- }
- public function getReference(): string {
- return $this->reference;
- }
- }
|