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