|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
-
- namespace Lc\CaracoleBundle\Transformer\Order;
-
- use App\Entity\Order\OrderShop;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Resolver\OrderShopResolver;
- use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
-
- class OrderShopTransformer
- {
- protected PriceSolver $priceSolver;
- protected OrderShopSolver $orderShopSolver;
- protected OrderShopResolver $orderShopResolver;
- protected TranslatorAdmin $translatorAdmin;
- protected UrlGeneratorInterface $urlGenerator;
-
-
- public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver, OrderShopResolver $orderShopResolver, TranslatorAdmin $translatorAdmin, UrlGeneratorInterface $urlGenerator)
- {
- $this->priceSolver = $priceSolver;
- $this->orderShopSolver = $orderShopSolver;
- $this->orderShopResolver = $orderShopResolver;
- $this->translatorAdmin = $translatorAdmin;
- $this->urlGenerator = $urlGenerator;
- }
-
- // getOrderDatas
- public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
- {
- $data = [];
-
- $data['order'] = $orderShop;
-
- if ($orderShop) {
- $data['count'] = $this->orderShopSolver->countQuantities($orderShop);
- $data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop);
- $data['order_products_by_category'] = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
- $data['total_remaining_to_be_paid'] = $this->orderShopResolver->getTotalRemainingToBePaid($orderShop);
- }
- return $data;
- }
-
- public function getAsArray(OrderShopInterface $orderShop): array
- {
- $data['id'] = $orderShop->getId();
- $data['user'] = $orderShop->getUser()->getSummary();
- $data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
- $data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
- $data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
- $data['total'] = $this->priceSolver->getTotal($orderShop);
- $data['totalWithTax'] = $this->priceSolver->getTotalWithTax($orderShop);
- $data['totalWithTaxAndReduction'] = $this->priceSolver->getTotalWithTax($orderShop);
- $i = 0;
-
- $orderProductsByParentCategory = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
- foreach ($orderProductsByParentCategory as $labelCategory => $orderProducts) {
- foreach ($orderProducts as $orderProduct) {
- $data['orderProducts'][$i]['id'] = $orderProduct->getId();
- $data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
- $data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
- $data['orderProducts'][$i]['labelCategory'] = $labelCategory;
- $data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
- $data['orderProducts'][$i]['price'] = $this->priceSolver->getPrice($orderProduct);
- $data['orderProducts'][$i]['priceWithTax'] = $this->priceSolver->getPriceWithTax($orderProduct);
- $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceSolver->getPriceWithTaxAndReduction(
- $orderProduct
- );
- $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
- $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceSolver->getTotalOrderProductsWithTaxAndReduction(
- array($orderProduct)
- );
- $i++;
- }
- }
-
- return $data;
- }
-
- public function getOrderReductionCartsInfosAsArray(OrderShop $order): array
- {
- $data = array();
- foreach ($order->getOrderReductionCarts() as $orderReductionCart) {
- $data[] = array(
- 'title' => $orderReductionCart->__toString(),
- 'id' => $orderReductionCart->getId(),
- 'orderReference' => $order->getReference(),
- 'amount' => $this->priceSolver->getOrderProductsReductionCartAmountWithTax(
- $order,
- $orderReductionCart
- )
- );
- }
- return $data;
- }
-
- public function getOrderPaymentsInfosAsArray(OrderShop $order): array
- {
- $data = array();
- foreach ($order->getOrderPayments() as $orderPayment) {
-
- $data[$orderPayment->getId()] = array(
- 'id' => $orderPayment->getId(),
- 'reference' => $orderPayment->getReference(),
- 'orderReference' => $order->getReference(),
- 'comment' => $orderPayment->getComment(),
- 'meanPayment' => $orderPayment->getMeanPayment(),
- 'meanPaymentText' => $this->translatorAdmin->transChoice(
- 'OrderPayment', 'meanPayment',$orderPayment->getMeanPayment()
- ),
- 'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'),
- 'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'),
- 'amount' => $orderPayment->getAmount(),
- 'editable' => $orderPayment->getEditable()
- );
- }
- return $data;
- }
-
- public function getOrderStatusHistoriesInfosAsArray(OrderShop $order): array
- {
- $data = array();
- foreach ($order->getOrderStatusHistories() as $orderStatusHistory) {
- $data[$orderStatusHistory->getId()] = array(
- 'id' => $orderStatusHistory->getId(),
- 'createdAt' => $orderStatusHistory->getCreatedAt()->format('d-m-Y H:i'),
- 'createdBy' => $orderStatusHistory->getCreatedBy() ? $orderStatusHistory->getCreatedBy(
- )->__toString() : 'aucun',
- 'orderStatus' => $orderStatusHistory->getOrderStatus()->getAlias(),
- 'origin' => $orderStatusHistory->getOrigin(),
- 'info' => $orderStatusHistory->__toString(),
- );
- }
- return $data;
- }
-
- public function getOrderReductionCreditsInfosAsArray(OrderShop $order): array
- {
- $data = array();
-
- foreach ($order->getOrderReductionCredits() as $orderReductionCredit) {
- $data[] = array(
- 'title' => $orderReductionCredit->__toString(),
- 'id' => $orderReductionCredit->getId(),
- 'orderReference' => $order->getReference(),
- 'amount' => $this->priceSolver->getOrderProductsReductionCreditAmountWithTax(
- $order,
- $orderReductionCredit
- )
- );
- }
- return $data;
- }
-
- public function getOrderTicketsInfosAsArray(OrderShop $order): array
- {
- $data = array();
- foreach ($order->getTickets() as $ticket) {
- $data[$ticket->getId()] = array(
- 'id' => $ticket->getId(),
- 'date' => $ticket->getCreatedAt()->format('d/m/Y'),
- 'status' => $this->translatorAdmin->trans(
- 'field.Ticket.statusOptions.' . $ticket->getStatus()
- ),
- 'subject' => $ticket->getSubject(),
- 'orderReference' => $order->getReference(),
- 'link' => '',
- );
- }
- return $data;
- }
-
- public function getOrderDocumentsInfosAsArray(OrderShop $order): array
- {
- $data = array();
- foreach ($order->getDocuments() as $orderDocument) {
- $data[$orderDocument->getId()] = array(
- 'id' => $orderDocument->getId(),
- 'date' => $orderDocument->getCreatedAt()->format('d/m/Y'),
- 'reference' => $orderDocument->getReference(),
- 'type' => $orderDocument->getType(),
- 'isSent' => $orderDocument->getIsSent(),
- 'orderReference' => $order->getReference(),
- 'link' => $this->urlGenerator->generate('document_download', ['id'=> $orderDocument->getId()])
- );
- }
- return $data;
- }
-
- }
|