src/Entity/Invoice.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Enum\InvoiceStateEnum;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\InvoiceRepository")
  12.  * @Vich\Uploadable
  13.  */
  14. class Invoice
  15. {
  16.     /**
  17.      * @ORM\Id()
  18.      * @ORM\GeneratedValue()
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="datetime")
  24.      * @Gedmo\Timestampable(on="create")
  25.      */
  26.     private $createdAt;
  27.     /**
  28.      * @ORM\Column(type="datetime", nullable=true)
  29.      * @Gedmo\Timestampable(on="update")
  30.      */
  31.     private $updatedAt;
  32.     /**
  33.      * @ORM\Column(type="float")
  34.      */
  35.     private $amount;
  36.     /**
  37.      * @ORM\Column(type="string", length=255, nullable=true)
  38.      */
  39.     private $referenceZervant;
  40.     /**
  41.      * @ORM\Column(type="string", length=25)
  42.      */
  43.     private $state InvoiceStateEnum::STATE_PENDING;
  44.     /**
  45.      * @ORM\Column(type="string", length=255,  nullable=true)
  46.      */
  47.     private $pdfPath;
  48.     /**
  49.      * @Vich\UploadableField(mapping="invoice_pdf", fileNameProperty="pdfPath")
  50.      * @var File
  51.      */
  52.     private $pdfFile;
  53.     /**
  54.      * @ORM\OneToOne(targetEntity="App\Entity\Order", mappedBy="invoice")
  55.      */
  56.     private $order;
  57.     /**
  58.      * @ORM\OneToOne(targetEntity=DeviceSale::class, mappedBy="invoice", cascade={"persist", "remove"})
  59.      */
  60.     private $deviceSale;
  61.     public function getLabel(): string
  62.     {
  63.         return 'Facture #'.$this->id;
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getCreatedAt(): ?DateTimeInterface
  70.     {
  71.         return $this->createdAt;
  72.     }
  73.     public function setCreatedAt(DateTimeInterface $createdAt): self
  74.     {
  75.         $this->createdAt $createdAt;
  76.         return $this;
  77.     }
  78.     public function getAmount(): ?float
  79.     {
  80.         return $this->amount;
  81.     }
  82.     public function getAmountHT(): ?float
  83.     {
  84.         return round($this->amount/1.2,2);
  85.     }
  86.     public function setAmount(float $amount): self
  87.     {
  88.         $this->amount $amount;
  89.         return $this;
  90.     }
  91.     public function getReferenceZervant(): ?string
  92.     {
  93.         return $this->referenceZervant;
  94.     }
  95.     public function setReferenceZervant(?string $referenceZervant): self
  96.     {
  97.         $this->referenceZervant $referenceZervant;
  98.         return $this;
  99.     }
  100.     public function getState(): ?string
  101.     {
  102.         return $this->state;
  103.     }
  104.     public function isPending(){
  105.         return $this->state == InvoiceStateEnum::STATE_PENDING;
  106.     }
  107.     public function isValidated(){
  108.         return $this->state == InvoiceStateEnum::STATE_VALIDATED;
  109.     }
  110.     public function canBeDownloaded(){
  111.         return $this->isValidated() && !is_null($this->getPdfPath());
  112.     }
  113.     public function setState(string $state): self
  114.     {
  115.         $this->state $state;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Order
  120.      */
  121.     public function getOrder()
  122.     {
  123.         return $this->order;
  124.     }
  125.     /**
  126.      * @param mixed $order
  127.      */
  128.     public function setOrder(Order $order): void
  129.     {
  130.         $this->order $order;
  131.         $this->order->setInvoice($this);
  132.     }
  133.     /**
  134.      * @return mixed
  135.      */
  136.     public function getPdfPath()
  137.     {
  138.         return $this->pdfPath;
  139.     }
  140.     /**
  141.      * @param mixed $pdfPath
  142.      */
  143.     public function setPdfPath($pdfPath): void
  144.     {
  145.         $this->pdfPath $pdfPath;
  146.     }
  147.     /**
  148.      * @return File
  149.      */
  150.     public function getPdfFile(): ?File
  151.     {
  152.         return $this->pdfFile;
  153.     }
  154.     /**
  155.      * @param File $pdfFile
  156.      */
  157.     public function setPdfFile(File $pdfFile): void
  158.     {
  159.         $this->pdfFile $pdfFile;
  160.         //update timestamp
  161.         if ($pdfFile) {
  162.             $this->updatedAt = new DateTime('now');
  163.         }
  164.     }
  165.     /**
  166.      * @return mixed
  167.      */
  168.     public function getUpdatedAt()
  169.     {
  170.         return $this->updatedAt;
  171.     }
  172.     /**
  173.      * @param mixed $updatedAt
  174.      */
  175.     public function setUpdatedAt($updatedAt): void
  176.     {
  177.         $this->updatedAt $updatedAt;
  178.     }
  179.     public function getDeviceSale(): ?DeviceSale
  180.     {
  181.         return $this->deviceSale;
  182.     }
  183.     public function setDeviceSale(?DeviceSale $deviceSale): self
  184.     {
  185.         $this->deviceSale $deviceSale;
  186.         // set (or unset) the owning side of the relation if necessary
  187.         $newInvoice null === $deviceSale null $this;
  188.         if ($deviceSale->getInvoice() !== $newInvoice) {
  189.             $deviceSale->setInvoice($newInvoice);
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * Return the associated freelancer, either linked by the order or by the sale
  195.      * @return Freelancer|null
  196.      */
  197.     public function getFreelancer(): ?Freelancer
  198.     {
  199.         if($this->order){
  200.             return $this->getOrder()->getFreelancer();
  201.         }elseif($this->deviceSale){
  202.             return $this->getDeviceSale()->getProspectOnStore()->getStore()->getAdministrator();
  203.         }
  204.         return null;
  205.     }
  206. }