|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
|
4
|
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Device; |
|
|
|
|
|
|
6
|
|
|
use ControleOnline\Entity\Order; |
|
7
|
|
|
use ControleOnline\Entity\ProductGroupProduct; |
|
|
|
|
|
|
8
|
|
|
use ControleOnline\Entity\Spool; |
|
|
|
|
|
|
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
10
|
|
|
use Exception; |
|
11
|
|
|
|
|
12
|
|
|
class OrderPrintService |
|
13
|
|
|
{ |
|
14
|
|
|
private $noQueue = 'Sem fila definida'; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private EntityManagerInterface $entityManager, |
|
18
|
|
|
private PrintService $printService, |
|
|
|
|
|
|
19
|
|
|
private ConfigService $configService, |
|
|
|
|
|
|
20
|
|
|
private DeviceService $deviceService, |
|
|
|
|
|
|
21
|
|
|
) {} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
private function getQueues(Order $order) |
|
25
|
|
|
{ |
|
26
|
|
|
$queues = []; |
|
27
|
|
|
foreach ($order->getOrderProducts() as $orderProduct) { |
|
28
|
|
|
$queueEntries = $orderProduct->getOrderProductQueues(); |
|
29
|
|
|
if ($queueEntries->isEmpty()) { |
|
30
|
|
|
if (!isset($queues[$this->noQueue])) { |
|
31
|
|
|
$queues[$this->noQueue] = []; |
|
32
|
|
|
} |
|
33
|
|
|
$queues[$this->noQueue][] = $orderProduct; |
|
34
|
|
|
} else { |
|
35
|
|
|
foreach ($queueEntries as $queueEntry) { |
|
36
|
|
|
$queue = $queueEntry->getQueue(); |
|
37
|
|
|
$queueName = $queue ? $queue->getQueue() : $this->noQueue; |
|
38
|
|
|
if (!isset($queues[$queueName])) { |
|
39
|
|
|
$queues[$queueName] = []; |
|
40
|
|
|
} |
|
41
|
|
|
$queues[$queueName][] = $orderProduct; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
return $queues; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function printOrder(Order $order, ?array $devices = []) |
|
49
|
|
|
{ |
|
50
|
|
|
if (empty($devices)) |
|
51
|
|
|
$devices = $this->configService->getConfig($order->getProvider(), 'order-print-devices', true); |
|
52
|
|
|
|
|
53
|
|
|
if ($devices) |
|
54
|
|
|
$devices = $this->deviceService->findDevices($devices); |
|
55
|
|
|
|
|
56
|
|
|
foreach ($devices as $device) |
|
57
|
|
|
$this->generatePrintData($order, $device, ['sound' => 'iFood']); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function printProduct($orderProduct, $indent = "- ") |
|
61
|
|
|
{ |
|
62
|
|
|
$product = $orderProduct->getProduct(); |
|
63
|
|
|
|
|
64
|
|
|
$quantity = $orderProduct->getQuantity(); |
|
65
|
|
|
$this->printService->addLine( |
|
66
|
|
|
$indent . $quantity . ' X ' . $product->getProduct(), |
|
67
|
|
|
" R$ " . number_format($orderProduct->getTotal(), 2, ',', '.'), |
|
68
|
|
|
'.' |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function printChildren($orderProducts) |
|
73
|
|
|
{ |
|
74
|
|
|
$groupedChildren = []; |
|
75
|
|
|
foreach ($orderProducts as $orderProductChild) { |
|
76
|
|
|
$productGroup = $orderProductChild->getProductGroup(); |
|
77
|
|
|
$groupName = $productGroup ? $productGroup->getProductGroup() : 'Sem Grupo'; |
|
78
|
|
|
if (!isset($groupedChildren[$groupName])) { |
|
79
|
|
|
$groupedChildren[$groupName] = []; |
|
80
|
|
|
} |
|
81
|
|
|
$groupedChildren[$groupName][] = $orderProductChild; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
foreach ($groupedChildren as $groupName => $orderProductChildren) { |
|
85
|
|
|
$this->printService->addLine(strtoupper($groupName) . ":"); |
|
86
|
|
|
foreach ($orderProductChildren as $orderProductChild) { |
|
87
|
|
|
$product = $orderProductChild->getProduct(); |
|
88
|
|
|
$this->printService->addLine(" - " . $product->getProduct()); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
$this->printService->addLine('', '', '-'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
private function printQueueProducts($orderProducts) |
|
95
|
|
|
{ |
|
96
|
|
|
$parentOrderProducts = array_filter($orderProducts, fn($orderProduct) => $orderProduct->getOrderProduct() === null); |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
foreach ($parentOrderProducts as $parentOrderProduct) { |
|
100
|
|
|
$this->printProduct($parentOrderProduct); |
|
101
|
|
|
|
|
102
|
|
|
$childs = $parentOrderProduct->getOrderProductComponents(); |
|
103
|
|
|
if (!empty($childs)) |
|
104
|
|
|
$this->printChildren($childs); |
|
105
|
|
|
|
|
106
|
|
|
$this->printService->addLine('', '', '-'); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
private function printQueues($queues) |
|
111
|
|
|
{ |
|
112
|
|
|
foreach ($queues as $queueName => $orderProducts) { |
|
113
|
|
|
$parentOrderProducts = array_filter($orderProducts, fn($orderProduct) => $orderProduct->getOrderProduct() === null); |
|
114
|
|
|
if (!empty($parentOrderProducts)) { |
|
115
|
|
|
$this->printService->addLine(strtoupper($queueName) . ":"); |
|
116
|
|
|
$this->printQueueProducts($orderProducts); |
|
117
|
|
|
$this->printService->addLine('', '', ' '); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function generatePrintData(Order $order, Device $device, ?array $aditionalData = []): Spool |
|
123
|
|
|
{ |
|
124
|
|
|
|
|
125
|
|
|
$this->printService->addLine("PEDIDO #" . $order->getId()); |
|
126
|
|
|
$this->printService->addLine($order->getOrderDate()->format('d/m/Y H:i')); |
|
127
|
|
|
$client = $order->getClient(); |
|
128
|
|
|
$this->printService->addLine(($client !== null ? $client->getName() : 'Não informado')); |
|
129
|
|
|
$this->printService->addLine("R$ " . number_format($order->getPrice(), 2, ',', '.')); |
|
130
|
|
|
$this->printService->addLine("", "", "-"); |
|
131
|
|
|
$queues = $this->getQueues($order); |
|
132
|
|
|
|
|
133
|
|
|
$this->printQueues($queues); |
|
134
|
|
|
$this->printService->addLine("", "", "-"); |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
return $this->printService->generatePrintData($device, $order->getProvider(), $aditionalData); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths