1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Order; |
|
|
|
|
6
|
|
|
use ControleOnline\Entity\ProductGroupProduct; |
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
8
|
|
|
use Exception; |
9
|
|
|
|
10
|
|
|
class PrintService |
11
|
|
|
{ |
12
|
|
|
private $noQueue = 'Sem fila definida'; |
13
|
|
|
private $initialSpace = 8; |
14
|
|
|
private $totalChars = 30; |
15
|
|
|
private $text = ''; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
private EntityManagerInterface $entityManager |
19
|
|
|
) {} |
20
|
|
|
|
21
|
|
|
private function addLine($pre = '', $pos = '', $delimiter = ' ') |
22
|
|
|
{ |
23
|
|
|
$initialSpace = str_repeat(" ", $this->initialSpace); |
24
|
|
|
$delimiter = str_repeat($delimiter, $this->totalChars - $initialSpace - strlen($pre) - strlen($pos)); |
25
|
|
|
$this->text .= $initialSpace . $pre . $delimiter . $pos . "\n"; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
private function getQueues(Order $order) |
30
|
|
|
{ |
31
|
|
|
$queues = []; |
32
|
|
|
foreach ($order->getOrderProducts() as $orderProduct) { |
33
|
|
|
$queueEntries = $orderProduct->getOrderProductQueues(); |
34
|
|
|
if ($queueEntries->isEmpty()) { |
35
|
|
|
if (!isset($queues[$this->noQueue])) |
36
|
|
|
$queues[$this->noQueue] = []; |
37
|
|
|
$queues[$this->noQueue][] = $orderProduct; |
38
|
|
|
} else |
39
|
|
|
foreach ($queueEntries as $queueEntry) { |
40
|
|
|
$queue = $queueEntry->getQueue(); |
41
|
|
|
$queueName = $queue ? $queue->getQueue() : $this->noQueue; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
if (!isset($queues[$queueName])) |
45
|
|
|
$queues[$queueName] = []; |
46
|
|
|
|
47
|
|
|
$queues[$queueName][] = $orderProduct; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
return $queues; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function generatePrintData(Order $order, string $printType, string $deviceType) |
54
|
|
|
{ |
55
|
|
|
|
56
|
|
|
if ($printType === 'pos') { |
57
|
|
|
$this->addLine("PEDIDO #" . $order->getId()); |
58
|
|
|
$this->addLine($order->getOrderDate()->format('d/m/Y H:i')); |
59
|
|
|
$client = $order->getClient(); |
60
|
|
|
$this->addLine(($client !== null ? $client->getName() : 'Não informado')); |
61
|
|
|
$this->addLine(number_format($order->getPrice(), 2, ',', '.')); |
62
|
|
|
$this->addLine("", "", "-"); |
63
|
|
|
|
64
|
|
|
$queues = $this->getQueues($order); |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
foreach ($queues as $queueName => $products) { |
68
|
|
|
$this->addLine(strtoupper($queueName) . ":"); |
69
|
|
|
foreach ($products as $orderProduct) { |
70
|
|
|
$product = $orderProduct->getProduct(); |
71
|
|
|
$unit = $product->getProductUnit()->getProductUnit(); |
72
|
|
|
$quantity = $orderProduct->getQuantity(); |
73
|
|
|
|
74
|
|
|
$this->addLine( |
75
|
|
|
"- " . $product->getProduct() . " (" . $quantity . " " . $unit . ")", |
76
|
|
|
" R$ " . number_format($product->getPrice() * $quantity, 2, ',', '.'), |
77
|
|
|
'.' |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
if ($product->getType() === 'custom') { |
82
|
|
|
$this->addLine(" Personalizações:"); |
83
|
|
|
$productGroupProducts = $this->entityManager->getRepository(ProductGroupProduct::class) |
84
|
|
|
->findBy(['product' => $product->getId()]); |
85
|
|
|
|
86
|
|
|
foreach ($productGroupProducts as $pgp) { |
87
|
|
|
$childProduct = $pgp->getProductChild(); |
88
|
|
|
if ($childProduct) |
89
|
|
|
$this->addLine(" - " . $childProduct->getProduct() . " (" . $pgp->getQuantity() . " " . $childProduct->getProductUnit()->getProductUnit() . ")"); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
$this->addLine('', '', ' '); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->addLine('', '', '-'); |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
if ($deviceType === 'cielo') |
100
|
|
|
return [ |
101
|
|
|
"operation" => "PRINT_TEXT", |
102
|
|
|
"styles" => [[]], |
103
|
|
|
"value" => [$this->text] |
104
|
|
|
]; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
throw new Exception("Unsupported print type", 1); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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