src/Entity/Delete/Proforma.php line 48

  1. <?php
  2. namespace App\Entity\Delete;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiProperty;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Delete;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Metadata\Patch;
  11. use ApiPlatform\Metadata\Post;
  12. use App\Doctrine\Type\Expediting\TransportMode;
  13. use App\Doctrine\Type\Finance\PayableStatus;
  14. use App\Dto\Delete\PayableLines;
  15. use App\Dto\Delete\ProformaCreationInput;
  16. use App\Entity\Common as Common;
  17. use App\Entity\Expediting\ShippingPlan;
  18. use App\Entity\Sales\WorkOrder;
  19. use App\Processor\Delete\ProformaCreationProcessor;
  20. use App\Validator\IsValidEnum\IsValidEnum;
  21. use Doctrine\Common\Collections\ArrayCollection;
  22. use Doctrine\Common\Collections\Collection;
  23. use Doctrine\DBAL\Types\Types;
  24. use Doctrine\ORM\Mapping as ORM;
  25. use Gedmo\Mapping\Annotation as Gedmo;
  26. use Symfony\Component\Validator\Constraints as Assert;
  27. #[ORM\Table(name'invoicing_proforma')]
  28. #[ORM\Entity]
  29. #[ApiResource(
  30.     operations: [
  31.         new Get(),
  32.         new GetCollection(),
  33.         new Post(inputProformaCreationInput::class, processorProformaCreationProcessor::class),
  34.         new Patch(inputFormats: ['json' => ['application/merge-patch+json']]),
  35.         new Delete(),
  36.     ],
  37.     routePrefix'/invoicing',
  38. )]
  39. #[ApiFilter(SearchFilter::class, properties: [
  40.     'slug' => 'ipartial',
  41.     'reference' => 'ipartial',
  42.     'orderNumber' => 'ipartial',
  43.     'workOrders' => 'ipartial',
  44. ])]
  45. class Proforma extends Invoiceable
  46. {
  47.     use Common\Blameable;
  48.     use Common\Trackable;
  49.     #[ORM\Id]
  50.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  51.     #[ORM\SequenceGenerator(sequenceName'invoicing_proforma_id_seq')]
  52.     #[ORM\Column(typeTypes::INTEGER)]
  53.     #[ApiProperty(identifierfalse)]
  54.     private int $id;
  55.     #[ORM\ManyToOne(targetEntityWorkOrder::class)]
  56.     #[ORM\JoinColumn(name'work_order_id')]
  57.     private ?WorkOrder $workOrder null;
  58.     #[ORM\ManyToOne(targetEntityShippingPlan::class)]
  59.     #[ORM\JoinColumn(name'shipping_plan_id')]
  60.     private ?ShippingPlan $shippingPlan null;
  61.     #[ORM\ManyToOne(targetEntityBatch::class)]
  62.     #[ORM\JoinColumn(name'batch_id')]
  63.     private ?Batch $batch null;
  64.     #[Gedmo\Slug(fields: ['number''reference'])]
  65.     #[ORM\Column(typeTypes::STRING)]
  66.     #[ApiProperty(identifiertrue)]
  67.     private string $slug;
  68.     #[Assert\NotBlank]
  69.     #[Assert\Type(typeTypes::STRING)]
  70.     #[ORM\Column(typeTypes::STRING)]
  71.     private ?string $number null;
  72.     #[Assert\NotBlank]
  73.     #[Assert\Type(typeTypes::STRING)]
  74.     #[ORM\Column(typeTypes::STRING)]
  75.     private ?string $destinationCountryCode null;
  76.     #[Assert\Type(typeTypes::STRING)]
  77.     #[ORM\Column(typeTypes::STRING)]
  78.     private ?string $workOrders null;
  79.     #[Assert\Type(typeTypes::STRING)]
  80.     #[ORM\Column(typeTypes::STRING)]
  81.     protected ?string $tariffZone null;
  82.     #[Assert\NotNull]
  83.     #[IsValidEnum(enumTransportMode::class)]
  84.     #[ORM\Column(typeTypes::STRINGenumTypeTransportMode::class)]
  85.     private ?TransportMode $transportMode TransportMode::SEA;
  86.     #[Assert\Type(typePayableLines::class)]
  87.     #[ORM\Column(type'json_document'options: ['jsonb' => true])]
  88.     private ?PayableLines $lines null;
  89.     #[Assert\NotNull]
  90.     #[IsValidEnum(enumPayableStatus::class)]
  91.     #[ORM\Column(typeTypes::STRINGenumTypePayableStatus::class)]
  92.     private ?PayableStatus $status PayableStatus::DRAFTED;
  93.     /** @var Collection<int, Box> */
  94.     #[ORM\ManyToMany(targetEntityBox::class)]
  95.     #[ORM\JoinTable(name'invoicing_proforma_box_map')]
  96.     #[ORM\JoinColumn(name'proforma_id')]
  97.     #[ORM\InverseJoinColumn(name'box_id')]
  98.     #[ORM\OrderBy(['id' => 'ASC'])]
  99.     #[ApiProperty(readableLinktrue)]
  100.     private Collection $boxes;
  101.     public function __construct()
  102.     {
  103.         $this->boxes = new ArrayCollection();
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getWorkOrder(): ?WorkOrder
  110.     {
  111.         return $this->workOrder;
  112.     }
  113.     public function setWorkOrder(?WorkOrder $workOrder): self
  114.     {
  115.         $this->workOrder $workOrder;
  116.         return $this;
  117.     }
  118.     public function getShippingPlan(): ?ShippingPlan
  119.     {
  120.         return $this->shippingPlan;
  121.     }
  122.     public function setShippingPlan(?ShippingPlan $shippingPlan): self
  123.     {
  124.         $this->shippingPlan $shippingPlan;
  125.         return $this;
  126.     }
  127.     public function getBatch(): ?Batch
  128.     {
  129.         return $this->batch;
  130.     }
  131.     public function setBatch(?Batch $batch): self
  132.     {
  133.         $this->batch $batch;
  134.         return $this;
  135.     }
  136.     public function getSlug(): ?string
  137.     {
  138.         return $this->slug;
  139.     }
  140.     public function setSlug(string $slug): self
  141.     {
  142.         $this->slug $slug;
  143.         return $this;
  144.     }
  145.     public function getNumber(): ?string
  146.     {
  147.         return $this->number;
  148.     }
  149.     public function setNumber(string $number): self
  150.     {
  151.         $this->number $number;
  152.         return $this;
  153.     }
  154.     public function getWorkOrders(): string
  155.     {
  156.         return $this->workOrders;
  157.     }
  158.     public function setWorkOrders(string $workOrders): self
  159.     {
  160.         $this->workOrders $workOrders;
  161.         return $this;
  162.     }
  163.     public function getWorkOrderReferences(): array
  164.     {
  165.         $references = [];
  166.         foreach ($this->boxes as $box) {
  167.             $boxReferenceParts explode('-'$box->getReference());
  168.             $references []= "{$boxReferenceParts[0]}-{$boxReferenceParts[1]}";
  169.         }
  170.         $references array_unique($references);
  171.         sort($references);
  172.         return $references;
  173.     }
  174.     public function getDestinationCountryCode(): ?string
  175.     {
  176.         return $this->destinationCountryCode;
  177.     }
  178.     public function setDestinationCountryCode(string $destinationCountryCode): self
  179.     {
  180.         $this->destinationCountryCode $destinationCountryCode;
  181.         return $this;
  182.     }
  183.     public function getTransportMode(): ?TransportMode
  184.     {
  185.         return $this->transportMode;
  186.     }
  187.     public function setTransportMode(?TransportMode $transportMode): self
  188.     {
  189.         $this->transportMode $transportMode;
  190.         return $this;
  191.     }
  192.     public function getLines(): ?PayableLines
  193.     {
  194.         return $this->lines;
  195.     }
  196.     public function setLines(?PayableLines $lines): self
  197.     {
  198.         $this->lines $lines;
  199.         return $this;
  200.     }
  201.     public function getAmount(): int|float|null
  202.     {
  203.         if (null === $this->lines) {
  204.             return null;
  205.         }
  206.         $amount 0;
  207.         foreach ($this->lines->lines as $line) {
  208.             $amount += $line->rate $line->quantity;
  209.         }
  210.         return $amount;
  211.     }
  212.     public function getStatus(): ?PayableStatus
  213.     {
  214.         return $this->status;
  215.     }
  216.     public function setStatus(?PayableStatus $status): self
  217.     {
  218.         $this->status $status;
  219.         return $this;
  220.     }
  221.     public function getChargeableWeight(): ?float
  222.     {
  223.         if (empty($this->chargeableWeight) && $this->transportMode === TransportMode::SEA) {
  224.             return max($this->weight$this->volume 1000);
  225.         }
  226.         if (empty($this->chargeableWeight) && $this->transportMode === TransportMode::AIR) {
  227.             return max($this->weight$this->volume 167);
  228.         }
  229.         return $this->chargeableWeight;
  230.     }
  231.     /**
  232.      * @return Collection<int, Box>
  233.      */
  234.     public function getBoxes(): Collection
  235.     {
  236.         return $this->boxes;
  237.     }
  238.     public function addBox(Box $box): self
  239.     {
  240.         if (!$this->boxes->contains($box)) {
  241.             $this->boxes->add($box);
  242.         }
  243.         return $this;
  244.     }
  245.     public function removeBox(Box $box): self
  246.     {
  247.         $this->boxes->removeElement($box);
  248.         return $this;
  249.     }
  250. }