|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
|
|
7
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator; |
|
|
|
|
|
|
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
9
|
|
|
use ControleOnline\Entity\Order; |
|
10
|
|
|
|
|
11
|
|
|
class PrintOrderAction |
|
12
|
|
|
{ |
|
13
|
|
|
private $entityManager; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(EntityManagerInterface $entityManager) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->entityManager = $entityManager; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function __invoke(Request $request, int $id): JsonResponse |
|
21
|
|
|
{ |
|
22
|
|
|
// Busca o pedido pelo ID |
|
23
|
|
|
$order = $this->entityManager->getRepository(Order::class)->find($id); |
|
24
|
|
|
if (!$order) { |
|
25
|
|
|
return new JsonResponse(['error' => 'Order not found'], 404); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// Pega os parâmetros da requisição (print-type e device-type) |
|
29
|
|
|
$data = json_decode($request->getContent(), true); |
|
30
|
|
|
$printType = $data['print-type'] ?? 'pos'; |
|
31
|
|
|
$deviceType = $data['device-type'] ?? 'cielo'; |
|
32
|
|
|
|
|
33
|
|
|
// Lógica para decidir o que retornar (texto ou imagem) |
|
34
|
|
|
$printData = $this->generatePrintData($order, $printType, $deviceType); |
|
35
|
|
|
|
|
36
|
|
|
// Retorna os dados a serem impressos |
|
37
|
|
|
return new JsonResponse($printData); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function generatePrintData(Order $order, string $printType, string $deviceType): array|string |
|
41
|
|
|
{ |
|
42
|
|
|
if ($deviceType !== 'cielo') { |
|
43
|
|
|
return ['error' => 'Unsupported device type']; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($printType === 'pos') { |
|
47
|
|
|
// Exemplo: retorna um texto simples para impressão no POS |
|
48
|
|
|
$text = "Order ID: " . $order->getId() . "\n"; |
|
49
|
|
|
$text .= "Client: " . $order->getClient()->getName() . "\n"; |
|
50
|
|
|
$text .= "Price: " . number_format($order->getPrice(), 2, ',', '.') . "\n"; |
|
51
|
|
|
$text .= "Date: " . $order->getOrderDate()->format('d/m/Y H:i:s') . "\n"; |
|
52
|
|
|
|
|
53
|
|
|
foreach ($order->getOrderProducts() as $product) { |
|
54
|
|
|
$text .= "- " . $product->getProduct()->getName() . " x" . $product->getQuantity() . "\n"; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $text; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// Caso queira suportar imagem no futuro |
|
61
|
|
|
// Exemplo fictício de imagem em base64 |
|
62
|
|
|
/* |
|
63
|
|
|
if ($printType === 'image') { |
|
64
|
|
|
$imagePath = $this->generateImage($order); // Implementar lógica para gerar imagem |
|
65
|
|
|
$imageContent = file_get_contents($imagePath); |
|
66
|
|
|
return base64_encode($imageContent); |
|
67
|
|
|
} |
|
68
|
|
|
*/ |
|
69
|
|
|
|
|
70
|
|
|
return ['error' => 'Unsupported print type']; |
|
71
|
|
|
} |
|
72
|
|
|
} |
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