1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Device; |
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
10
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
|
|
|
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
12
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
13
|
|
|
use ControleOnline\Entity\Spool; |
|
|
|
|
14
|
|
|
use ControleOnline\Service\HydratorService; |
|
|
|
|
15
|
|
|
use ControleOnline\Service\ProductService; |
16
|
|
|
use Exception; |
17
|
|
|
use Symfony\Component\Security\Http\Attribute\Security; |
|
|
|
|
18
|
|
|
use ControleOnline\Entity\Product; |
19
|
|
|
|
20
|
|
|
class ProductController extends AbstractController |
21
|
|
|
{ |
22
|
|
|
public function __construct( |
23
|
|
|
private EntityManagerInterface $manager, |
24
|
|
|
private ProductService $productService, |
25
|
|
|
private HydratorService $hydratorService |
26
|
|
|
|
27
|
|
|
) {} |
28
|
|
|
|
29
|
|
|
#[Route('/products/purchasing-suggestion', name: 'purchasing_suggestion', methods: ['GET'])] |
30
|
|
|
#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_CLIENT')")] |
31
|
|
|
public function getPurchasingSuggestion(Request $request): JsonResponse |
32
|
|
|
{ |
33
|
|
|
$company = $this->manager->getRepository(People::class)->find($request->get('company')); |
34
|
|
|
$data = $this->productService->getPurchasingSuggestion($company); |
35
|
|
|
return new JsonResponse($data); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
#[Route('/products/purchasing-suggestion/print', name: 'purchasing_suggestion_print', methods: ['POST'])] |
39
|
|
|
#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_CLIENT')")] |
40
|
|
|
public function printPurchasingSuggestion(Request $request): JsonResponse |
41
|
|
|
{ |
42
|
|
|
try { |
43
|
|
|
$data = json_decode($request->getContent(), true); |
44
|
|
|
$device = $this->manager->getRepository(Device::class)->findOneBy([ |
45
|
|
|
'device' => $data['device'] |
46
|
|
|
]); |
47
|
|
|
$company = $this->manager->getRepository(People::class)->find($data['people']); |
48
|
|
|
$printData = $this->productService->purchasingSuggestionPrintData($company, $device); |
49
|
|
|
|
50
|
|
|
return new JsonResponse($this->hydratorService->item(Spool::class, $printData->getId(), "spool_item:read"), Response::HTTP_OK); |
51
|
|
|
} catch (Exception $e) { |
52
|
|
|
return new JsonResponse($this->hydratorService->error($e)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
#[Route('/products/inventory', name: 'products_inventory', methods: ['GET'])] |
57
|
|
|
#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_CLIENT')")] |
58
|
|
|
public function getProductsInventory(Request $request): JsonResponse |
59
|
|
|
{ |
60
|
|
|
$company = $this->manager->getRepository(People::class)->find($request->get('company')); |
61
|
|
|
$data = $this->productService->getProductsInventory($company); |
62
|
|
|
return new JsonResponse($data); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
#[Route('/products/inventory/print', name: 'products_inventory_print', methods: ['POST'])] |
66
|
|
|
#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_CLIENT')")] |
67
|
|
|
public function print(Request $request): JsonResponse |
68
|
|
|
{ |
69
|
|
|
try { |
70
|
|
|
$data = json_decode($request->getContent(), true); |
71
|
|
|
$device = $this->manager->getRepository(Device::class)->findOneBy([ |
72
|
|
|
'device' => $data['device'] |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
$company = $this->manager->getRepository(People::class)->find($data['people']); |
76
|
|
|
$printData = $this->productService->productsInventoryPrintData($company, $device); |
77
|
|
|
return new JsonResponse($this->hydratorService->item(Spool::class, $printData->getId(), "spool_item:read"), Response::HTTP_OK); |
78
|
|
|
} catch (Exception $e) { |
79
|
|
|
return new JsonResponse($this->hydratorService->error($e)); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
#[Route('/products/sku', name: 'product_by_sku', methods: ['POST'])] |
84
|
|
|
#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_CLIENT')")] |
85
|
|
|
public function getProductBySku(Request $request): JsonResponse |
86
|
|
|
{ |
87
|
|
|
try { |
88
|
|
|
$data = json_decode($request->getContent(), true); |
89
|
|
|
|
90
|
|
|
if (!isset($data['sku'], $data['people'])) { |
91
|
|
|
return new JsonResponse(['error' => 'Parâmetros obrigatórios: sku e people'], Response::HTTP_BAD_REQUEST); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$sku = (int) ltrim($data['sku'], '0'); |
95
|
|
|
$company = $this->manager->getRepository(People::class)->find($data['people']); |
96
|
|
|
|
97
|
|
|
if (!$company) { |
98
|
|
|
return new JsonResponse(['error' => 'Empresa não encontrada'], Response::HTTP_NOT_FOUND); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$product = $this->manager |
102
|
|
|
->getRepository(Product::class) |
103
|
|
|
->findProductBySkuAsInteger($sku, $company); |
104
|
|
|
|
105
|
|
|
if (!$product) { |
106
|
|
|
return new JsonResponse(['error' => 'Produto não encontrado'], Response::HTTP_NOT_FOUND); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return new JsonResponse( |
110
|
|
|
$this->hydratorService->item(Product::class, $product->getId(), 'product:read'), |
111
|
|
|
Response::HTTP_OK |
112
|
|
|
); |
113
|
|
|
} catch (\Exception $e) { |
114
|
|
|
return new JsonResponse(['error' => $e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
#[Route('/teste', name: 'teste', methods: ['GET'])] |
119
|
|
|
public function teste(): JsonResponse |
120
|
|
|
{ |
121
|
|
|
return new JsonResponse(['message' => 'rota funcionando']); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
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