src/Entity/SaleOrder.php line 26

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. if (preg_match("/^(STATUS)/", $k)) {
  366. $statuses[ $const ] = 'capsule.order.status.' . $const;
  367. }
  368. }
  369. return $statuses;
  370. }
  371. /**
  372. * Retourne la société de l'admin adhérent (spécial algorel)
  373. *
  374. * @Serializer\VirtualProperty()
  375. * @SerializedName("agency")
  376. * @Expose()
  377. * @Groups({"get:read"})
  378. *
  379. */
  380. public function getAgency(): ?string
  381. {
  382. return $this->agency;
  383. }
  384. public function setAgency(?string $agency): self
  385. {
  386. $this->agency = $agency;
  387. return $this;
  388. }
  389. /**
  390. * Retourne le cumul des produits + frais de port + frais de commande
  391. *
  392. * @Serializer\VirtualProperty()
  393. * @SerializedName("totalAmount")
  394. * @Expose()
  395. * @Groups({"sale_order","sale_order:item", "sale_order:post", "get:read", "export_order_datatable"})
  396. *
  397. * @return float
  398. */
  399. public function getTotalAmount(): float
  400. {
  401. return $this->total + $this->shippingPrice + ($this->feesOrder ?? 0);
  402. }
  403. /**
  404. * Retourne le cumul en point des produits + frais de port + frais de commande
  405. *
  406. * @Serializer\VirtualProperty()
  407. * @SerializedName("totalRateAmount")
  408. * @Expose()
  409. * @Groups({"sale_order","sale_order:item", "sale_order:post", "get:read", "export_order_datatable"})
  410. *
  411. * @return float
  412. */
  413. public function getRateTotalAmount(): float
  414. {
  415. return round(
  416. ($this->total * $this->getOrderRate()) + ($this->shippingPrice * $this->getOrderRate()) + (($this->feesOrder ?? 0) * $this->getOrderRate())
  417. );
  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. \App\Constants\SaleOrder::STATUS_SHIPPED,
  453. \App\Constants\SaleOrder::STATUS_PROCESSING,
  454. \App\Constants\SaleOrder::STATUS_PENDING_PROCESSING,
  455. \App\Constants\SaleOrder::STATUS_TO_SHIP,
  456. \App\Constants\SaleOrder::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. return SaleOrderAddress::BILLING_ADDRESS;
  476. } elseif ($this->shippingAddress === $Address) {
  477. return SaleOrderAddress::SHIPPING_ADDRESS;
  478. }
  479. return FALSE;
  480. }
  481. public function getItemByReferenceWithStatus($reference, $statuses)
  482. {
  483. foreach ($this->getItems() as $item) {
  484. if ($item->getReference() == $reference && in_array($item->getStatus(), $statuses)) {
  485. return $item;
  486. }
  487. }
  488. return NULL;
  489. }
  490. /**
  491. * @return Collection|SaleOrderItem[]
  492. */
  493. public function getItems(): Collection
  494. {
  495. return $this->items;
  496. }
  497. /**
  498. * @param Collection $items
  499. *
  500. * @return $this
  501. */
  502. public function setItems(Collection $items): SaleOrder
  503. {
  504. $this->items = $items;
  505. return $this;
  506. }
  507. public function getStatus(): ?string
  508. {
  509. return $this->status;
  510. }
  511. public function setStatus(string $status): self
  512. {
  513. $this->status = $status;
  514. return $this;
  515. }
  516. public function getItemsByReferenceWithStatus($reference, $statuses = [])
  517. {
  518. $items = [];
  519. foreach ($this->getItems() as $item) {
  520. if ($item->getReference() == $reference) {
  521. if (empty($statuses) || in_array($item->getStatus(), $statuses)) {
  522. $items[] = $item;
  523. }
  524. }
  525. }
  526. return $items;
  527. }
  528. /**
  529. * Count items matching reference & status
  530. *
  531. * @param string $reference
  532. * @param array $statuses
  533. * @param bool $in
  534. *
  535. * @return int
  536. */
  537. public function countItemsByReferenceWithStatus(string $reference, array $statuses, bool $in = TRUE): int
  538. {
  539. $totalRef = $cnt = 0;
  540. foreach ($this->getItems() as $item) {
  541. if ($item->getReference() == $reference) {
  542. $totalRef++;
  543. if (in_array($item->getStatus(), $statuses)) {
  544. $cnt++;
  545. }
  546. }
  547. }
  548. return ($in) ? $cnt : ($totalRef - $cnt);
  549. }
  550. /*
  551. * ============================================================================================
  552. * ============================== FIN FONCTIONS CUSTOM ========================================
  553. * ============================================================================================
  554. */
  555. /**
  556. * Count items matching status
  557. *
  558. * @param $statuses
  559. * @param bool $in
  560. *
  561. * @return int
  562. */
  563. public function countItemsWithStatus($statuses, bool $in = TRUE): int
  564. {
  565. $cnt = 0;
  566. foreach ($this->getItems() as $item) {
  567. if (in_array($item->getStatus(), $statuses)) {
  568. $cnt++;
  569. }
  570. }
  571. return ($in) ? $cnt : (count($this->getItems()) - $cnt);
  572. }
  573. /**
  574. * Get an item from order matching reference
  575. *
  576. * @param $reference
  577. *
  578. * @return SaleOrderItem|null
  579. */
  580. public function getItemByReference($reference)
  581. {
  582. foreach ($this->getItems() as $item) {
  583. if ($item->getReference() == $reference) {
  584. return $item;
  585. }
  586. }
  587. return NULL;
  588. }
  589. public function hasAllItemsStatesCanceled()
  590. {
  591. return $this->hasAllItemsState(SaleOrderItem::STATUS_CANCELED);
  592. }
  593. public function hasAllItemsState($state)
  594. {
  595. foreach ($this->getItems() as $item) {
  596. if ($item->getStatus() != $state) {
  597. return FALSE;
  598. }
  599. }
  600. return TRUE;
  601. }
  602. public function getTotal(): ?float
  603. {
  604. return (float) $this->total;
  605. }
  606. public function setTotal($total): self
  607. {
  608. if ($total === null) {
  609. $this->total = '0.00';
  610. return $this;
  611. }
  612. $this->total = (string) $total;
  613. return $this;
  614. }
  615. public function getShippingMethod(): ?string
  616. {
  617. return $this->shippingMethod;
  618. }
  619. public function setShippingMethod(?string $shippingMethod): self
  620. {
  621. $this->shippingMethod = $shippingMethod;
  622. return $this;
  623. }
  624. public function getCancelMotif(): ?string
  625. {
  626. return $this->cancelMotif;
  627. }
  628. public function setCancelMotif(?string $cancelMotif): self
  629. {
  630. $this->cancelMotif = $cancelMotif;
  631. return $this;
  632. }
  633. public function getShippingPrice(): ?string
  634. {
  635. return $this->shippingPrice;
  636. }
  637. public function setShippingPrice(string $shippingPrice): self
  638. {
  639. $this->shippingPrice = $shippingPrice;
  640. return $this;
  641. }
  642. public function getInternalReference(): ?string
  643. {
  644. return $this->internalReference;
  645. }
  646. public function setInternalReference(?string $internalReference): self
  647. {
  648. $this->internalReference = $internalReference;
  649. return $this;
  650. }
  651. public function getComment(): ?string
  652. {
  653. return $this->comment;
  654. }
  655. public function setComment(?string $comment): self
  656. {
  657. $this->comment = $comment;
  658. return $this;
  659. }
  660. public function getIsManagedByCustomer(): ?bool
  661. {
  662. return $this->isManagedByCustomer;
  663. }
  664. public function setIsManagedByCustomer(bool $isManagedByCustomer): self
  665. {
  666. $this->isManagedByCustomer = $isManagedByCustomer;
  667. return $this;
  668. }
  669. public function getFeesOrder(): ?string
  670. {
  671. return $this->feesOrder;
  672. }
  673. public function setFeesOrder(?string $feesOrder): self
  674. {
  675. $this->feesOrder = $feesOrder;
  676. return $this;
  677. }
  678. public function getExtraCbPayment(): ?string
  679. {
  680. return $this->extraCbPayment;
  681. }
  682. public function setExtraCbPayment(?string $extraCbPayment): self
  683. {
  684. $this->extraCbPayment = $extraCbPayment;
  685. return $this;
  686. }
  687. /**
  688. * @return string|null
  689. * @deprecated NON UTILSÉ
  690. */
  691. public function getTotalBonusUsed(): ?string
  692. {
  693. return $this->totalBonusUsed;
  694. }
  695. /**
  696. * @param string|null $totalBonusUsed
  697. *
  698. * @return $this
  699. * @deprecated NON UTILSÉ
  700. */
  701. public function setTotalBonusUsed(?string $totalBonusUsed): self
  702. {
  703. $this->totalBonusUsed = $totalBonusUsed;
  704. return $this;
  705. }
  706. public function getNotBillable(): ?bool
  707. {
  708. return $this->notBillable;
  709. }
  710. public function setNotBillable(?bool $notBillable): self
  711. {
  712. $this->notBillable = $notBillable;
  713. return $this;
  714. }
  715. public function getOtherinformations(): ?array
  716. {
  717. return $this->otherinformations;
  718. }
  719. public function setOtherinformations(?array $otherinformations): self
  720. {
  721. $this->otherinformations = $otherinformations;
  722. return $this;
  723. }
  724. public function getBankReturn(): ?BankReturn
  725. {
  726. return $this->bankReturn;
  727. }
  728. public function setBankReturn(?BankReturn $bankReturn): self
  729. {
  730. $this->bankReturn = $bankReturn;
  731. return $this;
  732. }
  733. public function getUser(): ?User
  734. {
  735. return $this->user;
  736. }
  737. public function setUser(?User $user): self
  738. {
  739. $this->user = $user;
  740. return $this;
  741. }
  742. /**
  743. * @return Collection|SaleOrder[]
  744. */
  745. public function getSaleOrders(): Collection
  746. {
  747. return $this->saleOrders;
  748. }
  749. /**
  750. * @param SaleOrder $saleOrder
  751. *
  752. * @return $this
  753. * @deprecated
  754. */
  755. public function addSaleOrder(SaleOrder $saleOrder): self
  756. {
  757. if (!$this->saleOrders->contains($saleOrder)) {
  758. $this->saleOrders[] = $saleOrder;
  759. $saleOrder->setSaleorderGrouped($this);
  760. }
  761. return $this;
  762. }
  763. /**
  764. * @param SaleOrder $saleOrder
  765. *
  766. * @return $this
  767. * @deprecated
  768. */
  769. public function removeSaleOrder(SaleOrder $saleOrder): self
  770. {
  771. if ($this->saleOrders->removeElement($saleOrder)) {
  772. // set the owning side to null (unless already changed)
  773. if ($saleOrder->getSaleorderGrouped() === $this) {
  774. $saleOrder->setSaleorderGrouped(NULL);
  775. }
  776. }
  777. return $this;
  778. }
  779. /**
  780. * @deprecated
  781. */
  782. public function getSaleorderGrouped(): ?SaleOrder
  783. {
  784. return $this->saleorderGrouped;
  785. }
  786. /**
  787. * @deprecated
  788. */
  789. public function setSaleorderGrouped(?self $saleorderGrouped): SaleOrder
  790. {
  791. $this->saleorderGrouped = $saleorderGrouped;
  792. return $this;
  793. }
  794. public function getShippingAddress(): ?SaleOrderAddress
  795. {
  796. return $this->shippingAddress;
  797. }
  798. public function setShippingAddress(?SaleOrderAddress $shippingAddress): self
  799. {
  800. $this->shippingAddress = $shippingAddress;
  801. return $this;
  802. }
  803. public function getBillingAddress(): ?SaleOrderAddress
  804. {
  805. return $this->billingAddress;
  806. }
  807. public function setBillingAddress(?SaleOrderAddress $billingAddress): self
  808. {
  809. $this->billingAddress = $billingAddress;
  810. return $this;
  811. }
  812. public function addItem(SaleOrderItem $item): self
  813. {
  814. if (!$this->items->contains($item)) {
  815. $this->items[] = $item;
  816. $item->setSaleOrder($this);
  817. }
  818. return $this;
  819. }
  820. public function removeItem(SaleOrderItem $item): self
  821. {
  822. if ($this->items->removeElement($item)) {
  823. // set the owning side to null (unless already changed)
  824. if ($item->getSaleOrder() === $this) {
  825. $item->setSaleOrder(NULL);
  826. }
  827. }
  828. return $this;
  829. }
  830. /**
  831. * @return Collection|SaleOrderShipment[]
  832. */
  833. public function getShipments(): Collection
  834. {
  835. return $this->shipments;
  836. }
  837. public function addShipment(SaleOrderShipment $shipment): self
  838. {
  839. if (!$this->shipments->contains($shipment)) {
  840. $this->shipments[] = $shipment;
  841. $shipment->setSaleOrder($this);
  842. }
  843. return $this;
  844. }
  845. public function removeShipment(SaleOrderShipment $shipment): self
  846. {
  847. if ($this->shipments->removeElement($shipment)) {
  848. // set the owning side to null (unless already changed)
  849. if ($shipment->getSaleOrder() === $this) {
  850. $shipment->setSaleOrder(NULL);
  851. }
  852. }
  853. return $this;
  854. }
  855. public function getCart(): ?Cart
  856. {
  857. return $this->cart;
  858. }
  859. public function setCart(?Cart $cart): self
  860. {
  861. $this->cart = $cart;
  862. return $this;
  863. }
  864. /**
  865. * @Serializer\VirtualProperty()
  866. *
  867. * @Expose
  868. * @Groups ({"get:read"})
  869. * @SerializedName ("shipping_method")
  870. */
  871. public function getApiShippingMethod()
  872. {
  873. return $this->shippingMethod;
  874. }
  875. /**
  876. * @param string|null $type slug de pointTransactionType
  877. * @return Collection|PointTransaction[]
  878. */
  879. public function getPointTransactions(?string $type = null): Collection
  880. {
  881. if($type === null) return $this->pointTransactions;
  882. return $this->pointTransactions->filter(function ($pointTransaction) use ($type) {
  883. return $pointTransaction->getTransactionType(true) === $type;
  884. });
  885. }
  886. public function addPointTransaction(PointTransaction $pointTransaction): self
  887. {
  888. if(!$this->pointTransactions->contains($pointTransaction))
  889. {
  890. $this->pointTransactions[] = $pointTransaction;
  891. if($pointTransaction->getSaleOrder() !== $this) $pointTransaction->setSaleOrder($this);
  892. }
  893. return $this;
  894. }
  895. public function removePointTransaction(PointTransaction $pointTransaction): self
  896. {
  897. if($this->pointTransactions->removeElement($pointTransaction) && $pointTransaction->getSaleOrder() === $this)
  898. {
  899. $pointTransaction->setSaleOrder(null);
  900. }
  901. return $this;
  902. }
  903. public function getOldId(): ?int
  904. {
  905. return $this->oldId;
  906. }
  907. public function setOldId(?int $oldId): self
  908. {
  909. $this->oldId = $oldId;
  910. return $this;
  911. }
  912. public function getInvoice(): ?SaleOrderInvoice
  913. {
  914. return $this->invoice;
  915. }
  916. public function setInvoice(?SaleOrderInvoice $invoice): self
  917. {
  918. $this->invoice = $invoice;
  919. return $this;
  920. }
  921. public function getCategoryValues(): ?string
  922. {
  923. return $this->categoryValues;
  924. }
  925. public function setCategoryValues(?string $categoryValues): self
  926. {
  927. $this->categoryValues = $categoryValues;
  928. return $this;
  929. }
  930. public function getFeesCategoryValues(): ?string
  931. {
  932. return $this->feesCategoryValues;
  933. }
  934. public function setFeesCategoryValues(?string $feesCategoryValues): self
  935. {
  936. $this->feesCategoryValues = $feesCategoryValues;
  937. return $this;
  938. }
  939. public function getCustomQuestion(): ?string
  940. {
  941. return $this->customQuestion;
  942. }
  943. public function setCustomQuestion(?string $customQuestion): self
  944. {
  945. $this->customQuestion = $customQuestion;
  946. return $this;
  947. }
  948. public function getOrderRate(): float
  949. {
  950. return $this->orderRate ?? 1;
  951. }
  952. public function setOrderRate(float $orderRate): self
  953. {
  954. $this->orderRate = $orderRate;
  955. return $this;
  956. }
  957. public function isIsTrip(): ?bool
  958. {
  959. return $this->isTrip;
  960. }
  961. public function setIsTrip(bool $isTrip): self
  962. {
  963. $this->isTrip = $isTrip;
  964. return $this;
  965. }
  966. public function getOrderExtraData(): ?string
  967. {
  968. return $this->orderExtraData;
  969. }
  970. public function setOrderExtraData(?string $orderExtraData): self
  971. {
  972. $this->orderExtraData = $orderExtraData;
  973. return $this;
  974. }
  975. public function getUpdateFromBo(): ?bool
  976. {
  977. return $this->updateFromBo;
  978. }
  979. public function setUpdateFromBo(bool $updateFromBo): self
  980. {
  981. $this->updateFromBo = $updateFromBo;
  982. return $this;
  983. }
  984. /**
  985. * @return Collection<int, Invoice>
  986. */
  987. public function getInvoices(): Collection
  988. {
  989. return $this->invoices;
  990. }
  991. public function addInvoice(Invoice $invoice): self
  992. {
  993. if (!$this->invoices->contains($invoice)) {
  994. $this->invoices[] = $invoice;
  995. $invoice->setSaleOrder($this);
  996. }
  997. return $this;
  998. }
  999. public function removeInvoice(Invoice $invoice): self
  1000. {
  1001. if ($this->invoices->removeElement($invoice)) {
  1002. // set the owning side to null (unless already changed)
  1003. if ($invoice->getSaleOrder() === $this) {
  1004. $invoice->setSaleOrder(null);
  1005. }
  1006. }
  1007. return $this;
  1008. }
  1009. /**
  1010. * @return string|null
  1011. */
  1012. public function getWaitingStatus(): ?string
  1013. {
  1014. return $this->waitingStatus;
  1015. }
  1016. /**
  1017. * @param string|null $waitingStatus
  1018. *
  1019. * @return SaleOrder
  1020. */
  1021. public function setWaitingStatus(?string $waitingStatus): SaleOrder
  1022. {
  1023. $this->waitingStatus = $waitingStatus;
  1024. return $this;
  1025. }
  1026. /**
  1027. * @return bool
  1028. */
  1029. public function isWaitingPaiement(): bool
  1030. {
  1031. return $this->status === SaleOrderConstant::STATUS_WAITING_PAYMENT || $this->status === SaleOrderConstant::STATUS_PENDING_WAITING_PAYMENT;
  1032. }
  1033. /**
  1034. * @return bool
  1035. */
  1036. public function isCanceled(): bool
  1037. {
  1038. return $this->status === SaleOrderConstant::STATUS_CANCELED;
  1039. }
  1040. /**
  1041. * @return bool
  1042. */
  1043. public function isShipped(): bool
  1044. {
  1045. return $this->status === SaleOrderConstant::STATUS_SHIPPED;
  1046. }
  1047. public function isExpressDelivery(): ?bool
  1048. {
  1049. return $this->isExpressDelivery;
  1050. }
  1051. public function setExpressDelivery(bool $isExpressDelivery): self
  1052. {
  1053. $this->isExpressDelivery = $isExpressDelivery;
  1054. return $this;
  1055. }
  1056. }