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