add address and client element support

This commit is contained in:
Dennis Eichhorn 2020-10-18 20:56:51 +02:00
parent 176db29f64
commit c76fcaabcf
9 changed files with 215 additions and 90 deletions

View File

@ -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
}
}
},

43
Controller.js Normal file
View File

@ -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();

View File

@ -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'));

View File

@ -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;
}
}

View File

@ -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',
],
];
}

View File

@ -0,0 +1,64 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\ClientManagement
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/** @var \phpOMS\Views\View $this */
$clients = $this->getData('client');
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12">
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Clients'); ?><i class="fa fa-download floatRight download btn"></i></div>
<table id="iSalesClientList" class="default">
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<input id="clientList-r1-asc" name="clientList-sort" type="radio"><label for="clientList-r1-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="clientList-r1-desc" name="clientList-sort" type="radio"><label for="clientList-r1-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td class="wf-100"><?= $this->getHtml('Name'); ?>
<input id="clientList-r2-asc" name="clientList-sort" type="radio"><label for="clientList-r2-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="clientList-r2-desc" name="clientList-sort" type="radio"><label for="clientList-r2-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('City'); ?>
<input id="clientList-r5-asc" name="clientList-sort" type="radio"><label for="clientList-r5-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="clientList-r5-desc" name="clientList-sort" type="radio"><label for="clientList-r5-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('Zip'); ?>
<input id="clientList-r6-asc" name="clientList-sort" type="radio"><label for="clientList-r6-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="clientList-r6-desc" name="clientList-sort" type="radio"><label for="clientList-r6-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('Address'); ?>
<input id="clientList-r7-asc" name="clientList-sort" type="radio"><label for="clientList-r7-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="clientList-r7-desc" name="clientList-sort" type="radio"><label for="clientList-r7-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('Country'); ?>
<input id="clientList-r8-asc" name="clientList-sort" type="radio"><label for="clientList-r8-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="clientList-r8-desc" name="clientList-sort" type="radio"><label for="clientList-r8-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<tbody>
<?php $count = 0; foreach ($clients as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); ?>
<tr data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getNumber()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getProfile()->getAccount()->getName1()); ?> <?= $this->printHtml($value->getProfile()->getAccount()->getName2()); ?></a>
<td data-label="<?= $this->getHtml('City'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getCity()); ?></a>
<td data-label="<?= $this->getHtml('Zip'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getPostal()); ?></a>
<td data-label="<?= $this->getHtml('Address'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getAddress()); ?></a>
<td data-label="<?= $this->getHtml('Country'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getCountry()); ?></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="8" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</section>
</div>
</div>

View File

