src/Entity/SaleOrder.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SaleOrderRepository;
  4. use App\Traits\DateTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation as Serializer;
  9. use JMS\Serializer\Annotation\Expose;
  10. use JMS\Serializer\Annotation\Groups;
  11. use JMS\Serializer\Annotation\SerializedName;
  12. use ReflectionClass;
  13. use App\Constants\SaleOrder as SaleOrderConstant;
  14. /**
  15. * @ORM\Entity(repositoryClass=SaleOrderRepository::class)
  16. * @ORM\Table(indexes={
  17. * @ORM\Index(columns={"status"})
  18. * })
  19. *
  20. * @Serializer\ExclusionPolicy("ALL")
  21. */
  22. class SaleOrder
  23. {
  24. use DateTrait;
  25. /**
  26. * Identifiant interne auto incrémenté
  27. *
  28. * @ORM\Id
  29. * @ORM\GeneratedValue
  30. * @ORM\Column(type="integer")
  31. *
  32. * @Expose
  33. * @Groups({
  34. * "sale_order:id",
  35. * "sale_order:list",
  36. * "sale_order:updated",
  37. * "sale_order:item",
  38. * "sale_order",
  39. * "get:read",
  40. * "post:read",
  41. * "export_order_datatable"
  42. * })
  43. */
  44. private ?int $id = NULL;
  45. /**
  46. * Total de la commande HT
  47. *
  48. * @ORM\Column(type="decimal", precision=8, scale=2)
  49. *
  50. * @Expose
  51. * @Groups({
  52. * "sale_order:list",
  53. * "sale_order:updated",
  54. * "sale_order:item",
  55. * "sale_order",
  56. * "get:read",
  57. * "export_order_datatable"
  58. * })
  59. */
  60. private string $total = '0.00';
  61. /**
  62. * Méthode d'expédition
  63. *
  64. * @ORM\Column(type="string", length=64, nullable=true)
  65. *
  66. * @Expose
  67. * @Groups({
  68. * "sale_order:updated",
  69. * "sale_order",
  70. * "get:read"
  71. * })
  72. */
  73. private ?string $shippingMethod = NULL;
  74. /**
  75. * Statut de la commande
  76. * @ORM\Column(type="string", length=32, options={"default":"pending_processing"})
  77. *
  78. * @Expose
  79. * @Groups({
  80. * "sale_order:status",
  81. * "sale_order:list",
  82. * "sale_order:updated",
  83. * "sale_order:item",
  84. * "sale_order",
  85. * "get:read",
  86. * "post:read",
  87. * "export_order_datatable"
  88. * })
  89. */
  90. private string $status = SaleOrderConstant::STATUS_PENDING_PROCESSING;
  91. /**
  92. * Statut de la commande à attribuer après l'application d'un statut "waiting"
  93. * @ORM\Column(type="string", length=32, nullable=true)
  94. *
  95. * @Expose
  96. * @Groups({
  97. * "sale_order:status",
  98. * "sale_order:list",
  99. * "sale_order:updated",
  100. * "sale_order:item",
  101. * "sale_order",
  102. * "get:read",
  103. * "post:read",
  104. * "export_order_datatable"
  105. * })
  106. */
  107. private ?string $waitingStatus = null;
  108. /**
  109. * @ORM\OneToOne(targetEntity=BankReturn::class, cascade={"persist", "remove"})
  110. */
  111. private ?BankReturn $bankReturn = NULL;
  112. /**
  113. * Utilisateur
  114. *
  115. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
  116. *
  117. * @Expose
  118. * @Groups({
  119. * "sale_order:user",
  120. * "sale_order:item",
  121. * "sale_order:post",
  122. * "sale_order",
  123. * "get:read",
  124. * "post:read",
  125. * "export_order_datatable"
  126. * })
  127. */
  128. private ?User $user = NULL;
  129. /**
  130. * Motif d'annulation
  131. * @ORM\Column(type="text", nullable=true)
  132. *
  133. * @Expose
  134. * @Groups({
  135. * "sale_order:item",
  136. * "sale_order:updated",
  137. * "sale_order"
  138. * })
  139. */
  140. private ?string $cancelMotif = NULL;
  141. /**
  142. * Prix de la livraison
  143. *
  144. * @ORM\Column(type="decimal", precision=8, scale=2)
  145. *
  146. * @Expose
  147. * @Groups({
  148. * "sale_order:item",
  149. * "sale_order:updated",
  150. * "sale_order",
  151. * "get:read"
  152. * })
  153. */
  154. private $shippingPrice;
  155. /**
  156. * Référence interne
  157. *
  158. * @ORM\Column(type="string", length=64, nullable=true)
  159. *
  160. * @Expose
  161. * @Groups({
  162. * "sale_order:item",
  163. * "sale_order"
  164. * })
  165. */
  166. private ?string $internalReference = NULL;
  167. /**
  168. * Commentaire
  169. *
  170. * @ORM\Column(type="text", nullable=true)
  171. *
  172. * @Expose
  173. * @Groups({
  174. * "sale_order:item",
  175. * "sale_order",
  176. * "get:read"
  177. * })
  178. */
  179. private ?string $comment = NULL;
  180. /**
  181. * @ORM\Column(type="boolean", options={"default":false})
  182. *
  183. * @Expose
  184. * @Groups({
  185. * "sale_order",
  186. * "get:read"
  187. * })
  188. */
  189. private bool $isManagedByCustomer = FALSE;
  190. /**
  191. * @ORM\Column(type="decimal", precision=8, scale=2, nullable=true)
  192. *
  193. * @Expose
  194. * @Groups({
  195. * "sale_order",
  196. * "sale_order:updated"
  197. * })
  198. */
  199. private $feesOrder;
  200. /**
  201. * @ORM\Column(type="decimal", precision=8, scale=2, nullable=true)
  202. *
  203. * @Expose
  204. * @Groups({"sale_order"})
  205. */
  206. private $extraCbPayment;
  207. /**
  208. * @deprecated NON UTILISÉ
  209. *
  210. * @ORM\Column(type="decimal", precision=8, scale=2, nullable=true)
  211. *
  212. * @Expose
  213. * @Groups({"sale_order"})
  214. */
  215. private $totalBonusUsed;
  216. /**
  217. * @deprecated
  218. * @ORM\ManyToOne(targetEntity=SaleOrder::class, inversedBy="saleOrders")
  219. */
  220. private ?SaleOrder $saleorderGrouped = NULL;
  221. /**
  222. * @deprecated
  223. * @ORM\OneToMany(targetEntity=SaleOrder::class, mappedBy="saleorderGrouped")
  224. */
  225. private Collection $saleOrders;
  226. /**
  227. * @ORM\Column(type="boolean", nullable=true)
  228. *
  229. * @Expose
  230. * @Groups({"sale_order"})
  231. */
  232. private ?bool $notBillable = NULL;
  233. /**
  234. * @ORM\Column(type="array", nullable=true)
  235. *
  236. * @Expose
  237. * @Groups({"sale_order","get:read"})
  238. */
  239. private ?array $otherinformations = [];
  240. /**
  241. * Adresse de livraison
  242. *
  243. * @ORM\OneToOne(targetEntity=SaleOrderAddress::class, orphanRemoval=true, cascade={"persist", "remove"})
  244. * @ORM\JoinColumn(onDelete="SET NULL")
  245. *
  246. * @Expose
  247. * @Groups({"sale_order:item", "sale_order:post", "get:read", "sale_order", "export_order_datatable"})
  248. */
  249. private ?SaleOrderAddress $shippingAddress = NULL;
  250. /**
  251. * Adresse de facturation
  252. *
  253. * @ORM\OneToOne(targetEntity=SaleOrderAddress::class, orphanRemoval=true, cascade={"persist", "remove"})
  254. * @ORM\JoinColumn(onDelete="SET NULL")
  255. *
  256. * @Expose
  257. * @Groups({"sale_order:item", "sale_order:post", "get:read"})
  258. */
  259. private ?SaleOrderAddress $billingAddress = NULL;
  260. /**
  261. * Liste des produits commandés
  262. * @ORM\OneToMany(targetEntity=SaleOrderItem::class, mappedBy="saleOrder", cascade={"persist", "remove"})
  263. *
  264. * @Expose
  265. * @Groups({"sale_order:item", "sale_order:post", "get:read", "export_order_datatable"})
  266. */
  267. private Collection $items;
  268. /**
  269. * @ORM\OneToMany(targetEntity=SaleOrderShipment::class, mappedBy="saleOrder", cascade={"remove"})
  270. *
  271. * @Expose
  272. * @Groups({
  273. * "sale_order",
  274. * "sale_order:item",
  275. * "sale_order:updated",
  276. * "get:read",
  277. * "export_order_datatable"
  278. * })
  279. */
  280. private Collection $shipments;
  281. /**
  282. * @ORM\OneToOne(targetEntity=Cart::class, inversedBy="saleOrder", cascade={"persist", "remove"})
  283. */
  284. private ?Cart $cart = NULL;
  285. /**
  286. * @var Collection|PointTransaction[]
  287. *
  288. * @ORM\OneToMany(targetEntity=PointTransaction::class, mappedBy="saleOrder", cascade={"remove"})
  289. */
  290. private Collection $pointTransactions;
  291. /**
  292. * @ORM\Column(type="integer", nullable=true)
  293. *
  294. * @Expose
  295. * @Groups({
  296. * "sale_order",
  297. * "sale_order:updated",
  298. * "get:read",
  299. * "export_order_datatable"
  300. * })
  301. */
  302. private ?int $oldId = NULL;
  303. /**
  304. * @ORM\OneToOne(targetEntity=SaleOrderInvoice::class, inversedBy="saleOrder", cascade={"persist", "remove"})
  305. */
  306. private ?SaleOrderInvoice $invoice = NULL;
  307. /**
  308. * @ORM\Column(type="text", nullable=true)
  309. */
  310. private $categoryValues;
  311. /**
  312. * @ORM\Column(type="text", nullable=true)
  313. */
  314. private $feesCategoryValues;
  315. /**
  316. * @ORM\Column(type="string", length=255, nullable=true)
  317. *
  318. * @Expose
  319. * @Groups({"sale_order", "export_order_datatable", "get:read"})
  320. */
  321. private $customQuestion;
  322. /**
  323. * @ORM\Column(type="float", nullable=true)
  324. */
  325. private $orderRate;
  326. /**
  327. * @ORM\Column(type="boolean", options={"default":false})
  328. */
  329. private bool $isTrip = FALSE;
  330. private ?string $agency = NULL;
  331. /**
  332. * @Expose
  333. * @Groups({"get:read"})
  334. * @ORM\Column(type="text", nullable=true)
  335. */
  336. private ?string $orderExtraData = NULL;
  337. private ?bool $updateFromBo = false;
  338. /**
  339. * @ORM\OneToMany(targetEntity=Invoice::class, mappedBy="saleOrder")
  340. */
  341. private Collection $invoices;
  342. /**
  343. * @ORM\Column(type="boolean", options={"default": false})
  344. *
  345. * @Expose
  346. * @Groups({
  347. * "sale_order",
  348. * "get:read"
  349. * })
  350. */
  351. private bool $isExpressDelivery = false;
  352. public function __construct()
  353. {
  354. $this->saleOrders = new ArrayCollection();
  355. $this->items = new ArrayCollection();
  356. $this->shipments = new ArrayCollection();
  357. $this->pointTransactions = new ArrayCollection();
  358. $this->invoices = new ArrayCollection();
  359. }
  360. public static function getStatuses()
  361. {
  362. $statuses = [];
  363. $reflect = new ReflectionClass(SaleOrder::class);
  364. foreach($reflect->getConstants() as $k => $const)
  365. {
  366. if(preg_match("/^(STATUS)/", $k))
  367. {
  368. $statuses[$const] = 'capsule.order.status.' . $const;
  369. }
  370. }
  371. return $statuses;
  372. }
  373. /**
  374. * Retourne la société de l'admin adhérent (spécial algorel)
  375. *
  376. * @Serializer\VirtualProperty()
  377. * @SerializedName("agency")
  378. * @Expose()
  379. * @Groups({"get:read"})
  380. *
  381. */
  382. public function getAgency(): ?string
  383. {
  384. return $this->agency;
  385. }
  386. public function setAgency(?string $agency): self
  387. {
  388. $this->agency = $agency;
  389. return $this;
  390. }
  391. /**
  392. * Retourne le cumul des produits + frais de port + frais de commande
  393. *
  394. * @Serializer\VirtualProperty()
  395. * @SerializedName("totalAmount")
  396. * @Expose()
  397. * @Groups({"sale_order","sale_order:item", "sale_order:post", "get:read", "export_order_datatable"})
  398. *
  399. * @return float
  400. */
  401. public function getTotalAmount(): float
  402. {
  403. return $this->total + $this->shippingPrice + ($this->feesOrder ?? 0);
  404. }
  405. /**
  406. * Retourne le cumul en point des produits + frais de port + frais de commande
  407. *
  408. * @Serializer\VirtualProperty()
  409. * @SerializedName("totalRateAmount")
  410. * @Expose()
  411. * @Groups({"sale_order","sale_order:item", "sale_order:post", "get:read", "export_order_datatable"})
  412. *
  413. * @return float
  414. */
  415. public function getRateTotalAmount(): float
  416. {
  417. return round(($this->total * $this->getOrderRate()) + ($this->shippingPrice * $this->getOrderRate()) + (($this->feesOrder ?? 0) * $this->getOrderRate()));
  418. }
  419. /**
  420. * @Serializer\VirtualProperty()
  421. * @Serializer\SerializedName("array_category_values")
  422. *
  423. * @Expose()
  424. * @Groups({ "sale_order:array_category_values", "export_order_datatable" })
  425. */
  426. public function getArrayCategoryValues()
  427. {
  428. return json_decode($this->categoryValues, TRUE) ?? [];
  429. }
  430. /**
  431. * @Serializer\VirtualProperty()
  432. * @Serializer\SerializedName("array_category_values")
  433. *
  434. * @Expose()
  435. * @Groups({ "sale_order:array_category_values", "export_order_datatable" })
  436. */
  437. public function getArrayFeesCategoryValues()
  438. {
  439. return json_decode($this->feesCategoryValues, TRUE) ?? [];
  440. }
  441. /*
  442. * ============================================================================================
  443. * =============================== FONCTIONS CUSTOM ===========================================
  444. * ============================================================================================
  445. */
  446. /**
  447. * @return string[]
  448. */
  449. public static function getOrderedStatus(): array
  450. {
  451. return [
  452. SaleOrderConstant::STATUS_SHIPPED,
  453. SaleOrderConstant::STATUS_PROCESSING,
  454. SaleOrderConstant::STATUS_PENDING_PROCESSING,
  455. SaleOrderConstant::STATUS_TO_SHIP,
  456. SaleOrderConstant::STATUS_PARTIALLY_SHIPPED,
  457. ];
  458. }
  459. public function __toString()
  460. {
  461. return $this->getSku();
  462. }
  463. public function getSku()
  464. {
  465. $id = strval($this->getId());
  466. return 'SP' . str_pad($id, 10, '0', STR_PAD_LEFT);
  467. }
  468. public function getId(): ?int
  469. {
  470. return $this->id;
  471. }
  472. public function getAddressType(SaleOrderAddress $Address)
  473. {
  474. if($this->billingAddress === $Address)
  475. {
  476. return SaleOrderAddress::BILLING_ADDRESS;
  477. }
  478. elseif($this->shippingAddress === $Address)
  479. {
  480. return SaleOrderAddress::SHIPPING_ADDRESS;
  481. }
  482. return FALSE;
  483. }
  484. public function getItemByReferenceWithStatus($reference, $statuses)
  485. {
  486. foreach($this->getItems() as $item)
  487. {
  488. if($item->getReference() == $reference && in_array($item->getStatus(), $statuses))
  489. {
  490. return $item;
  491. }
  492. }
  493. return NULL;
  494. }
  495. /**
  496. * @return Collection|SaleOrderItem[]
  497. */
  498. public function getItems(): Collection
  499. {
  500. return $this->items;
  501. }
  502. /**
  503. * @param Collection $items
  504. *
  505. * @return $this
  506. */
  507. public function setItems(Collection $items): SaleOrder
  508. {
  509. $this->items = $items;
  510. return $this;
  511. }
  512. public function getStatus(): ?string
  513. {
  514. return $this->status;
  515. }
  516. public function setStatus(string $status): self
  517. {
  518. $this->status = $status;
  519. return $this;
  520. }
  521. public function getItemsByReferenceWithStatus($reference, $statuses = [])
  522. {
  523. $items = [];
  524. foreach($this->getItems() as $item)
  525. {
  526. if($item->getReference() == $reference)
  527. {
  528. if(empty($statuses) || in_array($item->getStatus(), $statuses))
  529. {
  530. $items[] = $item;
  531. }
  532. }
  533. }
  534. return $items;
  535. }
  536. /**
  537. * Count items matching reference & status
  538. *
  539. * @param string $reference
  540. * @param array $statuses
  541. * @param bool $in
  542. *
  543. * @return int
  544. */
  545. public function countItemsByReferenceWithStatus(string $reference, array $statuses, bool $in = TRUE): int
  546. {
  547. $totalRef = $cnt = 0;
  548. foreach($this->getItems() as $item)
  549. {
  550. if($item->getReference() == $reference)
  551. {
  552. $totalRef++;
  553. if(in_array($item->getStatus(), $statuses))
  554. {
  555. $cnt++;
  556. }
  557. }
  558. }
  559. return ($in) ? $cnt : ($totalRef - $cnt);
  560. }
  561. /*
  562. * ============================================================================================
  563. * ============================== FIN FONCTIONS CUSTOM ========================================
  564. * ============================================================================================
  565. */
  566. /**
  567. * Count items matching status
  568. *
  569. * @param $statuses
  570. * @param bool $in
  571. *
  572. * @return int
  573. */
  574. public function countItemsWithStatus($statuses, bool $in = TRUE): int
  575. {
  576. $cnt = 0;
  577. foreach($this->getItems() as $item)
  578. {
  579. if(in_array($item->getStatus(), $statuses))
  580. {
  581. $cnt++;
  582. }
  583. }
  584. return ($in) ? $cnt : (count($this->getItems()) - $cnt);
  585. }
  586. /**
  587. * Get an item from order matching reference
  588. *
  589. * @param $reference
  590. *
  591. * @return SaleOrderItem|null
  592. */
  593. public function getItemByReference($reference)
  594. {
  595. foreach($this->getItems() as $item)
  596. {
  597. if($item->getReference() == $reference)
  598. {
  599. return $item;
  600. }
  601. }
  602. return NULL;
  603. }
  604. public function hasAllItemsStatesCanceled()
  605. {
  606. return $this->hasAllItemsState(SaleOrderItem::STATUS_CANCELED);
  607. }
  608. public function hasAllItemsState($state)
  609. {
  610. foreach($this->getItems() as $item)
  611. {
  612. if($item->getStatus() != $state)
  613. {
  614. return FALSE;
  615. }
  616. }
  617. return TRUE;
  618. }
  619. public function getTotal(): ?float
  620. {
  621. return (float)$this->total;
  622. }
  623. public function setTotal($total): self
  624. {
  625. if($total === null)
  626. {
  627. $this->total = '0.00';
  628. return $this;
  629. }
  630. $this->total = (string)$total;
  631. return $this;
  632. }
  633. public function getShippingMethod(): ?string
  634. {
  635. return $this->shippingMethod;
  636. }
  637. public function setShippingMethod(?string $shippingMethod): self
  638. {
  639. $this->shippingMethod = $shippingMethod;
  640. return $this;
  641. }
  642. public function getCancelMotif(): ?string
  643. {
  644. return $this->cancelMotif;
  645. }
  646. public function setCancelMotif(?string $cancelMotif): self
  647. {
  648. $this->cancelMotif = $cancelMotif;
  649. return $this;
  650. }
  651. public function getShippingPrice(): ?string
  652. {
  653. return $this->shippingPrice;
  654. }
  655. public function setShippingPrice(string $shippingPrice): self
  656. {
  657. $this->shippingPrice = $shippingPrice;
  658. return $this;
  659. }
  660. public function getInternalReference(): ?string
  661. {
  662. return $this->internalReference;
  663. }
  664. public function setInternalReference(?string $internalReference): self
  665. {
  666. $this->internalReference = $internalReference;
  667. return $this;
  668. }
  669. public function getComment(): ?string
  670. {
  671. return $this->comment;
  672. }
  673. public function setComment(?string $comment): self
  674. {
  675. $this->comment = $comment;
  676. return $this;
  677. }
  678. public function getIsManagedByCustomer(): ?bool
  679. {
  680. return $this->isManagedByCustomer;
  681. }
  682. public function setIsManagedByCustomer(bool $isManagedByCustomer): self
  683. {
  684. $this->isManagedByCustomer = $isManagedByCustomer;
  685. return $this;
  686. }
  687. public function getFeesOrder(): ?string
  688. {
  689. return $this->feesOrder;
  690. }
  691. public function setFeesOrder(?string $feesOrder): self
  692. {
  693. $this->feesOrder = $feesOrder;
  694. return $this;
  695. }
  696. public function getExtraCbPayment(): ?string
  697. {
  698. return $this->extraCbPayment;
  699. }
  700. public function setExtraCbPayment(?string $extraCbPayment): self
  701. {
  702. $this->extraCbPayment = $extraCbPayment;
  703. return $this;
  704. }
  705. /**
  706. * @return string|null
  707. * @deprecated NON UTILSÉ
  708. */
  709. public function getTotalBonusUsed(): ?string
  710. {
  711. return $this->totalBonusUsed;
  712. }
  713. /**
  714. * @param string|null $totalBonusUsed
  715. *
  716. * @return $this
  717. * @deprecated NON UTILSÉ
  718. */
  719. public function setTotalBonusUsed(?string $totalBonusUsed): self
  720. {
  721. $this->totalBonusUsed = $totalBonusUsed;
  722. return $this;
  723. }
  724. public function getNotBillable(): ?bool
  725. {
  726. return $this->notBillable;
  727. }
  728. public function setNotBillable(?bool $notBillable): self
  729. {
  730. $this->notBillable = $notBillable;
  731. return $this;
  732. }
  733. public function getOtherinformations(): ?array
  734. {
  735. return $this->otherinformations;
  736. }
  737. public function setOtherinformations(?array $otherinformations): self
  738. {
  739. $this->otherinformations = $otherinformations;
  740. return $this;
  741. }
  742. public function getBankReturn(): ?BankReturn
  743. {
  744. return $this->bankReturn;
  745. }
  746. public function setBankReturn(?BankReturn $bankReturn): self
  747. {
  748. $this->bankReturn = $bankReturn;
  749. return $this;
  750. }
  751. public function getUser(): ?User
  752. {
  753. return $this->user;
  754. }
  755. public function setUser(?User $user): self
  756. {
  757. $this->user = $user;
  758. return $this;
  759. }
  760. /**
  761. * @return Collection|SaleOrder[]
  762. */
  763. public function getSaleOrders(): Collection
  764. {
  765. return $this->saleOrders;
  766. }
  767. /**
  768. * @param SaleOrder $saleOrder
  769. *
  770. * @return $this
  771. * @deprecated
  772. */
  773. public function addSaleOrder(SaleOrder $saleOrder): self
  774. {
  775. if(!$this->saleOrders->contains($saleOrder))
  776. {
  777. $this->saleOrders[] = $saleOrder;
  778. $saleOrder->setSaleorderGrouped($this);
  779. }
  780. return $this;
  781. }
  782. /**
  783. * @param SaleOrder $saleOrder
  784. *
  785. * @return $this
  786. * @deprecated
  787. */
  788. public function removeSaleOrder(SaleOrder $saleOrder): self
  789. {
  790. if($this->saleOrders->removeElement($saleOrder))
  791. {
  792. // set the owning side to null (unless already changed)
  793. if($saleOrder->getSaleorderGrouped() === $this)
  794. {
  795. $saleOrder->setSaleorderGrouped(NULL);
  796. }
  797. }
  798. return $this;
  799. }
  800. /**
  801. * @deprecated
  802. */
  803. public function getSaleorderGrouped(): ?SaleOrder
  804. {
  805. return $this->saleorderGrouped;
  806. }
  807. /**
  808. * @deprecated
  809. */
  810. public function setSaleorderGrouped(?self $saleorderGrouped): SaleOrder
  811. {
  812. $this->saleorderGrouped = $saleorderGrouped;
  813. return $this;
  814. }
  815. public function getShippingAddress(): ?SaleOrderAddress
  816. {
  817. return $this->shippingAddress;
  818. }
  819. public function setShippingAddress(?SaleOrderAddress $shippingAddress): self
  820. {
  821. $this->shippingAddress = $shippingAddress;
  822. return $this;
  823. }
  824. public function getBillingAddress(): ?SaleOrderAddress
  825. {
  826. return $this->billingAddress;
  827. }
  828. public function setBillingAddress(?SaleOrderAddress $billingAddress): self
  829. {
  830. $this->billingAddress = $billingAddress;
  831. return $this;
  832. }
  833. public function addItem(SaleOrderItem $item): self
  834. {
  835. if(!$this->items->contains($item))
  836. {
  837. $this->items[] = $item;
  838. $item->setSaleOrder($this);
  839. }
  840. return $this;
  841. }
  842. public function removeItem(SaleOrderItem $item): self
  843. {
  844. if($this->items->removeElement($item))
  845. {
  846. // set the owning side to null (unless already changed)
  847. if($item->getSaleOrder() === $this)
  848. {
  849. $item->setSaleOrder(NULL);
  850. }
  851. }
  852. return $this;
  853. }
  854. /**
  855. * @return Collection|SaleOrderShipment[]
  856. */
  857. public function getShipments(): Collection
  858. {
  859. return $this->shipments;
  860. }
  861. public function addShipment(SaleOrderShipment $shipment): self
  862. {
  863. if(!$this->shipments->contains($shipment))
  864. {
  865. $this->shipments[] = $shipment;
  866. $shipment->setSaleOrder($this);
  867. }
  868. return $this;
  869. }
  870. public function removeShipment(SaleOrderShipment $shipment): self
  871. {
  872. if($this->shipments->removeElement($shipment))
  873. {
  874. // set the owning side to null (unless already changed)
  875. if($shipment->getSaleOrder() === $this)
  876. {
  877. $shipment->setSaleOrder(NULL);
  878. }
  879. }
  880. return $this;
  881. }
  882. public function getCart(): ?Cart
  883. {
  884. return $this->cart;
  885. }
  886. public function setCart(?Cart $cart): self
  887. {
  888. $this->cart = $cart;
  889. return $this;
  890. }
  891. /**
  892. * @Serializer\VirtualProperty()
  893. *
  894. * @Expose
  895. * @Groups ({"get:read"})
  896. * @SerializedName ("shipping_method")
  897. */
  898. public function getApiShippingMethod()
  899. {
  900. return $this->shippingMethod;
  901. }
  902. /**
  903. * @param string|null $type slug de pointTransactionType
  904. * @return Collection|PointTransaction[]
  905. */
  906. public function getPointTransactions(?string $type = null): Collection
  907. {
  908. if($type === null) return $this->pointTransactions;
  909. return $this->pointTransactions->filter(function($pointTransaction) use ($type)
  910. {
  911. return $pointTransaction->getTransactionType(true) === $type;
  912. });
  913. }
  914. public function addPointTransaction(PointTransaction $pointTransaction): self
  915. {
  916. if(!$this->pointTransactions->contains($pointTransaction))
  917. {
  918. $this->pointTransactions[] = $pointTransaction;
  919. if($pointTransaction->getSaleOrder() !== $this) $pointTransaction->setSaleOrder($this);
  920. }
  921. return $this;
  922. }
  923. public function removePointTransaction(PointTransaction $pointTransaction): self
  924. {
  925. if($this->pointTransactions->removeElement($pointTransaction) && $pointTransaction->getSaleOrder() === $this)
  926. {
  927. $pointTransaction->setSaleOrder(null);
  928. }
  929. return $this;
  930. }
  931. public function getOldId(): ?int
  932. {
  933. return $this->oldId;
  934. }
  935. public function setOldId(?int $oldId): self
  936. {
  937. $this->oldId = $oldId;
  938. return $this;
  939. }
  940. public function getInvoice(): ?SaleOrderInvoice
  941. {
  942. return $this->invoice;
  943. }
  944. public function setInvoice(?SaleOrderInvoice $invoice): self
  945. {
  946. $this->invoice = $invoice;
  947. return $this;
  948. }
  949. public function getCategoryValues(): ?string
  950. {
  951. return $this->categoryValues;
  952. }
  953. public function setCategoryValues(?string $categoryValues): self
  954. {
  955. $this->categoryValues = $categoryValues;
  956. return $this;
  957. }
  958. public function getFeesCategoryValues(): ?string
  959. {
  960. return $this->feesCategoryValues;
  961. }
  962. public function setFeesCategoryValues(?string $feesCategoryValues): self
  963. {
  964. $this->feesCategoryValues = $feesCategoryValues;
  965. return $this;
  966. }
  967. public function getCustomQuestion(): ?string
  968. {
  969. return $this->customQuestion;
  970. }
  971. public function setCustomQuestion(?string $customQuestion): self
  972. {
  973. $this->customQuestion = $customQuestion;
  974. return $this;
  975. }
  976. public function getOrderRate(): float
  977. {
  978. return $this->orderRate ?? 1;
  979. }
  980. public function setOrderRate(float $orderRate): self
  981. {
  982. $this->orderRate = $orderRate;
  983. return $this;
  984. }
  985. public function isIsTrip(): ?bool
  986. {
  987. return $this->isTrip;
  988. }
  989. public function setIsTrip(bool $isTrip): self
  990. {
  991. $this->isTrip = $isTrip;
  992. return $this;
  993. }
  994. public function getOrderExtraData(): ?string
  995. {
  996. return $this->orderExtraData;
  997. }
  998. public function setOrderExtraData(?string $orderExtraData): self
  999. {
  1000. $this->orderExtraData = $orderExtraData;
  1001. return $this;
  1002. }
  1003. public function getUpdateFromBo(): ?bool
  1004. {
  1005. return $this->updateFromBo;
  1006. }
  1007. public function setUpdateFromBo(bool $updateFromBo): self
  1008. {
  1009. $this->updateFromBo = $updateFromBo;
  1010. return $this;
  1011. }
  1012. /**
  1013. * @return Collection<int, Invoice>
  1014. */
  1015. public function getInvoices(): Collection
  1016. {
  1017. return $this->invoices;
  1018. }
  1019. public function addInvoice(Invoice $invoice): self
  1020. {
  1021. if(!$this->invoices->contains($invoice))
  1022. {
  1023. $this->invoices[] = $invoice;
  1024. $invoice->setSaleOrder($this);
  1025. }
  1026. return $this;
  1027. }
  1028. public function removeInvoice(Invoice $invoice): self
  1029. {
  1030. if($this->invoices->removeElement($invoice))
  1031. {
  1032. // set the owning side to null (unless already changed)
  1033. if($invoice->getSaleOrder() === $this)
  1034. {
  1035. $invoice->setSaleOrder(null);
  1036. }
  1037. }
  1038. return $this;
  1039. }
  1040. /**
  1041. * @return string|null
  1042. */
  1043. public function getWaitingStatus(): ?string
  1044. {
  1045. return $this->waitingStatus;
  1046. }
  1047. /**
  1048. * @param string|null $waitingStatus
  1049. *
  1050. * @return SaleOrder
  1051. */
  1052. public function setWaitingStatus(?string $waitingStatus): SaleOrder
  1053. {
  1054. $this->waitingStatus = $waitingStatus;
  1055. return $this;
  1056. }
  1057. /**
  1058. * @return bool
  1059. */
  1060. public function isWaitingPaiement(): bool
  1061. {
  1062. return $this->status === SaleOrderConstant::STATUS_WAITING_PAYMENT || $this->status === SaleOrderConstant::STATUS_PENDING_WAITING_PAYMENT;
  1063. }
  1064. /**
  1065. * @return bool
  1066. */
  1067. public function isCanceled(): bool
  1068. {
  1069. return $this->status === SaleOrderConstant::STATUS_CANCELED;
  1070. }
  1071. /**
  1072. * @return bool
  1073. */
  1074. public function isShipped(): bool
  1075. {
  1076. return $this->status === SaleOrderConstant::STATUS_SHIPPED;
  1077. }
  1078. public function isExpressDelivery(): ?bool
  1079. {
  1080. return $this->isExpressDelivery;
  1081. }
  1082. public function setExpressDelivery(bool $isExpressDelivery): self
  1083. {
  1084. $this->isExpressDelivery = $isExpressDelivery;
  1085. return $this;
  1086. }
  1087. }