|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
|
4
|
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Config; |
|
6
|
|
|
use ControleOnline\Entity\Device; |
|
7
|
|
|
use ControleOnline\Entity\Module; |
|
8
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
|
|
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class ConfigService |
|
13
|
|
|
{ |
|
14
|
|
|
public function __construct( |
|
15
|
|
|
private EntityManagerInterface $manager, |
|
16
|
|
|
private WalletService $walletService |
|
|
|
|
|
|
17
|
|
|
) {} |
|
18
|
|
|
|
|
19
|
|
|
public function getConfig(People $people, $key, $json = false) |
|
20
|
|
|
{ |
|
21
|
|
|
$config = $this->discoveryConfig($people, $key, false); |
|
22
|
|
|
$value = $config ? $config->getConfigValue() : null; |
|
23
|
|
|
return $json ? json_decode($value, true) : $value; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
private function discoveryConfig(People $people, $key, $create = true): ?Config |
|
27
|
|
|
{ |
|
28
|
|
|
$config = $this->manager->getRepository(Config::class)->findOneBy([ |
|
29
|
|
|
'people' => $people, |
|
30
|
|
|
'configKey' => $key |
|
31
|
|
|
]); |
|
32
|
|
|
if ($config) |
|
33
|
|
|
return $config; |
|
34
|
|
|
if ($create) { |
|
35
|
|
|
$config = new Config(); |
|
36
|
|
|
$config->setConfigKey($key); |
|
37
|
|
|
$config->setPeople($people); |
|
38
|
|
|
|
|
39
|
|
|
return $config; |
|
40
|
|
|
} |
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function addConfig( |
|
45
|
|
|
People $people, |
|
46
|
|
|
string $key, |
|
47
|
|
|
$values, |
|
48
|
|
|
Module $module, |
|
49
|
|
|
$visibility = 'private' |
|
50
|
|
|
) { |
|
51
|
|
|
$config = $this->discoveryConfig($people, $key); |
|
52
|
|
|
|
|
53
|
|
|
if (is_array($values)) { |
|
54
|
|
|
$currentValue = json_decode($config->getConfigValue(), true); |
|
55
|
|
|
$newValue = is_array($currentValue) ? $currentValue : []; |
|
56
|
|
|
foreach ($values as $k => $v) { |
|
57
|
|
|
$newValue[$k] = $v; |
|
58
|
|
|
} |
|
59
|
|
|
$config->setConfigValue(json_encode($newValue)); |
|
60
|
|
|
} else { |
|
61
|
|
|
$config->setConfigValue($values); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$config->setVisibility($visibility); |
|
65
|
|
|
$config->setModule($module); |
|
66
|
|
|
$this->manager->persist($config); |
|
67
|
|
|
$this->manager->flush(); |
|
68
|
|
|
return $config; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function discoveryMainConfigs(People $people, Device $device) |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
$this->discoveryCashWallet($people); |
|
74
|
|
|
$this->discoveryWithdrawlWallet($people); |
|
75
|
|
|
$this->discoveryInfinitePayWallet($people); |
|
76
|
|
|
$this->discoveryCieloWallet($people); |
|
77
|
|
|
|
|
78
|
|
|
return $this->getCompanyConfigs($people); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getCompanyConfigs(People $people, $visibility = 'public') |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->manager->getRepository(Config::class)->findBy([ |
|
84
|
|
|
'people' => $people, |
|
85
|
|
|
'visibility' => $visibility |
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
private function discoveryCashWallet(People $company) |
|
90
|
|
|
{ |
|
91
|
|
|
|
|
92
|
|
|
$paymentTypes = [[ |
|
93
|
|
|
'paymentType' => 'Dinheiro', |
|
94
|
|
|
'frequency' => 'single', |
|
95
|
|
|
'installments' => 'single', |
|
96
|
|
|
'paymentCode' => null |
|
97
|
|
|
]]; |
|
98
|
|
|
/** |
|
99
|
|
|
* @todo Module need be variable |
|
100
|
|
|
*/ |
|
101
|
|
|
$module = $this->manager->getRepository(Module::class)->find(8); |
|
102
|
|
|
$wallet = $this->walletService->discoverWallet($company, 'Caixa'); |
|
103
|
|
|
$this->addConfig( |
|
104
|
|
|
$company, |
|
105
|
|
|
'pos-cash-wallet', |
|
106
|
|
|
$wallet->getId(), |
|
107
|
|
|
$module, |
|
108
|
|
|
'private' |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
foreach ($paymentTypes as $paymentType) |
|
112
|
|
|
$this->walletService->discoverWalletPaymentType( |
|
113
|
|
|
$wallet, |
|
114
|
|
|
$this->walletService->discoverPaymentType($company, $paymentType), |
|
115
|
|
|
$paymentType['paymentCode'] |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
private function discoveryWithdrawlWallet(People $company) |
|
120
|
|
|
{ |
|
121
|
|
|
|
|
122
|
|
|
$paymentTypes = [[ |
|
123
|
|
|
'paymentType' => 'Dinheiro', |
|
124
|
|
|
'frequency' => 'single', |
|
125
|
|
|
'installments' => 'single', |
|
126
|
|
|
'paymentCode' => null |
|
127
|
|
|
]]; |
|
128
|
|
|
|
|
129
|
|
|
$this->walletService->discoverWallet($company, 'Reserva'); |
|
130
|
|
|
/** |
|
131
|
|
|
* @todo Module need be variable |
|
132
|
|
|
*/ |
|
133
|
|
|
$module = $this->manager->getRepository(Module::class)->find(8); |
|
134
|
|
|
$wallet = $this->walletService->discoverWallet($company, 'Reserva'); |
|
135
|
|
|
$this->addConfig( |
|
136
|
|
|
$company, |
|
137
|
|
|
'pos-withdrawl-wallet', |
|
138
|
|
|
$wallet->getId(), |
|
139
|
|
|
$module, |
|
140
|
|
|
'private' |
|
141
|
|
|
); |
|
142
|
|
|
foreach ($paymentTypes as $paymentType) |
|
143
|
|
|
$this->walletService->discoverWalletPaymentType( |
|
144
|
|
|
$wallet, |
|
145
|
|
|
$this->walletService->discoverPaymentType($company, $paymentType), |
|
146
|
|
|
$paymentType['paymentCode'] |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
private function discoveryInfinitePayWallet(People $company) |
|
151
|
|
|
{ |
|
152
|
|
|
$paymentTypes = [ |
|
153
|
|
|
[ |
|
154
|
|
|
'paymentType' => 'Débito', |
|
155
|
|
|
'frequency' => 'single', |
|
156
|
|
|
'installments' => 'single', |
|
157
|
|
|
'paymentCode' => 'debit', |
|
158
|
|
|
], |
|
159
|
|
|
[ |
|
160
|
|
|
'paymentType' => 'Crédito à Vista', |
|
161
|
|
|
'frequency' => 'single', |
|
162
|
|
|
'installments' => 'single', |
|
163
|
|
|
'paymentCode' => 'credit', |
|
164
|
|
|
], |
|
165
|
|
|
[ |
|
166
|
|
|
'paymentType' => 'Crédito Parcelado', |
|
167
|
|
|
'frequency' => 'single', |
|
168
|
|
|
'installments' => 'split', |
|
169
|
|
|
'paymentCode' => 'credit', |
|
170
|
|
|
], |
|
171
|
|
|
]; |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @todo Module need be variable |
|
176
|
|
|
*/ |
|
177
|
|
|
$module = $this->manager->getRepository(Module::class)->find(8); |
|
178
|
|
|
$wallet = $this->walletService->discoverWallet($company, 'Infine Pay'); |
|
179
|
|
|
$this->addConfig( |
|
180
|
|
|
$company, |
|
181
|
|
|
'pos-infinite-pay-wallet', |
|
182
|
|
|
$wallet->getId(), |
|
183
|
|
|
$module, |
|
184
|
|
|
'private' |
|
185
|
|
|
); |
|
186
|
|
|
|
|
187
|
|
|
foreach ($paymentTypes as $paymentType) |
|
188
|
|
|
$this->walletService->discoverWalletPaymentType( |
|
189
|
|
|
$wallet, |
|
190
|
|
|
$this->walletService->discoverPaymentType($company, $paymentType), |
|
191
|
|
|
$paymentType['paymentCode'] |
|
192
|
|
|
); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
private function discoveryCieloWallet(People $company) |
|
196
|
|
|
{ |
|
197
|
|
|
|
|
198
|
|
|
$paymentTypes = [ |
|
199
|
|
|
[ |
|
200
|
|
|
'paymentType' => 'Débito', |
|
201
|
|
|
'frequency' => 'single', |
|
202
|
|
|
'installments' => 'single', |
|
203
|
|
|
|
|
204
|
|
|
'paymentCode' => 'DEBITO_AVISTA', |
|
205
|
|
|
], |
|
206
|
|
|
|
|
207
|
|
|
[ |
|
208
|
|
|
'paymentType' => 'Refeição', |
|
209
|
|
|
'frequency' => 'single', |
|
210
|
|
|
'installments' => 'single', |
|
211
|
|
|
|
|
212
|
|
|
'paymentCode' => 'VOUCHER_REFEICAO', |
|
213
|
|
|
], |
|
214
|
|
|
[ |
|
215
|
|
|
'paymentType' => 'Alimentação', |
|
216
|
|
|
'frequency' => 'single', |
|
217
|
|
|
'installments' => 'single', |
|
218
|
|
|
|
|
219
|
|
|
'paymentCode' => 'VOUCHER_ALIMENTACAO', |
|
220
|
|
|
], |
|
221
|
|
|
[ |
|
222
|
|
|
'paymentType' => 'Crédito à Vista', |
|
223
|
|
|
'frequency' => 'single', |
|
224
|
|
|
'installments' => 'single', |
|
225
|
|
|
|
|
226
|
|
|
'paymentCode' => 'CREDITO_AVISTA', |
|
227
|
|
|
], |
|
228
|
|
|
[ |
|
229
|
|
|
'paymentType' => 'PIX', |
|
230
|
|
|
'frequency' => 'single', |
|
231
|
|
|
'installments' => 'single', |
|
232
|
|
|
|
|
233
|
|
|
'paymentCode' => 'PIX', |
|
234
|
|
|
], |
|
235
|
|
|
[ |
|
236
|
|
|
'paymentType' => 'Crédito Parcelado - Cliente', |
|
237
|
|
|
'frequency' => 'single', |
|
238
|
|
|
'installments' => 'split', |
|
239
|
|
|
|
|
240
|
|
|
'paymentCode' => 'CREDITO_PARCELADO_CLIENTE', |
|
241
|
|
|
], |
|
242
|
|
|
[ |
|
243
|
|
|
'paymentType' => 'Crédito Parcelado - Loja', |
|
244
|
|
|
'frequency' => 'single', |
|
245
|
|
|
'installments' => 'split', |
|
246
|
|
|
|
|
247
|
|
|
'paymentCode' => 'CREDITO_PARCELADO_LOJA', |
|
248
|
|
|
], |
|
249
|
|
|
]; |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @todo Module need be variable |
|
253
|
|
|
*/ |
|
254
|
|
|
$module = $this->manager->getRepository(Module::class)->find(8); |
|
255
|
|
|
$wallet = $this->walletService->discoverWallet($company, 'Cielo'); |
|
256
|
|
|
$this->addConfig( |
|
257
|
|
|
$company, |
|
258
|
|
|
'pos-cielo-wallet', |
|
259
|
|
|
$wallet->getId(), |
|
260
|
|
|
$module, |
|
261
|
|
|
'private' |
|
262
|
|
|
); |
|
263
|
|
|
|
|
264
|
|
|
foreach ($paymentTypes as $paymentType) |
|
265
|
|
|
$this->walletService->discoverWalletPaymentType( |
|
266
|
|
|
$wallet, |
|
267
|
|
|
$this->walletService->discoverPaymentType($company, $paymentType), |
|
268
|
|
|
$paymentType['paymentCode'] |
|
269
|
|
|
); |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
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