Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

199 lines
8.6KB

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