| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- /**
- * @property string $name
- * @property int $quantity
- * @property float $price
- */
- class InvoiceLineItem {
- private $name = "Untitled Item";
- private $quantity = 0;
- private $price = 0;
- // Static methods
- // Object methods
- public function __construct(string $name) {
- $this->name = $name;
- }
- public function getName(): string {
- return $this->name;
- }
- public function setName(string $name): void {
- $this->name = $name;
- }
- public function incrementQuantity(): void {
- ++$this->quantity;
- }
- public function getQuantity(): int {
- return $this->quantity;
- }
- public function setQuantity(int $quantity): void {
- $this->quantity = $quantity;
- }
- public function getDisplayQuantity(): string {
- if($this->quantity == 0) return "-";
- return $this->quantity;
- }
- public function addPrice(float $price): void {
- $this->price += $price;
- }
- public function getPrice(): float {
- return $this->price;
- }
- public function setPrice(float $price): void {
- $this->price = $price;
- }
- public function getDisplayPrice(): string {
- if($this->quantity == 0) return "-";
- return "£" . number_format($this->getPrice(), 2);
- }
- public function getTotal(): float {
- if($this->quantity == 0) return $this->price;
- return $this->quantity * $this->price;
- }
- public function getDisplayTotal(): string {
- return "£" . number_format($this->getTotal(), 2);
- }
- }
|