<?php
namespace App\Entity;
use App\Enum\SalesStatus;
use App\Repository\SalesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SalesRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table(name: 'sales')]
class Sales extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $invoiceNumber;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2)]
private $totalPurchasePrice;
#[ORM\OneToMany(mappedBy: 'sales', targetEntity: ProductsSold::class)]
private $productsSolds;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'sales')]
#[ORM\JoinColumn(nullable: false)]
private $seller;
#[ORM\ManyToOne(targetEntity: Warehouse::class, inversedBy: 'sales')]
private $warehouse;
#[ORM\Column(type: 'date', nullable: true)]
private $salesDate;
#[ORM\Column(type: 'date', nullable: true)]
private $deliveryDate;
#[ORM\Column(type: 'date', nullable: true)]
private $dueDate;
#[ORM\Column(type: 'date', nullable: true)]
private $validDate;
#[ORM\ManyToOne(targetEntity: Customer::class, inversedBy: 'sales')]
#[ORM\JoinColumn(nullable: false)]
private $customer;
#[ORM\OneToMany(mappedBy: 'sales', targetEntity: Payment::class)]
private $payments;
#[ORM\OneToMany(mappedBy: 'sale', targetEntity: StockTransaction::class)]
private $stockTransactions;
#[ORM\OneToMany(mappedBy: 'sale', targetEntity: SalesReturn::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $returns;
#[ORM\OneToMany(mappedBy: 'sale', targetEntity: EmailMessage::class)]
private Collection $emailMessages;
#[ORM\OneToMany(mappedBy: 'sale', targetEntity: SalesHistory::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $historyEntries;
#[ORM\OneToMany(mappedBy: 'sale', targetEntity: GiftProduct::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $giftProducts;
#[ORM\OneToOne(targetEntity: Invoice::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\JoinColumn(name: 'invoice_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?Invoice $invoice = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $shippingNotes = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $paymentNotes = null;
#[ORM\Column(length: 255, nullable: true)]
private SalesStatus|null $status = null;
#[ORM\Column]
private ?bool $visible = true;
/**
* @return mixed
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param mixed $customer
*/
public function setCustomer($customer): void
{
$this->customer = $customer;
}
public function __construct()
{
$this->productsSolds = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->stockTransactions = new ArrayCollection();
$this->emailMessages = new ArrayCollection();
$this->historyEntries = new ArrayCollection();
$this->returns = new ArrayCollection();
$this->giftProducts = new ArrayCollection();
}
/**
* @return Collection<int, SalesReturn>
*/
public function getReturns(): Collection
{
return $this->returns;
}
public function addReturn(SalesReturn $salesReturn): self
{
if (!$this->returns->contains($salesReturn)) {
$this->returns->add($salesReturn);
$salesReturn->setSale($this);
}
return $this;
}
public function removeReturn(SalesReturn $salesReturn): self
{
if ($this->returns->removeElement($salesReturn)) {
if ($salesReturn->getSale() === $this) {
$salesReturn->setSale(null);
}
}
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getInvoiceNumber(): ?string
{
return $this->invoiceNumber;
}
public function setInvoiceNumber(?string $invoiceNumber): self
{
$this->invoiceNumber = $invoiceNumber;
return $this;
}
/**
* @return Collection<int, EmailMessage>
*/
public function getEmailMessages(): Collection
{
return $this->emailMessages;
}
public function addEmailMessage(EmailMessage $emailMessage): self
{
if (!$this->emailMessages->contains($emailMessage)) {
$this->emailMessages->add($emailMessage);
$emailMessage->setSale($this);
}
return $this;
}
public function removeEmailMessage(EmailMessage $emailMessage): self
{
if ($this->emailMessages->removeElement($emailMessage)) {
if ($emailMessage->getSale() === $this) {
$emailMessage->setSale(null);
}
}
return $this;
}
/**
* @return Collection<int, SalesHistory>
*/
public function getHistoryEntries(): Collection
{
return $this->historyEntries;
}
public function addHistoryEntry(SalesHistory $historyEntry): self
{
if (!$this->historyEntries->contains($historyEntry)) {
$this->historyEntries->add($historyEntry);
$historyEntry->setSale($this);
}
return $this;
}
public function removeHistoryEntry(SalesHistory $historyEntry): self
{
if ($this->historyEntries->removeElement($historyEntry)) {
if ($historyEntry->getSale() === $this) {
$historyEntry->setSale(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getSalesDate()
{
return $this->salesDate;
}
/**
* @param mixed $salesDate
*/
public function setSalesDate($salesDate): void
{
$this->salesDate = $salesDate;
}
public function getTotalPurchasePrice(): ?float
{
return $this->totalPurchasePrice;
}
public function setTotalPurchasePrice(float $totalPurchasePrice): self
{
$this->totalPurchasePrice = $totalPurchasePrice;
return $this;
}
/**
* @return Collection<int, ProductsSold>
*/
public function getProductsSolds(): Collection
{
return $this->productsSolds;
}
public function addProductsSold(ProductsSold $productsSold): self
{
if (!$this->productsSolds->contains($productsSold)) {
$this->productsSolds[] = $productsSold;
$productsSold->setSales($this);
}
return $this;
}
public function removeProductsSold(ProductsSold $productsSold): self
{
if ($this->productsSolds->removeElement($productsSold)) {
// set the owning side to null (unless already changed)
if ($productsSold->getSales() === $this) {
$productsSold->setSales(null);
}
}
return $this;
}
public function getSeller(): ?User
{
return $this->seller;
}
public function setSeller(?User $seller): self
{
$this->seller = $seller;
return $this;
}
public function getWarehouse(): ?Warehouse
{
return $this->warehouse;
}
public function setWarehouse(?Warehouse $warehouse): self
{
$this->warehouse = $warehouse;
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->setSales($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->getSales() === $this) {
$payment->setSales(null);
}
}
return $this;
}
/**
* @return Collection<int, StockTransaction>
*/
public function getStockTransactions(): Collection
{
return $this->stockTransactions;
}
public function addStockTransaction(StockTransaction $stockTransaction): self
{
if (!$this->stockTransactions->contains($stockTransaction)) {
$this->stockTransactions[] = $stockTransaction;
$stockTransaction->setSale($this);
}
return $this;
}
public function removeStockTransaction(StockTransaction $stockTransaction): self
{
if ($this->stockTransactions->removeElement($stockTransaction)) {
// set the owning side to null (unless already changed)
if ($stockTransaction->getSale() === $this) {
$stockTransaction->setSale(null);
}
}
return $this;
}
public function getInvoice(): ?Invoice
{
return $this->invoice;
}
public function setInvoice(?Invoice $invoice): self
{
$this->invoice = $invoice;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getShippingNotes(): ?string
{
return $this->shippingNotes;
}
public function setShippingNotes(?string $shippingNotes): static
{
$this->shippingNotes = $shippingNotes;
return $this;
}
public function getPaymentNotes(): ?string
{
return $this->paymentNotes;
}
public function setPaymentNotes(?string $paymentNotes): static
{
$this->paymentNotes = $paymentNotes;
return $this;
}
/**
* @return mixed
*/
public function getDeliveryDate()
{
return $this->deliveryDate;
}
/**
* @param mixed $deliveryDate
*/
public function setDeliveryDate($deliveryDate): void
{
$this->deliveryDate = $deliveryDate;
}
/**
* @return mixed
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* @param mixed $dueDate
*/
public function setDueDate($dueDate): void
{
$this->dueDate = $dueDate;
}
/**
* @return mixed
*/
public function getValidDate()
{
return $this->validDate;
}
/**
* @param mixed $validDate
*/
public function setValidDate($validDate): void
{
$this->validDate = $validDate;
}
public function getStatus(): ?SalesStatus
{
return $this->status;
}
public function setStatus(?SalesStatus $status): void
{
$this->status = $status;
}
public function isVisible(): ?bool
{
return $this->visible;
}
public function setVisible(bool $visible): static
{
$this->visible = $visible;
return $this;
}
/**
* @return Collection<int, GiftProduct>
*/
public function getGiftProducts(): Collection
{
return $this->giftProducts;
}
public function addGiftProduct(GiftProduct $giftProduct): self
{
if (!$this->giftProducts->contains($giftProduct)) {
$this->giftProducts->add($giftProduct);
$giftProduct->setSale($this);
}
return $this;
}
public function removeGiftProduct(GiftProduct $giftProduct): self
{
if ($this->giftProducts->removeElement($giftProduct)) {
if ($giftProduct->getSale() === $this) {
$giftProduct->setSale(null);
}
}
return $this;
}
}