1
0

invoice_line_item.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @property string $name
  4. * @property int $quantity
  5. * @property float $price
  6. */
  7. class InvoiceLineItem {
  8. private $name = "Untitled Item";
  9. private $quantity = 0;
  10. private $price = 0;
  11. // Static methods
  12. // Object methods
  13. public function __construct(string $name) {
  14. $this->name = $name;
  15. }
  16. public function getName(): string {
  17. return $this->name;
  18. }
  19. public function setName(string $name): void {
  20. $this->name = $name;
  21. }
  22. public function incrementQuantity(): void {
  23. ++$this->quantity;
  24. }
  25. public function getQuantity(): int {
  26. return $this->quantity;
  27. }
  28. public function setQuantity(int $quantity): void {
  29. $this->quantity = $quantity;
  30. }
  31. public function getDisplayQuantity(): string {
  32. if($this->quantity == 0) return "-";
  33. return $this->quantity;
  34. }
  35. public function addPrice(float $price): void {
  36. $this->price += $price;
  37. }
  38. public function getPrice(): float {
  39. return $this->price;
  40. }
  41. public function setPrice(float $price): void {
  42. $this->price = $price;
  43. }
  44. public function getDisplayPrice(): string {
  45. if($this->quantity == 0) return "-";
  46. return "£" . number_format($this->getPrice(), 2);
  47. }
  48. public function getTotal(): float {
  49. if($this->quantity == 0) return $this->price;
  50. return $this->quantity * $this->price;
  51. }
  52. public function getDisplayTotal(): string {
  53. return "£" . number_format($this->getTotal(), 2);
  54. }
  55. }