src/Entity/PurchaseOrder.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PurchaseOrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassPurchaseOrderRepository::class)]
  9. class PurchaseOrder
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private $id;
  15.     #[ORM\ManyToOne(targetEntityCurrency::class, inversedBy'purchaseOrders')]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private $currency;
  18.     #[ORM\Column(type'float')]
  19.     private $amount;
  20.     #[ORM\Column(type'string'length255nullabletrue)]
  21.     private $description;
  22.     #[ORM\Column(type'string'length255nullabletrue)]
  23.     private $filepath;
  24.     #[ORM\Column(type'integer')]
  25.     private $closed 0;
  26.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'purchaseOrders')]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private $createdBy;
  29.     #[ORM\Column(type'datetime')]
  30.     private $createdAt;
  31.     #[ORM\Column(type'datetime'nullabletrue)]
  32.     private $updatedAt;
  33.     #[ORM\ManyToOne(targetEntityUser::class)]
  34.     private $updatedBy;
  35.     #[ORM\Column(type'string'length20)]
  36.     private $PurchaseOrderNo;
  37.     #[ORM\OneToMany(targetEntitySalesOrder::class, mappedBy'purchaseOrder')]
  38.     private $salesOrder;
  39.     #[ORM\Column(type'string'length255nullabletrue)]
  40.     private $filename;
  41.     #[ORM\Column(type'string'length64nullabletrue)]
  42.     private $filetype;
  43.     #[ORM\OneToMany(targetEntitySalesOrderPurchaseOrder::class, mappedBy'PurchaseOrder')]
  44.     private $salesOrderPurchaseOrders;
  45.     #[ORM\Column(type'date'nullabletrue)]
  46.     private $date;
  47.     #[ORM\ManyToOne(targetEntityClient::class, inversedBy'projects')]
  48.     #[ORM\JoinColumn(nullabletrue)]
  49.     private $client;
  50.     #[ORM\Column(nullabletrue)]
  51.     private ?\DateTimeImmutable $cancelledAt null;
  52.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  53.     private ?string $cancelNote null;
  54.     public function __construct()
  55.     {
  56.         $this->salesOrder = new ArrayCollection();
  57.         $this->salesOrderPurchaseOrders = new ArrayCollection();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getCurrency(): ?Currency
  64.     {
  65.         return $this->currency;
  66.     }
  67.     public function setCurrency(?Currency $currency): self
  68.     {
  69.         $this->currency $currency;
  70.         return $this;
  71.     }
  72.     public function getAmount(): ?float
  73.     {
  74.         return $this->amount;
  75.     }
  76.     public function getAmountUsd(): ?float
  77.     {
  78.         global $kernel;
  79.         $currencyService $kernel->getContainer()->get('CurrencyService');
  80.         $dateStr $this->createdAt->format('Y-m-d');
  81.         return $currencyService->convertAtDate($dateStr$this->currency->getIso(), 'USD'$this->amount);
  82.     }
  83.     public function setAmount(float $amount): self
  84.     {
  85.         $this->amount $amount;
  86.         return $this;
  87.     }
  88.     public function getDescription(): ?string
  89.     {
  90.         return $this->description;
  91.     }
  92.     public function setDescription(?string $description): self
  93.     {
  94.         $this->description $description;
  95.         return $this;
  96.     }
  97.     public function getFilepath(): ?string
  98.     {
  99.         return $this->filepath;
  100.     }
  101.     public function setFilepath(?string $filepath): self
  102.     {
  103.         $this->filepath $filepath;
  104.         return $this;
  105.     }
  106.     public function getClosed(): ?int
  107.     {
  108.         return $this->closed;
  109.     }
  110.     public function setClosed(int $closed): self
  111.     {
  112.         $this->closed $closed;
  113.         return $this;
  114.     }
  115.     public function getCreatedBy(): ?User
  116.     {
  117.         return $this->createdBy;
  118.     }
  119.     public function setCreatedBy(?User $createdBy): self
  120.     {
  121.         $this->createdBy $createdBy;
  122.         return $this;
  123.     }
  124.     public function getCreatedAt(): ?\DateTimeInterface
  125.     {
  126.         return $this->createdAt;
  127.     }
  128.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  129.     {
  130.         $this->createdAt $createdAt;
  131.         return $this;
  132.     }
  133.     public function getUpdatedAt(): ?\DateTimeInterface
  134.     {
  135.         return $this->updatedAt;
  136.     }
  137.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  138.     {
  139.         $this->updatedAt $updatedAt;
  140.         return $this;
  141.     }
  142.     public function getUpdatedBy(): ?User
  143.     {
  144.         return $this->updatedBy;
  145.     }
  146.     public function setUpdatedBy(?User $updatedBy): self
  147.     {
  148.         $this->updatedBy $updatedBy;
  149.         return $this;
  150.     }
  151.     public function getPurchaseOrderNo(): ?string
  152.     {
  153.         return $this->PurchaseOrderNo;
  154.     }
  155.     public function setPurchaseOrderNo(string $PurchaseOrderNo): self
  156.     {
  157.         $this->PurchaseOrderNo $PurchaseOrderNo;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection<int, SalesOrder>
  162.      */
  163.     public function getSalesOrder(): Collection
  164.     {
  165.         return $this->salesOrder;
  166.     }
  167.     public function addSalesOrder(SalesOrder $salesOrder): self
  168.     {
  169.         if (!$this->salesOrder->contains($salesOrder)) {
  170.             $this->salesOrder[] = $salesOrder;
  171.             $salesOrder->setPurchaseOrder($this);
  172.         }
  173.         return $this;
  174.     }
  175.     public function removeSalesOrder(SalesOrder $salesOrder): self
  176.     {
  177.         if ($this->salesOrder->removeElement($salesOrder)) {
  178.             // set the owning side to null (unless already changed)
  179.             if ($salesOrder->getPurchaseOrder() === $this) {
  180.                 $salesOrder->setPurchaseOrder(null);
  181.             }
  182.         }
  183.         return $this;
  184.     }
  185.     public function getFilename(): ?string
  186.     {
  187.         return $this->filename;
  188.     }
  189.     public function setFilename(?string $filename): self
  190.     {
  191.         $this->filename $filename;
  192.         return $this;
  193.     }
  194.     public function getFiletype(): ?string
  195.     {
  196.         return $this->filetype;
  197.     }
  198.     public function setFiletype(?string $filetype): self
  199.     {
  200.         $this->filetype $filetype;
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return Collection<int, SalesOrderPurchaseOrder>
  205.      */
  206.     public function getSalesOrderPurchaseOrders(): Collection
  207.     {
  208.         return $this->salesOrderPurchaseOrders;
  209.     }
  210.     public function getAmountLeft(){
  211.         $amountLeft $this->getAmount();
  212.         $salesOrderPurchaseOrders $this->getSalesOrderPurchaseOrders();
  213.         foreach ($salesOrderPurchaseOrders as $salesOrderPurchaseOrder){
  214.             $amountLeft -= $salesOrderPurchaseOrder->getAmount();
  215.         }
  216.         return $amountLeft;
  217.     }
  218.     public function addSalesOrderPurchaseOrder(SalesOrderPurchaseOrder $salesOrderPurchaseOrder): self
  219.     {
  220.         if (!$this->salesOrderPurchaseOrders->contains($salesOrderPurchaseOrder)) {
  221.             $this->salesOrderPurchaseOrders[] = $salesOrderPurchaseOrder;
  222.             $salesOrderPurchaseOrder->setPurchaseOrder($this);
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeSalesOrderPurchaseOrder(SalesOrderPurchaseOrder $salesOrderPurchaseOrder): self
  227.     {
  228.         if ($this->salesOrderPurchaseOrders->removeElement($salesOrderPurchaseOrder)) {
  229.             // set the owning side to null (unless already changed)
  230.             if ($salesOrderPurchaseOrder->getPurchaseOrder() === $this) {
  231.                 $salesOrderPurchaseOrder->setPurchaseOrder(null);
  232.             }
  233.         }
  234.         return $this;
  235.     }
  236.     public function getDate(): ?\DateTimeInterface
  237.     {
  238.         return $this->date;
  239.     }
  240.     public function setDate(?\DateTimeInterface $date): self
  241.     {
  242.         $this->date $date;
  243.         return $this;
  244.     }
  245.     public function getClient(): ?Client
  246.     {
  247.         return $this->client;
  248.     }
  249.     public function setClient(?Client $client): self
  250.     {
  251.         $this->client $client;
  252.         return $this;
  253.     }
  254.     public function getTotalAllocatedUsd(){
  255.         $totalAllocated 0;
  256.         $salesOrderPurchaseOrders $this->getSalesOrderPurchaseOrders();
  257.         foreach ($salesOrderPurchaseOrders as $salesOrderPurchaseOrder){
  258.             $totalAllocated += $salesOrderPurchaseOrder->getAmountUsd();
  259.         }
  260.         return $totalAllocated;
  261.     }
  262.     public function getAmountLeftUsd(){
  263.         return $this->getAmountUsd() - $this->getTotalAllocatedUsd();
  264.     }
  265.     public function getCancelledAt(): ?\DateTimeImmutable
  266.     {
  267.         return $this->cancelledAt;
  268.     }
  269.     public function setCancelledAt(?\DateTimeImmutable $cancelledAt): self
  270.     {
  271.         $this->cancelledAt $cancelledAt;
  272.         return $this;
  273.     }
  274.     public function getCancelNote(): ?string
  275.     {
  276.         return $this->cancelNote;
  277.     }
  278.     public function setCancelNote(?string $cancelNote): self
  279.     {
  280.         $this->cancelNote $cancelNote;
  281.         return $this;
  282.     }
  283. }