<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use JMS\Serializer\Annotation\Expose;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class InvoiceBatch
* @package App\Entity
*
* @ORM\Table(name="malys_invoice_batch")
* @ORM\Entity(repositoryClass="App\Repository\InvoiceBatchRepository")
* @ORM\HasLifecycleCallbacks()
*/
class InvoiceBatch
{
public const STATUS_PENDING = '1-pending';
public const STATUS_PROCESSING = '0-processing';
public const STATUS_PROCESSED = '2-processed';
public const STATUSES = [
self::STATUS_PENDING,
self::STATUS_PROCESSING,
self::STATUS_PROCESSED
];
public const STATUSES_NOT_FINISHED = [
self::STATUS_PENDING,
self::STATUS_PROCESSING,
];
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="status", type="string", length=255, nullable=false, options={"default"=App\Entity\InvoiceBatch::STATUS_PENDING})
* @Assert\Choice(choices=InvoiceBatch::STATUSES, message="The status you chose is forbidden")
* @var string
*/
private $status = self::STATUS_PENDING;
/**
* @ORM\ManyToOne (targetEntity="App\Entity\Customer")
* @ORM\JoinColumn (name="requester_id", referencedColumnName="id")
*/
protected $requester;
/**
* @var DateTime
*
* @ORM\Column(name="createdAt", type="datetime", nullable=false)
*/
private $createdAt;
/**
* @var DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=false)
*/
private $updatedAt;
/**
* @var mixed
* One invoiceBatch has many invoices
* @ORM\OneToMany(targetEntity="App\Entity\Invoice", mappedBy="invoiceBatch")
* @ORM\OrderBy({"status" = "ASC"})
* @Expose
*/
protected $invoices;
/**
* @return mixed
*/
public function getRequester()
{
return $this->requester;
}
/**
* @param mixed $requester
*/
public function setRequester($requester): void
{
$this->requester = $requester;
}
public function __construct()
{
$this->invoices = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getStatus(): ?string
{
return $this->status;
}
/**
* @param $status
* @return $this
*/
public function setStatus($status): InvoiceBatch
{
$this->status = $status;
return $this;
}
/**
*
* @return InvoiceBatch
* @ORM\PrePersist
*/
public function prePersist(): InvoiceBatch
{
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return DateTime|null
*/
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
/**
* Set createdAt
*
* @param null $date
* @return InvoiceBatch
*/
public function setCreatedAt($date = null): InvoiceBatch
{
if (is_null($date)) {
$date = new DateTime();
}
$this->createdAt = $date;
return $this;
}
/**
* @return DateTime|null
*/
public function getUpdatedAt(): ?DateTime
{
return $this->updatedAt;
}
/**
* Set updatedAt
*
* @return InvoiceBatch
* @ORM\PreUpdate
* @throws Exception
*/
public function setUpdatedAt(): InvoiceBatch
{
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return mixed
*/
public function getInvoices()
{
return $this->invoices;
}
/**
* @param $invoices
*/
public function setInvoices($invoices)
{
$this->invoices = $invoices;
}
/**
* @param Invoice $invoice
* @return $this
*/
public function addInvoice(Invoice $invoice): InvoiceBatch
{
if (! $this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
}
return $this;
}
/**
* @param Invoice $invoice
* @return $this
*/
public function removeInvoice(Invoice $invoice): InvoiceBatch
{
if ($this->invoices->contains($invoice)) {
$this->invoices->removeElement($invoice);
}
return $this;
}
}