code fixes

This commit is contained in:
Dennis Eichhorn 2024-03-15 20:24:37 +00:00
parent c36a9d3799
commit 822f849d5d
9 changed files with 75 additions and 50 deletions

View File

@ -67,6 +67,10 @@ final class Installer extends InstallerAbstract
$module = $app->moduleManager->get('Balance', 'Api'); $module = $app->moduleManager->get('Balance', 'Api');
$structures = \scandir(__DIR__ . '/Install/Coa'); $structures = \scandir(__DIR__ . '/Install/Coa');
if ($structures === false) {
return;
}
foreach ($structures as $file) { foreach ($structures as $file) {
if ($file === '..' || $file === '.') { if ($file === '..' || $file === '.') {
continue; continue;
@ -80,17 +84,35 @@ final class Installer extends InstallerAbstract
$request->setData('name', \strtr(\basename($file, '.json'), '_', ' ')); $request->setData('name', \strtr(\basename($file, '.json'), '_', ' '));
$module->apiBalanceCreate($request, $response); $module->apiBalanceCreate($request, $response);
$responseData = $response->getData(''); $responseData = $response->getDataArray('');
$balance = \is_array($responseData['response']) $balance = \is_array($responseData['response'])
? $responseData['response'] ? $responseData['response']
: $responseData['response']->toArray(); : $responseData['response']->toArray();
$json = \json_decode(\file_get_contents(__DIR__ . '/Install/Coa/' . $file), true); $fileContent = \file_get_contents(__DIR__ . '/Install/Coa/' . $file);
if ($fileContent === false) {
return;
}
/** @var array $json */
$json = \json_decode($fileContent, true);
self::createElement($module, $json, (int) $balance['id'], null); self::createElement($module, $json, (int) $balance['id'], null);
} }
} }
/**
* Create balance element
*
* @param ApiController $module Module
* @param array $elements Elements to create
* @param int $structure Structure the elements belong to
* @param null|int $parent Parent element (null = none)
*
* @return void
*
* @since 1.0.0
*/
private static function createElement(ApiController $module, array $elements, int $structure, ?int $parent = null) : void private static function createElement(ApiController $module, array $elements, int $structure, ?int $parent = null) : void
{ {
$order = 0; $order = 0;
@ -116,6 +138,7 @@ final class Installer extends InstallerAbstract
} }
if (!empty($element['account'])) { if (!empty($element['account'])) {
/** @var AccountAbstract[] $accountObjects */
$accountObjects = AccountAbstractMapper::getAll() $accountObjects = AccountAbstractMapper::getAll()
->where('code', \array_map(function($account) { ->where('code', \array_map(function($account) {
return (string) $account; return (string) $account;
@ -123,7 +146,7 @@ final class Installer extends InstallerAbstract
->execute(); ->execute();
$request->setData('accounts', \implode(',', $request->setData('accounts', \implode(',',
\array_map(function (AccountAbstract $account) { \array_map(function (AccountAbstract $account) : int {
return $account->id; return $account->id;
}, $accountObjects) }, $accountObjects)
)); ));

View File

@ -162,14 +162,14 @@ final class ApiController extends Controller
*/ */
private function createBalanceElementFromRequest(RequestAbstract $request) : BalanceElement private function createBalanceElementFromRequest(RequestAbstract $request) : BalanceElement
{ {
$element = new BalanceElement(); $element = new BalanceElement();
$element->code = $request->getDataString('code') ?? ''; $element->code = $request->getDataString('code') ?? '';
$element->formula = $request->getDataString('formula') ?? ''; $element->formula = $request->getDataString('formula') ?? '';
$element->style = $request->getDataString('style') ?? ''; $element->style = $request->getDataString('style') ?? '';
$element->balance = $request->getDataInt('balance') ?? 0; $element->balance = $request->getDataInt('balance') ?? 0;
$element->order = $request->getDataInt('order') ?? 0; $element->order = $request->getDataInt('order') ?? 0;
$element->expanded = $request->getDataBool('expanded') ?? false; $element->expanded = $request->getDataBool('expanded') ?? false;
$element->parent = $request->getDataInt('parent'); $element->parent = $request->getDataInt('parent');
$accounts = $request->getDataList('accounts'); $accounts = $request->getDataList('accounts');
foreach ($accounts as $account) { foreach ($accounts as $account) {

View File

@ -66,6 +66,7 @@ final class BackendController extends Controller
$view->data['languages'] = []; $view->data['languages'] = [];
if (!empty($view->data['elements'])) { if (!empty($view->data['elements'])) {
/** @var \phpOMS\Localization\BaseStringL11n[] $tempL11ns */
$tempL11ns = BalanceElementL11nMapper::getAll() $tempL11ns = BalanceElementL11nMapper::getAll()
->where('ref', \reset($view->data['elements'])->id) ->where('ref', \reset($view->data['elements'])->id)
->execute(); ->execute();

View File

@ -44,6 +44,7 @@ class BalanceElement
public string $style = ''; public string $style = '';
public int $order = 0; public int $order = 0;
public bool $expanded = false; public bool $expanded = false;
public int $balance = 0; public int $balance = 0;

View File

@ -38,14 +38,14 @@ final class BalanceElementMapper extends DataMapperFactory
* @since 1.0.0 * @since 1.0.0
*/ */
public const COLUMNS = [ public const COLUMNS = [
'balance_balance_element_id' => ['name' => 'balance_balance_element_id', 'type' => 'int', 'internal' => 'id'], 'balance_balance_element_id' => ['name' => 'balance_balance_element_id', 'type' => 'int', 'internal' => 'id'],
'balance_balance_element_code' => ['name' => 'balance_balance_element_code', 'type' => 'string', 'internal' => 'code', 'autocomplete' => true], 'balance_balance_element_code' => ['name' => 'balance_balance_element_code', 'type' => 'string', 'internal' => 'code', 'autocomplete' => true],
'balance_balance_element_formula' => ['name' => 'balance_balance_element_formula', 'type' => 'string', 'internal' => 'formula', 'autocomplete' => true], 'balance_balance_element_formula' => ['name' => 'balance_balance_element_formula', 'type' => 'string', 'internal' => 'formula', 'autocomplete' => true],
'balance_balance_element_style' => ['name' => 'balance_balance_element_style', 'type' => 'string', 'internal' => 'style', 'autocomplete' => true], 'balance_balance_element_style' => ['name' => 'balance_balance_element_style', 'type' => 'string', 'internal' => 'style', 'autocomplete' => true],
'balance_balance_element_order' => ['name' => 'balance_balance_element_order', 'type' => 'int', 'internal' => 'order'], 'balance_balance_element_order' => ['name' => 'balance_balance_element_order', 'type' => 'int', 'internal' => 'order'],
'balance_balance_element_expanded' => ['name' => 'balance_balance_element_expanded', 'type' => 'bool', 'internal' => 'expanded'], 'balance_balance_element_expanded' => ['name' => 'balance_balance_element_expanded', 'type' => 'bool', 'internal' => 'expanded'],
'balance_balance_element_parent' => ['name' => 'balance_balance_element_parent', 'type' => 'int', 'internal' => 'parent'], 'balance_balance_element_parent' => ['name' => 'balance_balance_element_parent', 'type' => 'int', 'internal' => 'parent'],
'balance_balance_element_balance' => ['name' => 'balance_balance_element_balance', 'type' => 'int', 'internal' => 'balance'], 'balance_balance_element_balance' => ['name' => 'balance_balance_element_balance', 'type' => 'int', 'internal' => 'balance'],
]; ];
/** /**

View File

@ -37,11 +37,11 @@ final class BalanceMapper extends DataMapperFactory
* @since 1.0.0 * @since 1.0.0
*/ */
public const COLUMNS = [ public const COLUMNS = [
'balance_balance_id' => ['name' => 'balance_balance_id', 'type' => 'int', 'internal' => 'id'], 'balance_balance_id' => ['name' => 'balance_balance_id', 'type' => 'int', 'internal' => 'id'],
'balance_balance_code' => ['name' => 'balance_balance_code', 'type' => 'string', 'internal' => 'code', 'autocomplete' => true], 'balance_balance_code' => ['name' => 'balance_balance_code', 'type' => 'string', 'internal' => 'code', 'autocomplete' => true],
'balance_balance_name' => ['name' => 'balance_balance_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], 'balance_balance_name' => ['name' => 'balance_balance_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'balance_balance_default' => ['name' => 'balance_balance_default', 'type' => 'bool', 'internal' => 'isDefault'], 'balance_balance_default' => ['name' => 'balance_balance_default', 'type' => 'bool', 'internal' => 'isDefault'],
'balance_balance_unit' => ['name' => 'balance_balance_unit', 'type' => 'int', 'internal' => 'unit'], 'balance_balance_unit' => ['name' => 'balance_balance_unit', 'type' => 'int', 'internal' => 'unit'],
]; ];
/** /**

View File

@ -13,19 +13,19 @@
declare(strict_types=1); declare(strict_types=1);
return ['Balance' => [ return ['Balance' => [
'Start' => 'Start', 'Start' => 'Start',
'End' => 'Ende', 'End' => 'Ende',
'Overview' => 'Übersicht', 'Overview' => 'Übersicht',
'Metrics' => 'Metriken', 'Metrics' => 'Metriken',
'Charts' => 'Charts', 'Charts' => 'Charts',
'Interval' => 'Intervall', 'Interval' => 'Intervall',
'Environment' => 'Environment', 'Environment' => 'Environment',
'Monthly' => 'Monatlich', 'Monthly' => 'Monatlich',
'Quarterly' => 'Quartalsweise', 'Quarterly' => 'Quartalsweise',
'Annually' => 'Jährlich', 'Annually' => 'Jährlich',
'Category' => 'Kategorie', 'Category' => 'Kategorie',
'Subtotal' => 'Zwischensumme', 'Subtotal' => 'Zwischensumme',
'Total' => 'Summe', 'Total' => 'Summe',
'Diff' => 'Diff', 'Diff' => 'Diff',
'Diff%' => 'Diff %', 'Diff%' => 'Diff %',
]]; ]];

View File

@ -13,19 +13,19 @@
declare(strict_types=1); declare(strict_types=1);
return ['Balance' => [ return ['Balance' => [
'Start' => 'Start', 'Start' => 'Start',
'End' => 'End', 'End' => 'End',
'Overview' => 'Overview', 'Overview' => 'Overview',
'Metrics' => 'Metrics', 'Metrics' => 'Metrics',
'Charts' => 'Charts', 'Charts' => 'Charts',
'Interval' => 'Interval', 'Interval' => 'Interval',
'Environment' => 'Environment', 'Environment' => 'Environment',
'Monthly' => 'Monthly', 'Monthly' => 'Monthly',
'Quarterly' => 'Quarterly', 'Quarterly' => 'Quarterly',
'Annually' => 'Annually', 'Annually' => 'Annually',
'Category' => 'Category', 'Category' => 'Category',
'Subtotal' => 'Subtotal', 'Subtotal' => 'Subtotal',
'Total' => 'Total', 'Total' => 'Total',
'Diff' => 'Diff', 'Diff' => 'Diff',
'Diff%' => 'Diff %', 'Diff%' => 'Diff %',
]]; ]];

View File

@ -49,7 +49,7 @@ function render_elements(array $elements, ?int $parent = null) : string
{ {
$row = ''; $row = '';
$fn = 'render_elements'; $fn = 'render_elements';
$acc = 'render_accounts'; $acc = 'render_accounts';
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element->parent !== $parent) { if ($element->parent !== $parent) {