選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

200 行
8.7KB

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