1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (C) 2020 Jan Böhmer |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Affero General Public License as published |
7
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU Affero General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace App\Controller\Admin; |
20
|
|
|
|
21
|
|
|
use App\Admin\Field\VichyFileField; |
22
|
|
|
use App\Admin\Filter\ConfirmedFilter; |
23
|
|
|
use App\Admin\Filter\DepartmentTypeFilter; |
24
|
|
|
use App\Admin\Filter\MoneyAmountFilter; |
25
|
|
|
use App\Entity\PaymentOrder; |
26
|
|
|
use App\Helpers\ZIPBinaryFileResponseFacade; |
27
|
|
|
use App\Services\EmailConfirmation\ConfirmationEmailSender; |
28
|
|
|
use App\Services\PaymentOrderMailLinkGenerator; |
29
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
30
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; |
31
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; |
32
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets; |
33
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
34
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; |
35
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; |
36
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; |
37
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto; |
38
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; |
39
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField; |
40
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField; |
41
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; |
42
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; |
43
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; |
44
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; |
45
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField; |
46
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; |
47
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField; |
48
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
49
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter; |
50
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Filter\DateTimeFilter; |
51
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter; |
52
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Filter\TextFilter; |
53
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry; |
54
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; |
55
|
|
|
use RuntimeException; |
56
|
|
|
use Symfony\Component\HttpFoundation\Response; |
57
|
|
|
|
58
|
|
|
class PaymentOrderCrudController extends AbstractCrudController |
59
|
|
|
{ |
60
|
|
|
private $mailToGenerator; |
61
|
|
|
private $dashboardControllerRegistry; |
62
|
|
|
private $confirmationEmailSender; |
63
|
|
|
private $adminURLGenerator; |
64
|
|
|
private $entityManager; |
65
|
|
|
|
66
|
|
|
public function __construct(PaymentOrderMailLinkGenerator $mailToGenerator, |
67
|
|
|
DashboardControllerRegistry $dashboardControllerRegistry, EntityManagerInterface $entityManager, |
68
|
|
|
ConfirmationEmailSender $confirmationEmailSender, AdminUrlGenerator $adminUrlGenerator) |
69
|
|
|
{ |
70
|
|
|
$this->mailToGenerator = $mailToGenerator; |
71
|
|
|
$this->dashboardControllerRegistry = $dashboardControllerRegistry; |
72
|
|
|
$this->confirmationEmailSender = $confirmationEmailSender; |
73
|
|
|
$this->adminURLGenerator = $adminUrlGenerator; |
74
|
|
|
$this->entityManager = $entityManager; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public static function getEntityFqcn(): string |
78
|
|
|
{ |
79
|
|
|
return PaymentOrder::class; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function sepaXMLExport(BatchActionDto $batchActionDto): Response |
83
|
|
|
{ |
84
|
|
|
return $this->redirect( |
85
|
|
|
$this->adminURLGenerator->setRoute('payment_order_export') |
86
|
|
|
->set('ids', implode(',', $batchActionDto->getEntityIds())) |
87
|
|
|
->generateUrl() |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function referencesExport(BatchActionDto $batchActionDto): Response |
92
|
|
|
{ |
93
|
|
|
$this->denyAccessUnlessGranted('ROLE_SHOW_PAYMENT_ORDERS'); |
94
|
|
|
|
95
|
|
|
$entityManager = $this->getDoctrine()->getManagerForClass($batchActionDto->getEntityFqcn()); |
96
|
|
|
|
97
|
|
|
$data = []; |
98
|
|
|
foreach ($batchActionDto->getEntityIds() as $id) { |
99
|
|
|
/** @var PaymentOrder $payment_order */ |
100
|
|
|
$payment_order = $entityManager->find($batchActionDto->getEntityFqcn(), $id); |
101
|
|
|
$path = $payment_order->getReferencesFile() |
102
|
|
|
->getPathname(); |
103
|
|
|
$extension = $payment_order->getReferencesFile() |
104
|
|
|
->getExtension(); |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/* |
109
|
|
|
if (empty($payment_order->getDepartment()->getReferencesExportPrefix())) { |
110
|
|
|
$prefix = ''; |
111
|
|
|
} else { |
112
|
|
|
$prefix = $payment_order->getDepartment() |
113
|
|
|
->getReferencesExportPrefix().'/'; |
114
|
|
|
}*/ |
115
|
|
|
|
116
|
|
|
$prefix = ''; |
117
|
|
|
|
118
|
|
|
if ($payment_order->getDepartment() !== null && $payment_order->getDepartment()->getBankAccount() !== null) { |
119
|
|
|
//First folder for each bank account |
120
|
|
|
$prefix = $payment_order->getDepartment()->getBankAccount()->getName() . '/'; |
121
|
|
|
|
122
|
|
|
//A sub folder for each department |
123
|
|
|
$prefix .= $payment_order->getDepartment()->getName() . '/'; |
124
|
|
|
} elseif ($payment_order->getDepartment() !== null) { |
125
|
|
|
$prefix = $payment_order->getDepartment()->getName() . '/'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$project_name = $payment_order->getProjectName(); |
129
|
|
|
$project_name = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $project_name); |
130
|
|
|
$project_name = mb_ereg_replace("([\.]{2,})", '', $project_name); |
131
|
|
|
//Format: "ZA000001 Project Name.pdf" |
132
|
|
|
$filename = $prefix.$payment_order->getIDString().' '.$project_name.'.'.$extension; |
133
|
|
|
|
134
|
|
|
$data[$filename] = $path; |
135
|
|
|
|
136
|
|
|
if ($this->isGranted('ROLE_EXPORT_PAYMENT_ORDERS_REFERENCES')) { |
137
|
|
|
//Set exported status |
138
|
|
|
$payment_order->setReferencesExported(true); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if ($this->isGranted('ROLE_EXPORT_PAYMENT_ORDERS_REFERENCES')) { |
143
|
|
|
//Flush changes |
144
|
|
|
$this->entityManager->flush(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return ZIPBinaryFileResponseFacade::createZIPResponseFromFiles( |
148
|
|
|
$data, |
149
|
|
|
'Belege_'.date('Y-m-d_H-i-s').'.zip'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function configureCrud(Crud $crud): Crud |
153
|
|
|
{ |
154
|
|
|
return $crud |
155
|
|
|
->setEntityLabelInSingular('payment_order.label') |
156
|
|
|
->setEntityLabelInPlural('payment_order.labelp') |
157
|
|
|
->setSearchFields(['id', 'first_name', 'last_name', 'project_name', 'funding_id', 'contact_email', 'amount', 'comment', 'bank_info.account_owner', 'bank_info.street', 'bank_info.zip_code', 'bank_info.city', 'bank_info.iban', 'bank_info.bic', 'bank_info.bank_name', 'bank_info.reference']); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function configureFilters(Filters $filters): Filters |
161
|
|
|
{ |
162
|
|
|
return $filters |
163
|
|
|
->add(EntityFilter::new('department', 'payment_order.department.label')) |
164
|
|
|
->add(DepartmentTypeFilter::new('department_type', 'payment_order.department_type.label')) |
165
|
|
|
->add(MoneyAmountFilter::new('amount', 'payment_order.amount.label')) |
166
|
|
|
->add(BooleanFilter::new('factually_correct', 'payment_order.factually_correct.label')) |
167
|
|
|
->add(BooleanFilter::new('exported', 'payment_order.exported.label')) |
168
|
|
|
->add(BooleanFilter::new('mathematically_correct', 'payment_order.mathematically_correct.label')) |
169
|
|
|
->add(ConfirmedFilter::new('confirmed', 'payment_order.confirmed.label')) |
170
|
|
|
->add(TextFilter::new('funding_id', 'payment_order.funding_id.label')) |
171
|
|
|
->add(DateTimeFilter::new('creation_date', 'creation_date')) |
172
|
|
|
->add(DateTimeFilter::new('last_modified', 'last_modified')) |
173
|
|
|
->add(DateTimeFilter::new('booking_date', 'payment_order.booking_date.label')) |
174
|
|
|
->add(BooleanFilter::new('references_exported', 'payment_order.references_exported.label')) |
175
|
|
|
; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Handler for action if user click "resend" button in admin page. |
180
|
|
|
*/ |
181
|
|
|
public function resendConfirmationEmail(AdminContext $context): Response |
182
|
|
|
{ |
183
|
|
|
$this->denyAccessUnlessGranted('ROLE_EDIT_PAYMENT_ORDERS'); |
184
|
|
|
$payment_order = $context->getEntity() |
185
|
|
|
->getInstance(); |
186
|
|
|
|
187
|
|
|
$this->confirmationEmailSender->resendConfirmations($payment_order); |
188
|
|
|
|
189
|
|
|
$this->addFlash('success', 'payment_order.action.resend_confirmation.success'); |
190
|
|
|
|
191
|
|
|
return $this->redirect($context->getReferrer() ?? '/admin'); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Handler for action if user click "check mathematically" button in admin page. |
196
|
|
|
*/ |
197
|
|
|
public function checkMathematicallyCorrect(AdminContext $context): Response |
198
|
|
|
{ |
199
|
|
|
$this->denyAccessUnlessGranted('ROLE_PO_MATHEMATICALLY'); |
200
|
|
|
|
201
|
|
|
/** @var PaymentOrder $payment_order */ |
202
|
|
|
$payment_order = $context->getEntity() |
203
|
|
|
->getInstance(); |
204
|
|
|
$payment_order->setMathematicallyCorrect(true); |
205
|
|
|
$this->entityManager->flush(); |
206
|
|
|
$this->addFlash('success', 'payment_order.action.mathematically_correct.success'); |
207
|
|
|
|
208
|
|
|
return $this->redirect($context->getReferrer() ?? '/admin'); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Handler for action if user click "check factually" button in admin page. |
213
|
|
|
*/ |
214
|
|
|
public function checkFactuallyCorrect(AdminContext $context): Response |
215
|
|
|
{ |
216
|
|
|
$this->denyAccessUnlessGranted('ROLE_PO_FACTUALLY'); |
217
|
|
|
|
218
|
|
|
/** @var PaymentOrder $payment_order */ |
219
|
|
|
$payment_order = $context->getEntity() |
220
|
|
|
->getInstance(); |
221
|
|
|
$payment_order->setFactuallyCorrect(true); |
222
|
|
|
$this->entityManager->flush(); |
223
|
|
|
$this->addFlash('success', 'payment_order.action.factually_correct.success'); |
224
|
|
|
|
225
|
|
|
return $this->redirect($context->getReferrer() ?? '/admin'); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function configureAssets(Assets $assets): Assets |
229
|
|
|
{ |
230
|
|
|
return $assets |
231
|
|
|
->addJsFile('js/admin/apply_row_color.js'); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function configureActions(Actions $actions): Actions |
235
|
|
|
{ |
236
|
|
|
if ($this->isGranted('ROLE_EXPORT_PAYMENT_ORDERS')) { |
237
|
|
|
// Button with text and icon |
238
|
|
|
$actions->addBatchAction(Action::new('sepaXMLExport', 'payment_order.action.export_xml') |
239
|
|
|
->linkToCrudAction('sepaXMLExport') |
240
|
|
|
->addCssClass('btn btn-primary') |
241
|
|
|
->setHtmlAttributes([ |
242
|
|
|
/*'onclick' => '$("#modal-batch-action").on("shown.bs.modal", function(e){ |
243
|
|
|
$("#modal-batch-action").addClass("d-none"); |
244
|
|
|
$("#modal-batch-action-button").trigger("click"); |
245
|
|
|
});'*/ |
246
|
|
|
//Very ugly hack to skip the confirmation dialog. |
247
|
|
|
'onclick' => ' |
248
|
|
|
let $actionElement = $(this); |
249
|
|
|
$("#modal-batch-action").addClass("d-none"); |
250
|
|
|
$actionElement.off("click"); |
251
|
|
|
|
252
|
|
|
const actionName = $actionElement.attr("data-action-name"); |
253
|
|
|
const selectedItems = $("input[type=\'checkbox\'].form-batch-checkbox:checked"); |
254
|
|
|
|
255
|
|
|
$form = document.createElement("form"); |
256
|
|
|
$form.setAttribute("action", $actionElement.attr("data-action-url")); |
257
|
|
|
$form.setAttribute("method", "POST"); |
258
|
|
|
|
259
|
|
|
$actionNameInput = document.createElement("input"); |
260
|
|
|
$actionNameInput.setAttribute("type", "hidden"); |
261
|
|
|
$actionNameInput.setAttribute("name", "batchActionName"); |
262
|
|
|
$actionNameInput.setAttribute("value", $actionElement.attr("data-action-name")); |
263
|
|
|
$form.appendChild($actionNameInput); |
264
|
|
|
|
265
|
|
|
$entityFqcnInput = document.createElement("input"); |
266
|
|
|
$entityFqcnInput.setAttribute("type", "hidden"); |
267
|
|
|
$entityFqcnInput.setAttribute("name", "entityFqcn"); |
268
|
|
|
$entityFqcnInput.setAttribute("value", $actionElement.attr("data-entity-fqcn")); |
269
|
|
|
$form.appendChild($entityFqcnInput); |
270
|
|
|
|
271
|
|
|
$actionUrlInput = document.createElement("input"); |
272
|
|
|
$actionUrlInput.setAttribute("type", "hidden"); |
273
|
|
|
$actionUrlInput.setAttribute("name", "batchActionUrl"); |
274
|
|
|
$actionUrlInput.setAttribute("value", $actionElement.attr("data-action-url")); |
275
|
|
|
$form.appendChild($actionUrlInput); |
276
|
|
|
|
277
|
|
|
$csrfTokenInput = document.createElement("input"); |
278
|
|
|
$csrfTokenInput.setAttribute("type", "hidden"); |
279
|
|
|
$csrfTokenInput.setAttribute("name", "batchActionCsrfToken"); |
280
|
|
|
$csrfTokenInput.setAttribute("value", $actionElement.attr("data-action-csrf-token")); |
281
|
|
|
$form.appendChild($csrfTokenInput); |
282
|
|
|
|
283
|
|
|
selectedItems.each((i, item) => { |
284
|
|
|
$entityIdInput = document.createElement("input"); |
285
|
|
|
$entityIdInput.setAttribute("type", "hidden"); |
286
|
|
|
$entityIdInput.setAttribute("name", `batchActionEntityIds[${i}]`); |
287
|
|
|
$entityIdInput.setAttribute("value", item.value); |
288
|
|
|
$form.appendChild($entityIdInput); |
289
|
|
|
}); |
290
|
|
|
|
291
|
|
|
document.body.appendChild($form); |
292
|
|
|
|
293
|
|
|
//modalTitle.text(titleContentWithPlaceholders); |
294
|
|
|
$form.submit(); |
295
|
|
|
' |
296
|
|
|
]) |
297
|
|
|
->setIcon('fas fa-file-export') |
298
|
|
|
); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
//if ($this->isGranted('ROLE_EXPORT_PAYMENT_ORDERS_REFERENCES')) { |
302
|
|
|
$actions->addBatchAction(Action::new('referencesExport', 'payment.order.action.export.export_references') |
303
|
|
|
->linkToCrudAction('referencesExport') |
304
|
|
|
->addCssClass('btn btn-primary') |
305
|
|
|
->setIcon('fas fa-file-invoice') |
306
|
|
|
); |
307
|
|
|
//} |
308
|
|
|
|
309
|
|
|
$actions->setPermissions([ |
310
|
|
|
Action::INDEX => 'ROLE_SHOW_PAYMENT_ORDERS', |
311
|
|
|
Action::DETAIL => 'ROLE_SHOW_PAYMENT_ORDERS', |
312
|
|
|
Action::EDIT => 'ROLE_EDIT_PAYMENT_ORDERS', |
313
|
|
|
Action::DELETE => 'ROLE_EDIT_PAYMENT_ORDERS', |
314
|
|
|
Action::NEW => 'ROLE_EDIT_PAYMENT_ORDERS', |
315
|
|
|
]); |
316
|
|
|
|
317
|
|
|
$emailAction = Action::new('sendEmail', 'payment_order.action.email', 'fas fa-envelope') |
318
|
|
|
->linkToUrl(function (PaymentOrder $paymentOrder) { |
319
|
|
|
return $this->mailToGenerator->generateContactMailLink($paymentOrder); |
320
|
|
|
}) |
321
|
|
|
->setCssClass('text-dark'); |
322
|
|
|
|
323
|
|
|
//Hide action if no contact emails are associated with department |
324
|
|
|
$emailAction->displayIf(function (PaymentOrder $paymentOrder) { |
325
|
|
|
return null !== $this->mailToGenerator->generateContactMailLink($paymentOrder); |
326
|
|
|
}); |
327
|
|
|
|
328
|
|
|
$hhv_action = Action::new('contactHHV', 'payment_order.action.contact_hhv', 'fas fa-comment-dots') |
329
|
|
|
->linkToUrl(function (PaymentOrder $paymentOrder) { |
330
|
|
|
return $this->mailToGenerator->getHHVMailLink($paymentOrder); |
331
|
|
|
}) |
332
|
|
|
->setCssClass('mr-2 text-dark'); |
333
|
|
|
|
334
|
|
|
$resend_confirmation_action = Action::new('resendConfirmation', 'payment_order.action.resend_confirmation', 'fas fa-redo') |
335
|
|
|
->linkToCrudAction('resendConfirmationEmail') |
336
|
|
|
->displayIf(function (PaymentOrder $paymentOrder) { |
337
|
|
|
return $this->isGranted('ROLE_EDIT_PAYMENT_ORDERS') && !$paymentOrder->isConfirmed(); |
338
|
|
|
}) |
339
|
|
|
->setCssClass('mr-2 text-dark'); |
340
|
|
|
|
341
|
|
|
$mathematically_correct_action = Action::new('mathematicallyCorrect', 'payment_order.action.mathematically_correct', 'fas fa-check') |
342
|
|
|
->linkToCrudAction('checkMathematicallyCorrect') |
343
|
|
|
->displayIf(function (PaymentOrder $paymentOrder) { |
344
|
|
|
return $this->isGranted('ROLE_PO_MATHEMATICALLY') |
345
|
|
|
&& $paymentOrder->isConfirmed() |
346
|
|
|
&& !$paymentOrder->isMathematicallyCorrect(); |
347
|
|
|
}) |
348
|
|
|
->setCssClass('mr-2 btn btn-success'); |
349
|
|
|
|
350
|
|
|
$factually_correct_action = Action::new('factuallyCorrect', 'payment_order.action.factually_correct', 'fas fa-check') |
351
|
|
|
->linkToCrudAction('checkFactuallyCorrect') |
352
|
|
|
->displayIf(function (PaymentOrder $paymentOrder) { |
353
|
|
|
return $this->isGranted('ROLE_PO_FACTUALLY') |
354
|
|
|
&& $paymentOrder->isConfirmed() |
355
|
|
|
&& !$paymentOrder->isFactuallyCorrect() |
356
|
|
|
&& $paymentOrder->isMathematicallyCorrect(); |
357
|
|
|
}) |
358
|
|
|
->setCssClass('mr-2 btn btn-success'); |
359
|
|
|
|
360
|
|
|
$manual_confirmation = Action::new('manual_confirmation', 'payment_order.action.manual_confirmation', 'fas fa-exclamation-triangle') |
361
|
|
|
->setCssClass('mr-1 text-dark') |
362
|
|
|
->linkToRoute('payment_order_manual_confirm', function (PaymentOrder $paymentOrder) { |
363
|
|
|
return [ |
364
|
|
|
'id' => $paymentOrder->getId(), |
365
|
|
|
]; |
366
|
|
|
}) |
367
|
|
|
->displayIf(function (PaymentOrder $paymentOrder) { |
368
|
|
|
return $this->isGranted('ROLE_MANUAL_CONFIRMATION') |
369
|
|
|
&& !$paymentOrder->isConfirmed(); |
370
|
|
|
}); |
371
|
|
|
|
372
|
|
|
$actions->add(Crud::PAGE_EDIT, $emailAction); |
373
|
|
|
$actions->add(Crud::PAGE_DETAIL, $emailAction); |
374
|
|
|
|
375
|
|
|
$actions->add(Crud::PAGE_EDIT, $hhv_action); |
376
|
|
|
$actions->add(Crud::PAGE_DETAIL, $hhv_action); |
377
|
|
|
|
378
|
|
|
$actions->disable(Crud::PAGE_NEW); |
379
|
|
|
|
380
|
|
|
if(!$this->isGranted('ROLE_EDIT_PAYMENT_ORDERS')) { |
381
|
|
|
$actions->disable('batchDelete'); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
$actions->add(Crud::PAGE_DETAIL, $resend_confirmation_action); |
385
|
|
|
$actions->add(Crud::PAGE_EDIT, $resend_confirmation_action); |
386
|
|
|
|
387
|
|
|
$actions->add(Crud::PAGE_DETAIL, $mathematically_correct_action); |
388
|
|
|
$actions->add(Crud::PAGE_DETAIL, $factually_correct_action); |
389
|
|
|
|
390
|
|
|
$actions->add(Crud::PAGE_DETAIL, $manual_confirmation); |
391
|
|
|
$actions->add(Crud::PAGE_EDIT, $manual_confirmation); |
392
|
|
|
|
393
|
|
|
return $actions->add(Crud::PAGE_INDEX, Action::DETAIL); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
public function configureFields(string $pageName): iterable |
397
|
|
|
{ |
398
|
|
|
//Documents |
399
|
|
|
$documentsPanel = FormField::addPanel('payment_order.group.documents'); |
400
|
|
|
$printed_form = VichyFileField::new('printed_form_file', 'payment_order.printed_form.label'); |
401
|
|
|
$references = VichyFileField::new('references_file', 'payment_order.references.label'); |
402
|
|
|
|
403
|
|
|
//Basic informations |
404
|
|
|
$infoPanel = FormField::addPanel('payment_order.group.info'); |
405
|
|
|
$id = IntegerField::new('id', 'payment_order.id.label'); |
406
|
|
|
$firstName = TextField::new('first_name', 'payment_order.first_name.label'); |
407
|
|
|
$lastName = TextField::new('last_name', 'payment_order.last_name.label'); |
408
|
|
|
$contact_email = EmailField::new('contact_email', 'payment_order.contact_email.label') |
409
|
|
|
->setFormTypeOption('empty_data', '') |
410
|
|
|
->setRequired(false); |
411
|
|
|
|
412
|
|
|
if (Crud::PAGE_INDEX === $pageName) { |
413
|
|
|
$tmp = 'payment_order.department.label_short'; |
414
|
|
|
} else { |
415
|
|
|
$tmp = 'payment_order.department.label'; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
$department = AssociationField::new('department', $tmp) |
419
|
|
|
->setFormTypeOption('attr', [ |
420
|
|
|
'data-widget' => 'select2', |
421
|
|
|
]); |
422
|
|
|
|
423
|
|
|
$amount = MoneyField::new('amount', 'payment_order.amount.label') |
424
|
|
|
->setCurrency('EUR') |
425
|
|
|
->setStoredAsCents(true); |
426
|
|
|
$projectName = TextField::new('project_name', 'payment_order.project_name.label'); |
427
|
|
|
$funding_id = TextField::new('funding_id', 'payment_order.funding_id.label') |
428
|
|
|
->setRequired(false) |
429
|
|
|
->setFormTypeOption('empty_data', ''); |
430
|
|
|
//Use short name for index |
431
|
|
|
$funding_id_index = TextField::new('funding_id', 'payment_order.funding_id.label_short') |
432
|
|
|
->setHelp('payment_order.funding_id.label'); |
433
|
|
|
$fsr_kom = BooleanField::new('fsr_kom_resolution', 'payment_order.fsr_kom.label') |
434
|
|
|
->setRequired(false); |
435
|
|
|
$resolution_date = DateField::new('resolution_date', 'payment_order.resolution_date.label') |
436
|
|
|
->setRequired(false); |
437
|
|
|
$comment = TextEditorField::new('comment', 'payment_order.comment.label') |
438
|
|
|
->setRequired(false) |
439
|
|
|
->setFormTypeOption('empty_data', ''); |
440
|
|
|
$lastModified = DateTimeField::new('last_modified', 'last_modified'); |
441
|
|
|
$creationDate = DateTimeField::new('creation_date', 'creation_date') |
442
|
|
|
->setTemplatePath('admin/field/datetime_overdue_hint.html.twig'); |
443
|
|
|
//$creationDate = TextField::new('creation_date', 'creation_date'); |
444
|
|
|
|
445
|
|
|
//Status informations |
446
|
|
|
$statusPanel = FormField::addPanel('payment_order.group.status'); |
447
|
|
|
$mathematicallyCorrect = BooleanField::new('mathematically_correct', 'payment_order.mathematically_correct.label') |
448
|
|
|
->setHelp('payment_order.mathematically_correct.help') |
449
|
|
|
//Disable fields (and show coloumns as read only tags) if user does not have proper permissions to change |
450
|
|
|
//factually and mathematically correct status |
451
|
|
|
->setFormTypeOption('disabled', !$this->isGranted('ROLE_PO_MATHEMATICALLY')) |
452
|
|
|
->renderAsSwitch($this->isGranted('ROLE_PO_MATHEMATICALLY')); |
453
|
|
|
$exported = BooleanField::new('exported', 'payment_order.exported.label') |
454
|
|
|
->setHelp('payment_order.exported.help'); |
455
|
|
|
$factuallyCorrect = BooleanField::new('factually_correct', 'payment_order.factually_correct.label') |
456
|
|
|
->setHelp('payment_order.factually_correct.help') |
457
|
|
|
->setFormTypeOption('disabled', !$this->isGranted('ROLE_PO_FACTUALLY')) |
458
|
|
|
->renderAsSwitch($this->isGranted('ROLE_PO_FACTUALLY')); |
459
|
|
|
$booking_date = DateTimeField::new('booking_date', 'payment_order.booking_date.label'); |
460
|
|
|
$confirmed_1 = DateTimeField::new('confirm1_timestamp', 'payment_order.confirmed_1.label'); |
461
|
|
|
$confirmed_2 = DateTimeField::new('confirm2_timestamp', 'payment_order.confirmed_2.label'); |
462
|
|
|
$references_exported = BooleanField::new('references_exported', 'payment_order.references_exported.label'); |
463
|
|
|
|
464
|
|
|
//Payee informations |
465
|
|
|
$payeePanel = FormField::addPanel('payment_order.group.receiver'); |
466
|
|
|
$bankInfoAccountOwner = TextField::new('bank_info.account_owner', 'bank_info.account_owner.label'); |
467
|
|
|
$bankInfoStreet = TextField::new('bank_info.street', 'bank_info.street.label'); |
468
|
|
|
$bankInfoZipCode = TextField::new('bank_info.zip_code', 'bank_info.zip_code.label'); |
469
|
|
|
$bankInfoCity = TextField::new('bank_info.city', 'bank_info.city.label'); |
470
|
|
|
|
471
|
|
|
//Payee bank account infos |
472
|
|
|
$bankInfoPanel = FormField::addPanel('payment_order.group.bank_info'); |
473
|
|
|
$bankInfoIban = TextField::new('bank_info.iban', 'bank_info.iban.label'); |
474
|
|
|
$bankInfoBic = TextField::new('bank_info.bic', 'bank_info.bic.label') |
475
|
|
|
->setRequired(false) |
476
|
|
|
->setFormTypeOption('empty_data', ''); |
477
|
|
|
$bankInfoBankName = TextField::new('bank_info.bank_name', 'bank_info.bank_name.label'); |
478
|
|
|
$bankInfoReference = TextField::new('bank_info.reference', 'bank_info.reference.label') |
479
|
|
|
->setRequired(false) |
480
|
|
|
->setFormTypeOption('empty_data', ''); |
481
|
|
|
|
482
|
|
|
if (Crud::PAGE_INDEX === $pageName) { |
483
|
|
|
return [$id, $projectName, $department, $amount, $mathematicallyCorrect, $factuallyCorrect, $funding_id_index, $creationDate]; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
if (Crud::PAGE_DETAIL === $pageName) { |
487
|
|
|
return [ |
488
|
|
|
//Documents section |
489
|
|
|
$documentsPanel, |
490
|
|
|
$printed_form, |
491
|
|
|
$references, |
492
|
|
|
//Basic informations |
493
|
|
|
$infoPanel, |
494
|
|
|
$id, |
495
|
|
|
$firstName, |
496
|
|
|
$lastName, |
497
|
|
|
$contact_email, |
498
|
|
|
$projectName, |
499
|
|
|
$department, |
500
|
|
|
$amount, |
501
|
|
|
$funding_id, |
502
|
|
|
$resolution_date, |
503
|
|
|
$fsr_kom, |
504
|
|
|
$comment, |
505
|
|
|
$lastModified, |
506
|
|
|
$creationDate, |
507
|
|
|
//Status infos |
508
|
|
|
$statusPanel, |
509
|
|
|
$mathematicallyCorrect, |
510
|
|
|
$exported, |
511
|
|
|
$factuallyCorrect, |
512
|
|
|
$booking_date, |
513
|
|
|
$confirmed_1, |
514
|
|
|
$confirmed_2, |
515
|
|
|
//Payee informations |
516
|
|
|
$payeePanel, |
517
|
|
|
$bankInfoAccountOwner, |
518
|
|
|
$bankInfoStreet, |
519
|
|
|
$bankInfoZipCode, |
520
|
|
|
$bankInfoCity, |
521
|
|
|
//Banking informations |
522
|
|
|
$bankInfoPanel, |
523
|
|
|
$bankInfoIban, |
524
|
|
|
$bankInfoBic, |
525
|
|
|
$bankInfoBankName, |
526
|
|
|
$bankInfoReference, |
527
|
|
|
]; |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
if (Crud::PAGE_EDIT === $pageName) { |
531
|
|
|
return [ |
532
|
|
|
//Documents section |
533
|
|
|
$documentsPanel, |
534
|
|
|
$printed_form, |
535
|
|
|
$references, |
536
|
|
|
//Basic informations |
537
|
|
|
$infoPanel, |
538
|
|
|
$firstName, |
539
|
|
|
$lastName, |
540
|
|
|
$contact_email, |
541
|
|
|
$projectName, |
542
|
|
|
$department, |
543
|
|
|
$amount, |
544
|
|
|
$funding_id, |
545
|
|
|
$resolution_date, |
546
|
|
|
$fsr_kom, |
547
|
|
|
$comment, |
548
|
|
|
//Status infos |
549
|
|
|
$statusPanel, |
550
|
|
|
$mathematicallyCorrect, |
551
|
|
|
$exported, |
552
|
|
|
$factuallyCorrect, |
553
|
|
|
$references_exported, |
554
|
|
|
//Payee informations |
555
|
|
|
$payeePanel, |
556
|
|
|
$bankInfoAccountOwner, |
557
|
|
|
$bankInfoStreet, |
558
|
|
|
$bankInfoZipCode, |
559
|
|
|
$bankInfoCity, |
560
|
|
|
//Banking informations |
561
|
|
|
$bankInfoPanel, |
562
|
|
|
$bankInfoIban, |
563
|
|
|
$bankInfoBic, |
564
|
|
|
$bankInfoBankName, |
565
|
|
|
$bankInfoReference, |
566
|
|
|
]; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
throw new RuntimeException('It should not be possible to reach this point...'); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void |
573
|
|
|
{ |
574
|
|
|
if (!$this->isGranted('ROLE_EDIT_PAYMENT_ORDERS')) { |
575
|
|
|
$this->addFlash('error', 'You are not allowed to delete Payment Orders!'); |
576
|
|
|
return; |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** @var PaymentOrder $entityInstance */ |
580
|
|
|
//Forbit delete process if PaymentOrder was already exported or booked |
581
|
|
|
if ($entityInstance->isExported() |
582
|
|
|
|| null != $entityInstance->getBookingDate()) { |
583
|
|
|
$this->addFlash('warning', 'payment_order.flash.can_not_delete_checked_payment_order'); |
584
|
|
|
|
585
|
|
|
return; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
parent::deleteEntity($entityManager, $entityInstance); |
589
|
|
|
} |
590
|
|
|
} |
591
|
|
|
|