invoice.php 1.3 KB

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