<?php
namespace App\Entity;
use App\Repository\CustomerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
#[ORM\Entity(repositoryClass: CustomerRepository::class)]
class Customer extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $fullName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $phone;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $address;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $email;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Sales::class, cascade: ['persist', 'remove'])]
private $sales;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Invoice::class, cascade: ['persist', 'remove'])]
private $invoices;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Payment::class)]
private $payments;
#[ORM\Column(length: 255, nullable: true)]
private ?string $code = null;
public function __construct()
{
$this->sales = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->invoices = new ArrayCollection();
}
public function getSales(): Collection
{
return $this->sales;
}
public function addSale(Sales $sale): self
{
if (!$this->sales->contains($sale)) {
$this->sales[] = $sale;
$sale->setCustomer($this);
}
return $this;
}
public function removeSale(Sales $sale): self
{
if ($this->sales->removeElement($sale)) {
if ($sale->getCustomer() === $this) {
$sale->setCustomer(null);
}
}
}
public function getId(): ?int
{
return $this->id;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return Collection<int, Payment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments[] = $payment;
$payment->setCustomer($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->removeElement($payment)) {
// set the owning side to null (unless already changed)
if ($payment->getCustomer() === $this) {
$payment->setCustomer(null);
}
}
return $this;
}
public function getInvoices(): ArrayCollection|PersistentCollection
{
return $this->invoices;
}
public function setInvoices(ArrayCollection|PersistentCollection $invoices): void
{
$this->invoices = $invoices;
}
public function addInvoice(Invoice $invoice):self{
$this->invoices->add($invoice);
return $this;
}
public function removeInvoice(Invoice $invoice):self{
$this->invoices->removeElement($invoice);
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): static
{
$this->code = $code;
return $this;
}
}