diff --git a/Controller.js b/Controller.js index 48ca412..dcee1de 100755 --- a/Controller.js +++ b/Controller.js @@ -1,10 +1,8 @@ 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.SupplierManager = class { +jsOMS.Modules.SupplierManagement = class { /** * @constructor * @@ -17,24 +15,31 @@ jsOMS.Modules.SupplierManager = class { bind (id) { - const e = typeof id === 'undefined' ? document.getElementsByTagName('canvas') : [document.getElementById(id)], - length = e.length; + const charts = typeof id === 'undefined' ? document.getElementsByTagName('canvas') : [document.getElementById(id)]; + let length = charts.length; for (let i = 0; i < length; ++i) { - if (e[i].getAttribute('data-chart') === null - && e[i].getAttribute('data-chart') !== 'undefined' + if (charts[i].getAttribute('data-chart') === null + && charts[i].getAttribute('data-chart') !== 'undefined' ) { continue; } - this.bindElement(e[i]); + this.bindChart(charts[i]); + } + + const maps = typeof id === 'undefined' ? document.getElementsByClassName('map') : [document.getElementById(id)]; + length = maps.length; + + for (let i = 0; i < length; ++i) { + this.bindMap(maps[i]); } }; - bindElement (chart) + bindChart (chart) { if (typeof chart === 'undefined' || !chart) { - jsOMS.Log.Logger.instance.error('Invalid chart: ' + chart, 'SupplierManagementController'); + jsOMS.Log.Logger.instance.error('Invalid chart: ' + chart, 'SupplierManagement'); return; } @@ -44,6 +49,42 @@ jsOMS.Modules.SupplierManager = class { const myChart = new Chart(chart.getContext('2d'), data); }; + + bindMap (map) + { + if (typeof map === 'undefined' || !map) { + jsOMS.Log.Logger.instance.error('Invalid map: ' + map, 'SupplierManagement'); + + return; + } + + const mapObj = new OpenLayers.Map(map.getAttribute('id'), { + controls: [ + new OpenLayers.Control.Navigation( + { + zoomBoxEnabled: true, + zoomWheelEnabled: false + } + ), + new OpenLayers.Control.Zoom(), + new OpenLayers.Control.Attribution() + ] + }); + + mapObj.addLayer(new OpenLayers.Layer.OSM()); + + const fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984 + const toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection + const position = new OpenLayers.LonLat(map.getAttribute('data-lon'), map.getAttribute('data-lat')).transform(fromProjection, toProjection); + const zoom = 12; + + const markers = new OpenLayers.Layer.Markers("Markers"); + mapObj.addLayer(markers); + + markers.addMarker(new OpenLayers.Marker(position)); + + mapObj.setCenter(position, zoom); + }; }; -window.omsApp.moduleManager.get('SupplierManager').bind(); +window.omsApp.moduleManager.get('SupplierManagement').bind(); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index c3e8462..72f9466 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -15,12 +15,15 @@ declare(strict_types=1); namespace Modules\SupplierManagement\Controller; use Modules\Billing\Models\PurchaseBillMapper; +use Modules\Media\Models\MediaMapper; +use Modules\Media\Models\MediaTypeMapper; use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper; use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper; use Modules\SupplierManagement\Models\SupplierAttributeValueMapper; use Modules\SupplierManagement\Models\SupplierMapper; use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; +use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\OrderType; use phpOMS\Localization\Money; use phpOMS\Message\RequestAbstract; @@ -196,11 +199,11 @@ final class BackendController extends Controller */ public function viewSupplierManagementSupplierProfile(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : RenderableInterface { - /** @var \phpOMS\Model\Html\Head $head */ - $head = $response->get('Content')->head; + $head = $response->data['Content']->head; $head->addAsset(AssetType::CSS, 'Resources/chartjs/Chartjs/chart.css'); $head->addAsset(AssetType::JSLATE, 'Resources/chartjs/Chartjs/chart.js'); - $head->addAsset(AssetType::JSLATE, 'Modules/SupplierManagement/Controller.js', ['type' => 'module']); + $head->addAsset(AssetType::JSLATE, 'Resources/OpenLayers/OpenLayers.js'); + $head->addAsset(AssetType::JSLATE, 'Modules/ClientManagement/Controller.js', ['type' => 'module']); $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-profile'); @@ -218,6 +221,34 @@ final class BackendController extends Controller $view->data['supplier'] = $supplier; + // Get item profile image + // It might not be part of the 5 newest item files from above + // @todo: It would be nice to have something like this as a default method in the model e.g. + // ItemManagement::getRelations()->with('types')->where(...); + // This should return the relations and NOT the model itself + $query = new Builder($this->app->dbPool->get()); + $results = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file') + ->from(SupplierMapper::TABLE) + ->leftJoin(SupplierMapper::HAS_MANY['files']['table']) + ->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['self'], '=', SupplierMapper::TABLE . '.' . SupplierMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::TABLE) + ->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::HAS_MANY['types']['table']) + ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) + ->leftJoin(MediaTypeMapper::TABLE) + ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) + ->where(SupplierMapper::HAS_MANY['files']['self'], '=', $supplier->id) + ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image'); + + + $clientImage = MediaMapper::get() + ->with('types') + ->where('id', $results) + ->limit(1) + ->execute(); + + $view->data['clientImage'] = $clientImage; + // stats if ($this->app->moduleManager->isActive('Billing')) { $ytd = PurchaseBillMapper::getPurchaseBySupplierId($supplier->id, new SmartDateTime('Y-01-01'), new SmartDateTime('now')); diff --git a/Theme/Backend/supplier-list.tpl.php b/Theme/Backend/supplier-list.tpl.php index 8897a63..86b5e03 100755 --- a/Theme/Backend/supplier-list.tpl.php +++ b/Theme/Backend/supplier-list.tpl.php @@ -27,7 +27,6 @@ echo $this->data['nav']->render(); ?>
| = $this->getHtml('ID', '0', '0'); ?> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| = $this->printHtml($value->number); ?> - | = $this->printHtml($value->profile->account->name1); ?> = $this->printHtml($value->profile->account->name2); ?> + | = $this->printHtml($value->account->name1); ?> = $this->printHtml($value->account->name2); ?> | = $this->printHtml($value->mainAddress->city); ?> | = $this->printHtml($value->mainAddress->postal); ?> | = $this->printHtml($value->mainAddress->address); ?>
diff --git a/Theme/Backend/supplier-profile-bills.tpl.php b/Theme/Backend/supplier-profile-bills.tpl.php
new file mode 100644
index 0000000..9e9792f
--- /dev/null
+++ b/Theme/Backend/supplier-profile-bills.tpl.php
@@ -0,0 +1,194 @@
+data['newestInvoices'] ?? [];
+
+?>
+
+
+
diff --git a/Theme/Backend/supplier-profile-items.tpl.php b/Theme/Backend/supplier-profile-items.tpl.php
new file mode 100644
index 0000000..2884062
--- /dev/null
+++ b/Theme/Backend/supplier-profile-items.tpl.php
@@ -0,0 +1,160 @@
+data['items'] ?? [];
+
+?>
+
+
+
+
+
+ = $this->getHtml('Bills'); ?>
+
+
diff --git a/Theme/Backend/supplier-profile.tpl.php b/Theme/Backend/supplier-profile.tpl.php
index da15cf6..36e089b 100755
--- a/Theme/Backend/supplier-profile.tpl.php
+++ b/Theme/Backend/supplier-profile.tpl.php
@@ -12,7 +12,8 @@
*/
declare(strict_types=1);
-use Modules\Profile\Models\ContactType;
+use Modules\Admin\Models\ContactType;
+use Modules\Media\Models\NullMedia;
use phpOMS\Uri\UriFactory;
$countryCodes = \phpOMS\Localization\ISO3166TwoEnum::getConstants();
@@ -22,11 +23,13 @@ $countries = \phpOMS\Localization\ISO3166NameEnum::getConstants();
* @var \Modules\SupplierManagement\Models\Supplier $supplier
*/
$supplier = $this->data['supplier'];
-$notes = $supplier->getNotes();
-$files = $supplier->files;
+$notes = $supplier->getNotes();
+$files = $supplier->files;
-$newestInvoices = $this->data['newestInvoices'] ?? [];
-$monthlyPurchaseCosts = $this->data['monthlyPurchaseCosts'] ?? [];
+$supplierImage = $this->getData('supplierImage') ?? new NullMedia();
+
+$newestInvoices = $this->data['newestInvoices'] ?? [];
+$monthlySalesCosts = $this->data['monthlySalesCosts'] ?? [];
/**
* @var \phpOMS\Views\View $this
@@ -37,24 +40,20 @@ echo $this->data['nav']->render();
+
+= $this->getHtml('Items'); ?>
+
@@ -62,7 +61,16 @@ echo $this->data['nav']->render();
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||