1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Order; |
6
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
7
|
|
|
use ControleOnline\Entity\Status; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
10
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
|
|
11
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class OrderService |
14
|
|
|
{ |
15
|
|
|
private $request; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
private EntityManagerInterface $manager, |
19
|
|
|
private Security $security, |
20
|
|
|
private PeopleService $PeopleService, |
|
|
|
|
21
|
|
|
RequestStack $requestStack |
22
|
|
|
|
23
|
|
|
) { |
24
|
|
|
$this->request = $requestStack->getCurrentRequest(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function calculateOrderPrice(Order $order) |
28
|
|
|
{ |
29
|
|
|
$sql = 'SELECT SUM(total) as total FROM order_product WHERE order_id = :order_id'; |
30
|
|
|
$connection = $this->manager->getConnection(); |
31
|
|
|
$statement = $connection->prepare($sql); |
32
|
|
|
$statement->execute(['order_id' => $order->getId()]); |
33
|
|
|
|
34
|
|
|
$result = $statement->fetchOne(); |
35
|
|
|
$order->setPrice($result); |
36
|
|
|
$this->manager->persist($order); |
37
|
|
|
$this->manager->flush(); |
38
|
|
|
return $order; |
39
|
|
|
} |
40
|
|
|
public function createOrder(People $receiver, People $payer) |
41
|
|
|
{ |
42
|
|
|
$status = $this->manager->getRepository(Status::class)->findOneBy([ |
43
|
|
|
'status' => 'waiting payment', |
44
|
|
|
'context' => 'order' |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
$order = new Order(); |
48
|
|
|
$order->setProvider($receiver); |
49
|
|
|
$order->setClient($payer); |
50
|
|
|
$order->setPayer($payer); |
51
|
|
|
$order->setOrderType('sale'); |
52
|
|
|
$order->setStatus($status); |
53
|
|
|
$order->setApp('Asaas'); |
54
|
|
|
|
55
|
|
|
$this->manager->persist($order); |
56
|
|
|
$this->manager->flush(); |
57
|
|
|
return $order; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function secutiryFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$companies = $this->PeopleService->getMyCompanies(); |
63
|
|
|
|
64
|
|
|
if ($invoice = $this->request->query->get('invoiceId', null)) { |
65
|
|
|
$queryBuilder->join(sprintf('%s.invoice', $rootAlias), 'OrderInvoice'); |
66
|
|
|
$queryBuilder->andWhere(sprintf('OrderInvoice.invoice IN(:invoice)', $rootAlias, $rootAlias)); |
67
|
|
|
$queryBuilder->setParameter('invoice', $invoice); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$queryBuilder->andWhere(sprintf('%s.client IN(:companies) OR %s.provider IN(:companies)', $rootAlias, $rootAlias)); |
71
|
|
|
$queryBuilder->setParameter('companies', $companies); |
72
|
|
|
|
73
|
|
|
if ($provider = $this->request->query->get('provider', null)) { |
74
|
|
|
$queryBuilder->andWhere(sprintf('%s.provider IN(:provider)', $rootAlias)); |
75
|
|
|
$queryBuilder->setParameter('provider', preg_replace("/[^0-9]/", "", $provider)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ($client = $this->request->query->get('client', null)) { |
79
|
|
|
$queryBuilder->andWhere(sprintf('%s.client IN(:client)', $rootAlias)); |
80
|
|
|
$queryBuilder->setParameter('client', preg_replace("/[^0-9]/", "", $client)); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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