diff --git a/Admin/Install/Coa/SKR03_DE_GAAP.json b/Admin/Install/Coa/SKR03_DE_GAAP.json new file mode 100644 index 0000000..15321be --- /dev/null +++ b/Admin/Install/Coa/SKR03_DE_GAAP.json @@ -0,0 +1,810 @@ +[ + { + "name": "Assets", + "l11n": { + "en": "Assets", + "de": "Aktivseite" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.A", + "l11n": { + "en": "Capital Assets", + "de": "Anlagevermögen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.A.I", + "l11n": { + "en": "Intangible Assets", + "de": "Immaterielle Vermögensgegenständ" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.A.I.1", + "l11n": { + "en": "Self-determined trademarks and similar rights and values", + "de": "Selbst geschaffene gewerbliche Schutzrechte und ähnliche Rechte und Werte" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.I.2", + "l11n": { + "en": "Purchased licenses, trademarks and similar rights and values as well as licenses to such rights and values", + "de": "entgeltlich erworbene Konzessionen, gewerbliche Schutzrechte und ähnliche Rechte und Werte sowie Lizenzen an solchen Rechten und Werten" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.I.3", + "l11n": { + "en": "Goodwill", + "de": "Geschäfts- oder Firmenwert" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.I.4", + "l11n": { + "en": "Advance payments made", + "de": "geleistete Anzahlungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "A.A.II", + "l11n": { + "en": "Tangible Assets", + "de": "Sachanlagen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.A.II.1", + "l11n": { + "en": "Properties, rights equivalent to real property and buildings, including buildings on third-party land", + "de": "Grundstücke, grundstücksgleiche Rechte und Bauten einschließlich der Bauten auf fremden Grundstücken" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.II.2", + "l11n": { + "en": "Technical equipment and machinery", + "de": "technische Anlagen und Maschinen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.II.3", + "l11n": { + "en": "Other equipment, operating and office equipment", + "de": "andere Anlagen, Betriebs- und Geschäftsausstattung" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.II.4", + "l11n": { + "en": "Advance payments made and construction in progress", + "de": "geleistete Anzahlungen und Anlagen im Bau" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "A.A.III", + "l11n": { + "en": "Financial Assets", + "de": "Finanzanlagen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.A.III.1", + "l11n": { + "en": "Shares in affiliated companies", + "de": "Anteile an verbundenen Unternehmen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.III.2", + "l11n": { + "en": "Loans to affiliated companies", + "de": "Ausleihungen an verbundene Unternehmen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.III.3", + "l11n": { + "en": "Other long-term equity investments", + "de": "Beteiligungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.III.4", + "l11n": { + "en": "Loans to other long-term investees and investors", + "de": "Ausleihungen an Unternehmen, mit denen ein Beteiligungsverhältnis besteht" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.III.5", + "l11n": { + "en": "Long-term securities", + "de": "Wertpapiere des Anlagevermögens" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.A.III.6", + "l11n": { + "en": "Other loans", + "de": "sonstige Ausleihungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + } + ] + }, + { + "name": "A.B", + "l11n": { + "en": "Current Assets", + "de": "Umlaufvermögen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.B.I", + "l11n": { + "en": "Inventories", + "de": "Vorräte" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.B.I.1", + "l11n": { + "en": "Raw materials, consumables and supplies", + "de": "Roh-, Hilfs- und Betriebsstoffe" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.I.2", + "l11n": { + "en": "Work in progress", + "de": "unfertige Erzeugnisse, unfertige Leistungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.I.3", + "l11n": { + "en": "Finished goods and merchandise", + "de": "fertige Erzeugnisse und Waren" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.I.4", + "l11n": { + "en": "Advance payments made", + "de": "geleistete Anzahlungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "A.B.II", + "l11n": { + "en": "Accounts Receivables and other Payables", + "de": "Forderungen und sonstige Vermögensgegenstände" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.B.II.1", + "l11n": { + "en": "Trade receivables", + "de": "Forderungen aus Lieferungen und Leistungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.II.2", + "l11n": { + "en": "Receivables from affiliated companies", + "de": "Forderungen gegen verbundene Unternehmen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.II.3", + "l11n": { + "en": "Receivables from other long-term investees and investors", + "de": "Forderungen gegen Unternehmen, mit denen ein Beteiligungsverhältnis besteht" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.II.4", + "l11n": { + "en": "Other assets or other liabilities", + "de": "sonstige Vermögensgegenstände" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "A.B.III", + "l11n": { + "en": "Securities", + "de": "Wertpapiere" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "A.B.III.1", + "l11n": { + "en": "Shares in affiliated companies", + "de": "Anteile an verbundenen Unternehmen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.B.III.2", + "l11n": { + "en": "Other securities", + "de": "sonstige Wertpapiere" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "A.B.IV", + "l11n": { + "en": "Cash Assets", + "de": "Kassenbestand, Bundesbankguthaben, Guthaben bei Kreditinstituten und Schecks" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "A.C", + "l11n": { + "en": "Accrual", + "de": "Rechnungsabgrenzungsposten" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.D", + "l11n": { + "en": "Deferred tax assets", + "de": "Aktive latente Steuern" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "A.E", + "l11n": { + "en": "Difference", + "de": "Aktiver Unterschiedsbetrag aus der Vermögensverrechnung" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "Liabilities", + "l11n": { + "en": "Liabilities", + "de": "Passivseite" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.A", + "l11n": { + "en": "Equity", + "de": "Eigenkapital" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.A.I", + "l11n": { + "en": "Subscribed Capital", + "de": "Gezeichnetes Kapital" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.A.II", + "l11n": { + "en": "Capital Reserve", + "de": "Kapitalrücklage" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.A.III", + "l11n": { + "en": "Retained Earnings", + "de": "Gewinnrücklagen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.A.III.1", + "l11n": { + "en": "Mandatory reserve", + "de": "gesetzliche Rücklage" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.A.III.2", + "l11n": { + "en": "Reserve for shares in a parent or majority investor", + "de": "Rücklage für Anteile an einem herrschenden oder mehrheitlich beteiligten Unternehmen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.A.III.3", + "l11n": { + "en": "Reserves provided for by the article of association", + "de": "satzungsmäßige Rücklagen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.A.III.4", + "l11n": { + "en": "Other retained earnings", + "de": "andere Gewinnrücklagen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "P.A.IV", + "l11n": { + "en": "Earnings carryover/Loss carryover", + "de": "Gewinnvortrag/Verlustvortrag" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.A.V", + "l11n": { + "en": "Annual Net Profit/Annual Net Deficit", + "de": "Jahresüberschuss/Jahresfehlbetrag" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "P.B", + "l11n": { + "en": "Provisions", + "de": "Rückstellungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.B.1", + "l11n": { + "en": "Provisions for pensions and similar obligations", + "de": "Rückstellungen für Pensionen und ähnliche Verpflichtungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.B.2", + "l11n": { + "en": "Provisions for taxes", + "de": "Steuerrückstellungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.B.3", + "l11n": { + "en": "Other provisions", + "de": "sonstige Rückstellungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "P.C", + "l11n": { + "en": "Liabilities", + "de": "Verbindlichkeiten" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.C.1", + "l11n": { + "en": "Bonds", + "de": "Anleihen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.C.1.a", + "l11n": { + "en": "thereof convertible", + "de": "davon konvertibel" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + }, + { + "name": "P.C.2", + "l11n": { + "en": "Liabilities to financial institutions", + "de": "Verbindlichkeiten gegenüber Kreditinstituten" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.3", + "l11n": { + "en": "Advance payments received on orders", + "de": "erhaltene Anzahlungen auf Bestellungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.4", + "l11n": { + "en": "Trade payables", + "de": "Verbindlichkeiten aus Lieferungen und Leistungen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.5", + "l11n": { + "en": "Liabilities on bills accepted and drawn", + "de": "Verbindlichkeiten aus der Annahme gezogener Wechsel und der Ausstellung eigener Wechsel" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.6", + "l11n": { + "en": "Liabilities to affiliated companies", + "de": "Verbindlichkeiten gegenüber verbundenen Unternehmen" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.7", + "l11n": { + "en": "Liabilities to companies invested in", + "de": "Verbindlichkeiten gegenüber Unternehmen, mit denen ein Beteiligungsverhältnis besteht" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.8", + "l11n": { + "en": "Other liabilities", + "de": "sonstige Verbindlichkeiten" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [ + { + "name": "P.C.8.a", + "l11n": { + "en": "thereof from taxes", + "de": "davon aus Steuern" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.C.8.b", + "l11n": { + "en": "thereof social security liabilities", + "de": "davon im Rahmen der sozialen Sicherheit" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + } + ] + }, + { + "name": "P.D", + "l11n": { + "en": "Accrual", + "de": "Rechnungsabgrenzungsposten" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + }, + { + "name": "P.E", + "l11n": { + "en": "Deferred tax liabilities", + "de": "Passive latente Steuern" + }, + "account": [], + "type": "category", + "formula": "", + "style": "category", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/Admin/Install/db.json b/Admin/Install/db.json new file mode 100644 index 0000000..b79c7d7 --- /dev/null +++ b/Admin/Install/db.json @@ -0,0 +1,91 @@ +{ + "balance_balance": { + "name": "balance_balance", + "fields": { + "balance_balance_id": { + "name": "balance_balance_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "balance_balance_code": { + "name": "balance_balance_code", + "type": "VARCHAR(255)", + "null": false + }, + "balance_balance_name": { + "name": "balance_balance_name", + "type": "VARCHAR(255)", + "null": false + } + } + }, + "balance_balance_element": { + "name": "balance_balance_element", + "fields": { + "balance_balance_element_id": { + "name": "balance_balance_element_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "balance_balance_element_code": { + "name": "balance_balance_element_code", + "type": "VARCHAR(255)", + "null": false + }, + "balance_balance_element_order": { + "name": "balance_balance_element_order", + "type": "INT", + "null": false + }, + "balance_balance_element_parent": { + "name": "balance_balance_element_parent", + "type": "INT", + "null": true, + "foreignTable": "balance_balance_element", + "foreignKey": "balance_balance_element_id" + }, + "balance_balance_element_balance": { + "name": "balance_balance_element_balance", + "type": "INT", + "null": false, + "foreignTable": "balance_balance", + "foreignKey": "balance_balance_id" + } + } + }, + "balance_balance_element_l11n": { + "name": "balance_balance_element_l11n", + "fields": { + "balance_balance_element_l11n_id": { + "name": "balance_balance_element_l11n_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "balance_balance_element_l11n_title": { + "name": "balance_balance_element_l11n_title", + "type": "VARCHAR(255)", + "null": false + }, + "balance_balance_element_l11n_element": { + "name": "balance_balance_element_l11n_element", + "type": "INT(11)", + "null": false, + "foreignTable": "balance_balance_element", + "foreignKey": "balance_balance_element_id" + }, + "balance_balance_element_l11n_lang": { + "name": "balance_balance_element_l11n_lang", + "type": "VARCHAR(2)", + "null": false, + "foreignTable": "language", + "foreignKey": "language_639_1" + } + } + } +} \ No newline at end of file diff --git a/Admin/Installer.php b/Admin/Installer.php index aa034d4..e1c1ab9 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -14,7 +14,14 @@ declare(strict_types=1); namespace Modules\Balance\Admin; +use Modules\Balance\Controller\ApiController; +use phpOMS\Application\ApplicationAbstract; +use phpOMS\Config\SettingsInterface; +use phpOMS\Message\Http\HttpRequest; +use phpOMS\Message\Http\HttpResponse; use phpOMS\Module\InstallerAbstract; +use phpOMS\Module\ModuleInfo; +use phpOMS\Uri\HttpUri; /** * Installer class. @@ -33,4 +40,118 @@ final class Installer extends InstallerAbstract * @since 1.0.0 */ public const PATH = __DIR__; + + /** + * {@inheritdoc} + */ + public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void + { + parent::install($app, $info, $cfgHandler); + + self::importStructures($app); + } + + /** + * Import accounts + * + * @param ApplicationAbstract $app Application + * + * @return void + * + * @since 1.0.0 + */ + private static function importStructures(ApplicationAbstract $app) : void + { + /** @var \Modules\Balance\Controller\ApiController $module */ + $module = $app->moduleManager->getModuleInstance('Balance', 'Api'); + + $structures = \scandir(__DIR__ . '/Install/Coa'); + foreach ($structures as $file) { + if ($file === '..' || $file === '.') { + continue; + } + + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('code', \strtolower(\basename($file))); + $request->setData('name', \strtr(\basename($file), '_', ' ')); + + $responseData = $module->apiBalanceCreate($request, $response); + + $responseData = $response->getData(''); + if (!\is_array($responseData)) { + continue; + } + + $balance = \is_array($responseData['response']) + ? $responseData['response'] + : $responseData['response']->toArray(); + + $json = \json_decode(\file_get_contents(__DIR__ . '/Install/Coa/' . $file), true); + + foreach ($json as $element) { + self::createElement($module, [$element], (int) $balance['id'], null); + } + } + } + + private static function createElement(ApiController $module, array $elements, int $structure, int $parent = null) + { + $order = 0; + foreach ($elements as $element) { + ++$order; + + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('code', $element['name']); + $request->setData('content', \reset($element['l11n'])); + $request->setData('language', \array_keys($element['l11n'])[0] ?? 'en'); + $request->setData('accounts', \implode(',', $element['account'])); + $request->setData('formula', $element['formula']); + $request->setData('type', $element['type']); + $request->setData('balance', $structure); + $request->setData('order', $order); + + if ($parent !== null) { + $request->setData('parent', $parent); + } + + $module->apiBalanceElementCreate($request, $response); + + $responseData = $response->getData(''); + if (!\is_array($responseData)) { + continue; + } + + $balanceElement = \is_array($responseData['response']) + ? $responseData['response'] + : $responseData['response']->toArray(); + + $isFirst = true; + foreach ($element['l11n'] as $language => $l11n) { + if ($isFirst) { + $isFirst = false; + continue; + } + + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('title', $l11n); + $request->setData('language', $language); + $request->setData('ref', $balanceElement['id']); + + $module->apiBalanceElementL11nCreate($request, $response); + } + + if (!empty($element['children'])) { + self::createElement($module, $element['children'], $structure, $balanceElement['id']); + } + } + } } diff --git a/Controller/ApiController.php b/Controller/ApiController.php new file mode 100644 index 0000000..438f4a8 --- /dev/null +++ b/Controller/ApiController.php @@ -0,0 +1,243 @@ +validateBalanceCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $balance = $this->createBalanceFromRequest($request); + $this->createModel($request->header->account, $balance, BalanceMapper::class, 'balance', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $balance); + } + + /** + * Validate balance create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateBalanceCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['code'] = !$request->hasData('code')) + || ($val['name'] = !$request->hasData('name')) + ) { + return $val; + } + + return []; + } + + /** + * Method to create balance from request. + * + * @param RequestAbstract $request Request + * + * @return Balance + * + * @since 1.0.0 + */ + private function createBalanceFromRequest(RequestAbstract $request) : Balance + { + $balance = new Balance(); + $balance->code = (string) $request->getData('code'); + $balance->name = (string) $request->getData('name'); + + return $balance; + } + + /** + * Api method to create an account + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiBalanceElementCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateBalanceElementCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $element = $this->createBalanceElementFromRequest($request); + $this->createModel($request->header->account, $element, BalanceElementMapper::class, 'balance_element', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $element); + } + + /** + * Validate account create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateBalanceElementCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['balance'] = !$request->hasData('balance')) + || ($val['code'] = !$request->hasData('code')) + || ($val['content'] = !$request->hasData('content')) + ) { + return $val; + } + + return []; + } + + /** + * Method to create account from request. + * + * @param RequestAbstract $request Request + * + * @return BalanceElement + * + * @since 1.0.0 + */ + private function createBalanceElementFromRequest(RequestAbstract $request) : BalanceElement + { + $element = new BalanceElement(); + $element->code = $request->getDataString('code') ?? ''; + $element->balance = $request->getDataInt('balance') ?? 0; + $element->order = $request->getDataInt('order') ?? 0; + + $element->setL11n($request->getDataString('content') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); + + return $element; + } + + /** + * Api method to create item attribute l11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiBalanceElementL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateBalanceElementL11nCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $elementL11n = $this->createBalanceElementL11nFromRequest($request); + $this->createModel($request->header->account, $elementL11n, BalanceElementL11nMapper::class, 'balance_element_l11n', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $elementL11n); + } + + /** + * Method to create item attribute l11n from request. + * + * @param RequestAbstract $request Request + * + * @return BaseStringL11n + * + * @since 1.0.0 + */ + private function createBalanceElementL11nFromRequest(RequestAbstract $request) : BaseStringL11n + { + $elementL11n = new BaseStringL11n(); + $elementL11n->ref = $request->getDataInt('ref') ?? 0; + $elementL11n->setLanguage( + $request->getDataString('language') ?? $request->header->l11n->language + ); + $elementL11n->content = $request->getDataString('content') ?? ''; + + return $elementL11n; + } + + /** + * Validate item attribute l11n create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateBalanceElementL11nCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['content'] = !$request->hasData('content')) + || ($val['ref'] = !$request->hasData('ref')) + ) { + return $val; + } + + return []; + } +} \ No newline at end of file diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 9d648e2..f22d0bc 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -30,7 +30,7 @@ use phpOMS\Views\View; final class BackendController extends Controller { /** - * Routing end-point for application behaviour. + * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response diff --git a/Models/Balance.php b/Models/Balance.php new file mode 100644 index 0000000..27ce680 --- /dev/null +++ b/Models/Balance.php @@ -0,0 +1,56 @@ + $this->id, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } +} diff --git a/Models/BalanceElement.php b/Models/BalanceElement.php new file mode 100644 index 0000000..748c1ba --- /dev/null +++ b/Models/BalanceElement.php @@ -0,0 +1,111 @@ +l11n = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { + $this->l11n->content = $l11n; + $this->l11n->setLanguage($lang); + } else { + $this->l11n = new BaseStringL11n(); + $this->l11n->content = $l11n; + $this->l11n->setLanguage($lang); + } + } + + /** + * @return string + * + * @since 1.0.0 + */ + public function getL11n() : string + { + if (!isset($this->l11n)) { + return ''; + } + + return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } +} diff --git a/Models/BalanceElementL11nMapper.php b/Models/BalanceElementL11nMapper.php new file mode 100644 index 0000000..63afabd --- /dev/null +++ b/Models/BalanceElementL11nMapper.php @@ -0,0 +1,69 @@ + + */ +final class BalanceElementL11nMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'balance_balance_element_l11n_id' => ['name' => 'balance_balance_element_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'balance_balance_element_l11n_title' => ['name' => 'balance_balance_element_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'balance_balance_element_l11n_element' => ['name' => 'balance_balance_element_l11n_element', 'type' => 'int', 'internal' => 'ref'], + 'balance_balance_element_l11n_lang' => ['name' => 'balance_balance_element_l11n_lang', 'type' => 'string', 'internal' => 'language'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'balance_balance_element_l11n'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'balance_balance_element_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; +} diff --git a/Models/BalanceElementMapper.php b/Models/BalanceElementMapper.php new file mode 100644 index 0000000..ecaee46 --- /dev/null +++ b/Models/BalanceElementMapper.php @@ -0,0 +1,62 @@ + + */ +final class BalanceElementMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + '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_order' => ['name' => 'balance_balance_element_order', 'type' => 'int', 'internal' => 'order'], + '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'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'balance_balance_element'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'balance_balance_element_id'; +} diff --git a/Models/BalanceMapper.php b/Models/BalanceMapper.php new file mode 100644 index 0000000..115148b --- /dev/null +++ b/Models/BalanceMapper.php @@ -0,0 +1,60 @@ + + */ +final class BalanceMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + '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_name' => ['name' => 'balance_balance_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'balance_balance'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'balance_balance_id'; +} diff --git a/Models/NullBalance.php b/Models/NullBalance.php new file mode 100644 index 0000000..73241d4 --- /dev/null +++ b/Models/NullBalance.php @@ -0,0 +1,46 @@ +id = $id; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return ['id' => $this->id]; + } +} diff --git a/Models/NullBalanceElement.php b/Models/NullBalanceElement.php new file mode 100644 index 0000000..8466436 --- /dev/null +++ b/Models/NullBalanceElement.php @@ -0,0 +1,46 @@ +id = $id; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return ['id' => $this->id]; + } +} diff --git a/Models/PermissionState.php b/Models/PermissionState.php index e4b4195..2c2416a 100644 --- a/Models/PermissionState.php +++ b/Models/PermissionState.php @@ -17,7 +17,7 @@ namespace Modules\Balance\Models; use phpOMS\Stdlib\Base\Enum; /** - * Permision state enum. + * Permission category enum. * * @package Modules\Balance\Models * @license OMS License 2.0 diff --git a/info.json b/info.json index 88f4490..383ea6a 100644 --- a/info.json +++ b/info.json @@ -14,7 +14,6 @@ "name": "Jingga", "website": "jingga.app" }, - "description": "Budget Management module.", "directory": "Balance", "dependencies": { "Controlling": "*"