src/Entity/SaleOrder.php line 26

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