@ -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();
<tr><td><input type="text" id="iName2" name="name2" value="<?= $this->printHtml($client->getProfile()->getAccount()->getName2()); ?>">
<tr><td><label for="iName3"><?= $this->getHtml('Name3'); ?></label>
<tr><td><input type="text" id="iName3" name="name3" value="<?= $this->printHtml($client->getProfile()->getAccount()->getName3()); ?>">
<tr><td>Address
<tr><td>
<tr><td>
<tr><td>
<tr><td>
</table>
</div>
<div class="portlet-foot">
@ -76,27 +77,48 @@ echo $this->getData('nav')->render();
</form>
</section>
<section class="portlet highlight-4">
<section class="portlet">
<div class="portlet-head">Contact</div>
<div class="portlet-body">
<textarea class="undecorated"></textarea>
<table class="layout wf-100">
<tr><td><label for="iName1"><?= $this->getHtml('Phone'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainContactElement(ContactType::PHONE)->getContent()); ?>">
<tr><td><label for="iName1"><?= $this->getHtml('Email'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainContactElement(ContactType::EMAIL)->getContent()); ?>">
<tr><td><label for="iName1"><?= $this->getHtml('Website'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainContactElement(ContactType::WEBSITE)->getContent()); ?>">
</table>
</div>
</section>
<section class="portlet">
<div class="portlet-head">Contact</div>
<div class="portlet-head"><?= $this->getHtml('Address'); ?></div>
<div class="portlet-body">
<table class="layout wf-100">
<?php if (!empty($client->getMainAddress()->getAddition())) : ?>
<tr><td><label for="iName1"><?= $this->getHtml('Addition'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getAddition()); ?>">
<?php endif; ?>
<tr><td><label for="iName1"><?= $this->getHtml('Address'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getAddress()); ?>" required>
<tr><td><label for="iName1"><?= $this->getHtml('Postal'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getPostal()); ?>" required>
<tr><td><label for="iName1"><?= $this->getHtml('City'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getCity()); ?>" required>
<tr><td><label for="iName1"><?= $this->getHtml('Country'); ?></label>
<tr><td><select>
<?php foreach ($countryCodes as $code3 => $code2) : ?>
<option value="<?= $this->printHtml($code2); ?>"<?= $this->printHtml($code2 === $client->getMainAddress()->getCountry() ? ' selected' : ''); ?>><?= $this->printHtml($countries[$code3]); ?>
<?php endforeach; ?>
</select>
<tr><td><img id="iMap" style="width: 100%;" src="<?= UriFactory::build('phpOMS/Localization/Maps/svg/' . \strtolower($client->getMainAddress()->getCountry()) . '.svg'); ?>">
</table>
</div>
</section>
<section class="portlet highlight-4">
<div class="portlet-body">
<table>
<tr><td>Main:
<tr><td>Phone:
<td>
<tr><td>Email:
<td>
<tr><td>Accounting:
<tr><td>Phone:
<td>
<tr><td>Email:
<td>
</table>
<textarea class="undecorated"><?= $this->printHtml($client->getInfo()); ?></textarea>
</div>
</section>
</div>
@ -325,7 +347,7 @@ echo $this->getData('nav')->render();
<section class="box wf-100">
<header><h1><?= $this->getHtml('Price'); ?></h1></header>
<div class="inner">
<form action="<?= \phpOMS\Uri\UriFactory::build('{/api}...'); ?>" method="post">
<form action="<?= UriFactory::build('{/api}...'); ?>" method="post">
<table class="layout wf-100">
<tbody>
<tr><td colspan="2"><label for="iPType"><?= $this->getHtml('Type'); ?></label>
@ -367,7 +389,7 @@ echo $this->getData('nav')->render();
<section class="box wf-100">
<header><h1><?= $this->getHtml('AreaManager'); ?></h1></header>
<div class="inner">
<form action="<?= \phpOMS\Uri\UriFactory::build('{/api}...'); ?>" method="post">
<form action="<?= UriFactory::build('{/api}...'); ?>" method="post">
<table class="layout wf-100">
<tbody>
<tr><td><label for="iManager"><?= $this->getHtml('AreaManager'); ?></label>

View File

@ -1,56 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\ClientManagement
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/** @var \phpOMS\Views\View $this */
$clients = $this->getData('client');
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12">
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Clients'); ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default">
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<td><?= $this->getHtml('Name1'); ?>
<td><?= $this->getHtml('Name2'); ?>
<td class="wf-100"><?= $this->getHtml('Name3'); ?>
<td><?= $this->getHtml('City'); ?>
<td><?= $this->getHtml('Zip'); ?>
<td><?= $this->getHtml('Address'); ?>
<td><?= $this->getHtml('Country'); ?>
<tbody>
<?php $count = 0; foreach ($clients as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); ?>
<tr data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getNumber()); ?></a>
<td data-label="<?= $this->getHtml('Name1'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getProfile()->getAccount()->getName1()); ?></a>
<td data-label="<?= $this->getHtml('Name2'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getProfile()->getAccount()->getName2()); ?></a>
<td data-label="<?= $this->getHtml('Name3'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getProfile()->getAccount()->getName3()); ?></a>
<td data-label="<?= $this->getHtml('City'); ?>">
<td data-label="<?= $this->getHtml('Zip'); ?>">
<td data-label="<?= $this->getHtml('Address'); ?>">
<td data-label="<?= $this->getHtml('Country'); ?>">
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="8" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</section>
</div>
</div>