From c76fcaabcf2ef1d2f70c7901af802dcae4c7f436 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 18 Oct 2020 20:56:51 +0200 Subject: [PATCH] add address and client element support --- Admin/Install/db.json | 17 +++-- Controller.js | 43 ++++++++++++ Controller/BackendController.php | 10 ++- Models/Client.php | 39 +++++++++++ Models/ClientMapper.php | 10 ++- ...s-create.tpl.php => client-create.tpl.php} | 0 Theme/Backend/client-list.tpl.php | 64 ++++++++++++++++++ ...profile.tpl.php => client-profile.tpl.php} | 66 ++++++++++++------- Theme/Backend/clients-list.tpl.php | 56 ---------------- 9 files changed, 215 insertions(+), 90 deletions(-) create mode 100644 Controller.js rename Theme/Backend/{clients-create.tpl.php => client-create.tpl.php} (100%) create mode 100644 Theme/Backend/client-list.tpl.php rename Theme/Backend/{clients-profile.tpl.php => client-profile.tpl.php} (86%) delete mode 100644 Theme/Backend/clients-list.tpl.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 54b34d1..9d3b557 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -46,6 +46,14 @@ "null": false, "foreignTable": "profile_account", "foreignKey": "profile_account_id" + }, + "clientmgmt_client_address": { + "name": "clientmgmt_client_address", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "address", + "foreignKey": "address_id" } } }, @@ -63,8 +71,8 @@ "name": "clientmgmt_client_contactelement_dst", "type": "INT", "null": false, - "foreignTable": "profile_contactelement", - "foreignKey": "profile_contactelement_id" + "foreignTable": "profile_contact_element", + "foreignKey": "profile_contact_element_id" }, "clientmgmt_client_contactelement_src": { "name": "clientmgmt_client_contactelement_src", @@ -72,11 +80,6 @@ "null": false, "foreignTable": "clientmgmt_client", "foreignKey": "clientmgmt_client_id" - }, - "clientmgmt_client_contactelement_type": { - "name": "clientmgmt_client_contactelement_type", - "type": "TINYINT", - "null": false } } }, diff --git a/Controller.js b/Controller.js new file mode 100644 index 0000000..73cf423 --- /dev/null +++ b/Controller.js @@ -0,0 +1,43 @@ +import { Autoloader } from '../../jsOMS/Autoloader.js'; +import { NotificationMessage } from '../../jsOMS/Message/Notification/NotificationMessage.js'; +import { NotificationType } from '../../jsOMS/Message/Notification/NotificationType.js'; + +Autoloader.defineNamespace('jsOMS.Modules'); + +jsOMS.Modules.ClientManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (app) + { + this.app = app; + }; + + bind (id) + { + /* + const map = document.getElementById('iMap'); + fetch(map.src).then(res => res.text()).then(data => { + const parser = new DOMParser(); + const svg = parser.parseFromString(data, 'image/svg+xml').querySelector('svg'); + + if (map.id) svg.id = map.id; + if (map.className) svg.classList = map.classList; + + map.parentNode.replaceChild(svg, map); + + return svg; + }) + .then(svg => { + //svg.setAttribute('width', 100); + //svg.setAttribute('height', 136); + //svg.setAttribute('viewbox', '0 0 1000 1360'); + //svg.style.width = '100%'; + }); + */ + }; +}; + +window.omsApp.moduleManager.get('ClientManager').bind(); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 309bb9a..e86f9eb 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -19,6 +19,7 @@ use phpOMS\Contract\RenderableInterface; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Views\View; +use phpOMS\Asset\AssetType; /** * ClientManagement class. @@ -45,7 +46,7 @@ final class BackendController extends Controller public function viewClientManagementClientList(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/ClientManagement/Theme/Backend/clients-list'); + $view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response)); $client = ClientMapper::getAll(); @@ -69,7 +70,7 @@ final class BackendController extends Controller public function viewClientManagementClientCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/ClientManagement/Theme/Backend/clients-create'); + $view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-create'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response)); return $view; @@ -89,8 +90,11 @@ final class BackendController extends Controller */ public function viewClientManagementClientProfile(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { + $head = $response->get('Content')->getData('head'); + $head->addAsset(AssetType::JSLATE, 'Modules/ClientManagement/Controller.js', ['type' => 'module']); + $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/ClientManagement/Theme/Backend/clients-profile'); + $view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-profile'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response)); $client = ClientMapper::get((int) $request->getData('id')); diff --git a/Models/Client.php b/Models/Client.php index cb57485..aa2ca0b 100644 --- a/Models/Client.php +++ b/Models/Client.php @@ -14,8 +14,11 @@ declare(strict_types=1); namespace Modules\ClientManagement\Models; +use Modules\Admin\Models\NullAddress; use Modules\Media\Models\Media; use Modules\Profile\Models\Profile; +use Modules\Profile\Models\ContactElement; +use Modules\Profile\Models\NullContactElement; /** * Account class. @@ -49,6 +52,8 @@ class Client private array $contactElements = []; + private $mainAddress = null; + private array $address = []; private array $partners = []; @@ -70,6 +75,7 @@ class Client { $this->createdAt = new \DateTimeImmutable('now'); $this->profile = new Profile(); + $this->mainAddress = new NullAddress(); } /** @@ -334,6 +340,16 @@ class Client $this->profile = $profile; } + public function setMainAddress($address) : void + { + $this->mainAddress = $address; + } + + public function getMainAddress() + { + return $this->mainAddress; + } + /** * Get media. * @@ -383,4 +399,27 @@ class Client { return $this->contactElements; } + + private function orderContactElements(ContactElement $a, ContactElement $b) : int + { + return $a->getOrder() <=> $b->getOrder(); + } + + public function getMainContactElement(int $type) : ContactElement + { + \uasort($this->contactElements, [$this, 'orderContactElements']); + + foreach ($this->contactElements as $element) { + if ($element->getType() === $type) { + return $element; + } + } + + return new NullContactElement(); + } + + public function addContactElement($element) : void + { + $this->contactElements[] = $element; + } } diff --git a/Models/ClientMapper.php b/Models/ClientMapper.php index e3824ce..e2e020a 100644 --- a/Models/ClientMapper.php +++ b/Models/ClientMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\ClientManagement\Models; +use Modules\Admin\Models\AddressMapper; use Modules\Media\Models\MediaMapper; use Modules\Profile\Models\ContactElementMapper; use Modules\Profile\Models\ProfileMapper; @@ -44,6 +45,7 @@ final class ClientMapper extends DataMapperAbstract 'clientmgmt_client_info' => ['name' => 'clientmgmt_client_info', 'type' => 'string', 'internal' => 'info'], 'clientmgmt_client_created_at' => ['name' => 'clientmgmt_client_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], 'clientmgmt_client_profile' => ['name' => 'clientmgmt_client_profile', 'type' => 'int', 'internal' => 'profile'], + 'clientmgmt_client_address' => ['name' => 'clientmgmt_client_address', 'type' => 'int', 'internal' => 'mainAddress'], ]; /** @@ -81,6 +83,10 @@ final class ClientMapper extends DataMapperAbstract 'mapper' => ProfileMapper::class, 'self' => 'clientmgmt_client_profile', ], + 'mainAddress' => [ + 'mapper' => AddressMapper::class, + 'self' => 'clientmgmt_client_address', + ], ]; /** @@ -99,8 +105,8 @@ final class ClientMapper extends DataMapperAbstract 'contactElements' => [ 'mapper' => ContactElementMapper::class, 'table' => 'clientmgmt_client_contactelement', - 'external' => 'clientmgmt_client_contactelement_dst', - 'self' => 'clientmgmt_client_contactelement_src', + 'external' => 'clientmgmt_client_contactelement_src', + 'self' => 'clientmgmt_client_contactelement_dst', ], ]; } diff --git a/Theme/Backend/clients-create.tpl.php b/Theme/Backend/client-create.tpl.php similarity index 100% rename from Theme/Backend/clients-create.tpl.php rename to Theme/Backend/client-create.tpl.php diff --git a/Theme/Backend/client-list.tpl.php b/Theme/Backend/client-list.tpl.php new file mode 100644 index 0000000..5735f85 --- /dev/null +++ b/Theme/Backend/client-list.tpl.php @@ -0,0 +1,64 @@ +getData('client'); + +echo $this->getData('nav')->render(); ?> +
+
+
+
getHtml('Clients'); ?>
+ + + + + $value) : ++$count; + $url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); ?> + +
getHtml('ID', '0', '0'); ?> + + + getHtml('Name'); ?> + + + getHtml('City'); ?> + + + getHtml('Zip'); ?> + + + getHtml('Address'); ?> + + + getHtml('Country'); ?> + + +
printHtml($value->getNumber()); ?> + printHtml($value->getProfile()->getAccount()->getName1()); ?> printHtml($value->getProfile()->getAccount()->getName2()); ?> + printHtml($value->getMainAddress()->getCity()); ?> + printHtml($value->getMainAddress()->getPostal()); ?> + printHtml($value->getMainAddress()->getAddress()); ?> + printHtml($value->getMainAddress()->getCountry()); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+
+
+
diff --git a/Theme/Backend/clients-profile.tpl.php b/Theme/Backend/client-profile.tpl.php similarity index 86% rename from Theme/Backend/clients-profile.tpl.php rename to Theme/Backend/client-profile.tpl.php index ccb7014..602e1f5 100644 --- a/Theme/Backend/clients-profile.tpl.php +++ b/Theme/Backend/client-profile.tpl.php @@ -12,6 +12,12 @@ */ declare(strict_types=1); +use Modules\Profile\Models\ContactType; +use phpOMS\Uri\UriFactory; + +$countryCodes = \phpOMS\Localization\ISO3166TwoEnum::getConstants(); +$countries = \phpOMS\Localization\ISO3166NameEnum::getConstants(); + /** * @var \Modules\ClientManagement\Models\Client $client */ @@ -63,11 +69,6 @@ echo $this->getData('nav')->render(); - Address - - - -
@@ -76,27 +77,48 @@ echo $this->getData('nav')->render(); -
+
+
Contact
- + +
+
+
+
+
+
+
-
Contact
+
getHtml('Address'); ?>
+
+ + getMainAddress()->getAddition())) : ?> +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
- -
Main: -
Phone: - -
Email: - -
Accounting: -
Phone: - -
Email: - -
+
@@ -325,7 +347,7 @@ echo $this->getData('nav')->render();

getHtml('Price'); ?>

-
+
@@ -367,7 +389,7 @@ echo $this->getData('nav')->render();

getHtml('AreaManager'); ?>

- +
diff --git a/Theme/Backend/clients-list.tpl.php b/Theme/Backend/clients-list.tpl.php deleted file mode 100644 index 221133d..0000000 --- a/Theme/Backend/clients-list.tpl.php +++ /dev/null @@ -1,56 +0,0 @@ -getData('client'); - -echo $this->getData('nav')->render(); ?> -
-
-
-
getHtml('Clients'); ?>
- - - - - $value) : ++$count; - $url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); ?> - -
getHtml('ID', '0', '0'); ?> - getHtml('Name1'); ?> - getHtml('Name2'); ?> - getHtml('Name3'); ?> - getHtml('City'); ?> - getHtml('Zip'); ?> - getHtml('Address'); ?> - getHtml('Country'); ?> -
printHtml($value->getNumber()); ?> - printHtml($value->getProfile()->getAccount()->getName1()); ?> - printHtml($value->getProfile()->getAccount()->getName2()); ?> - printHtml($value->getProfile()->getAccount()->getName3()); ?> - - - - - - -
getHtml('Empty', '0', '0'); ?> - -
-
-
-