src/Entity/InvoiceBatch.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Exception;
  7. use JMS\Serializer\Annotation\Expose;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * Class InvoiceBatch
  11.  * @package App\Entity
  12.  *
  13.  * @ORM\Table(name="malys_invoice_batch")
  14.  * @ORM\Entity(repositoryClass="App\Repository\InvoiceBatchRepository")
  15.  * @ORM\HasLifecycleCallbacks()
  16.  */
  17. class InvoiceBatch
  18. {
  19.     public const STATUS_PENDING '1-pending';
  20.     public const STATUS_PROCESSING '0-processing';
  21.     public const STATUS_PROCESSED '2-processed';
  22.     public const STATUSES = [
  23.         self::STATUS_PENDING,
  24.         self::STATUS_PROCESSING,
  25.         self::STATUS_PROCESSED
  26.     ];
  27.     public const STATUSES_NOT_FINISHED = [
  28.         self::STATUS_PENDING,
  29.         self::STATUS_PROCESSING,
  30.     ];
  31.     /**
  32.      * @var integer
  33.      *
  34.      * @ORM\Column(name="id", type="integer")
  35.      * @ORM\Id
  36.      * @ORM\GeneratedValue(strategy="AUTO")
  37.      */
  38.     protected $id;
  39.     /**
  40.      * @ORM\Column(name="status", type="string", length=255, nullable=false, options={"default"=App\Entity\InvoiceBatch::STATUS_PENDING})
  41.      * @Assert\Choice(choices=InvoiceBatch::STATUSES, message="The status you chose is forbidden")
  42.      * @var string
  43.      */
  44.     private $status self::STATUS_PENDING;
  45.     /**
  46.      * @ORM\ManyToOne (targetEntity="App\Entity\Customer")
  47.      * @ORM\JoinColumn (name="requester_id", referencedColumnName="id")
  48.      */
  49.     protected $requester;
  50.     /**
  51.      * @var DateTime
  52.      *
  53.      * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  54.      */
  55.     private $createdAt;
  56.     /**
  57.      * @var DateTime
  58.      *
  59.      * @ORM\Column(name="updatedAt", type="datetime", nullable=false)
  60.      */
  61.     private $updatedAt;
  62.     /**
  63.      * @var mixed
  64.      * One invoiceBatch has many invoices
  65.      * @ORM\OneToMany(targetEntity="App\Entity\Invoice", mappedBy="invoiceBatch")
  66.      * @ORM\OrderBy({"status" = "ASC"})
  67.      * @Expose
  68.      */
  69.     protected $invoices;
  70.     /**
  71.      * @return mixed
  72.      */
  73.     public function getRequester()
  74.     {
  75.         return $this->requester;
  76.     }
  77.     /**
  78.      * @param mixed $requester
  79.      */
  80.     public function setRequester($requester): void
  81.     {
  82.         $this->requester $requester;
  83.     }
  84.     public function __construct()
  85.     {
  86.         $this->invoices = new ArrayCollection();
  87.     }
  88.     /**
  89.      * @return int|null
  90.      */
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     /**
  96.      * @return string|null
  97.      */
  98.     public function getStatus(): ?string
  99.     {
  100.         return $this->status;
  101.     }
  102.     /**
  103.      * @param $status
  104.      * @return $this
  105.      */
  106.     public function setStatus($status): InvoiceBatch
  107.     {
  108.         $this->status $status;
  109.         return $this;
  110.     }
  111.     /**
  112.      *
  113.      * @return InvoiceBatch
  114.      * @ORM\PrePersist
  115.      */
  116.     public function prePersist(): InvoiceBatch
  117.     {
  118.         $this->createdAt = new DateTime();
  119.         $this->updatedAt = new DateTime();
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return DateTime|null
  124.      */
  125.     public function getCreatedAt(): ?DateTime
  126.     {
  127.         return $this->createdAt;
  128.     }
  129.     /**
  130.      * Set createdAt
  131.      *
  132.      * @param null $date
  133.      * @return InvoiceBatch
  134.      */
  135.     public function setCreatedAt($date null): InvoiceBatch
  136.     {
  137.         if (is_null($date)) {
  138.             $date = new DateTime();
  139.         }
  140.         $this->createdAt $date;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return DateTime|null
  145.      */
  146.     public function getUpdatedAt(): ?DateTime
  147.     {
  148.         return $this->updatedAt;
  149.     }
  150.     /**
  151.      * Set updatedAt
  152.      *
  153.      * @return InvoiceBatch
  154.      * @ORM\PreUpdate
  155.      * @throws Exception
  156.      */
  157.     public function setUpdatedAt(): InvoiceBatch
  158.     {
  159.         $this->updatedAt = new DateTime();
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return mixed
  164.      */
  165.     public function getInvoices()
  166.     {
  167.         return $this->invoices;
  168.     }
  169.     /**
  170.      * @param $invoices
  171.      */
  172.     public function setInvoices($invoices)
  173.     {
  174.         $this->invoices $invoices;
  175.     }
  176.     /**
  177.      * @param Invoice $invoice
  178.      * @return $this
  179.      */
  180.     public function addInvoice(Invoice $invoice): InvoiceBatch
  181.     {
  182.         if (! $this->invoices->contains($invoice)) {
  183.             $this->invoices->add($invoice);
  184.         }
  185.         return $this;
  186.     }
  187.     /**
  188.      * @param Invoice $invoice
  189.      * @return $this
  190.      */
  191.     public function removeInvoice(Invoice $invoice): InvoiceBatch
  192.     {
  193.         if ($this->invoices->contains($invoice)) {
  194.             $this->invoices->removeElement($invoice);
  195.         }
  196.         return $this;
  197.     }
  198. }