Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
2.78% |
1 / 36 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Installer | |
2.78% |
1 / 36 |
|
0.00% |
0 / 2 |
66.81 | |
0.00% |
0 / 1 |
install | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
1.12 | |||
importAccounts | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package Modules\Accounting\Admin |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace Modules\Accounting\Admin; |
16 | |
17 | use phpOMS\Application\ApplicationAbstract; |
18 | use phpOMS\Config\SettingsInterface; |
19 | use phpOMS\Message\Http\HttpRequest; |
20 | use phpOMS\Message\Http\HttpResponse; |
21 | use phpOMS\Module\InstallerAbstract; |
22 | use phpOMS\Module\ModuleInfo; |
23 | use phpOMS\Uri\HttpUri; |
24 | |
25 | /** |
26 | * Installer class. |
27 | * |
28 | * @package Modules\Accounting\Admin |
29 | * @license OMS License 2.0 |
30 | * @link https://jingga.app |
31 | * @since 1.0.0 |
32 | */ |
33 | final class Installer extends InstallerAbstract |
34 | { |
35 | /** |
36 | * Path of the file |
37 | * |
38 | * @var string |
39 | * @since 1.0.0 |
40 | */ |
41 | public const PATH = __DIR__; |
42 | |
43 | /** |
44 | * {@inheritdoc} |
45 | */ |
46 | public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void |
47 | { |
48 | parent::install($app, $info, $cfgHandler); |
49 | |
50 | self::importAccounts($app); |
51 | } |
52 | |
53 | /** |
54 | * Import accounts |
55 | * |
56 | * @param ApplicationAbstract $app Application |
57 | * |
58 | * @return void |
59 | * |
60 | * @since 1.0.0 |
61 | */ |
62 | private static function importAccounts(ApplicationAbstract $app) : void |
63 | { |
64 | /** @var \Modules\Accounting\Controller\ApiController $module */ |
65 | $module = $app->moduleManager->getModuleInstance('Accounting', 'Api'); |
66 | |
67 | $fp = \fopen(__DIR__ . '/Install/Coa/skr03.csv', 'r'); |
68 | if ($fp === false) { |
69 | return; |
70 | } |
71 | |
72 | $c = 0; |
73 | $definitions = []; |
74 | $languages = 0; |
75 | |
76 | while (($line = \fgetcsv($fp)) !== false) { |
77 | ++$c; |
78 | |
79 | if ($c === 2) { |
80 | $definitions = $line; |
81 | $languages = \count($definitions) - 19; |
82 | } |
83 | |
84 | if ($c < 3) { |
85 | continue; |
86 | } |
87 | |
88 | $response = new HttpResponse(); |
89 | $request = new HttpRequest(new HttpUri('')); |
90 | |
91 | $request->header->account = 1; |
92 | $request->setData('account', $line[0]); |
93 | $request->setData('content', \trim($line[19])); |
94 | $request->setData('language', $definitions[19]); |
95 | $module->apiAccountCreate($request, $response); |
96 | |
97 | $responseData = $response->get(''); |
98 | if (!\is_array($responseData)) { |
99 | continue; |
100 | } |
101 | |
102 | $accountId = $responseData['response']->id; |
103 | |
104 | for ($i = 1; $i < $languages; ++$i) { |
105 | $response = new HttpResponse(); |
106 | $request = new HttpRequest(new HttpUri('')); |
107 | |
108 | $request->header->account = 1; |
109 | $request->setData('ref', $accountId); |
110 | $request->setData('content', \trim($line[19 + $i])); |
111 | $request->setData('language', $definitions[19 + $i]); |
112 | $module->apiAccountL11nCreate($request, $response); |
113 | } |
114 | } |
115 | |
116 | \fclose($fp); |
117 | } |
118 | } |