1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\ExtraFields; |
|
|
|
|
6
|
|
|
use ControleOnline\Entity\Order; |
7
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface as Security; |
|
|
|
|
10
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
|
|
11
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
|
12
|
|
|
use Doctrine\DBAL\Types\Type; |
|
|
|
|
13
|
|
|
|
14
|
|
|
class OrderService |
15
|
|
|
{ |
16
|
|
|
private $request; |
17
|
|
|
|
18
|
|
|
public function __construct( |
19
|
|
|
private EntityManagerInterface $manager, |
20
|
|
|
private Security $security, |
21
|
|
|
private PeopleService $peopleService, |
|
|
|
|
22
|
|
|
private StatusService $statusService, |
|
|
|
|
23
|
|
|
RequestStack $requestStack |
24
|
|
|
) { |
25
|
|
|
$this->request = $requestStack->getCurrentRequest(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function calculateOrderPrice(Order $order) |
29
|
|
|
{ |
30
|
|
|
$sql = 'UPDATE orders O |
31
|
|
|
JOIN ( |
32
|
|
|
SELECT order_id, IFNULL(SUM(total), 0) AS new_total |
33
|
|
|
FROM order_product |
34
|
|
|
WHERE order_product_id IS NULL |
35
|
|
|
GROUP BY order_id |
36
|
|
|
) AS subquery ON O.id = subquery.order_id |
37
|
|
|
SET O.price = IFNULL(subquery.new_total, 0) |
38
|
|
|
WHERE O.id = :order_id; |
39
|
|
|
'; |
40
|
|
|
$connection = $this->manager->getConnection(); |
41
|
|
|
$statement = $connection->prepare($sql); |
42
|
|
|
$statement->bindValue(':order_id', $order->getId(), Type::getType('integer')); |
43
|
|
|
$statement->executeStatement(); |
44
|
|
|
|
45
|
|
|
return $order; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function calculateGroupProductPrice(Order $order) |
49
|
|
|
{ |
50
|
|
|
$sql = 'UPDATE order_product OPO |
51
|
|
|
JOIN ( |
52
|
|
|
SELECT |
53
|
|
|
OP.order_product_id, |
54
|
|
|
(CASE |
55
|
|
|
WHEN PG.price_calculation = "biggest" THEN MAX(PGP.price) |
56
|
|
|
WHEN PG.price_calculation = "sum" THEN SUM(PGP.price) |
57
|
|
|
WHEN PG.price_calculation = "average" THEN AVG(PGP.price) |
58
|
|
|
WHEN PG.price_calculation = "free" THEN 0 |
59
|
|
|
ELSE NULL |
60
|
|
|
END) AS calculated_price |
61
|
|
|
FROM order_product OP |
62
|
|
|
INNER JOIN product_group PG ON OP.product_group_id = PG.id |
63
|
|
|
INNER JOIN product_group_product PGP ON PGP.product_group_id = OP.product_group_id AND PGP.product_child_id = OP.product_id |
64
|
|
|
INNER JOIN product P ON P.id = OP.product_id |
65
|
|
|
WHERE OP.parent_product_id IS NOT NULL AND OP.order_id = :order_id |
66
|
|
|
GROUP BY OP.order_product_id, PG.id |
67
|
|
|
) AS subquery ON OPO.id = subquery.order_product_id |
68
|
|
|
SET OPO.price = subquery.calculated_price, |
69
|
|
|
OPO.total = (subquery.calculated_price * OPO.quantity) |
70
|
|
|
'; |
71
|
|
|
$connection = $this->manager->getConnection(); |
72
|
|
|
$statement = $connection->prepare($sql); |
73
|
|
|
$statement->bindValue(':order_id', $order->getId(), Type::getType('integer')); |
74
|
|
|
$statement->executeStatement(); |
75
|
|
|
|
76
|
|
|
return $order; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function createOrder(People $receiver, People $payer, $app) |
80
|
|
|
{ |
81
|
|
|
|
82
|
|
|
$status = $this->statusService->discoveryStatus( |
83
|
|
|
'pending', |
84
|
|
|
'waiting payment', |
85
|
|
|
'order' |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$order = new Order(); |
89
|
|
|
$order->setProvider($receiver); |
90
|
|
|
$order->setClient($payer); |
91
|
|
|
$order->setPayer($payer); |
92
|
|
|
$order->setOrderType('sale'); |
93
|
|
|
$order->setStatus($status); |
94
|
|
|
$order->setApp($app); |
95
|
|
|
|
96
|
|
|
$this->manager->persist($order); |
97
|
|
|
$this->manager->flush(); |
98
|
|
|
return $order; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$companies = $this->peopleService->getMyCompanies(); |
104
|
|
|
|
105
|
|
|
if ($invoice = $this->request->query->get('invoiceId', null)) { |
106
|
|
|
$queryBuilder->join(sprintf('%s.invoice', $rootAlias), 'OrderInvoice'); |
107
|
|
|
$queryBuilder->andWhere(sprintf('OrderInvoice.invoice IN(:invoice)', $rootAlias, $rootAlias)); |
108
|
|
|
$queryBuilder->setParameter('invoice', $invoice); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$queryBuilder->andWhere(sprintf('%s.client IN(:companies) OR %s.provider IN(:companies)', $rootAlias, $rootAlias)); |
112
|
|
|
$queryBuilder->setParameter('companies', $companies); |
113
|
|
|
|
114
|
|
|
if ($provider = $this->request->query->get('provider', null)) { |
115
|
|
|
$queryBuilder->andWhere(sprintf('%s.provider IN(:provider)', $rootAlias)); |
116
|
|
|
$queryBuilder->setParameter('provider', preg_replace("/[^0-9]/", "", $provider)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if ($client = $this->request->query->get('client', null)) { |
120
|
|
|
$queryBuilder->andWhere(sprintf('%s.client IN(:client)', $rootAlias)); |
121
|
|
|
$queryBuilder->setParameter('client', preg_replace("/[^0-9]/", "", $client)); |
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