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 float $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. private 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 $this->total;
  605. }
  606. public function setTotal($total): self
  607. {
  608. if (is_string($total)) {
  609. $total = floatval($total);
  610. }
  611. $this->total = $total;
  612. return $this;
  613. }
  614. public function getShippingMethod(): ?string
  615. {
  616. return $this->shippingMethod;
  617. }
  618. public function setShippingMethod(?string $shippingMethod): self
  619. {
  620. $this->shippingMethod = $shippingMethod;
  621. return $this;
  622. }
  623. public function getCancelMotif(): ?string
  624. {
  625. return $this->cancelMotif;
  626. }
  627. public function setCancelMotif(?string $cancelMotif): self
  628. {
  629. $this->cancelMotif = $cancelMotif;
  630. return $this;
  631. }
  632. public function getShippingPrice(): ?string
  633. {
  634. return $this->shippingPrice;
  635. }
  636. public function setShippingPrice(string $shippingPrice): self
  637. {
  638. $this->shippingPrice = $shippingPrice;
  639. return $this;
  640. }
  641. public function getInternalReference(): ?string
  642. {
  643. return $this->internalReference;
  644. }
  645. public function setInternalReference(?string $internalReference): self
  646. {
  647. $this->internalReference = $internalReference;
  648. return $this;
  649. }
  650. public function getComment(): ?string
  651. {
  652. return $this->comment;
  653. }
  654. public function setComment(?string $comment): self
  655. {
  656. $this->comment = $comment;
  657. return $this;
  658. }
  659. public function getIsManagedByCustomer(): ?bool
  660. {
  661. return $this->isManagedByCustomer;
  662. }
  663. public function setIsManagedByCustomer(bool $isManagedByCustomer): self
  664. {
  665. $this->isManagedByCustomer = $isManagedByCustomer;
  666. return $this;
  667. }
  668. public function getFeesOrder(): ?string
  669. {
  670. return $this->feesOrder;
  671. }
  672. public function setFeesOrder(?string $feesOrder): self
  673. {
  674. $this->feesOrder = $feesOrder;
  675. return $this;
  676. }
  677. public function getExtraCbPayment(): ?string
  678. {
  679. return $this->extraCbPayment;
  680. }
  681. public function setExtraCbPayment(?string $extraCbPayment): self
  682. {
  683. $this->extraCbPayment = $extraCbPayment;
  684. return $this;
  685. }
  686. /**
  687. * @return string|null
  688. * @deprecated NON UTILSÉ
  689. */
  690. public function getTotalBonusUsed(): ?string
  691. {
  692. return $this->totalBonusUsed;
  693. }
  694. /**
  695. * @param string|null $totalBonusUsed
  696. *
  697. * @return $this
  698. * @deprecated NON UTILSÉ
  699. */
  700. public function setTotalBonusUsed(?string $totalBonusUsed): self
  701. {
  702. $this->totalBonusUsed = $totalBonusUsed;
  703. return $this;
  704. }
  705. public function getNotBillable(): ?bool
  706. {
  707. return $this->notBillable;
  708. }
  709. public function setNotBillable(?bool $notBillable): self
  710. {
  711. $this->notBillable = $notBillable;
  712. return $this;
  713. }
  714. public function getOtherinformations(): ?array
  715. {
  716. return $this->otherinformations;
  717. }
  718. public function setOtherinformations(?array $otherinformations): self
  719. {
  720. $this->otherinformations = $otherinformations;
  721. return $this;
  722. }
  723. public function getBankReturn(): ?BankReturn
  724. {
  725. return $this->bankReturn;
  726. }
  727. public function setBankReturn(?BankReturn $bankReturn): self
  728. {
  729. $this->bankReturn = $bankReturn;
  730. return $this;
  731. }
  732. public function getUser(): ?User
  733. {
  734. return $this->user;
  735. }
  736. public function setUser(?User $user): self
  737. {
  738. $this->user = $user;
  739. return $this;
  740. }
  741. /**
  742. * @return Collection|SaleOrder[]
  743. */
  744. public function getSaleOrders(): Collection
  745. {
  746. return $this->saleOrders;
  747. }
  748. /**
  749. * @param SaleOrder $saleOrder
  750. *
  751. * @return $this
  752. * @deprecated
  753. */
  754. public function addSaleOrder(SaleOrder $saleOrder): self
  755. {
  756. if (!$this->saleOrders->contains($saleOrder)) {
  757. $this->saleOrders[] = $saleOrder;
  758. $saleOrder->setSaleorderGrouped($this);
  759. }
  760. return $this;
  761. }
  762. /**
  763. * @param SaleOrder $saleOrder
  764. *
  765. * @return $this
  766. * @deprecated
  767. */
  768. public function removeSaleOrder(SaleOrder $saleOrder): self
  769. {
  770. if ($this->saleOrders->removeElement($saleOrder)) {
  771. // set the owning side to null (unless already changed)
  772. if ($saleOrder->getSaleorderGrouped() === $this) {
  773. $saleOrder->setSaleorderGrouped(NULL);
  774. }
  775. }
  776. return $this;
  777. }
  778. /**
  779. * @deprecated
  780. */
  781. public function getSaleorderGrouped(): ?SaleOrder
  782. {
  783. return $this->saleorderGrouped;
  784. }
  785. /**
  786. * @deprecated
  787. */
  788. public function setSaleorderGrouped(?self $saleorderGrouped): SaleOrder
  789. {
  790. $this->saleorderGrouped = $saleorderGrouped;
  791. return $this;
  792. }
  793. public function getShippingAddress(): ?SaleOrderAddress
  794. {
  795. return $this->shippingAddress;
  796. }
  797. public function setShippingAddress(?SaleOrderAddress $shippingAddress): self
  798. {
  799. $this->shippingAddress = $shippingAddress;
  800. return $this;
  801. }
  802. public function getBillingAddress(): ?SaleOrderAddress
  803. {
  804. return $this->billingAddress;
  805. }
  806. public function setBillingAddress(?SaleOrderAddress $billingAddress): self
  807. {
  808. $this->billingAddress = $billingAddress;
  809. return $this;
  810. }
  811. public function addItem(SaleOrderItem $item): self
  812. {
  813. if (!$this->items->contains($item)) {
  814. $this->items[] = $item;
  815. $item->setSaleOrder($this);
  816. }
  817. return $this;
  818. }
  819. public function removeItem(SaleOrderItem $item): self
  820. {
  821. if ($this->items->removeElement($item)) {
  822. // set the owning side to null (unless already changed)
  823. if ($item->getSaleOrder() === $this) {
  824. $item->setSaleOrder(NULL);
  825. }
  826. }
  827. return $this;
  828. }
  829. /**
  830. * @return Collection|SaleOrderShipment[]
  831. */
  832. public function getShipments(): Collection
  833. {
  834. return $this->shipments;
  835. }
  836. public function addShipment(SaleOrderShipment $shipment): self
  837. {
  838. if (!$this->shipments->contains($shipment)) {
  839. $this->shipments[] = $shipment;
  840. $shipment->setSaleOrder($this);
  841. }
  842. return $this;
  843. }
  844. public function removeShipment(SaleOrderShipment $shipment): self
  845. {
  846. if ($this->shipments->removeElement($shipment)) {
  847. // set the owning side to null (unless already changed)
  848. if ($shipment->getSaleOrder() === $this) {
  849. $shipment->setSaleOrder(NULL);
  850. }
  851. }
  852. return $this;
  853. }
  854. public function getCart(): ?Cart
  855. {
  856. return $this->cart;
  857. }
  858. public function setCart(?Cart $cart): self
  859. {
  860. $this->cart = $cart;
  861. return $this;
  862. }
  863. /**
  864. * @Serializer\VirtualProperty()
  865. *
  866. * @Expose
  867. * @Groups ({"get:read"})
  868. * @SerializedName ("shipping_method")
  869. */
  870. public function getApiShippingMethod()
  871. {
  872. return $this->shippingMethod;
  873. }
  874. /**
  875. * @param string|null $type slug de pointTransactionType
  876. * @return Collection|PointTransaction[]
  877. */
  878. public function getPointTransactions(?string $type = null): Collection
  879. {
  880. if($type === null) return $this->pointTransactions;
  881. return $this->pointTransactions->filter(function ($pointTransaction) use ($type) {
  882. return $pointTransaction->getTransactionType(true) === $type;
  883. });
  884. }
  885. public function addPointTransaction(PointTransaction $pointTransaction): self
  886. {
  887. if(!$this->pointTransactions->contains($pointTransaction))
  888. {
  889. $this->pointTransactions[] = $pointTransaction;
  890. if($pointTransaction->getSaleOrder() !== $this) $pointTransaction->setSaleOrder($this);
  891. }
  892. return $this;
  893. }
  894. public function removePointTransaction(PointTransaction $pointTransaction): self
  895. {
  896. if($this->pointTransactions->removeElement($pointTransaction) && $pointTransaction->getSaleOrder() === $this)
  897. {
  898. $pointTransaction->setSaleOrder(null);
  899. }
  900. return $this;
  901. }
  902. public function getOldId(): ?int
  903. {
  904. return $this->oldId;
  905. }
  906. public function setOldId(?int $oldId): self
  907. {
  908. $this->oldId = $oldId;
  909. return $this;
  910. }
  911. public function getInvoice(): ?SaleOrderInvoice
  912. {
  913. return $this->invoice;
  914. }
  915. public function setInvoice(?SaleOrderInvoice $invoice): self
  916. {
  917. $this->invoice = $invoice;
  918. return $this;
  919. }
  920. public function getCategoryValues(): ?string
  921. {
  922. return $this->categoryValues;
  923. }
  924. public function setCategoryValues(?string $categoryValues): self
  925. {
  926. $this->categoryValues = $categoryValues;
  927. return $this;
  928. }
  929. public function getFeesCategoryValues(): ?string
  930. {
  931. return $this->feesCategoryValues;
  932. }
  933. public function setFeesCategoryValues(?string $feesCategoryValues): self
  934. {
  935. $this->feesCategoryValues = $feesCategoryValues;
  936. return $this;
  937. }
  938. public function getCustomQuestion(): ?string
  939. {
  940. return $this->customQuestion;
  941. }
  942. public function setCustomQuestion(?string $customQuestion): self
  943. {
  944. $this->customQuestion = $customQuestion;
  945. return $this;
  946. }
  947. public function getOrderRate(): float
  948. {
  949. return $this->orderRate ?? 1;
  950. }
  951. public function setOrderRate(float $orderRate): self
  952. {
  953. $this->orderRate = $orderRate;
  954. return $this;
  955. }
  956. public function isIsTrip(): ?bool
  957. {
  958. return $this->isTrip;
  959. }
  960. public function setIsTrip(bool $isTrip): self
  961. {
  962. $this->isTrip = $isTrip;
  963. return $this;
  964. }
  965. public function getOrderExtraData(): ?string
  966. {
  967. return $this->orderExtraData;
  968. }
  969. public function setOrderExtraData(?string $orderExtraData): self
  970. {
  971. $this->orderExtraData = $orderExtraData;
  972. return $this;
  973. }
  974. public function getUpdateFromBo(): ?bool
  975. {
  976. return $this->updateFromBo;
  977. }
  978. public function setUpdateFromBo(bool $updateFromBo): self
  979. {
  980. $this->updateFromBo = $updateFromBo;
  981. return $this;
  982. }
  983. /**
  984. * @return Collection<int, Invoice>
  985. */
  986. public function getInvoices(): Collection
  987. {
  988. return $this->invoices;
  989. }
  990. public function addInvoice(Invoice $invoice): self
  991. {
  992. if (!$this->invoices->contains($invoice)) {
  993. $this->invoices[] = $invoice;
  994. $invoice->setSaleOrder($this);
  995. }
  996. return $this;
  997. }
  998. public function removeInvoice(Invoice $invoice): self
  999. {
  1000. if ($this->invoices->removeElement($invoice)) {
  1001. // set the owning side to null (unless already changed)
  1002. if ($invoice->getSaleOrder() === $this) {
  1003. $invoice->setSaleOrder(null);
  1004. }
  1005. }
  1006. return $this;
  1007. }
  1008. /**
  1009. * @return string|null
  1010. */
  1011. public function getWaitingStatus(): ?string
  1012. {
  1013. return $this->waitingStatus;
  1014. }
  1015. /**
  1016. * @param string|null $waitingStatus
  1017. *
  1018. * @return SaleOrder
  1019. */
  1020. public function setWaitingStatus(?string $waitingStatus): SaleOrder
  1021. {
  1022. $this->waitingStatus = $waitingStatus;
  1023. return $this;
  1024. }
  1025. /**
  1026. * @return bool
  1027. */
  1028. public function isWaitingPaiement(): bool
  1029. {
  1030. return $this->status === SaleOrderConstant::STATUS_WAITING_PAYMENT || $this->status === SaleOrderConstant::STATUS_PENDING_WAITING_PAYMENT;
  1031. }
  1032. /**
  1033. * @return bool
  1034. */
  1035. public function isCanceled(): bool
  1036. {
  1037. return $this->status === SaleOrderConstant::STATUS_CANCELED;
  1038. }
  1039. /**
  1040. * @return bool
  1041. */
  1042. public function isShipped(): bool
  1043. {
  1044. return $this->status === SaleOrderConstant::STATUS_SHIPPED;
  1045. }
  1046. public function isExpressDelivery(): ?bool
  1047. {
  1048. return $this->isExpressDelivery;
  1049. }
  1050. public function setExpressDelivery(bool $isExpressDelivery): self
  1051. {
  1052. $this->isExpressDelivery = $isExpressDelivery;
  1053. return $this;
  1054. }
  1055. }