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\Entity\BankAccount; |
22
|
|
|
use App\Entity\Contracts\DBElementInterface; |
23
|
|
|
use App\Entity\Department; |
24
|
|
|
use App\Entity\PaymentOrder; |
25
|
|
|
use App\Entity\SEPAExport; |
26
|
|
|
use App\Entity\User; |
27
|
|
|
use App\Services\GitVersionInfo; |
28
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; |
29
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; |
30
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets; |
31
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
32
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; |
33
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Menu\CrudMenuItem; |
34
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; |
35
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu; |
36
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController; |
37
|
|
|
use Symfony\Component\HttpFoundation\Response; |
38
|
|
|
use Symfony\Component\Intl\Languages; |
39
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
40
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
41
|
|
|
|
42
|
|
|
class DashboardController extends AbstractDashboardController |
43
|
|
|
{ |
44
|
|
|
private $app_version; |
45
|
|
|
private $gitVersionInfo; |
46
|
|
|
|
47
|
|
|
private const FILTER_DATETIME_FORMAT = 'Y-m-d\TH:i:s'; |
48
|
|
|
|
49
|
|
|
public function __construct(string $app_version, GitVersionInfo $gitVersionInfo) |
50
|
|
|
{ |
51
|
|
|
$this->app_version = $app_version; |
52
|
|
|
$this->gitVersionInfo = $gitVersionInfo; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function configureDashboard(): Dashboard |
56
|
|
|
{ |
57
|
|
|
return Dashboard::new() |
58
|
|
|
->setTitle('StuRa Finanzen'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Route("/admin", name="admin_dashboard", ) |
63
|
|
|
*/ |
64
|
|
|
public function index(): Response |
65
|
|
|
{ |
66
|
|
|
return $this->render('admin/dashboard.html.twig'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function addFiltersToMenuItem(CrudMenuItem $menuItem, array $filters): CrudMenuItem |
70
|
|
|
{ |
71
|
|
|
//Set referrer or we encounter errrors... (not needed in JB custom version)) |
72
|
|
|
|
73
|
|
|
//$referrer = $this->crud_url_generator->build()->currentPageReferrer; |
74
|
|
|
//$menuItem->setQueryParameter('referrer', $referrer); |
75
|
|
|
|
76
|
|
|
foreach ($filters as $filter => $value) { |
77
|
|
|
if (is_array($value)) { |
78
|
|
|
foreach ($value as $subfilter => $subvalue) { |
79
|
|
|
$menuItem->setQueryParameter('filters['.$filter.']['.$subfilter.']', $subvalue); |
80
|
|
|
} |
81
|
|
|
} else { |
82
|
|
|
$menuItem->setQueryParameter('filters['.$filter.']', $value); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$menuItem->setQueryParameter('crudAction', 'index'); |
87
|
|
|
|
88
|
|
|
return $menuItem; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function configureActions(): Actions |
92
|
|
|
{ |
93
|
|
|
$actions = parent::configureActions(); |
94
|
|
|
|
95
|
|
|
$showLog = Action::new('showLog', 'action.show_logs', 'fas fa-binoculars') |
96
|
|
|
->displayIf(function (DBElementInterface $entity) { |
|
|
|
|
97
|
|
|
return $this->isGranted('ROLE_VIEW_AUDITS'); |
98
|
|
|
}) |
99
|
|
|
->setCssClass('btn btn-secondary') |
100
|
|
|
->linkToRoute('dh_auditor_show_entity_history', function (DBElementInterface $entity) { |
101
|
|
|
return [ |
102
|
|
|
'entity' => str_replace('\\', '-', get_class($entity)), |
103
|
|
|
'id' => $entity->getId(), |
104
|
|
|
]; |
105
|
|
|
}); |
106
|
|
|
|
107
|
|
|
return $actions |
108
|
|
|
->add(Crud::PAGE_DETAIL, $showLog) |
109
|
|
|
->add(Crud::PAGE_EDIT, $showLog); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function configureMenuItems(): iterable |
113
|
|
|
{ |
114
|
|
|
/* Menu items for payment orders menu */ |
115
|
|
|
|
116
|
|
|
$mathematically_checking = MenuItem::linkToCrud('payment_order.mathematically_checking_needed', '', PaymentOrder::class) |
117
|
|
|
->setDefaultSort([ |
118
|
|
|
'creation_date' => 'ASC', |
119
|
|
|
]); |
120
|
|
|
$this->addFiltersToMenuItem($mathematically_checking, [ |
121
|
|
|
'mathematically_correct' => 0, |
122
|
|
|
'confirmed' => 1, |
123
|
|
|
]); |
124
|
|
|
|
125
|
|
|
$ready_for_export_section = MenuItem::linkToCrud('payment_order.ready_for_export.section', '', PaymentOrder::class) |
126
|
|
|
->setDefaultSort([ |
127
|
|
|
'creation_date' => 'ASC', |
128
|
|
|
]); |
129
|
|
|
$this->addFiltersToMenuItem($ready_for_export_section, [ |
130
|
|
|
'mathematically_correct' => 1, |
131
|
|
|
'exported' => 0, |
132
|
|
|
'confirmed' => 1, |
133
|
|
|
]); |
134
|
|
|
|
135
|
|
|
$factually_checking_fsr = MenuItem::linkToCrud('payment_order.factually_checking_needed.fsr', '', PaymentOrder::class) |
136
|
|
|
->setDefaultSort([ |
137
|
|
|
'creation_date' => 'ASC', |
138
|
|
|
]); |
139
|
|
|
$this->addFiltersToMenuItem($factually_checking_fsr, [ |
140
|
|
|
'factually_correct' => 0, |
141
|
|
|
'department_type' => 'fsr', |
142
|
|
|
'exported' => 1, |
143
|
|
|
'confirmed' => 1, |
144
|
|
|
]); |
145
|
|
|
|
146
|
|
|
$factually_checking_section = MenuItem::linkToCrud('payment_order.factually_checking_needed.section', '', PaymentOrder::class) |
147
|
|
|
->setDefaultSort([ |
148
|
|
|
'creation_date' => 'ASC', |
149
|
|
|
]); |
150
|
|
|
$this->addFiltersToMenuItem($factually_checking_section, [ |
151
|
|
|
'factually_correct' => 0, |
152
|
|
|
'department_type' => 'section_misc', |
153
|
|
|
'exported' => 1, |
154
|
|
|
'confirmed' => 1, |
155
|
|
|
]); |
156
|
|
|
|
157
|
|
|
$finished = MenuItem::linkToCrud('payment_order.finished', '', PaymentOrder::class) |
158
|
|
|
->setDefaultSort([ |
159
|
|
|
'creation_date' => 'DESC', |
160
|
|
|
]); |
161
|
|
|
$this->addFiltersToMenuItem($finished, [ |
162
|
|
|
'factually_correct' => 1, |
163
|
|
|
'mathematically_correct' => 1, |
164
|
|
|
'exported' => 1, |
165
|
|
|
'confirmed' => 1, |
166
|
|
|
]); |
167
|
|
|
|
168
|
|
|
$unconfirmed = MenuItem::linkToCrud('payment_order.unconfirmed', '', PaymentOrder::class) |
169
|
|
|
->setDefaultSort([ |
170
|
|
|
'creation_date' => 'ASC', |
171
|
|
|
]); |
172
|
|
|
$this->addFiltersToMenuItem($unconfirmed, [ |
173
|
|
|
'confirmed' => 0, |
174
|
|
|
]); |
175
|
|
|
|
176
|
|
|
$items = [ |
177
|
|
|
$mathematically_checking, |
178
|
|
|
$ready_for_export_section, |
179
|
|
|
$factually_checking_fsr, |
180
|
|
|
$factually_checking_section, |
181
|
|
|
$finished, |
182
|
|
|
$unconfirmed, |
183
|
|
|
MenuItem::linkToCrud('payment_order.all', '', PaymentOrder::class), |
184
|
|
|
]; |
185
|
|
|
|
186
|
|
|
/* Menu items for accountancy firm menu */ |
187
|
|
|
$accountancy_exported_this_month = MenuItem::linkToCrud('accountancy_firm_menu.exported_this_month', '', PaymentOrder::class); |
188
|
|
|
$this->addFiltersToMenuItem($accountancy_exported_this_month, [ |
189
|
|
|
'references_exported' => false, |
190
|
|
|
'factually_correct' => true, |
191
|
|
|
'booking_date' => [ |
192
|
|
|
'comparison' => 'between', |
193
|
|
|
'value' => (new \DateTime('first day of this month'))->setTime(0, 0, 0) |
194
|
|
|
->format(self::FILTER_DATETIME_FORMAT), |
195
|
|
|
'value2' => (new \DateTime('last day of this month'))->setTime(23, 59, 59) |
196
|
|
|
->format(self::FILTER_DATETIME_FORMAT), |
197
|
|
|
], |
198
|
|
|
]); |
199
|
|
|
|
200
|
|
|
/* Menu items for accountancy firm menu */ |
201
|
|
|
$accountancy_exported_last_month = MenuItem::linkToCrud('accountancy_firm_menu.exported_last_month', '', PaymentOrder::class); |
202
|
|
|
$this->addFiltersToMenuItem($accountancy_exported_last_month, [ |
203
|
|
|
'references_exported' => false, |
204
|
|
|
'factually_correct' => true, |
205
|
|
|
'booking_date' => [ |
206
|
|
|
'comparison' => 'between', |
207
|
|
|
'value' => (new \DateTime('first day of last month'))->setTime(0, 0, 0) |
208
|
|
|
->format(self::FILTER_DATETIME_FORMAT), |
209
|
|
|
'value2' => (new \DateTime('last day of last month'))->setTime(23, 59, 59) |
210
|
|
|
->format(self::FILTER_DATETIME_FORMAT), |
211
|
|
|
], |
212
|
|
|
]); |
213
|
|
|
|
214
|
|
|
$accountancy_exported = MenuItem::linkToCrud('accountancy_firm_menu.exported', '', PaymentOrder::class); |
215
|
|
|
$this->addFiltersToMenuItem($accountancy_exported, [ |
216
|
|
|
'references_exported' => true, |
217
|
|
|
'factually_correct' => true, |
218
|
|
|
]); |
219
|
|
|
|
220
|
|
|
$accountancy_not_exported_all = MenuItem::linkToCrud('accountancy_firm_menu.not_exported.all', '', PaymentOrder::class); |
221
|
|
|
$this->addFiltersToMenuItem($accountancy_not_exported_all, [ |
222
|
|
|
'references_exported' => false, |
223
|
|
|
]); |
224
|
|
|
|
225
|
|
|
yield MenuItem::subMenu('accountancy_firm_menu.label', 'fas fa-balance-scale') |
226
|
|
|
->setPermission('ROLE_EXPORT_REFERENCES') |
227
|
|
|
->setSubItems([ |
228
|
|
|
MenuItem::section('accountancy_firm_menu.references', 'fas fa-file-download'), |
229
|
|
|
$accountancy_exported_this_month, |
230
|
|
|
$accountancy_exported_last_month, |
231
|
|
|
$accountancy_not_exported_all, |
232
|
|
|
$accountancy_exported, |
233
|
|
|
]); |
234
|
|
|
|
235
|
|
|
yield MenuItem::subMenu('payment_order.labelp', 'fas fa-file-invoice-dollar') |
236
|
|
|
->setPermission('ROLE_SHOW_PAYMENT_ORDERS') |
237
|
|
|
->setSubItems($items); |
238
|
|
|
|
239
|
|
|
yield MenuItem::linkToCrud('sepa_export.labelp', 'fas fa-money-check-alt', SEPAExport::class) |
240
|
|
|
->setPermission('ROLE_SHOW_SEPA_EXPORTS'); |
241
|
|
|
|
242
|
|
|
yield MenuItem::linkToCrud('department.labelp', 'fas fa-sitemap', Department::class) |
243
|
|
|
->setPermission('ROLE_READ_ORGANISATIONS'); |
244
|
|
|
yield MenuItem::linkToCrud('bank_account.labelp', 'fas fa-university', BankAccount::class) |
245
|
|
|
->setPermission('ROLE_READ_BANK_ACCOUNTS'); |
246
|
|
|
yield MenuItem::linkToCrud('user.labelp', 'fas fa-user', User::class) |
247
|
|
|
->setPermission('ROLE_READ_USER'); |
248
|
|
|
|
249
|
|
|
$version = $this->app_version.'-'.$this->gitVersionInfo->getGitCommitHash() ?? ''; |
250
|
|
|
yield MenuItem::section('Version '.$version, 'fas fa-info'); |
251
|
|
|
yield MenuItem::linktoRoute('dashboard.menu.audits', 'fas fa-binoculars', 'dh_auditor_list_audits') |
252
|
|
|
->setPermission('ROLE_VIEW_AUDITS'); |
253
|
|
|
yield MenuItem::linktoRoute('dashboard.menu.homepage', 'fas fa-home', 'homepage'); |
254
|
|
|
yield MenuItem::linkToUrl('dashboard.menu.stura', 'fab fa-rebel', 'https://www.stura.uni-jena.de/'); |
255
|
|
|
yield MenuItem::linkToUrl('dashboard.menu.github', 'fab fa-github', 'https://github.com/jbtronics/StuRa-Finanzsoftware'); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function configureUserMenu(UserInterface $user): UserMenu |
259
|
|
|
{ |
260
|
|
|
/** @var User $user */ |
261
|
|
|
|
262
|
|
|
return parent::configureUserMenu($user) |
263
|
|
|
->setName((string) $user) |
264
|
|
|
->displayUserName(true) |
265
|
|
|
->addMenuItems([ |
266
|
|
|
MenuItem::linktoRoute('user.settings.title', 'fas fa-user-cog', 'user_settings'), |
267
|
|
|
//It is important to use LinkToUrl here. LinkToCrud will put the route name into a param, but does not change the prefix |
268
|
|
|
MenuItem::linkToUrl(Languages::getName('de', 'de').' (DE)', '', '/de/admin'), |
269
|
|
|
MenuItem::linkToUrl(Languages::getName('en', 'en').' (EN)', '', '/en/admin'), |
270
|
|
|
]); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function configureCrud(): Crud |
274
|
|
|
{ |
275
|
|
|
return parent::configureCrud() |
276
|
|
|
->setPaginatorPageSize(40); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
public function configureAssets(): Assets |
280
|
|
|
{ |
281
|
|
|
return Assets::new() |
282
|
|
|
//->addJsFile('configurable-date-input-polyfill.dist.js') |
283
|
|
|
->addJsFile('assets/js/jquery.slim.js') |
284
|
|
|
->addJsFile('assets/js/select2.full.min.js') |
285
|
|
|
->addCssFile('assets/css/select2.min.css') |
286
|
|
|
->addCssFile('admin_styles.css'); |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.