@@ -7,7 +7,7 @@ |
||
7 | 7 | use ControleOnline\Entity\Status; |
8 | 8 | use Doctrine\ORM\EntityManagerInterface; |
9 | 9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface |
10 | - AS Security; |
|
10 | + AS Security; |
|
11 | 11 | |
12 | 12 | class OrderInvoiceService |
13 | 13 | { |
@@ -22,7 +22,7 @@ |
||
22 | 22 | private StatusService $statusService, |
23 | 23 | RequestStack $requestStack |
24 | 24 | ) { |
25 | - $this->request = $requestStack->getCurrentRequest(); |
|
25 | + $this->request = $requestStack->getCurrentRequest(); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public function calculateOrderPrice(Order $order) |
@@ -79,17 +79,21 @@ discard block |
||
79 | 79 | $order = $orderProduct->getOrder(); |
80 | 80 | $product = $orderProduct->getProduct(); |
81 | 81 | |
82 | - if ($order->getOrderType() == 'sale' && !$orderProduct->getOutInventory()) |
|
83 | - $orderProduct->setOutInventory($product->getDefaultOutInventory()); |
|
82 | + if ($order->getOrderType() == 'sale' && !$orderProduct->getOutInventory()) { |
|
83 | + $orderProduct->setOutInventory($product->getDefaultOutInventory()); |
|
84 | + } |
|
84 | 85 | |
85 | - if ($order->getOrderType() == 'purchase' && !$orderProduct->getInInventory()) |
|
86 | - $orderProduct->setInInventory($product->getDefaultInInventory()); |
|
86 | + if ($order->getOrderType() == 'purchase' && !$orderProduct->getInInventory()) { |
|
87 | + $orderProduct->setInInventory($product->getDefaultInInventory()); |
|
88 | + } |
|
87 | 89 | } |
88 | 90 | |
89 | 91 | public function postPersist(OrderProduct $orderProduct) |
90 | 92 | { |
91 | 93 | |
92 | - if (!self::$mainProduct || !$this->request) return; |
|
94 | + if (!self::$mainProduct || !$this->request) { |
|
95 | + return; |
|
96 | + } |
|
93 | 97 | self::$mainProduct = false; |
94 | 98 | |
95 | 99 | $json = json_decode($this->request->getContent(), true); |
@@ -107,7 +111,9 @@ discard block |
||
107 | 111 | public function preRemove(OrderProduct $orderProduct) |
108 | 112 | { |
109 | 113 | |
110 | - if (!self::$mainProduct) return; |
|
114 | + if (!self::$mainProduct) { |
|
115 | + return; |
|
116 | + } |
|
111 | 117 | self::$mainProduct = false; |
112 | 118 | $order = $orderProduct->getOrder(); |
113 | 119 | $this->manager->persist($order->setPrice(0)); |
@@ -116,8 +122,9 @@ discard block |
||
116 | 122 | 'parentProduct' => $orderProduct->getProduct(), |
117 | 123 | ]); |
118 | 124 | |
119 | - foreach ($parentProducts as $parentProduct) |
|
120 | - $this->manager->remove($parentProduct); |
|
125 | + foreach ($parentProducts as $parentProduct) { |
|
126 | + $this->manager->remove($parentProduct); |
|
127 | + } |
|
121 | 128 | $this->manager->flush(); |
122 | 129 | |
123 | 130 | self::$calculateBefore[] = $order; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->request = $this->requestStack->getCurrentRequest(); |
34 | 34 | } |
35 | 35 | |
36 | - public function addOrderProduct(Order $order, Product $product, $quantity, $price, ?ProductGroup $productGroup = null, ?Product $parentProduct = null, ?OrderProduct $orderProductParent = null): OrderProduct |
|
36 | + public function addOrderProduct(Order $order, Product $product, $quantity, $price, ?ProductGroup $productGroup = null, ?Product $parentProduct = null, ?OrderProduct $orderProductParent = null): OrderProduct |
|
37 | 37 | { |
38 | 38 | $OProduct = new OrderProduct(); |
39 | 39 | $OProduct->setOrder($order); |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | $this->orderProductQueueService->addProductToQueue($OProduct); |
76 | 76 | } |
77 | 77 | |
78 | - private function checkInventory(OrderProduct &$orderProduct) |
|
78 | + private function checkInventory(OrderProduct & $orderProduct) |
|
79 | 79 | { |
80 | 80 | $order = $orderProduct->getOrder(); |
81 | - $product = $orderProduct->getProduct(); |
|
81 | + $product = $orderProduct->getProduct(); |
|
82 | 82 | |
83 | 83 | if ($order->getOrderType() == 'sale' && !$orderProduct->getOutInventory()) |
84 | 84 | $orderProduct->setOutInventory($product->getDefaultOutInventory()); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $subProducts = $json['sub_products']; |
100 | 100 | foreach ($subProducts as $subproduct) { |
101 | 101 | $product = $this->manager->getRepository(Product::class)->find($subproduct['product']); |
102 | - $productGroup = $this->manager->getRepository(ProductGroup::class)->find($subproduct['productGroup']); |
|
102 | + $productGroup = $this->manager->getRepository(ProductGroup::class)->find($subproduct['productGroup']); |
|
103 | 103 | $this->addSubproduct($orderProduct, $product, $productGroup, $subproduct['quantity']); |
104 | 104 | } |
105 | 105 | } |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | if ($printForm) $this->printService->addLine('', '', ' '); |
68 | 68 | |
69 | 69 | $this->printService->addLine( |
70 | - $indent . $quantity . ' X ' . $product->getProduct(), |
|
71 | - " R$ " . number_format($total, 2, ',', '.'), |
|
70 | + $indent.$quantity.' X '.$product->getProduct(), |
|
71 | + " R$ ".number_format($total, 2, ',', '.'), |
|
72 | 72 | '.' |
73 | 73 | ); |
74 | 74 | |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | foreach ($groupedChildren as $groupName => $orderProductChildren) { |
91 | - $this->printService->addLine(strtoupper($groupName) . ":"); |
|
91 | + $this->printService->addLine(strtoupper($groupName).":"); |
|
92 | 92 | foreach ($orderProductChildren as $orderProductChild) { |
93 | 93 | $product = $orderProductChild->getProduct(); |
94 | - $this->printService->addLine(" - " . $product->getProduct()); |
|
94 | + $this->printService->addLine(" - ".$product->getProduct()); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | $this->printService->addLine('', '', '-'); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | foreach ($parentOrderProducts as $parentOrderProduct) { |
105 | 105 | $quantity = $printForm ? $parentOrderProduct->getQuantity() : 1; |
106 | 106 | for ($i = 0; $i < $quantity; $i++) { |
107 | - $this->printProduct($parentOrderProduct, "- ", $printForm); |
|
107 | + $this->printProduct($parentOrderProduct, "- ", $printForm); |
|
108 | 108 | |
109 | 109 | $childs = $parentOrderProduct->getOrderProductComponents(); |
110 | 110 | if (!empty($childs)) |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | foreach ($queues as $queueName => $orderProducts) { |
121 | 121 | $parentOrderProducts = array_filter($orderProducts, fn($orderProduct) => $orderProduct->getOrderProduct() === null); |
122 | 122 | if (!empty($parentOrderProducts)) { |
123 | - if (!$printForm) $this->printService->addLine(strtoupper($queueName) . ":"); |
|
123 | + if (!$printForm) $this->printService->addLine(strtoupper($queueName).":"); |
|
124 | 124 | $this->printQueueProducts($orderProducts, $printForm); |
125 | 125 | if ($printForm) $this->printService->addLine('', '', ' '); |
126 | 126 | $this->printService->addLine('', '', ' '); |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | |
137 | 137 | $printForm = ($device_configs->getConfigs(true)['print-mode'] ?? 'order') == 'form'; |
138 | 138 | |
139 | - $this->printService->addLine("PEDIDO #" . $order->getId()); |
|
139 | + $this->printService->addLine("PEDIDO #".$order->getId()); |
|
140 | 140 | $this->printService->addLine($order->getOrderDate()->format('d/m/Y H:i')); |
141 | 141 | |
142 | 142 | if (!$printForm) { |
143 | 143 | $client = $order->getClient(); |
144 | 144 | $this->printService->addLine(($client !== null ? $client->getName() : 'Não informado')); |
145 | - $this->printService->addLine("R$ " . number_format($order->getPrice(), 2, ',', '.')); |
|
145 | + $this->printService->addLine("R$ ".number_format($order->getPrice(), 2, ',', '.')); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $this->printService->addLine("", "", "-"); |
@@ -48,14 +48,17 @@ discard block |
||
48 | 48 | |
49 | 49 | public function printOrder(Order $order, ?array $devices = []) |
50 | 50 | { |
51 | - if (empty($devices)) |
|
52 | - $devices = $this->configService->getConfig($order->getProvider(), 'order-print-devices', true); |
|
51 | + if (empty($devices)) { |
|
52 | + $devices = $this->configService->getConfig($order->getProvider(), 'order-print-devices', true); |
|
53 | + } |
|
53 | 54 | |
54 | - if ($devices) |
|
55 | - $devices = $this->deviceService->findDevices($devices); |
|
55 | + if ($devices) { |
|
56 | + $devices = $this->deviceService->findDevices($devices); |
|
57 | + } |
|
56 | 58 | |
57 | - foreach ($devices as $device) |
|
58 | - $this->generatePrintData($order, $device); |
|
59 | + foreach ($devices as $device) { |
|
60 | + $this->generatePrintData($order, $device); |
|
61 | + } |
|
59 | 62 | } |
60 | 63 | |
61 | 64 | private function printProduct($orderProduct, $indent = "- ", $printForm = false) |
@@ -64,7 +67,9 @@ discard block |
||
64 | 67 | $quantity = $printForm ? 1 : $orderProduct->getQuantity(); |
65 | 68 | $total = $printForm ? $orderProduct->getPrice() : $orderProduct->getTotal(); |
66 | 69 | |
67 | - if ($printForm) $this->printService->addLine('', '', ' '); |
|
70 | + if ($printForm) { |
|
71 | + $this->printService->addLine('', '', ' '); |
|
72 | + } |
|
68 | 73 | |
69 | 74 | $this->printService->addLine( |
70 | 75 | $indent . $quantity . ' X ' . $product->getProduct(), |
@@ -72,7 +77,9 @@ discard block |
||
72 | 77 | '.' |
73 | 78 | ); |
74 | 79 | |
75 | - if ($printForm) $this->printService->addLine('', '', ' '); |
|
80 | + if ($printForm) { |
|
81 | + $this->printService->addLine('', '', ' '); |
|
82 | + } |
|
76 | 83 | } |
77 | 84 | |
78 | 85 | private function printChildren($orderProducts) |
@@ -107,8 +114,9 @@ discard block |
||
107 | 114 | $this->printProduct($parentOrderProduct, "- ", $printForm); |
108 | 115 | |
109 | 116 | $childs = $parentOrderProduct->getOrderProductComponents(); |
110 | - if (!empty($childs)) |
|
111 | - $this->printChildren($childs); |
|
117 | + if (!empty($childs)) { |
|
118 | + $this->printChildren($childs); |
|
119 | + } |
|
112 | 120 | |
113 | 121 | $this->printService->addLine('', '', '-'); |
114 | 122 | } |
@@ -120,9 +128,13 @@ discard block |
||
120 | 128 | foreach ($queues as $queueName => $orderProducts) { |
121 | 129 | $parentOrderProducts = array_filter($orderProducts, fn($orderProduct) => $orderProduct->getOrderProduct() === null); |
122 | 130 | if (!empty($parentOrderProducts)) { |
123 | - if (!$printForm) $this->printService->addLine(strtoupper($queueName) . ":"); |
|
131 | + if (!$printForm) { |
|
132 | + $this->printService->addLine(strtoupper($queueName) . ":"); |
|
133 | + } |
|
124 | 134 | $this->printQueueProducts($orderProducts, $printForm); |
125 | - if ($printForm) $this->printService->addLine('', '', ' '); |
|
135 | + if ($printForm) { |
|
136 | + $this->printService->addLine('', '', ' '); |
|
137 | + } |
|
126 | 138 | $this->printService->addLine('', '', ' '); |
127 | 139 | } |
128 | 140 | } |