1
0

invoice.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class Invoice {
  3. private $lineItems = [];
  4. private $taxRate = 0.2;
  5. private $reference = "";
  6. public function addLineItem(InvoiceLineItem $item): void {
  7. $this->lineItems[] = $item;
  8. }
  9. public function addLineItems(array $items): void {
  10. foreach($items as $item) {
  11. $this->addLineItem($item);
  12. }
  13. }
  14. /**
  15. * @return InvoiceLineItem[]
  16. */
  17. public function getLineItems(): array {
  18. return $this->lineItems;
  19. }
  20. public function getTotal() {
  21. $total = 0;
  22. foreach($this->lineItems as $item) {
  23. $total += $item->getTotal();
  24. }
  25. return $total;
  26. }
  27. public function getTaxRate(): float {
  28. return $this->taxRate;
  29. }
  30. public function setTaxRate(float $tax_rate): void {
  31. $this->taxRate = $tax_rate;
  32. }
  33. public function getTax(): float {
  34. return round($this->getTotal() * $this->taxRate, 2);
  35. }
  36. public function getTotalIncTax(): float {
  37. return $this->getTotal() + $this->getTax();
  38. }
  39. public function setReference(string $reference): void {
  40. $this->reference = $reference;
  41. }
  42. public function getReference(): string {
  43. return $this->reference;
  44. }
  45. }