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