1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Device; |
|
|
|
|
6
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
7
|
|
|
use ControleOnline\Entity\Product; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
10
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class ProductService |
13
|
|
|
{ |
14
|
|
|
public function __construct( |
15
|
|
|
private EntityManagerInterface $manager, |
16
|
|
|
private Security $security, |
17
|
|
|
private PrintService $printService, |
|
|
|
|
18
|
|
|
private PeopleService $PeopleService |
|
|
|
|
19
|
|
|
) {} |
20
|
|
|
|
21
|
|
|
public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
// $this->PeopleService->checkCompany('company', $queryBuilder, $resourceClass, $applyTo, $rootAlias); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getPurchasingSuggestion(People $company) |
27
|
|
|
{ |
28
|
|
|
return $this->manager->getRepository(Product::class)->getPurchasingSuggestion($company); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function purchasingSuggestionPrintData(?People $provider, string $printType, string $deviceType) |
32
|
|
|
{ |
33
|
|
|
$products = $this->getPurchasingSuggestion($provider); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$groupedByCompany = []; |
36
|
|
|
foreach ($products as $product) { |
37
|
|
|
$companyName = $product['company_name'] ?? 'Empresa Desconhecida'; |
38
|
|
|
if (!isset($groupedByCompany[$companyName])) { |
39
|
|
|
$groupedByCompany[$companyName] = []; |
40
|
|
|
} |
41
|
|
|
$groupedByCompany[$companyName][] = $product; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->printService->addLine("", "", "-"); |
45
|
|
|
$this->printService->addLine("SUGESTAO DE COMPRA", "", " "); |
46
|
|
|
$this->printService->addLine("", "", "-"); |
47
|
|
|
|
48
|
|
|
foreach ($groupedByCompany as $companyName => $items) { |
49
|
|
|
$this->printService->addLine($companyName, "", " "); |
50
|
|
|
$this->printService->addLine("", "", "-"); |
51
|
|
|
$this->printService->addLine("Produto", "Necessario", " "); |
52
|
|
|
$this->printService->addLine("", "", "-"); |
53
|
|
|
|
54
|
|
|
foreach ($items as $item) { |
55
|
|
|
$productName = substr($item['product_name'], 0, 20); |
56
|
|
|
if (!empty($item['description'])) { |
57
|
|
|
$productName .= " " . substr($item['description'], 0, 10); |
58
|
|
|
} |
59
|
|
|
if (!empty($item['unity'])) { |
60
|
|
|
$productName .= " (" . $item['unity'] . ")"; |
61
|
|
|
} |
62
|
|
|
$needed = str_pad($item['needed'], 4, " ", STR_PAD_LEFT); |
63
|
|
|
$this->printService->addLine($productName, $needed, " "); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->printService->addLine("", "", "-"); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->printService->generatePrintData($printType, $deviceType); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function updateProductInventory(): void |
74
|
|
|
{ |
75
|
|
|
|
76
|
|
|
$sql = "INSERT INTO `product_inventory` ( |
77
|
|
|
`inventory_id`, |
78
|
|
|
`product_id`, |
79
|
|
|
`product_unity_id`, |
80
|
|
|
`available`, |
81
|
|
|
`ordered`, |
82
|
|
|
`transit`, |
83
|
|
|
`minimum`, |
84
|
|
|
`maximum`, |
85
|
|
|
`sales` |
86
|
|
|
) |
87
|
|
|
SELECT |
88
|
|
|
op.`inventory_id`, |
89
|
|
|
op.`product_id`, |
90
|
|
|
p.`product_unity_id`, |
91
|
|
|
(SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:purchasing_status) THEN op.`quantity` ELSE 0 END) - |
92
|
|
|
SUM(CASE WHEN o.`order_type` = 'sale' AND o.`status_id` IN (:sales_status) THEN op.`quantity` ELSE 0 END)) AS `available`, |
93
|
|
|
SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:ordered_status) THEN op.`quantity` ELSE 0 END) AS `ordered`, |
94
|
|
|
SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:transit_status) THEN op.`quantity` ELSE 0 END) AS `transit`, |
95
|
|
|
0 AS `minimum`, |
96
|
|
|
0 AS `maximum`, |
97
|
|
|
SUM(CASE WHEN o.`order_type` = 'sale' AND o.`status_id` IN (:sales_status) THEN op.`quantity` ELSE 0 END) AS `sales` |
98
|
|
|
FROM `orders` o |
99
|
|
|
JOIN `order_product` op ON o.`id` = op.`order_id` |
100
|
|
|
JOIN `product` p ON op.`product_id` = p.`id` |
101
|
|
|
WHERE o.`order_type` IN ('purchasing', 'sale') |
102
|
|
|
AND o.`status_id` IN (:all_status) |
103
|
|
|
AND p.`type` IN ('product', 'feedstock') |
104
|
|
|
AND ( |
105
|
|
|
(o.`order_type` = 'sale' AND o.`provider_id` IN (:provider_id)) |
106
|
|
|
OR |
107
|
|
|
(o.`order_type` = 'purchasing' AND o.`client_id` IN (:client_id)) |
108
|
|
|
) |
109
|
|
|
GROUP BY op.`inventory_id`, op.`product_id`, p.`product_unity_id` |
110
|
|
|
ON DUPLICATE KEY UPDATE |
111
|
|
|
`available` = VALUES(`available`), |
112
|
|
|
`ordered` = VALUES(`ordered`), |
113
|
|
|
`transit` = VALUES(`transit`), |
114
|
|
|
`sales` = VALUES(`sales`) |
115
|
|
|
"; |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
$purchasingStatus = [7]; |
119
|
|
|
$orderedStatus = [5]; |
120
|
|
|
$transitStatus = [6]; |
121
|
|
|
$salesStatus = [6]; |
122
|
|
|
$companies = [1, 2, 3]; |
123
|
|
|
$allStatus = array_unique(array_merge($purchasingStatus, $orderedStatus, $transitStatus, $salesStatus)); |
124
|
|
|
|
125
|
|
|
try { |
126
|
|
|
$stmt = $this->manager->getConnection()->prepare($sql); |
127
|
|
|
|
128
|
|
|
$stmt->bindValue('purchasing_status', implode(',', $purchasingStatus), \PDO::PARAM_STR); |
129
|
|
|
$stmt->bindValue('sales_status', implode(',', $salesStatus), \PDO::PARAM_STR); |
130
|
|
|
$stmt->bindValue('ordered_status', implode(',', $orderedStatus), \PDO::PARAM_STR); |
131
|
|
|
$stmt->bindValue('transit_status', implode(',', $transitStatus), \PDO::PARAM_STR); |
132
|
|
|
$stmt->bindValue('all_status', implode(',', $allStatus), \PDO::PARAM_STR); |
133
|
|
|
$stmt->bindValue('provider_id', implode(',', $companies), \PDO::PARAM_STR); |
134
|
|
|
$stmt->bindValue('client_id', implode(',', $companies), \PDO::PARAM_STR); |
135
|
|
|
|
136
|
|
|
$stmt->executeQuery(); |
137
|
|
|
} catch (\Exception $e) { |
138
|
|
|
throw new \Exception("Erro ao atualizar o estoque: " . $e->getMessage()); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
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