1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
8
|
|
|
use ControleOnline\Entity\Order; |
9
|
|
|
use ControleOnline\Entity\OrderProduct; |
10
|
|
|
use ControleOnline\Entity\Product; |
|
|
|
|
11
|
|
|
use ControleOnline\Entity\ProductGroupProduct; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class PrintOrderAction |
14
|
|
|
{ |
15
|
|
|
private $entityManager; |
16
|
|
|
|
17
|
|
|
public function __construct(EntityManagerInterface $entityManager) |
18
|
|
|
{ |
19
|
|
|
$this->entityManager = $entityManager; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function __invoke(Request $request, int $id): JsonResponse |
23
|
|
|
{ |
24
|
|
|
$order = $this->entityManager->getRepository(Order::class)->find($id); |
25
|
|
|
if (!$order) { |
26
|
|
|
return new JsonResponse(['error' => 'Order not found'], 404); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$data = json_decode($request->getContent(), true); |
30
|
|
|
$printType = $data['print-type'] ?? 'pos'; |
31
|
|
|
$deviceType = $data['device-type'] ?? 'cielo'; |
32
|
|
|
|
33
|
|
|
$printData = $this->generatePrintData($order, $printType, $deviceType); |
34
|
|
|
|
35
|
|
|
return new JsonResponse($printData); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
private function generatePrintData(Order $order, string $printType, string $deviceType) |
39
|
|
|
{ |
40
|
|
|
if ($deviceType !== 'cielo') { |
41
|
|
|
return ['error' => 'Unsupported device type']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($printType === 'pos') { |
45
|
|
|
$text = "PEDIDO #" . $order->getId() . "\n"; |
46
|
|
|
$text .= "Data: " . $order->getOrderDate()->format('d/m/Y H:i') . "\n"; |
47
|
|
|
|
48
|
|
|
// Correção: Verificar explicitamente se getClient() é null |
49
|
|
|
$client = $order->getClient(); |
50
|
|
|
$text .= "Cliente: " . ($client !== null ? $client->getName() : 'Não informado') . "\n"; |
51
|
|
|
|
52
|
|
|
$text .= "Total: R$ " . number_format($order->getPrice(), 2, ',', '.') . "\n"; |
53
|
|
|
$text .= "------------------------\n"; |
54
|
|
|
|
55
|
|
|
// Agrupar produtos por fila diretamente |
56
|
|
|
$queues = []; |
57
|
|
|
foreach ($order->getOrderProducts() as $orderProduct) { |
58
|
|
|
$queue = $orderProduct->getQueue(); |
59
|
|
|
$queueName = $queue ? $queue->getQueue() : 'Sem fila definida'; |
60
|
|
|
if (!isset($queues[$queueName])) { |
61
|
|
|
$queues[$queueName] = []; |
62
|
|
|
} |
63
|
|
|
$queues[$queueName][] = $orderProduct; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Exibir produtos organizados por fila |
67
|
|
|
foreach ($queues as $queueName => $products) { |
68
|
|
|
$text .= strtoupper($queueName) . ":\n"; |
69
|
|
|
foreach ($products as $orderProduct) { |
70
|
|
|
$product = $orderProduct->getProduct(); |
71
|
|
|
$unit = $product->getProductUnit()->getProductUnit(); |
72
|
|
|
$quantity = $orderProduct->getQuantity(); |
73
|
|
|
|
74
|
|
|
$text .= "- " . $product->getProduct() . " (" . $quantity . " " . $unit . ")\n"; |
75
|
|
|
$text .= " R$ " . number_format($product->getPrice() * $quantity, 2, ',', '.') . "\n"; |
76
|
|
|
|
77
|
|
|
// Verifica se o produto é customizado |
78
|
|
|
if ($product->getType() === 'custom') { |
79
|
|
|
$text .= " Personalizações:\n"; |
80
|
|
|
$productGroupProducts = $this->entityManager->getRepository(ProductGroupProduct::class) |
81
|
|
|
->findBy(['product' => $product->getId()]); |
82
|
|
|
|
83
|
|
|
foreach ($productGroupProducts as $pgp) { |
84
|
|
|
$childProduct = $pgp->getProductChild(); |
85
|
|
|
if ($childProduct) { |
86
|
|
|
$text .= " - " . $childProduct->getProduct() . " (" . $pgp->getQuantity() . " " . $childProduct->getProductUnit()->getProductUnit() . ")\n"; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
$text .= "\n"; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$text .= "------------------------\n"; |
95
|
|
|
$text .= "Status: " . $order->getStatus()->getStatus() . "\n"; |
96
|
|
|
|
97
|
|
|
return $text; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return ['error' => 'Unsupported print type']; |
101
|
|
|
} |
102
|
|
|
} |
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