From bd78091c8ec62d72f769ca0afd50a1a410c7a57e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 11 Mar 2023 23:38:19 +0100 Subject: [PATCH] too many changes --- Admin/Install/attributes.json | 70 +++++++++++++++++++++ Admin/Install/db.json | 8 +-- Admin/Installer.php | 4 +- Controller/ApiController.php | 12 ++-- Controller/BackendController.php | 7 +-- Models/Supplier.php | 15 ++++- Models/SupplierAttributeMapper.php | 2 +- Models/SupplierAttributeType.php | 11 ++++ Models/SupplierAttributeTypeL11nMapper.php | 2 +- Models/SupplierAttributeTypeMapper.php | 2 +- Models/SupplierAttributeValueL11nMapper.php | 2 +- Models/SupplierAttributeValueMapper.php | 2 +- Models/SupplierL11nMapper.php | 2 +- Models/SupplierL11nTypeMapper.php | 2 +- Models/SupplierMapper.php | 12 ++-- Theme/Backend/supplier-profile.tpl.php | 6 +- composer.json | 2 +- info.json | 4 +- 18 files changed, 127 insertions(+), 38 deletions(-) diff --git a/Admin/Install/attributes.json b/Admin/Install/attributes.json index 86228cd..c356cb7 100644 --- a/Admin/Install/attributes.json +++ b/Admin/Install/attributes.json @@ -141,6 +141,50 @@ "default_value": "", "values": [] }, + { + "name": "purchase_tax_code", + "l11n": { + "en": "Purchse tax code", + "de": "VSt. code" + }, + "value_type": 2, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": true, + "default_value": "", + "values": [ + { "value": "AT" }, + { "value": "BE" }, + { "value": "BG" }, + { "value": "HR" }, + { "value": "CY" }, + { "value": "CZ" }, + { "value": "DK" }, + { "value": "EE" }, + { "value": "FI" }, + { "value": "FR" }, + { "value": "DE" }, + { "value": "GR" }, + { "value": "HU" }, + { "value": "IE" }, + { "value": "IT" }, + { "value": "LV" }, + { "value": "LT" }, + { "value": "LU" }, + { "value": "MT" }, + { "value": "NL" }, + { "value": "PL" }, + { "value": "PT" }, + { "value": "RO" }, + { "value": "SK" }, + { "value": "SI" }, + { "value": "ES" }, + { "value": "SE" }, + { "value": "GB" }, + { "value": "INT" }, + { "value": "EU" } + ] + }, { "name": "order_limit", "l11n": { @@ -166,5 +210,31 @@ "is_required": false, "default_value": "", "values": [] + }, + { + "name": "bill_match_pattern", + "l11n": { + "en": "Bill match pattern", + "de": "Beleg-Zeichenkette" + }, + "value_type": 2, + "is_custom_allowed": true, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [] + }, + { + "name": "bill_date_format", + "l11n": { + "en": "Bill date format", + "de": "Beleg-Datumsformat" + }, + "value_type": 2, + "is_custom_allowed": true, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [] } ] \ No newline at end of file diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 26c848d..802d042 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -39,12 +39,12 @@ "type": "DATETIME", "null": false }, - "suppliermgmt_supplier_profile": { - "name": "suppliermgmt_supplier_profile", + "suppliermgmt_supplier_account": { + "name": "suppliermgmt_supplier_account", "type": "INT", "null": false, - "foreignTable": "profile_account", - "foreignKey": "profile_account_id" + "foreignTable": "account", + "foreignKey": "account_id" }, "suppliermgmt_supplier_address": { "name": "suppliermgmt_supplier_address", diff --git a/Admin/Installer.php b/Admin/Installer.php index 9a82aa3..b7e88a9 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -203,8 +203,8 @@ final class Installer extends InstallerAbstract $request->header->account = 1; $request->setData('value', $value['value'] ?? ''); $request->setData('unit', $value['unit'] ?? ''); - $request->setData('default', isset($attribute['values']) && !empty($attribute['values'])); - $request->setData('attributetype', $supplierAttrType[$attribute['name']]['id']); + $request->setData('default', true); + $request->setData('type', $supplierAttrType[$attribute['name']]['id']); if (isset($value['l11n']) && !empty($value['l11n'])) { $request->setData('title', \reset($value['l11n'])); diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 58c44f4..2694872 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -97,11 +97,9 @@ final class ApiController extends Controller $account->name1 = (string) ($request->getData('name1') ?? ''); $account->name2 = (string) ($request->getData('name2') ?? ''); - $profile = new Profile($account); - $supplier = new Supplier(); $supplier->number = (string) ($request->getData('number') ?? ''); - $supplier->profile = $profile; + $supplier->account = $account; $addr = new Address(); $addr->address = (string) ($request->getData('address') ?? ''); @@ -161,7 +159,7 @@ final class ApiController extends Controller $supplierL11n = $this->createSupplierL11nFromRequest($request); $this->createModel($request->header->account, $supplierL11n, SupplierL11nMapper::class, 'supplier_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Supplier localization', 'Supplier localization successfully created', $supplierL11n); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $supplierL11n); } /** @@ -232,7 +230,7 @@ final class ApiController extends Controller $supplierL11nType = $this->createSupplierL11nTypeFromRequest($request); $this->createModel($request->header->account, $supplierL11nType, SupplierL11nTypeMapper::class, 'supplier_l11n_type', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Supplier localization type', 'Supplier localization type successfully created', $supplierL11nType); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization type', 'Localization type successfully created', $supplierL11nType); } /** @@ -364,7 +362,7 @@ final class ApiController extends Controller $attrL11n = $this->createSupplierAttributeTypeL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, SupplierAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type localization', 'Attribute type localization successfully created', $attrL11n); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); } /** @@ -589,7 +587,7 @@ final class ApiController extends Controller $attrL11n = $this->createSupplierAttributeValueL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, SupplierAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type localization', 'Attribute type localization successfully created', $attrL11n); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); } /** diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 4f4cbbd..c7298ec 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -145,9 +145,7 @@ final class BackendController extends Controller $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response)); $supplier = SupplierMapper::getAll() - ->with('profile') - ->with('profile/account') - ->with('profile/image') + ->with('account') ->with('mainAddress') ->limit(25) ->execute(); @@ -204,8 +202,7 @@ final class BackendController extends Controller /** @var \Modules\SupplierManagement\Models\Supplier $supplier */ $supplier = SupplierMapper::get() - ->with('profile') - ->with('profile/account') + ->with('account') ->with('contactElements') ->with('mainAddress') ->with('files')->limit(5, 'files')->sort('files/id', OrderType::DESC) diff --git a/Models/Supplier.php b/Models/Supplier.php index dbdcd36..487a215 100755 --- a/Models/Supplier.php +++ b/Models/Supplier.php @@ -54,7 +54,7 @@ class Supplier public \DateTimeImmutable $createdAt; - public Profile $profile; + public Account $account; /** * Attributes. @@ -104,7 +104,7 @@ class Supplier public function __construct() { $this->createdAt = new \DateTimeImmutable('now'); - $this->profile = new Profile(); + $this->account = new Account(); $this->mainAddress = new NullAddress(); } @@ -276,6 +276,17 @@ class Supplier return $this->attributes; } + public function getAttributeByTypeName(string $name) : SupplierAttribute + { + foreach ($this->attributes as $attribute) { + if ($attribute->type->name === $name) { + return $attribute; + } + } + + return new NullSupplierAttribute(); + } + /** * Get contacts. * diff --git a/Models/SupplierAttributeMapper.php b/Models/SupplierAttributeMapper.php index 67db57a..0cefa30 100755 --- a/Models/SupplierAttributeMapper.php +++ b/Models/SupplierAttributeMapper.php @@ -70,5 +70,5 @@ final class SupplierAttributeMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_supplier_attr_id'; + public const PRIMARYFIELD = 'suppliermgmt_supplier_attr_id'; } diff --git a/Models/SupplierAttributeType.php b/Models/SupplierAttributeType.php index 8c7b790..9b15f04 100755 --- a/Models/SupplierAttributeType.php +++ b/Models/SupplierAttributeType.php @@ -109,6 +109,17 @@ class SupplierAttributeType implements \JsonSerializable return $this->id; } + public function getDefaultByValue(mixed $value) : SupplierAttributeValue + { + foreach ($this->defaults as $default) { + if ($default->getValue() === $value) { + return $default; + } + } + + return new NullSupplierAttributeValue(); + } + /** * Set l11n * diff --git a/Models/SupplierAttributeTypeL11nMapper.php b/Models/SupplierAttributeTypeL11nMapper.php index d567879..39c251b 100755 --- a/Models/SupplierAttributeTypeL11nMapper.php +++ b/Models/SupplierAttributeTypeL11nMapper.php @@ -54,7 +54,7 @@ final class SupplierAttributeTypeL11nMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_attr_type_l11n_id'; + public const PRIMARYFIELD = 'suppliermgmt_attr_type_l11n_id'; /** * Model to use by the mapper. diff --git a/Models/SupplierAttributeTypeMapper.php b/Models/SupplierAttributeTypeMapper.php index 7144dd1..3972812 100755 --- a/Models/SupplierAttributeTypeMapper.php +++ b/Models/SupplierAttributeTypeMapper.php @@ -78,5 +78,5 @@ final class SupplierAttributeTypeMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_attr_type_id'; + public const PRIMARYFIELD = 'suppliermgmt_attr_type_id'; } diff --git a/Models/SupplierAttributeValueL11nMapper.php b/Models/SupplierAttributeValueL11nMapper.php index 4fd115e..8f4e3f1 100644 --- a/Models/SupplierAttributeValueL11nMapper.php +++ b/Models/SupplierAttributeValueL11nMapper.php @@ -54,7 +54,7 @@ final class SupplierAttributeValueL11nMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_attr_value_l11n_id'; + public const PRIMARYFIELD = 'suppliermgmt_attr_value_l11n_id'; /** * Model to use by the mapper. diff --git a/Models/SupplierAttributeValueMapper.php b/Models/SupplierAttributeValueMapper.php index c1ef51c..43a4750 100755 --- a/Models/SupplierAttributeValueMapper.php +++ b/Models/SupplierAttributeValueMapper.php @@ -73,5 +73,5 @@ final class SupplierAttributeValueMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_attr_value_id'; + public const PRIMARYFIELD = 'suppliermgmt_attr_value_id'; } diff --git a/Models/SupplierL11nMapper.php b/Models/SupplierL11nMapper.php index a26bea0..2ec83ef 100755 --- a/Models/SupplierL11nMapper.php +++ b/Models/SupplierL11nMapper.php @@ -67,5 +67,5 @@ final class SupplierL11nMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_supplier_l11n_id'; + public const PRIMARYFIELD = 'suppliermgmt_supplier_l11n_id'; } diff --git a/Models/SupplierL11nTypeMapper.php b/Models/SupplierL11nTypeMapper.php index 7a6a0d7..c5649f9 100755 --- a/Models/SupplierL11nTypeMapper.php +++ b/Models/SupplierL11nTypeMapper.php @@ -52,5 +52,5 @@ final class SupplierL11nTypeMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_supplier_l11n_type_id'; + public const PRIMARYFIELD = 'suppliermgmt_supplier_l11n_type_id'; } diff --git a/Models/SupplierMapper.php b/Models/SupplierMapper.php index 90e054b..e2463c5 100755 --- a/Models/SupplierMapper.php +++ b/Models/SupplierMapper.php @@ -14,11 +14,11 @@ declare(strict_types=1); namespace Modules\SupplierManagement\Models; +use Modules\Admin\Models\AccountMapper; use Modules\Admin\Models\AddressMapper; use Modules\Editor\Models\EditorDocMapper; use Modules\Media\Models\MediaMapper; use Modules\Profile\Models\ContactElementMapper; -use Modules\Profile\Models\ProfileMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -45,7 +45,7 @@ final class SupplierMapper extends DataMapperFactory 'suppliermgmt_supplier_type' => ['name' => 'suppliermgmt_supplier_type', 'type' => 'int', 'internal' => 'type'], 'suppliermgmt_supplier_info' => ['name' => 'suppliermgmt_supplier_info', 'type' => 'string', 'internal' => 'info'], 'suppliermgmt_supplier_created_at' => ['name' => 'suppliermgmt_supplier_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], - 'suppliermgmt_supplier_profile' => ['name' => 'suppliermgmt_supplier_profile', 'type' => 'int', 'internal' => 'profile'], + 'suppliermgmt_supplier_account' => ['name' => 'suppliermgmt_supplier_account', 'type' => 'int', 'internal' => 'account'], 'suppliermgmt_supplier_address' => ['name' => 'suppliermgmt_supplier_address', 'type' => 'int', 'internal' => 'mainAddress'], 'suppliermgmt_supplier_unit' => ['name' => 'suppliermgmt_supplier_unit', 'type' => 'int', 'internal' => 'unit'], ]; @@ -64,7 +64,7 @@ final class SupplierMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD ='suppliermgmt_supplier_id'; + public const PRIMARYFIELD = 'suppliermgmt_supplier_id'; /** * Created at column @@ -81,9 +81,9 @@ final class SupplierMapper extends DataMapperFactory * @since 1.0.0 */ public const OWNS_ONE = [ - 'profile' => [ - 'mapper' => ProfileMapper::class, - 'external' => 'suppliermgmt_supplier_profile', + 'account' => [ + 'mapper' => AccountMapper::class, + 'external' => 'suppliermgmt_supplier_account', ], 'mainAddress' => [ 'mapper' => AddressMapper::class, diff --git a/Theme/Backend/supplier-profile.tpl.php b/Theme/Backend/supplier-profile.tpl.php index b246aa0..2d77a5f 100755 --- a/Theme/Backend/supplier-profile.tpl.php +++ b/Theme/Backend/supplier-profile.tpl.php @@ -69,11 +69,11 @@ echo $this->getData('nav')->render(); - + - + - +
diff --git a/composer.json b/composer.json index fcc0462..8cb1788 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "karaka/karaka", - "description": "PHP Framework for Karaka.", + "description": "PHP Framework for Jingga.", "authors": [ { "name": "Dennis Eichhorn", diff --git a/info.json b/info.json index 386fb1e..7863307 100755 --- a/info.json +++ b/info.json @@ -11,13 +11,15 @@ "phpOMS-db": "1.0.0" }, "creator": { - "name": "Karaka", + "name": "Jingga", "website": "jingga.app" }, "description": "Supplier management module.", "directory": "SupplierManagement", "dependencies": { "Admin": "1.0.0", + "Media": "1.0.0", + "Payment": "1.0.0", "Editor": "1.0.0" }, "providing": {