<?php
namespace App\Entity;
use App\Repository\ItemRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: '`escappart_item`')]
#[ORM\Entity(repositoryClass: ItemRepository::class)]
class Item
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $description = null;
#[ORM\Column(length: 255)]
private ?string $price = null;
#[ORM\Column]
private ?int $quantity = null;
#[ORM\Column]
private ?int $discount = null;
#[ORM\ManyToOne(inversedBy: 'items')]
#[ORM\JoinColumn(nullable: false)]
private ?Invoice $invoice = null;
#[ORM\Column(length: 255)]
private ?string $subtotal = null;
#[ORM\Column(length: 255)]
private ?string $unit_price = null;
public function __construct() {
$this->price = 1;
$this->subtotal = 0;
$this->unit_price = 0;
$this->discount = 0;
$this->quantity = 1;
}
public function getId(): ?int
{
return $this->id;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): self
{
$this->price = $price;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getDiscount(): ?int
{
return $this->discount;
}
public function setDiscount(int $discount): self
{
$this->discount = $discount;
return $this;
}
public function getInvoice(): ?Invoice
{
return $this->invoice;
}
public function setInvoice(?Invoice $invoice): self
{
$this->invoice = $invoice;
return $this;
}
public function getSubtotal(): ?string
{
return $this->subtotal;
}
public function setSubtotal(string $subtotal): self
{
$this->subtotal = $subtotal;
return $this;
}
public function getUnitPrice(): ?string
{
return $this->unit_price;
}
public function setUnitPrice(string $unit_price): self
{
$this->unit_price = $unit_price;
return $this;
}
public function manageImportedItem($imported_item, $vat_rate): self
{
$this->description = $imported_item["description"];
$this->quantity = $imported_item["qty"];
$this->price = $imported_item["price"];
$unit_price = $imported_item["price"] / $imported_item["qty"];
$this->unit_price = $vat_rate == 'included' ? round($unit_price / ((6 / 100) + 1), 2) : $unit_price;
$this->subtotal = $this->quantity * $this->unit_price;
return $this;
}
public function manageHotelItem(Season $season, $price): self
{
$this->description = 'Location du '.$season->getNumber().' trimestre '.$season->getYear().' ('.$season->getName().')';
$this->quantity = 1;
$this->price = $price;
$this->unit_price = round($price / ((6 / 100) + 1), 2);
$this->subtotal = $this->quantity * $this->unit_price;
return $this;
}
}