|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
|
4
|
|
|
|
|
5
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
|
|
6
|
|
|
use ControleOnline\Entity\Product; |
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
8
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
9
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class ProductService |
|
12
|
|
|
{ |
|
13
|
|
|
public function __construct( |
|
14
|
|
|
private EntityManagerInterface $manager, |
|
15
|
|
|
private Security $security, |
|
16
|
|
|
private PeopleService $PeopleService |
|
|
|
|
|
|
17
|
|
|
) {} |
|
18
|
|
|
|
|
19
|
|
|
public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
// $this->PeopleService->checkCompany('company', $queryBuilder, $resourceClass, $applyTo, $rootAlias); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getPurchasingSuggestion(People $company) |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->manager->getRepository(Product::class)->getPurchasingSuggestion($company); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function updateProductInventory(): void |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
$sql = "INSERT INTO `product_inventory` ( |
|
33
|
|
|
`inventory_id`, |
|
34
|
|
|
`product_id`, |
|
35
|
|
|
`product_unity_id`, |
|
36
|
|
|
`available`, |
|
37
|
|
|
`ordered`, |
|
38
|
|
|
`transit`, |
|
39
|
|
|
`minimum`, |
|
40
|
|
|
`maximum`, |
|
41
|
|
|
`sales` |
|
42
|
|
|
) |
|
43
|
|
|
SELECT |
|
44
|
|
|
op.`inventory_id`, |
|
45
|
|
|
op.`product_id`, |
|
46
|
|
|
p.`product_unity_id`, |
|
47
|
|
|
(SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:purchasing_status) THEN op.`quantity` ELSE 0 END) - |
|
48
|
|
|
SUM(CASE WHEN o.`order_type` = 'sale' AND o.`status_id` IN (:sales_status) THEN op.`quantity` ELSE 0 END)) AS `available`, |
|
49
|
|
|
SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:ordered_status) THEN op.`quantity` ELSE 0 END) AS `ordered`, |
|
50
|
|
|
SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:transit_status) THEN op.`quantity` ELSE 0 END) AS `transit`, |
|
51
|
|
|
0 AS `minimum`, |
|
52
|
|
|
0 AS `maximum`, |
|
53
|
|
|
SUM(CASE WHEN o.`order_type` = 'sale' AND o.`status_id` IN (:sales_status) THEN op.`quantity` ELSE 0 END) AS `sales` |
|
54
|
|
|
FROM `orders` o |
|
55
|
|
|
JOIN `order_product` op ON o.`id` = op.`order_id` |
|
56
|
|
|
JOIN `product` p ON op.`product_id` = p.`id` |
|
57
|
|
|
WHERE o.`order_type` IN ('purchasing', 'sale') |
|
58
|
|
|
AND o.`status_id` IN (:all_status) |
|
59
|
|
|
AND p.`type` IN ('product', 'feedstock') |
|
60
|
|
|
AND ( |
|
61
|
|
|
(o.`order_type` = 'sale' AND o.`provider_id` IN (:provider_id)) |
|
62
|
|
|
OR |
|
63
|
|
|
(o.`order_type` = 'purchasing' AND o.`client_id` IN (:client_id)) |
|
64
|
|
|
) |
|
65
|
|
|
GROUP BY op.`inventory_id`, op.`product_id`, p.`product_unity_id` |
|
66
|
|
|
ON DUPLICATE KEY UPDATE |
|
67
|
|
|
`available` = VALUES(`available`), |
|
68
|
|
|
`ordered` = VALUES(`ordered`), |
|
69
|
|
|
`transit` = VALUES(`transit`), |
|
70
|
|
|
`sales` = VALUES(`sales`) |
|
71
|
|
|
"; |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$purchasingStatus = [7]; |
|
75
|
|
|
$orderedStatus = [5]; |
|
76
|
|
|
$transitStatus = [6]; |
|
77
|
|
|
$salesStatus = [6]; |
|
78
|
|
|
$companies = [1, 2, 3]; |
|
79
|
|
|
$allStatus = array_unique(array_merge($purchasingStatus, $orderedStatus, $transitStatus, $salesStatus)); |
|
80
|
|
|
|
|
81
|
|
|
try { |
|
82
|
|
|
$stmt = $this->manager->getConnection()->prepare($sql); |
|
83
|
|
|
|
|
84
|
|
|
$stmt->bindValue('purchasing_status', implode(',', $purchasingStatus), \PDO::PARAM_STR); |
|
85
|
|
|
$stmt->bindValue('sales_status', implode(',', $salesStatus), \PDO::PARAM_STR); |
|
86
|
|
|
$stmt->bindValue('ordered_status', implode(',', $orderedStatus), \PDO::PARAM_STR); |
|
87
|
|
|
$stmt->bindValue('transit_status', implode(',', $transitStatus), \PDO::PARAM_STR); |
|
88
|
|
|
$stmt->bindValue('all_status', implode(',', $allStatus), \PDO::PARAM_STR); |
|
89
|
|
|
$stmt->bindValue('provider_id', implode(',', $companies), \PDO::PARAM_STR); |
|
90
|
|
|
$stmt->bindValue('client_id', implode(',', $companies), \PDO::PARAM_STR); |
|
91
|
|
|
|
|
92
|
|
|
$stmt->executeQuery(); |
|
93
|
|
|
} catch (\Exception $e) { |
|
94
|
|
|
throw new \Exception("Erro ao atualizar o estoque: " . $e->getMessage()); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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