1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Service\Exporter; |
6
|
|
|
|
7
|
|
|
use Application\Model\Account; |
8
|
|
|
use Application\Model\User; |
9
|
|
|
use Application\Repository\AccountRepository; |
10
|
|
|
use Application\Service\Exporter\AccountingReport; |
11
|
|
|
use ApplicationTest\Traits\TestWithSpreadsheet; |
12
|
|
|
use ApplicationTest\Traits\TestWithTransactionAndUser; |
13
|
|
|
use Cake\Chronos\Date; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
class AccountingReportTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
use TestWithTransactionAndUser; |
19
|
|
|
use TestWithSpreadsheet; |
20
|
|
|
|
21
|
|
|
public function testExportAccountingReport(): void |
22
|
|
|
{ |
23
|
|
|
/** @var User $user */ |
24
|
|
|
$user = _em()->getRepository(User::class)->getOneByLogin('responsible'); |
25
|
|
|
User::setCurrent($user); |
26
|
|
|
|
27
|
|
|
$hostname = 'my-ichtus.lan'; |
28
|
|
|
|
29
|
|
|
$accountingConfig = [ |
30
|
|
|
'salesAccountCode' => 3200, |
31
|
|
|
'bankAccountCode' => 1020, |
32
|
|
|
'customerDepositsAccountCode' => 2030, |
33
|
|
|
'report' => [ |
34
|
|
|
'showAccountsWithZeroBalance' => true, |
35
|
|
|
'maxAccountDepth' => 2, |
36
|
|
|
], |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
// Query to generate the Excel file on disk |
40
|
|
|
/** @var AccountRepository $repository */ |
41
|
|
|
$repository = _em()->getRepository(Account::class); |
42
|
|
|
$query = $repository->getRootAccountsQuery(); |
43
|
|
|
|
44
|
|
|
$handler = new AccountingReport($hostname, $accountingConfig); |
45
|
|
|
$handler->setDate(new Date('2019-12-31')); |
46
|
|
|
$url = $handler->export($query->getResult()); |
47
|
|
|
|
48
|
|
|
$spreadsheet = $this->readExport($hostname, $url); |
49
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
50
|
|
|
|
51
|
|
|
// Test a few arbitrary data |
52
|
|
|
self::assertSame('my-ichtus.lan: rapport comptable au 31.12.2019', $sheet->getCell('A1')->getCalculatedValue()); |
53
|
|
|
self::assertSame('Actifs', $sheet->getCell('A3')->getCalculatedValue()); |
54
|
|
|
self::assertSame('Passifs', $sheet->getCell('E3')->getCalculatedValue()); |
55
|
|
|
self::assertSame('Charges', $sheet->getCell('I3')->getCalculatedValue()); |
56
|
|
|
self::assertSame('Profits', $sheet->getCell('M3')->getCalculatedValue()); |
57
|
|
|
self::assertSame(35187.50, $sheet->getCell('C44')->getCalculatedValue()); |
58
|
|
|
self::assertSame(240.0, $sheet->getCell('M44')->getCalculatedValue()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|