From a66a61bd9aa4d8ff40cfeca4d81d3b37e378423d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 20 Feb 2021 21:19:43 +0100 Subject: [PATCH] improve billing --- Controller.js | 49 +++++++++++ Controller/BackendController.php | 31 +++++++ Theme/Backend/supplier-profile.tpl.php | 111 +++++++++++++++++++++++-- 3 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 Controller.js diff --git a/Controller.js b/Controller.js new file mode 100644 index 0000000..48ca412 --- /dev/null +++ b/Controller.js @@ -0,0 +1,49 @@ +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 { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (app) + { + this.app = app; + }; + + bind (id) + { + const e = typeof id === 'undefined' ? document.getElementsByTagName('canvas') : [document.getElementById(id)], + length = e.length; + + for (let i = 0; i < length; ++i) { + if (e[i].getAttribute('data-chart') === null + && e[i].getAttribute('data-chart') !== 'undefined' + ) { + continue; + } + + this.bindElement(e[i]); + } + }; + + bindElement (chart) + { + if (typeof chart === 'undefined' || !chart) { + jsOMS.Log.Logger.instance.error('Invalid chart: ' + chart, 'SupplierManagementController'); + + return; + } + + const self = this; + const data = JSON.parse(chart.getAttribute('data-chart')); + + const myChart = new Chart(chart.getContext('2d'), data); + }; +}; + +window.omsApp.moduleManager.get('SupplierManager').bind(); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e5b6494..3b6efe8 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -15,9 +15,14 @@ declare(strict_types=1); namespace Modules\SupplierManagement\Controller; use Modules\SupplierManagement\Models\SupplierMapper; +use Modules\Billing\Models\PurchaseBillMapper; +use Modules\Billing\Models\BillTypeL11n; +use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; +use phpOMS\Localization\Money; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; +use phpOMS\Stdlib\Base\SmartDateTime; use phpOMS\Views\View; /** @@ -89,6 +94,11 @@ final class BackendController extends Controller */ public function viewSupplierManagementSupplierProfile(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { + $head = $response->get('Content')->getData('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']); + $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-profile'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response)); @@ -96,6 +106,27 @@ final class BackendController extends Controller $supplier = SupplierMapper::get((int) $request->getData('id')); $view->setData('supplier', $supplier); + // stats + if ($this->app->moduleManager->isActive('Billing')) { + $ytd = PurchaseBillMapper::getPurchaseBySupplierId($supplier->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now')); + $mtd = PurchaseBillMapper::getPurchaseBySupplierId($supplier->getId(), new SmartDateTime('Y-m-01'), new SmartDateTime('now')); + $lastOrder = PurchaseBillMapper::getLastOrderDateBySupplierId($supplier->getId()); + $newestInvoices = PurchaseBillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class])::getNewestSupplierInvoices($supplier->getId(), 5); + $monthlyPurchaseCosts = PurchaseBillMapper::getSupplierMonthlyPurchaseCosts($supplier->getId(), (new SmartDateTime('now'))->createModify(-1), new SmartDateTime('now')); + } else { + $ytd = new Money(); + $mtd = new Money(); + $lastOrder = null; + $newestInvoices = []; + $monthlyPurchaseCosts = []; + } + + $view->addData('ytd', $ytd); + $view->addData('mtd', $mtd); + $view->addData('lastOrder', $lastOrder); + $view->addData('newestInvoices', $newestInvoices); + $view->addData('monthlyPurchaseCosts', $monthlyPurchaseCosts); + return $view; } diff --git a/Theme/Backend/supplier-profile.tpl.php b/Theme/Backend/supplier-profile.tpl.php index c4f4b7a..3e7b8f7 100755 --- a/Theme/Backend/supplier-profile.tpl.php +++ b/Theme/Backend/supplier-profile.tpl.php @@ -4,7 +4,7 @@ * * PHP Version 8.0 * - * @package Modules\ClientManagement + * @package Modules\SupplierManagement * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -12,6 +12,9 @@ */ declare(strict_types=1); +use Modules\Profile\Models\ContactType; +use phpOMS\Uri\UriFactory; + $countryCodes = \phpOMS\Localization\ISO3166TwoEnum::getConstants(); $countries = \phpOMS\Localization\ISO3166NameEnum::getConstants(); @@ -20,6 +23,9 @@ $countries = \phpOMS\Localization\ISO3166NameEnum::getConstants(); */ $supplier = $this->getData('supplier'); +$newestInvoices = $this->getData('newestInvoices') ?? []; +$monthlyPurchaseCosts = $this->getData('monthlyPurchaseCosts') ?? []; + /** * @var \phpOMS\Views\View $this */ @@ -188,8 +194,25 @@ echo $this->getData('nav')->render();
-
getHtml('Invoices'); ?>
-
+
getHtml('RecentInvoices'); ?>
+ + + + + getId()); + ?> + +
getHtml('Number'); ?> + getHtml('Name'); ?> + getHtml('Net'); ?> + getHtml('Date'); ?> +
getNumber(); ?> + billTo; ?> + net->getCurrency(); ?> + createdAt->format('Y-m-d'); ?> + +
@@ -204,8 +227,86 @@ echo $this->getData('nav')->render();
-
getHtml('Sales'); ?>
-
+
getHtml('Purchase'); ?>
+
+ + + ], + "datasets": [ + { + "label": "getHtml('Margin'); ?>", + "type": "line", + "data": [ + + + ], + "yAxisID": "axis-2", + "fill": false, + "borderColor": "rgb(255, 99, 132)", + "backgroundColor": "rgb(255, 99, 132)" + }, + { + "label": "getHtml('Purchase'); ?>", + "type": "bar", + "data": [ + + + ], + "yAxisID": "axis-1", + "backgroundColor": "rgb(54, 162, 235)" + } + ] + }, + "options": { + "scales": { + "yAxes": [ + { + "id": "axis-1", + "display": true, + "position": "left" + }, + { + "id": "axis-2", + "display": true, + "position": "right", + "scaleLabel": { + "display": true, + "labelString": "getHtml('Margin'); ?> %" + }, + "gridLines": { + "display": false + }, + "beginAtZero": true, + "ticks": { + "min": 0, + "max": 100, + "stepSize": 10 + } + } + ] + } + } + }'> +