diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index 79ed66b..0de0c69 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -4,7 +4,7 @@ "pid": "/", "type": 2, "subtype": 1, - "name": "Investment", + "name": "Investments", "uri": "{/base}finance/investment/list?{?}", "target": "self", "icon": null, diff --git a/Admin/Install/db.json b/Admin/Install/db.json index d8104dc..71a510a 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -1,4 +1,52 @@ { + "investmgmt_investment_type": { + "name": "investmgmt_investment_type", + "fields": { + "investmgmt_investment_type_id": { + "name": "investmgmt_investment_type_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "investmgmt_investment_type_name": { + "name": "investmgmt_investment_type_name", + "type": "VARCHAR(255)", + "null": false + } + } + }, + "investmgmt_investment_type_l11n": { + "name": "investmgmt_investment_type_l11n", + "fields": { + "investmgmt_investment_type_l11n_id": { + "name": "investmgmt_investment_type_l11n_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "investmgmt_investment_type_l11n_title": { + "name": "investmgmt_investment_type_l11n_title", + "type": "VARCHAR(255)", + "null": false + }, + "investmgmt_investment_type_l11n_type": { + "name": "investmgmt_investment_type_l11n_type", + "type": "INT(11)", + "null": false, + "foreignTable": "investmgmt_investment_type", + "foreignKey": "investmgmt_investment_type_id" + }, + "investmgmt_investment_type_l11n_lang": { + "name": "investmgmt_investment_type_l11n_lang", + "type": "VARCHAR(2)", + "null": false, + "foreignTable": "language", + "foreignKey": "language_639_1" + } + } + }, "investmgmt_investment": { "name": "investmgmt_investment", "fields": { @@ -24,6 +72,12 @@ "type": "TINYINT", "null": false }, + "investmgmt_investment_type": { + "name": "investmgmt_investment_type", + "type": "INT", + "foreignTable": "investmgmt_investment_type", + "foreignKey": "investmgmt_investment_type_id" + }, "investmgmt_investment_depreciation_type": { "name": "investmgmt_investment_depreciation_type", "type": "TINYINT", @@ -56,25 +110,25 @@ } } }, - "investmgmt_investmen_media": { - "name": "investmgmt_investmen_media", + "investmgmt_investment_media": { + "name": "investmgmt_investment_media", "fields": { - "investmgmt_investmen_media_id": { - "name": "investmgmt_investmen_media_id", + "investmgmt_investment_media_id": { + "name": "investmgmt_investment_media_id", "type": "INT", "null": false, "primary": true, "autoincrement": true }, - "investmgmt_investmen_media_investment": { - "name": "investmgmt_investmen_media_investment", + "investmgmt_investment_media_investment": { + "name": "investmgmt_investment_media_investment", "type": "INT", "null": false, - "foreignTable": "investmgmt_investmen", - "foreignKey": "investmgmt_investmen_id" + "foreignTable": "investmgmt_investment", + "foreignKey": "investmgmt_investment_id" }, - "investmgmt_investmen_media_media": { - "name": "investmgmt_investmen_media_media", + "investmgmt_investment_media_media": { + "name": "investmgmt_investment_media_media", "type": "INT", "null": false, "foreignTable": "media", @@ -82,25 +136,25 @@ } } }, - "investmgmt_investmen_note": { - "name": "investmgmt_investmen_note", + "investmgmt_investment_note": { + "name": "investmgmt_investment_note", "fields": { - "investmgmt_investmen_note_id": { - "name": "investmgmt_investmen_note_id", + "investmgmt_investment_note_id": { + "name": "investmgmt_investment_note_id", "type": "INT", "null": false, "primary": true, "autoincrement": true }, - "investmgmt_investmen_note_investment": { - "name": "investmgmt_investmen_note_investment", + "investmgmt_investment_note_investment": { + "name": "investmgmt_investment_note_investment", "type": "INT", "null": false, - "foreignTable": "investmgmt_investmen", - "foreignKey": "investmgmt_investmen_id" + "foreignTable": "investmgmt_investment", + "foreignKey": "investmgmt_investment_id" }, - "investmgmt_investmen_note_doc": { - "name": "investmgmt_investmen_note_doc", + "investmgmt_investment_note_doc": { + "name": "investmgmt_investment_note_doc", "type": "INT", "null": false, "foreignTable": "editor_doc", @@ -173,7 +227,7 @@ "default": null, "foreignTable": "investmgmt_option", "foreignKey": "investmgmt_option_id" - }, + } } }, "investmgmt_option_media": { @@ -190,7 +244,7 @@ "name": "investmgmt_option_media_option", "type": "INT", "null": false, - "foreignTable": "investmgmt_investmen", + "foreignTable": "investmgmt_option", "foreignKey": "investmgmt_option_id" }, "investmgmt_option_media_media": { @@ -216,7 +270,7 @@ "name": "investmgmt_option_note_option", "type": "INT", "null": false, - "foreignTable": "investmgmt_investmen", + "foreignTable": "investmgmt_option", "foreignKey": "investmgmt_option_id" }, "investmgmt_option_note_doc": { diff --git a/Admin/Installer.php b/Admin/Installer.php index 1ee2d39..91bf541 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -47,7 +47,7 @@ final class Installer extends InstallerAbstract { parent::install($app, $info, $cfgHandler); - /* Fuel types */ + /* Amount types */ $fileContent = \file_get_contents(__DIR__ . '/Install/amounttypes.json'); if ($fileContent === false) { return; @@ -86,7 +86,7 @@ final class Installer extends InstallerAbstract $request->setData('title', \reset($type['l11n'])); $request->setData('language', \array_keys($type['l11n'])[0] ?? 'en'); - $module->apiFuelTypeCreate($request, $response); + $module->apiAmountTypeCreate($request, $response); $responseData = $response->get(''); if (!\is_array($responseData)) { @@ -112,7 +112,7 @@ final class Installer extends InstallerAbstract $request->setData('language', $language); $request->setData('type', $amountTypes[$type['name']]['id']); - $module->apiFuelTypeL11nCreate($request, $response); + $module->apiAmountTypeL11nCreate($request, $response); } } diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 6d557cb..c3b510c 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -24,8 +24,6 @@ use Modules\InvestmentManagement\Models\InvestmentObject; use Modules\InvestmentManagement\Models\InvestmentObjectMapper; use Modules\InvestmentManagement\Models\InvestmentMapper; use Modules\InvestmentManagement\Models\InvestmentStatus; -use Modules\InvestmentManagement\Models\InvestmentTypeL11nMapper; -use Modules\InvestmentManagement\Models\InvestmentTypeMapper; use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\MediaMapper; use Modules\Media\Models\NullMedia; @@ -51,7 +49,7 @@ use phpOMS\Stdlib\Base\FloatInt; * @link https://jingga.app * @since 1.0.0 */ -final class ApiInvestmentController extends Controller +final class ApiController extends Controller { /** * Api method to create a investment @@ -109,9 +107,12 @@ final class ApiInvestmentController extends Controller $investment = new Investment(); $investment->name = $request->getDataString('name') ?? ''; $investment->description = $request->getDataString('description') ?? ''; + $investment->status = (int) ($request->getDataInt('status') ?? InvestmentStatus::DRAFT); + $investment->type = new NullBaseStringL11nType((int) ($request->getDataInt('type') ?? 0)); + $investment->description = $request->getDataString('description') ?? ''; $investment->unit = $request->getDataInt('unit') ?? $this->app->unitId; $investment->createdBy = new NullAccount($request->header->account); - $investment->performanceDate = $request->getDataDateTime('performance') ?? $investment->createdAt; + $investment->performanceDate = $request->getDataDateTime('performance') ?? new \DateTime($investment->createdAt->format('Y-m-d H:i:s')); return $investment; } @@ -491,7 +492,7 @@ final class ApiInvestmentController extends Controller $investment->link = $request->getDataString('link') ?? ''; $investment->investment = (int) $request->getData('investment'); $investment->parent = $request->getDataInt('parent'); - $investment->supplier = $request->getDataInt('supplier') ?? 0; + $investment->supplier = $request->getDataInt('supplier'); $investment->supplierName = $request->getDataString('supplierName') ?? ''; $investment->item = $request->getDataInt('item'); diff --git a/Models/Investment.php b/Models/Investment.php index 31c71a3..0fd028a 100644 --- a/Models/Investment.php +++ b/Models/Investment.php @@ -17,6 +17,7 @@ namespace Modules\InvestmentManagement\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; use phpOMS\Business\Finance\DepreciationType; +use phpOMS\Localization\BaseStringL11nType; /** * Investment model. @@ -38,6 +39,8 @@ class Investment public int $status = InvestmentStatus::DRAFT; + public BaseStringL11nType $type; + public array $options = []; /** @@ -57,14 +60,15 @@ class Investment /** * Constructor. - * + * * @since 1.0.0 */ - public __construct() + public function __construct() { $this->createdBy = new NullAccount(); $this->createdAt = new \DateTimeImmutable('now'); - $this->perforamnceDate = new \DateTime('now'); + $this->performanceDate = new \DateTime('now'); + $this->type = new BaseStringL11nType(); } use \Modules\Media\Models\MediaListTrait; diff --git a/Models/InvestmentMapper.php b/Models/InvestmentMapper.php index efece21..d83c203 100644 --- a/Models/InvestmentMapper.php +++ b/Models/InvestmentMapper.php @@ -51,6 +51,19 @@ final class InvestmentMapper extends DataMapperFactory 'investmgmt_investment_created_at' => ['name' => 'investmgmt_investment_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], ]; + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + public const OWNS_ONE = [ + 'type' => [ + 'mapper' => InvestmentTypeMapper::class, + 'external' => 'investmgmt_investment_type', + ], + ]; + /** * Has many relation. * diff --git a/Models/InvestmentObject.php b/Models/InvestmentObject.php index 780a31c..25e27b9 100644 --- a/Models/InvestmentObject.php +++ b/Models/InvestmentObject.php @@ -30,7 +30,7 @@ class InvestmentObject public string $description = ''; - public int $supplier = 0; + public ?int $supplier = null; public string $supplierName = ''; diff --git a/Models/InvestmentTypeMapper.php b/Models/InvestmentTypeMapper.php new file mode 100644 index 0000000..60c924e --- /dev/null +++ b/Models/InvestmentTypeMapper.php @@ -0,0 +1,84 @@ + + */ +final class InvestmentTypeMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'investmgmt_investment_type_id' => ['name' => 'investmgmt_investment_type_id', 'type' => 'int', 'internal' => 'id'], + 'investmgmt_investment_type_name' => ['name' => 'investmgmt_investment_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + public const HAS_MANY = [ + 'l11n' => [ + 'mapper' => InvestmentTypeL11nMapper::class, + 'table' => 'investmgmt_investment_type_l11n', + 'self' => 'investmgmt_investment_type_l11n_type', + 'column' => 'content', + 'external' => null, + ], + ]; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11nType::class; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'investmgmt_investment_type'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'investmgmt_investment_type_id'; +} diff --git a/Models/VehicleTypeL11nMapper.php b/Models/VehicleTypeL11nMapper.php new file mode 100644 index 0000000..c0b5ecd --- /dev/null +++ b/Models/VehicleTypeL11nMapper.php @@ -0,0 +1,69 @@ + + */ +final class InvestmentTypeL11nMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'investmgmt_investment_type_l11n_id' => ['name' => 'investmgmt_investment_type_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'investmgmt_investment_type_l11n_title' => ['name' => 'investmgmt_investment_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'investmgmt_investment_type_l11n_type' => ['name' => 'investmgmt_investment_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], + 'investmgmt_investment_type_l11n_lang' => ['name' => 'investmgmt_investment_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'investmgmt_investment_type_l11n'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'investmgmt_investment_type_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; +} diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php index 175f4cc..9b38377 100755 --- a/Theme/Backend/Lang/Navigation.en.lang.php +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -13,6 +13,6 @@ declare(strict_types=1); return ['Navigation' => [ - 'PurchaseInquiries' => 'PurchaseInquiries', - 'Investment' => 'Investment', + 'PurchaseInquiries' => 'Purchase Inquiries', + 'Investments' => 'Investments', ]];