src/Entity/Order.php line 28

  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\UnitType;
  4. use App\Enum\AmountUnitType;
  5. use App\Enum\CustomerClass;
  6. use App\Enum\CustomerGeneralClass;
  7. use App\Enum\OrderCommissionable;
  8. use App\Enum\OrderStatus;
  9. use App\Entity\OrderType;
  10. use App\Enum\State;
  11. use App\Repository\OrderRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\DBAL\Types\Types;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Gedmo\Timestampable\Traits\TimestampableEntity;
  17. #[ORM\Entity(repositoryClassOrderRepository::class)]
  18. #[ORM\Table(name'`order`')]
  19. #[ORM\Index(columns: ['invoice_number'], name'invoice_number_idx')]
  20. #[ORM\Index(columns: ['order_code''item_code'], name'order_code_item_code_idx')]
  21. #[ORM\Index(columns: ['user_payment_period_id''customer_general_class'], name'upp_customer_general_class_idx')]
  22. #[ORM\Index(columns: ['incentive_date'], name'order_incentive_date')]
  23. #[ORM\Index(columns: ['user_id'], name'order_user_id')]
  24. class Order
  25. {
  26.     use TimestampableEntity;
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column]
  30.     private ?int $id null;
  31.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  32.     private ?\DateTimeInterface $incentiveDate null;
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $batchName null;
  35.     #[ORM\Column(nullabletrue)]
  36.     private ?float $amount null;
  37.     #[ORM\Column(nullabletrue)]
  38.     private ?AmountUnitType $amountUnitType null;
  39.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  40.     private ?\DateTimeInterface $statusDate null;
  41.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  42.     private ?\DateTimeInterface $createdDate null;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $customerName null;
  45.     #[ORM\Column(length255nullabletrue)]
  46.     private ?CustomerClass $customerSalesClass null;
  47.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  48.     private ?string $description null;
  49.     #[ORM\Column(nullabletrue)]
  50.     private ?int $discount null;
  51.     #[ORM\Column(nullabletrue)]
  52.     private ?int $quantity 1;
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $relatedItemCode null;
  55.     #[ORM\Column(length255nullabletrue)]
  56.     private ?string $relatedOrderCode null;
  57.     #[ORM\Column(nullabletrue)]
  58.     private ?int $shipToNumber null;
  59.     #[ORM\Column(length255nullabletrue)]
  60.     private ?State $shipToState null;
  61.     #[ORM\Column(length255nullabletrue)]
  62.     private ?string $shipToZip null;
  63.     #[ORM\Column(length255nullabletrue)]
  64.     private ?string $invoiceNumber null;
  65.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  66.     private ?\DateTimeInterface $invoiceDate null;
  67.     #[ORM\Column(length255nullabletrue)]
  68.     private ?string $orderRefNumber null;
  69.     #[ORM\Column(length255nullabletrue)]
  70.     private ?string $independentRepNumber null;
  71.     #[ORM\Column(nullabletrue)]
  72.     private ?float $commissionRatePercent null;
  73.     #[ORM\ManyToOne(fetch"EAGER")]
  74.     private ?User $user null;
  75.     #[ORM\Column]
  76.     private ?int $splitPercent 0;
  77.     #[ORM\Column]
  78.     private bool $isCommissionable true;
  79.     #[ORM\Column(length255nullabletrue)]
  80.     private ?string $customerEmployeeRepCode null;
  81.     #[ORM\ManyToOne(cascade: ['REMOVE'], inversedBy'orders')]
  82.     private ?UserPaymentPeriod $userPaymentPeriod null;
  83.     #[ORM\Column(length255nullabletrue)]
  84.     private ?CustomerGeneralClass $customerGeneralClass null;
  85.     #[ORM\Column(length255nullabletrue)]
  86.     private ?string $employeeRepCode null;
  87.     #[ORM\Column(length255nullabletrue)]
  88.     private ?UnitType $commissionRateUnitType null;
  89.     #[ORM\Column(length255nullabletrue)]
  90.     private ?string $orderCode null;
  91.     #[ORM\Column(length255nullabletrue)]
  92.     private ?string $itemCode null;
  93.     #[ORM\ManyToOne(inversedBy'orders')]
  94.     private ?Period $period null;
  95.     #[ORM\ManyToOne(inversedBy'orders'fetch"EAGER")]
  96.     private ?Customer $customer null;
  97.     #[ORM\Column(length255nullabletrue)]
  98.     private ?string $customerNumber null;
  99.     #[ORM\ManyToOne(inversedBy'orders'fetch"EAGER")]
  100.     private ?OrderType $orderType null;
  101.     #[ORM\ManyToOne(inversedBy'orders'fetch"EAGER")]
  102.     private ?BatchType $batchType null;
  103.     #[ORM\OneToMany(mappedBy'orderItem'targetEntityCommission::class, cascade: ['persist''remove'])]
  104.     #[ORM\OrderBy(['user' => 'ASC'])]
  105.     private Collection $commissions;
  106.     #[ORM\OneToMany(mappedBy'orderItem'targetEntityCredit::class, cascade: ['persist''remove'])]
  107.     #[ORM\OrderBy(['user' => 'ASC'])]
  108.     private Collection $credits;
  109.     #[ORM\Column(length255)]
  110.     private ?OrderStatus $status OrderStatus::NEW;
  111.     #[ORM\OneToMany(mappedBy'orderItem'targetEntityOrderAssignment::class, cascade: ['persist''remove'])]
  112.     private Collection $orderAssignments;
  113.     #[ORM\Column(length255nullabletrue)]
  114.     private ?string $customerNumber2 null;
  115.     #[ORM\Column(length255nullabletrue)]
  116.     private ?string $customerNumberTruncated null;
  117.     #[ORM\ManyToOne(inversedBy'orders')]
  118.     private ?ImportFile $importFile null;
  119.     #[ORM\Column]
  120.     private ?bool $rollable true;
  121.     #[ORM\Column]
  122.     private ?bool $manual false;
  123.     public function __construct()
  124.     {
  125.         $this->commissions = new ArrayCollection();
  126.         $this->credits = new ArrayCollection();
  127.         $this->orderAssignments = new ArrayCollection();
  128.     }
  129.     public function setId($id): ?int
  130.     {
  131.         return $this->id $id;
  132.     }
  133.     public function getId(): ?int
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function getIncentiveDate(): ?\DateTimeInterface
  138.     {
  139.         return $this->incentiveDate;
  140.     }
  141.     public function setIncentiveDate(?\DateTimeInterface $incentiveDate): self
  142.     {
  143.         $this->incentiveDate $incentiveDate;
  144.         return $this;
  145.     }
  146.     public function getBatchName(): ?string
  147.     {
  148.         return $this->batchName;
  149.     }
  150.     public function setBatchName(?string $batchName): self
  151.     {
  152.         $this->batchName $batchName;
  153.         return $this;
  154.     }
  155.     public function getDividedAmount(): ?float
  156.     {
  157.         return ($this->amount ?: 0) / 100.00;
  158.     }
  159.     public function getAmount(): ?float
  160.     {
  161.         return $this->amount;
  162.     }
  163.     public function setAmount(?float $amount): self
  164.     {
  165.         $this->amount $amount;
  166.         return $this;
  167.     }
  168.     public function getAmountUnitType() : ?AmountUnitType
  169.     {
  170.         return $this->amountUnitType;
  171.     }
  172.     public function getAmountUnitTypeString() : string
  173.     {
  174.        return $this->amountUnitType?->value ?: 'USD';
  175.     }
  176.     public function setAmountUnitType(?AmountUnitType $amountUnitType): self
  177.     {
  178.         $this->amountUnitType $amountUnitType;
  179.         return $this;
  180.     }
  181.     public function getStatusDate(): ?\DateTimeInterface
  182.     {
  183.         return $this->statusDate;
  184.     }
  185.     public function setStatusDate(?\DateTimeInterface $statusDate): self
  186.     {
  187.         $this->statusDate $statusDate;
  188.         return $this;
  189.     }
  190.     public function getCreatedDate(): ?\DateTimeInterface
  191.     {
  192.         return $this->createdDate;
  193.     }
  194.     public function setCreatedDate(?\DateTimeInterface $createdDate): self
  195.     {
  196.         $this->createdDate $createdDate;
  197.         return $this;
  198.     }
  199.     public function getCustomerName(): ?string
  200.     {
  201.         return $this->customerName;
  202.     }
  203.     public function setCustomerName(?string $customerName): self
  204.     {
  205.         $this->customerName $customerName;
  206.         return $this;
  207.     }
  208.     public function getDescription(): ?string
  209.     {
  210.         return $this->description;
  211.     }
  212.     public function setDescription(?string $description): self
  213.     {
  214.         $this->description $description;
  215.         return $this;
  216.     }
  217.     public function getDiscount(): ?int
  218.     {
  219.         return $this->discount;
  220.     }
  221.     public function setDiscount(?int $discount): self
  222.     {
  223.         $this->discount $discount;
  224.         return $this;
  225.     }
  226.     public function getQuantity(): ?int
  227.     {
  228.         return $this->quantity;
  229.     }
  230.     public function setQuantity(?int $quantity): self
  231.     {
  232.         $this->quantity $quantity;
  233.         return $this;
  234.     }
  235.     public function getRelatedItemCode(): ?string
  236.     {
  237.         return $this->relatedItemCode;
  238.     }
  239.     public function setRelatedItemCode(?string $relatedItemCode): self
  240.     {
  241.         $this->relatedItemCode $relatedItemCode;
  242.         return $this;
  243.     }
  244.     public function getRelatedOrderCode(): ?string
  245.     {
  246.         return $this->relatedOrderCode;
  247.     }
  248.     public function setRelatedOrderCode(?string $relatedOrderCode): self
  249.     {
  250.         $this->relatedOrderCode $relatedOrderCode;
  251.         return $this;
  252.     }
  253.     public function getShipToNumber(): ?int
  254.     {
  255.         return $this->shipToNumber;
  256.     }
  257.     public function setShipToNumber(?int $shipToNumber): self
  258.     {
  259.         $this->shipToNumber $shipToNumber;
  260.         return $this;
  261.     }
  262.     public function getShipToState(): ?string
  263.     {
  264.         return $this->shipToState?->value ?: '';
  265.     }
  266.     public function setShipToState(?State $shipToState): self
  267.     {
  268.         $this->shipToState $shipToState;
  269.         return $this;
  270.     }
  271.     public function getShipToZip(): ?string
  272.     {
  273.         return $this->shipToZip;
  274.     }
  275.     public function setShipToZip(?string $shipToZip): self
  276.     {
  277.         $this->shipToZip $shipToZip;
  278.         return $this;
  279.     }
  280.     public function getInvoiceNumber(): ?string
  281.     {
  282.         return $this->invoiceNumber;
  283.     }
  284.     public function setInvoiceNumber(?string $invoiceNumber): self
  285.     {
  286.         $this->invoiceNumber $invoiceNumber;
  287.         return $this;
  288.     }
  289.     public function getOrderRefNumber(): ?string
  290.     {
  291.         return $this->orderRefNumber;
  292.     }
  293.     public function setOrderRefNumber(?string $orderRefNumber): self
  294.     {
  295.         $this->orderRefNumber $orderRefNumber;
  296.         return $this;
  297.     }
  298.     public function getCustomerSalesClass(): ?CustomerClass
  299.     {
  300.         return $this->customerSalesClass;
  301.     }
  302.     public function setCustomerSalesClass(?CustomerClass $customerSalesClass): self
  303.     {
  304.         $this->customerSalesClass $customerSalesClass;
  305.         $general null;
  306.         if ($customerSalesClass) {
  307.             if ($customerSalesClass == CustomerClass::TM_OTG) {
  308.                 $general CustomerGeneralClass::OTG;
  309.             } else {
  310.                 $general CustomerGeneralClass::from($customerSalesClass->value);
  311.             }
  312.         }
  313.         $this->setCustomerGeneralClass($general);
  314.         return $this;
  315.     }
  316.     public function getIndependentRepNumber(): ?string
  317.     {
  318.         return $this->independentRepNumber;
  319.     }
  320.     public function setIndependentRepNumber(?string $independentRepNumber): self
  321.     {
  322.         $this->independentRepNumber $independentRepNumber;
  323.         return $this;
  324.     }
  325.     public function getCommissionRatePercent(): ?float
  326.     {
  327.         return $this->commissionRatePercent;
  328.     }
  329.     public function setCommissionRatePercent(?float $commissionRatePercent): self
  330.     {
  331.         $this->commissionRatePercent $commissionRatePercent;
  332.         return $this;
  333.     }
  334.     public function getInvoiceDate(): ?\DateTimeInterface
  335.     {
  336.         return $this->invoiceDate;
  337.     }
  338.     public function setInvoiceDate(?\DateTimeInterface $invoiceDate): self
  339.     {
  340.         $this->invoiceDate $invoiceDate;
  341.         return $this;
  342.     }
  343.     public function getUser(): ?User
  344.     {
  345.         return $this->user;
  346.     }
  347.     public function setUser(?User $user): self
  348.     {
  349.         $this->user $user;
  350.         return $this;
  351.     }
  352.     public function getSplitPercent(): ?int
  353.     {
  354.         return $this->splitPercent;
  355.     }
  356.     public function setSplitPercent(?int $splitPercent): self
  357.     {
  358.         $this->splitPercent $splitPercent;
  359.         return $this;
  360.     }
  361.     public function getIsCommissionable(): bool
  362.     {
  363.         return $this->isCommissionable;
  364.     }
  365.     public function setIsCommissionable(bool $isCommissionable): self
  366.     {
  367.         $this->isCommissionable $isCommissionable;
  368.         return $this;
  369.     }
  370.     public function getCustomerEmployeeRepCode(): ?string
  371.     {
  372.         return $this->customerEmployeeRepCode;
  373.     }
  374.     public function setCustomerEmployeeRepCode(?string $customerEmployeeRepCode): self
  375.     {
  376.         $this->customerEmployeeRepCode $customerEmployeeRepCode;
  377.         return $this;
  378.     }
  379.     public function getUserPaymentPeriod(): ?UserPaymentPeriod
  380.     {
  381.         return $this->userPaymentPeriod;
  382.     }
  383.     public function setUserPaymentPeriod(?UserPaymentPeriod $userPaymentPeriod): self
  384.     {
  385.         $this->userPaymentPeriod $userPaymentPeriod;
  386.         return $this;
  387.     }
  388.     public function getCustomerGeneralClass(): ?CustomerGeneralClass
  389.     {
  390.         return $this->customerGeneralClass;
  391.     }
  392.     public function setCustomerGeneralClass(?CustomerGeneralClass $customerGeneralClass): self
  393.     {
  394.         $this->customerGeneralClass $customerGeneralClass;
  395.         return $this;
  396.     }
  397.     public function getEmployeeRepCode(): ?string
  398.     {
  399.         return $this->employeeRepCode;
  400.     }
  401.     public function setEmployeeRepCode(?string $employeeRepCode): self
  402.     {
  403.         $this->employeeRepCode $employeeRepCode;
  404.         return $this;
  405.     }
  406.     public function getCommissionRateUnitType(): ?UnitType
  407.     {
  408.         return $this->commissionRateUnitType;
  409.     }
  410.     public function setCommissionRateUnitType(?UnitType $commissionRateUnitType): self
  411.     {
  412.         $this->commissionRateUnitType $commissionRateUnitType;
  413.         return $this;
  414.     }
  415.     public function getOrderCode(): ?string
  416.     {
  417.         return $this->orderCode;
  418.     }
  419.     public function setOrderCode(?string $orderCode): self
  420.     {
  421.         $this->orderCode $orderCode;
  422.         return $this;
  423.     }
  424.     public function getItemCode(): ?string
  425.     {
  426.         return $this->itemCode;
  427.     }
  428.     public function setItemCode(?string $itemCode): self
  429.     {
  430.         $this->itemCode $itemCode;
  431.         return $this;
  432.     }
  433.     public function getPeriod(): ?Period
  434.     {
  435.         return $this->period;
  436.     }
  437.     public function setPeriod(?Period $period): self
  438.     {
  439.         $this->period $period;
  440.         return $this;
  441.     }
  442.     public function getCustomer(): ?Customer
  443.     {
  444.         return $this->customer;
  445.     }
  446.     public function setCustomer(?Customer $customer): self
  447.     {
  448.         $this->customer $customer;
  449.         return $this;
  450.     }
  451.     public function getCustomerNumber(): ?string
  452.     {
  453.         return $this->customerNumber;
  454.     }
  455.     public function setCustomerNumber(?string $customerNumber): self
  456.     {
  457.         $this->customerNumber $customerNumber;
  458.         return $this;
  459.     }
  460.     public function getOrderType(): ?OrderType
  461.     {
  462.         return $this->orderType;
  463.     }
  464.     public function setOrderType(?OrderType $orderType): self
  465.     {
  466.         $this->orderType $orderType;
  467.         return $this;
  468.     }
  469.     public function getBatchType(): ?BatchType
  470.     {
  471.         return $this->batchType;
  472.     }
  473.     public function setBatchType(?BatchType $batchType): self
  474.     {
  475.         $this->batchType $batchType;
  476.         return $this;
  477.     }
  478.     /**
  479.      * @return Collection<int, Commission>
  480.      */
  481.     public function getCommissions(): Collection
  482.     {
  483.         return $this->commissions;
  484.     }
  485.     public function getXactlyCommissions(): Collection
  486.     {
  487.         return $this->commissions->filter(function (Commission $commission) {
  488.             return !$commission->isL6();
  489.         });
  490.     }
  491.     /**
  492.      * @return Collection<int, Credit>
  493.      */
  494.     public function getL6Commissions(): Collection
  495.     {
  496.         return $this->commissions->filter(function (Commission $commission) {
  497.             return $commission->isL6();
  498.         });
  499.     }
  500.     public function addCommission(Commission $commission): static
  501.     {
  502.         if (!$this->commissions->contains($commission)) {
  503.             $this->commissions->add($commission);
  504.             $commission->setOrderItem($this);
  505.         }
  506.         return $this;
  507.     }
  508.     public function removeCommission(Commission $commission): static
  509.     {
  510.         if ($this->commissions->removeElement($commission)) {
  511.             // set the owning side to null (unless already changed)
  512.             if ($commission->getOrderItem() === $this) {
  513.                 $commission->setOrderItem(null);
  514.             }
  515.         }
  516.         return $this;
  517.     }
  518.     /**
  519.      * @return Collection<int, Credit>
  520.      */
  521.     public function getCredits(): Collection
  522.     {
  523.         return $this->credits;
  524.     }
  525.     /**
  526.      * @return Collection<int, Credit>
  527.      */
  528.     public function getXactlyCredits(): Collection
  529.     {
  530.         return $this->credits->filter(function (Credit $credit) {
  531.             return !$credit->isL6();
  532.         });
  533.     }
  534.     /**
  535.      * @return Collection<int, Credit>
  536.      */
  537.     public function getL6Credits(): Collection
  538.     {
  539.         return $this->credits->filter(function (Credit $credit) {
  540.             return $credit->isL6();
  541.         });
  542.     }
  543.     public function addCredit(Credit $credit): static
  544.     {
  545.         if (!$this->credits->contains($credit)) {
  546.             $this->credits->add($credit);
  547.             $credit->setOrderItem($this);
  548.         }
  549.         return $this;
  550.     }
  551.     public function removeCredit(Credit $credit): static
  552.     {
  553.         if ($this->credits->removeElement($credit)) {
  554.             // set the owning side to null (unless already changed)
  555.             if ($credit->getOrderItem() === $this) {
  556.                 $credit->setOrderItem(null);
  557.             }
  558.         }
  559.         return $this;
  560.     }
  561.     public function getStatus(): ?OrderStatus
  562.     {
  563.         return $this->status;
  564.     }
  565.     public function setStatus(OrderStatus $status): static
  566.     {
  567.         $this->status $status;
  568.         $this->statusDate = new \DateTime('now', new \DateTimeZone('UTC'));
  569.         return $this;
  570.     }
  571.     /**
  572.      * @return Collection<int, OrderAssignment>
  573.      */
  574.     public function getOrderAssignments(): Collection
  575.     {
  576.         return $this->orderAssignments;
  577.     }
  578.     public function addOrderAssignment(OrderAssignment $orderAssignment): static
  579.     {
  580.         if (!$this->orderAssignments->contains($orderAssignment)) {
  581.             $this->orderAssignments->add($orderAssignment);
  582.             $orderAssignment->setOrderItem($this);
  583.         }
  584.         return $this;
  585.     }
  586.     public function removeOrderAssignment(OrderAssignment $orderAssignment): static
  587.     {
  588.         if ($this->orderAssignments->removeElement($orderAssignment)) {
  589.             // set the owning side to null (unless already changed)
  590.             if ($orderAssignment->getOrderItem() === $this) {
  591.                 $orderAssignment->setOrderItem(null);
  592.             }
  593.         }
  594.         return $this;
  595.     }
  596.     public function getCustomerNumber2(): ?string
  597.     {
  598.         return $this->customerNumber2;
  599.     }
  600.     public function setCustomerNumber2(?string $customerNumber2): static
  601.     {
  602.         $this->customerNumber2 $customerNumber2;
  603.         return $this;
  604.     }
  605.     public function getCustomerNumberTruncated(): ?string
  606.     {
  607.         return $this->customerNumberTruncated;
  608.     }
  609.     public function setCustomerNumberTruncated(?string $customerNumberTruncated): static
  610.     {
  611.         $this->customerNumberTruncated $customerNumberTruncated;
  612.         return $this;
  613.     }
  614.     public function getImportFile(): ?ImportFile
  615.     {
  616.         return $this->importFile;
  617.     }
  618.     public function setImportFile(?ImportFile $importFile): static
  619.     {
  620.         $this->importFile $importFile;
  621.         return $this;
  622.     }
  623.     public function __toString(): string
  624.     {
  625.         return sprintf('%s - %s'$this->getOrderCode(), $this->getItemCode());
  626.     }
  627.     public function isRollable(): ?bool
  628.     {
  629.         return $this->rollable;
  630.     }
  631.     public function setRollable(bool $rollable): static
  632.     {
  633.         $this->rollable $rollable;
  634.         return $this;
  635.     }
  636.     public function isManual(): ?bool
  637.     {
  638.         return $this->manual;
  639.     }
  640.     public function setManual(bool $manual): static
  641.     {
  642.         $this->manual $manual;
  643.         return $this;
  644.     }
  645. }