|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\Account; |
|
8
|
|
|
use Application\Repository\AccountRepository; |
|
9
|
|
|
use Application\Service\Exporter\AccountingReport; |
|
10
|
|
|
use Ecodev\Felix\Api\Field\FieldInterface; |
|
11
|
|
|
use GraphQL\Type\Definition\Type; |
|
12
|
|
|
use Mezzio\Session\SessionInterface; |
|
13
|
|
|
|
|
14
|
|
|
abstract class ExportAccountingReport implements FieldInterface |
|
15
|
|
|
{ |
|
16
|
1 |
|
public static function build(): iterable |
|
17
|
|
|
{ |
|
18
|
1 |
|
yield 'exportAccountingReport' => fn () => [ |
|
19
|
1 |
|
'type' => Type::nonNull(Type::string()), |
|
20
|
1 |
|
'description' => 'Prepare an accounting report and return the URL to download it', |
|
21
|
1 |
|
'args' => [ |
|
22
|
1 |
|
'date' => Type::nonNull(_types()->get('Date')), |
|
23
|
1 |
|
'datePrevious' => _types()->get('Date'), |
|
24
|
1 |
|
'showBudget' => Type::nonNull(Type::boolean()), |
|
25
|
1 |
|
], |
|
26
|
1 |
|
'resolve' => function ($root, array $args, SessionInterface $session): string { |
|
27
|
|
|
global $container; |
|
28
|
|
|
|
|
29
|
|
|
/** @var AccountingReport $exporter */ |
|
30
|
|
|
$exporter = $container->get(AccountingReport::class); |
|
31
|
|
|
|
|
32
|
|
|
if ($args['date']) { |
|
33
|
|
|
$exporter->setDate($args['date']); |
|
34
|
|
|
} |
|
35
|
|
|
if ($args['datePrevious']) { |
|
36
|
|
|
$exporter->setDatePrevious($args['datePrevious']); |
|
37
|
|
|
} |
|
38
|
|
|
$exporter->showBudget($args['showBudget']); |
|
39
|
|
|
|
|
40
|
|
|
// Select root accounts |
|
41
|
|
|
/** @var AccountRepository $accountRepository */ |
|
42
|
|
|
$accountRepository = _em()->getRepository(Account::class); |
|
43
|
|
|
$rootAccountsQuery = $accountRepository->getRootAccountsQuery(); |
|
44
|
|
|
|
|
45
|
|
|
return $exporter->export($rootAccountsQuery->getResult()); |
|
|
|
|
|
|
46
|
1 |
|
}, |
|
47
|
1 |
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|