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.

OrderShopTransformer.php 8.7KB

3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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' => $orderPayment->getMeanPayment() ?
  105. $this->translatorAdmin->transChoice(
  106. 'OrderPayment',
  107. 'meanPayment',
  108. $orderPayment->getMeanPayment()
  109. ) : '',
  110. 'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'),
  111. 'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'),
  112. 'amount' => $orderPayment->getAmount(),
  113. 'editable' => $orderPayment->getEditable()
  114. );
  115. }
  116. return $data;
  117. }
  118. public function getOrderStatusHistoriesInfosAsArray(OrderShop $order): array
  119. {
  120. $data = array();
  121. foreach ($order->getOrderStatusHistories() as $orderStatusHistory) {
  122. $data[$orderStatusHistory->getId()] = array(
  123. 'id' => $orderStatusHistory->getId(),
  124. 'createdAt' => $orderStatusHistory->getCreatedAt()->format('d-m-Y H:i'),
  125. 'createdBy' => $orderStatusHistory->getCreatedBy() ? $orderStatusHistory->getCreatedBy(
  126. )->__toString() : 'aucun',
  127. 'orderStatus' => $orderStatusHistory->getOrderStatus()->getAlias(),
  128. 'origin' => $orderStatusHistory->getOrigin(),
  129. 'info' => $orderStatusHistory->__toString(),
  130. );
  131. }
  132. return $data;
  133. }
  134. public function getOrderReductionCreditsInfosAsArray(OrderShop $order): array
  135. {
  136. $data = array();
  137. foreach ($order->getOrderReductionCredits() as $orderReductionCredit) {
  138. $data[] = array(
  139. 'title' => $orderReductionCredit->__toString(),
  140. 'id' => $orderReductionCredit->getId(),
  141. 'orderReference' => $order->getReference(),
  142. 'amount' => $this->priceSolver->getOrderProductsReductionCreditAmountWithTax(
  143. $order,
  144. $orderReductionCredit
  145. )
  146. );
  147. }
  148. return $data;
  149. }
  150. public function getOrderTicketsInfosAsArray(OrderShop $order): array
  151. {
  152. $data = array();
  153. foreach ($order->getTickets() as $ticket) {
  154. $data[$ticket->getId()] = array(
  155. 'id' => $ticket->getId(),
  156. 'date' => $ticket->getCreatedAt()->format('d/m/Y'),
  157. 'status' => $this->translatorAdmin->trans(
  158. 'field.Ticket.statusOptions.' . $ticket->getStatus()
  159. ),
  160. 'subject' => $ticket->getSubject(),
  161. 'orderReference' => $order->getReference(),
  162. 'link' => '',
  163. );
  164. }
  165. return $data;
  166. }
  167. public function getOrderDocumentsInfosAsArray(OrderShop $order): array
  168. {
  169. $data = array();
  170. foreach ($order->getDocuments() as $orderDocument) {
  171. $data[$orderDocument->getId()] = array(
  172. 'id' => $orderDocument->getId(),
  173. 'date' => $orderDocument->getCreatedAt()->format('d/m/Y'),
  174. 'reference' => $orderDocument->getReference(),
  175. 'type' => $orderDocument->getType(),
  176. 'isSent' => $orderDocument->getIsSent(),
  177. 'orderReference' => $order->getReference(),
  178. 'link' => $this->urlGenerator->generate('document_download', ['id' => $orderDocument->getId()])
  179. );
  180. }
  181. return $data;
  182. }
  183. }