<?php
namespace App\Entity;
use App\Repository\InvoiceAutomationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=InvoiceAutomationRepository::class)
*/
class InvoiceAutomation
{
const STATE_INICIALIZED = 'init';
const STATE_APPROVED = 'approved';
const STATE_COMPLAINE = 'complain';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $invoiceNumber;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="invoices")
* @ORM\JoinColumn(nullable=false)
*/
private $merchant;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $merchantEmail;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $merchantPhone;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="invoices")
* @ORM\JoinColumn(nullable=false)
*/
private $subscriber;
/**
* @ORM\Column(type="float")
*/
private $amount;
/**
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $approved;
/**
* @ORM\Column(type="string", length=255)
*/
private $status;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $approverMessage;
/**
* @ORM\OneToMany(targetEntity=InvoiceAutomationItem::class, mappedBy="invoice", orphanRemoval=true, cascade={"persist"})
*/
private $invoiceAutomationItems;
/**
* @ORM\Column(type="boolean")
*/
private $paid = false;
/**
* @ORM\Column(type="string", length=12, nullable=true)
*/
private $currency = 'CZK';
/**
* @ORM\Column(type="float", nullable=true)
*/
private $expand1Value;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $expand2Value;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $expand3Value;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $expand4Value;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $residue;
/**
* @ORM\Column(type="boolean")
*/
private $isExpanded = false;
public function __construct()
{
$this->invoiceAutomationItems = new ArrayCollection();
}
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;
}
public function getSubject(): ?string
{
return $this->subject;
}
public function setSubject(?string $subject): self
{
$this->subject = $subject;
return $this;
}
public function getMerchant(): ?User
{
return $this->merchant;
}
public function setMerchant(?User $merchant): self
{
$this->merchant = $merchant;
return $this;
}
public function getMerchantEmail(): ?string
{
return $this->merchantEmail;
}
public function setMerchantEmail(?string $merchantEmail): self
{
$this->merchantEmail = $merchantEmail;
return $this;
}
public function getMerchantPhone(): ?string
{
return $this->merchantPhone;
}
public function setMerchantPhone(?string $merchantPhone): self
{
$this->merchantPhone = $merchantPhone;
return $this;
}
public function getSubscriber(): ?Company
{
return $this->subscriber;
}
public function setSubscriber(?Company $subscriber): self
{
$this->subscriber = $subscriber;
return $this;
}
public function getAmount(): ?float
{
$total = 0;
/** @var InvoiceAutomationItem $invoiceAutomationItem */
foreach ($this->invoiceAutomationItems as $invoiceAutomationItem) {
if($invoiceAutomationItem->isHideOnInvoice() == false) {
$total = $total + $invoiceAutomationItem->getPriceTotal();
}
}
return $total;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getDueDate(): ?\DateTimeInterface
{
$dueDate = clone $this->created;
$dueDate->modify('+10 days');
return $dueDate;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getApproved(): ?\DateTimeInterface
{
return $this->approved;
}
public function setApproved(?\DateTimeInterface $approved): self
{
$this->approved = $approved;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getApproverMessage(): ?string
{
return $this->approverMessage;
}
public function setApproverMessage(?string $approverMessage): self
{
$this->approverMessage = $approverMessage;
return $this;
}
/**
* @return Collection<int, InvoiceAutomationItem>
*/
public function getItems(): Collection
{
return $this->invoiceAutomationItems;
}
public function addItem(InvoiceAutomationItem $invoiceAutomationItem): self
{
if (!$this->invoiceAutomationItems->contains($invoiceAutomationItem)) {
$this->invoiceAutomationItems[] = $invoiceAutomationItem;
$invoiceAutomationItem->setInvoice($this);
}
return $this;
}
public function removeItem(InvoiceAutomationItem $invoiceAutomationItem): self
{
if ($this->invoiceAutomationItems->removeElement($invoiceAutomationItem)) {
// set the owning side to null (unless already changed)
if ($invoiceAutomationItem->getInvoice() === $this) {
$invoiceAutomationItem->setInvoice(null);
}
}
return $this;
}
public function isPaid(): ?bool
{
return $this->paid;
}
public function setPaid(bool $paid): self
{
$this->paid = $paid;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getExpand1Value(): ?float
{
return $this->expand1Value;
}
public function setExpand1Value(?float $expand1Value): self
{
$this->expand1Value = $expand1Value;
return $this;
}
public function getExpand2Value(): ?float
{
return $this->expand2Value;
}
public function setExpand2Value(?float $expand2Value): self
{
$this->expand2Value = $expand2Value;
return $this;
}
public function getExpand3Value(): ?float
{
return $this->expand3Value;
}
public function setExpand3Value(?float $expand3Value): self
{
$this->expand3Value = $expand3Value;
return $this;
}
public function getExpand4Value(): ?float
{
return $this->expand4Value;
}
public function setExpand4Value(?float $expand4Value): self
{
$this->expand4Value = $expand4Value;
return $this;
}
public function getResidue(): ?float
{
return $this->residue;
}
public function setResidue(?float $residue): self
{
$this->residue = $residue;
return $this;
}
public function isIsExpanded(): ?bool
{
return $this->isExpanded;
}
public function setIsExpanded(bool $isExpanded): self
{
$this->isExpanded = $isExpanded;
return $this;
}
}