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; |
||
20 | |||
21 | use App\Entity\BankAccount; |
||
22 | use App\Entity\PaymentOrder; |
||
23 | use App\Exception\SEPAExportAutoModeNotPossible; |
||
24 | use App\Form\SepaExportType; |
||
25 | use App\Helpers\SEPAXML\SEPAXMLExportResult; |
||
26 | use App\Helpers\ZIPBinaryFileResponseFacade; |
||
27 | use App\Services\PaymentOrdersSEPAExporter_old; |
||
0 ignored issues
–
show
|
|||
28 | use App\Services\SEPAExport\PaymentOrderSEPAExporter; |
||
29 | use Doctrine\ORM\EntityManagerInterface; |
||
30 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
||
31 | use Symfony\Component\HttpFoundation\Request; |
||
32 | use Symfony\Component\HttpFoundation\Response; |
||
33 | use Symfony\Component\Routing\Annotation\Route; |
||
34 | use Symfony\Contracts\Translation\TranslatorInterface; |
||
35 | |||
36 | /** |
||
37 | * @Route("/admin/payment_order") |
||
38 | */ |
||
39 | class ExportController extends AbstractController |
||
40 | { |
||
41 | protected $sepaExporter; |
||
42 | protected $translator; |
||
43 | protected $entityManager; |
||
44 | |||
45 | public function __construct(PaymentOrderSEPAExporter $sepaExporter, EntityManagerInterface $entityManager, TranslatorInterface $translator) |
||
46 | { |
||
47 | $this->sepaExporter = $sepaExporter; |
||
48 | $this->translator = $translator; |
||
49 | $this->entityManager = $entityManager; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @Route("/export", name="payment_order_export") |
||
54 | */ |
||
55 | public function export(Request $request, EntityManagerInterface $entityManager) |
||
56 | { |
||
57 | $this->denyAccessUnlessGranted('ROLE_EXPORT_PAYMENT_ORDERS'); |
||
58 | |||
59 | $ids = $request->query->get('ids'); |
||
60 | $id_array = explode(',', $ids); |
||
61 | //Retrieve all payment orders which should be retrieved from DB: |
||
62 | $payment_orders = []; |
||
63 | foreach ($id_array as $id) { |
||
64 | $payment_orders[] = $entityManager->find(PaymentOrder::class, $id); |
||
65 | } |
||
66 | |||
67 | $form = $this->createForm(SepaExportType::class); |
||
68 | |||
69 | $form->handleRequest($request); |
||
70 | |||
71 | if ($form->isSubmitted() && $form->isValid()) { |
||
72 | //Determine the Values to use |
||
73 | $data = $form->getData(); |
||
74 | //If user has selected a bank account preset, then use the data from it |
||
75 | if ($data['bank_account'] instanceof BankAccount) { |
||
76 | $iban = $data['bank_account']->getIban(); |
||
77 | $bic = $data['bank_account']->getBic(); |
||
78 | $name = $data['bank_account']->getExportAccountName(); |
||
79 | } else { //Use the manual inputted data |
||
80 | $iban = $data['iban']; |
||
81 | $bic = $data['bic']; |
||
82 | $name = $data['name']; |
||
83 | } |
||
84 | |||
85 | try { |
||
86 | //Call function depending on the selected mode |
||
87 | switch($data['mode']) { |
||
88 | case 'auto': |
||
89 | $result = $this->sepaExporter->exportAuto($payment_orders); |
||
90 | break; |
||
91 | case 'auto_single': |
||
92 | $result = $this->sepaExporter->exportAutoSingle($payment_orders); |
||
93 | break; |
||
94 | case 'manual': |
||
95 | $result = new SEPAXMLExportResult( |
||
96 | [ |
||
97 | $this->sepaExporter->exportUsingGivenIBAN($payment_orders, $iban, $bic, $name) |
||
98 | ] |
||
99 | ); |
||
100 | break; |
||
101 | default: |
||
102 | throw new \RuntimeException('Unknown mode!'); |
||
103 | } |
||
104 | |||
105 | //Set exported flag for each payment order |
||
106 | foreach ($payment_orders as $paymentOrder) { |
||
107 | $paymentOrder->setExported(true); |
||
108 | } |
||
109 | |||
110 | //Persist the SEPA exports to database |
||
111 | $result->persistSEPAExports($this->entityManager); |
||
112 | |||
113 | $this->entityManager->flush(); |
||
114 | |||
115 | //Return the download |
||
116 | return $result->getDownloadResponse('export_'.date('Y-m-d_H-i-s')); |
||
117 | |||
118 | } catch (SEPAExportAutoModeNotPossible $exception) { |
||
119 | //Show error if auto mode is not possible |
||
120 | $this->addFlash('danger', |
||
121 | $this->translator->trans('sepa_export.error.department_missing_account') |
||
122 | .': '.$exception->getWrongDepartment()->getName()); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | return $this->render('admin/payment_order/export/export.html.twig', [ |
||
127 | 'payment_orders' => $payment_orders, |
||
128 | 'form' => $form->createView(), |
||
129 | ]); |
||
130 | } |
||
131 | } |
||
132 |
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