Conditions | 4 |
Paths | 1 |
Total Lines | 26 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
16 | 1 | public static function build(): iterable |
|
17 | { |
||
18 | 1 | yield 'accountingClosing' => fn () => [ |
|
19 | 1 | 'type' => _types()->getOutput(Transaction::class), |
|
20 | 1 | 'description' => 'Generate the closing entries at the end of an accounting period', |
|
21 | 1 | 'args' => [ |
|
22 | 1 | 'date' => _types()->get('Date'), |
|
23 | 1 | ], |
|
24 | 1 | 'resolve' => function ($root, array $args, SessionInterface $session): ?Transaction { |
|
25 | global $container; |
||
26 | |||
27 | $user = User::getCurrent(); |
||
28 | if (!$user || $user->getRole() !== User::ROLE_ADMINISTRATOR) { |
||
29 | throw new Exception('Seul un administrateur peut effectuer le bouclement comptable'); |
||
30 | } |
||
31 | |||
32 | /** @var Accounting $accounting */ |
||
33 | $accounting = $container->get(Accounting::class); |
||
34 | |||
35 | if ($args['date']) { |
||
36 | $transaction = $accounting->close($args['date']); |
||
37 | |||
38 | return $transaction; |
||
39 | } |
||
40 | |||
41 | throw new Exception('Date de bouclement invalide'); |
||
42 | 1 | }, |
|
46 |