src/Entity/Invoice.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Product\GuestProduct;
  4. use DateTime;
  5. use DateTimeImmutable;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Exception;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11.  * Class Invoice
  12.  * @package App\Entity
  13.  *
  14.  * @ORM\Table(name="malys_invoice")
  15.  * @ORM\Entity(repositoryClass="App\Repository\InvoiceRepository")
  16.  * @ORM\HasLifecycleCallbacks()
  17.  * @Vich\Uploadable
  18.  */
  19. class Invoice
  20. {
  21.     public const STATUS_PROCESSING '0-processing';
  22.     public const STATUS_PENDING '1-pending';
  23.     public const STATUS_PROCESSED '2-processed';
  24.     public const STATUS_REJECTED '3-rejected';
  25.     public const STATUSES = [
  26.         self::STATUS_PENDING,
  27.         self::STATUS_PROCESSING,
  28.         self::STATUS_PROCESSED,
  29.         self::STATUS_REJECTED
  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\Invoice::STATUS_PENDING})
  41.      * @Assert\Choice(choices=Invoice::STATUSES, message="The status you chose is forbidden")
  42.      * @var string
  43.      */
  44.     private $status;
  45.     /**
  46.      * @ORM\Column(name="adherentNumber", type="string", length=255, nullable=true)
  47.      * @var string
  48.      */
  49.     private $adherentNumber;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity="App\Entity\InvoiceBatch", inversedBy="invoices", cascade={"persist"})
  52.      * @ORM\JoinColumn(name="invoice_batch_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  53.      */
  54.     public $invoiceBatch;
  55.     /**
  56.      * @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="invoices");
  57.      * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  58.      */
  59.     private $customer;
  60.     /**
  61.      * @ORM\ManyToOne(targetEntity="App\Entity\Supplier", inversedBy="invoices");
  62.      * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  63.      */
  64.     private $supplier;
  65.     /**
  66.      * @var DateTime
  67.      *
  68.      * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  69.      */
  70.     private $createdAt;
  71.     /**
  72.      * @var DateTime
  73.      *
  74.      * @ORM\Column(name="updatedAt", type="datetime", nullable=false)
  75.      */
  76.     private $updatedAt;
  77.     /**
  78.      * @ORM\Column(name="fileName", type="string", nullable=false)
  79.      */
  80.     protected $fileName;
  81.     /**
  82.      * @ORM\Column(name="mime_type", type="string", nullable=false)
  83.      */
  84.     protected $mimeType;
  85.     /**
  86.      * @Vich\UploadableField(mapping="invoice_file", fileNameProperty="fileName", mimeType="mimeType")
  87.      * @Assert\File(
  88.      *     groups={"invoices", "Default"},
  89.      *     maxSize="10M",
  90.      *     maxSizeMessage="Fichier trop volumineux. Max : 10MB",
  91.      *     mimeTypes={"image/jpeg", "image/png", "application/pdf"},
  92.      *     mimeTypesMessage="Type de fichier interdit. Format autorisés : jpeg, jpg, png, pdf"
  93.      * )
  94.      */
  95.     private $fileUpload;
  96.     /**
  97.      * @ORM\ManyToMany(targetEntity="App\Entity\Product\GuestProduct", inversedBy="invoices", cascade={"persist"})
  98.      * @ORM\JoinTable(name="malys_invoices_products",
  99.      *     joinColumns={@ORM\JoinColumn(name="invoice_id", referencedColumnName="id")},
  100.      *     inverseJoinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")}
  101.      * )
  102.      */
  103.     private $products;
  104.     public function __construct()
  105.     {
  106.         $this->setStatus(self::STATUS_PENDING);
  107.     }
  108.     /**
  109.      * @return int|null
  110.      */
  111.     public function getId(): ?int
  112.     {
  113.         return $this->id;
  114.     }
  115.     /**
  116.      * @return string|null
  117.      */
  118.     public function getStatus(): ?string
  119.     {
  120.         return $this->status;
  121.     }
  122.     /**
  123.      * @param $status
  124.      * @return $this
  125.      */
  126.     public function setStatus($status): Invoice
  127.     {
  128.         $this->status $status;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return null|string
  133.      */
  134.     public function getAdherentNumber(): ?string
  135.     {
  136.         return $this->adherentNumber;
  137.     }
  138.     /**
  139.      * @param string|null $adherentNumber
  140.      */
  141.     public function setAdherentNumber(?string $adherentNumber): void
  142.     {
  143.         $this->adherentNumber $adherentNumber;
  144.     }
  145.     /**
  146.      * @return ?InvoiceBatch
  147.      */
  148.     public function getInvoiceBatch(): ?InvoiceBatch
  149.     {
  150.         return $this->invoiceBatch;
  151.     }
  152.     /**
  153.      * @param InvoiceBatch $invoiceBatch
  154.      * @return Invoice
  155.      */
  156.     public function setInvoiceBatch(InvoiceBatch $invoiceBatch): Invoice
  157.     {
  158.         $this->invoiceBatch $invoiceBatch;
  159.         $invoiceBatch->addInvoice($this);
  160.         return $this;
  161.     }
  162.     /**
  163.      *
  164.      * @return Invoice
  165.      * @ORM\PrePersist
  166.      */
  167.     public function prePersist(): Invoice
  168.     {
  169.         $this->createdAt = new DateTime();
  170.         $this->updatedAt = new DateTime();
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return DateTime|null
  175.      */
  176.     public function getCreatedAt(): ?DateTime
  177.     {
  178.         return $this->createdAt;
  179.     }
  180.     /**
  181.      * Set createdAt
  182.      *
  183.      * @param null $date
  184.      * @return Invoice
  185.      */
  186.     public function setCreatedAt($date null): Invoice
  187.     {
  188.         if (is_null($date)) {
  189.             $date = new DateTime();
  190.         }
  191.         $this->createdAt $date;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return DateTime|null
  196.      */
  197.     public function getUpdatedAt(): ?DateTime
  198.     {
  199.         return $this->updatedAt;
  200.     }
  201.     /**
  202.      * Set updatedAt
  203.      *
  204.      * @return Invoice
  205.      * @ORM\PreUpdate
  206.      * @throws Exception
  207.      */
  208.     public function setUpdatedAt(): Invoice
  209.     {
  210.         $this->updatedAt = new DateTime();
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return mixed
  215.      */
  216.     public function getFileName()
  217.     {
  218.         return $this->fileName;
  219.     }
  220.     /**
  221.      * @param mixed $fileName
  222.      */
  223.     public function setFileName($fileName): void
  224.     {
  225.         $this->fileName $fileName;
  226.     }
  227.     /**
  228.      * @return mixed
  229.      */
  230.     public function getFileUpload()
  231.     {
  232.         return $this->fileUpload;
  233.     }
  234.     /**
  235.      * @param mixed $fileUpload
  236.      */
  237.     public function setFileUpload($fileUpload null): void
  238.     {
  239.         $this->fileUpload $fileUpload;
  240.         if (!is_null($fileUpload)) {
  241.             $this->updatedAt = new DateTimeImmutable();
  242.         }
  243.     }
  244.     /**
  245.      * @return mixed
  246.      */
  247.     public function getProducts()
  248.     {
  249.         return $this->products;
  250.     }
  251.     /**
  252.      * @param mixed $products
  253.      */
  254.     public function setProducts($products): void
  255.     {
  256.         $this->products $products;
  257.     }
  258.     /**
  259.      * @return mixed
  260.      */
  261.     public function getCustomer()
  262.     {
  263.         return $this->customer;
  264.     }
  265.     /**
  266.      * @param Customer $customer
  267.      * @return Invoice
  268.      */
  269.     public function setCustomer(Customer $customer): Invoice
  270.     {
  271.         $this->customer $customer;
  272.         return $this;
  273.     }
  274.     /**
  275.      * @return mixed
  276.      */
  277.     public function getSupplier()
  278.     {
  279.         return $this->supplier;
  280.     }
  281.     /**
  282.      * @param mixed $supplier
  283.      * @return Invoice
  284.      */
  285.     public function setSupplier($supplier): Invoice
  286.     {
  287.         $this->supplier $supplier;
  288.         return $this;
  289.     }
  290.     /**
  291.      * @return mixed
  292.      */
  293.     public function getMimeType(): ?string
  294.     {
  295.         return $this->mimeType;
  296.     }
  297.     /**
  298.      * @param mixed $mimeType
  299.      */
  300.     public function setMimeType($mimeType): void
  301.     {
  302.         $this->mimeType $mimeType;
  303.     }
  304.     /**
  305.      * @param GuestProduct $product
  306.      */
  307.     public function addProduct(GuestProduct $product)
  308.     {
  309.         if (! $this->products->contains($product)) {
  310.             $this->products->add($product);
  311.             $product->addInvoice($this);
  312.         }
  313.     }
  314.     /**
  315.      * @param GuestProduct $product
  316.      */
  317.     public function removeProduct(GuestProduct $product)
  318.     {
  319.         if ($this->products->contains($product)) {
  320.             $this->products->removeElement($product);
  321.         }
  322.     }
  323. }