You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
8.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Transformer\Order;
  3. use App\Entity\Order\OrderShop;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Resolver\OrderShopResolver;
  6. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  7. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  8. use Lc\SovBundle\Model\User\UserInterface;
  9. use Lc\SovBundle\Translation\TranslatorAdmin;
  10. class OrderShopTransformer
  11. {
  12. protected PriceSolver $priceSolver;
  13. protected OrderShopSolver $orderShopSolver;
  14. protected OrderShopResolver $orderShopResolver;
  15. protected TranslatorAdmin $translatorAdmin;
  16. public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver, OrderShopResolver $orderShopResolver, TranslatorAdmin $translatorAdmin)
  17. {
  18. $this->priceSolver = $priceSolver;
  19. $this->orderShopSolver = $orderShopSolver;
  20. $this->orderShopResolver = $orderShopResolver;
  21. $this->translatorAdmin = $translatorAdmin;
  22. }
  23. // getOrderDatas
  24. public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
  25. {
  26. $data = [];
  27. $data['order'] = $orderShop;
  28. if ($orderShop) {
  29. $data['count'] = $this->orderShopSolver->countQuantities($orderShop);
  30. $data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop);
  31. $data['order_products_by_category'] = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
  32. $data['total_remaining_to_be_paid'] = $this->orderShopResolver->getTotalRemainingToBePaid($orderShop);
  33. }
  34. return $data;
  35. }
  36. public function getAsArray(OrderShopInterface $orderShop): array
  37. {
  38. $data['id'] = $orderShop->getId();
  39. $data['user'] = $orderShop->getUser()->getSummary();
  40. $data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
  41. $data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
  42. $data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
  43. $data['total'] = $this->priceSolver->getTotal($orderShop);
  44. $data['totalWithTax'] = $this->priceSolver->getTotalWithTax($orderShop);
  45. $data['totalWithTaxAndReduction'] = $this->priceSolver->getTotalWithTax($orderShop);
  46. $i = 0;
  47. $orderProductsByParentCategory = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
  48. foreach ($orderProductsByParentCategory as $labelCategory => $orderProducts) {
  49. foreach ($orderProducts as $orderProduct) {
  50. $data['orderProducts'][$i]['id'] = $orderProduct->getId();
  51. $data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
  52. $data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
  53. $data['orderProducts'][$i]['labelCategory'] = $labelCategory;
  54. $data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
  55. $data['orderProducts'][$i]['price'] = $this->priceSolver->getPrice($orderProduct);
  56. $data['orderProducts'][$i]['priceWithTax'] = $this->priceSolver->getPriceWithTax($orderProduct);
  57. $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceSolver->getPriceWithTaxAndReduction(
  58. $orderProduct
  59. );
  60. $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
  61. $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceSolver->getTotalOrderProductsWithTaxAndReduction(
  62. array($orderProduct)
  63. );
  64. $i++;
  65. }
  66. }
  67. return $data;
  68. }
  69. public function getOrderReductionCartsInfosAsArray(OrderShop $order): array
  70. {
  71. $data = array();
  72. foreach ($order->getOrderReductionCarts() as $orderReductionCart) {
  73. $data[] = array(
  74. 'title' => $orderReductionCart->__toString(),
  75. 'id' => $orderReductionCart->getId(),
  76. 'orderReference' => $order->getReference(),
  77. 'amount' => $this->priceSolver->getOrderProductsReductionCartAmountWithTax(
  78. $order,
  79. $orderReductionCart
  80. )
  81. );
  82. }
  83. return $data;
  84. }
  85. public function getOrderPaymentsInfosAsArray(OrderShop $order): array
  86. {
  87. $data = array();
  88. foreach ($order->getOrderPayments() as $orderPayment) {
  89. $data[$orderPayment->getId()] = array(
  90. 'id' => $orderPayment->getId(),
  91. 'reference' => $orderPayment->getReference(),
  92. 'orderReference' => $order->getReference(),
  93. 'comment' => $orderPayment->getComment(),
  94. 'meanPayment' => $orderPayment->getMeanPayment(),
  95. 'meanPaymentText' => $this->translatorAdmin->trans(
  96. 'field.default.meanPaymentOptions.' . $orderPayment->getMeanPayment()
  97. ),
  98. 'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'),
  99. 'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'),
  100. 'amount' => $orderPayment->getAmount(),
  101. 'editable' => $orderPayment->getEditable()
  102. );
  103. }
  104. return $data;
  105. }
  106. public function getOrderStatusHistoriesInfosAsArray(OrderShop $order): array
  107. {
  108. $data = array();
  109. foreach ($order->getOrderStatusHistories() as $orderStatusHistory) {
  110. $data[$orderStatusHistory->getId()] = array(
  111. 'id' => $orderStatusHistory->getId(),
  112. 'createdAt' => $orderStatusHistory->getCreatedAt()->format('d-m-Y H:i'),
  113. 'createdBy' => $orderStatusHistory->getCreatedBy() ? $orderStatusHistory->getCreatedBy(
  114. )->__toString() : 'aucun',
  115. 'orderStatus' => $orderStatusHistory->getOrderStatus()->getAlias(),
  116. 'origin' => $orderStatusHistory->getOrigin(),
  117. 'info' => $orderStatusHistory->__toString(),
  118. );
  119. }
  120. return $data;
  121. }
  122. public function getOrderReductionCreditsInfosAsArray(OrderShop $order): array
  123. {
  124. $data = array();
  125. foreach ($order->getOrderReductionCredits() as $orderReductionCredit) {
  126. $data[] = array(
  127. 'title' => $orderReductionCredit->__toString(),
  128. 'id' => $orderReductionCredit->getId(),
  129. 'orderReference' => $order->getReference(),
  130. 'amount' => $this->priceSolver->getOrderProductsReductionCreditAmountWithTax(
  131. $order,
  132. $orderReductionCredit
  133. )
  134. );
  135. }
  136. return $data;
  137. }
  138. public function getOrderTicketsInfosAsArray(OrderShop $order): array
  139. {
  140. $data = array();
  141. foreach ($order->getTickets() as $ticket) {
  142. $data[$ticket->getId()] = array(
  143. 'id' => $ticket->getId(),
  144. 'date' => $ticket->getCreatedAt()->format('d/m/Y'),
  145. 'status' => $this->translatorAdmin->trans(
  146. 'field.Ticket.statusOptions.' . $ticket->getStatus()
  147. ),
  148. 'subject' => $ticket->getSubject(),
  149. 'orderReference' => $order->getReference(),
  150. 'link' => '',
  151. );
  152. }
  153. return $data;
  154. }
  155. public function getOrderDocumentsInfosAsArray(OrderShop $order): array
  156. {
  157. $data = array();
  158. foreach ($order->getDocuments() as $orderDocument) {
  159. $data[$orderDocument->getId()] = array(
  160. 'id' => $orderDocument->getId(),
  161. 'date' => $orderDocument->getCreatedAt()->format('d/m/Y'),
  162. 'reference' => $orderDocument->getReference(),
  163. 'type' => $orderDocument->getType(),
  164. 'isSent' => $orderDocument->getIsSent(),
  165. 'orderReference' => $order->getReference(),
  166. );
  167. }
  168. return $data;
  169. }
  170. }