improve billing

This commit is contained in:
Dennis Eichhorn 2021-02-20 21:19:43 +01:00
parent a7003fd6b4
commit a66a61bd9a
3 changed files with 186 additions and 5 deletions

49
Controller.js Normal file
View File

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

View File

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

View File

@ -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();
<div class="row">
<div class="col-xs-12">
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Invoices'); ?></div>
<div class="portlet-body"></div>
<div class="portlet-head"><?= $this->getHtml('RecentInvoices'); ?></div>
<table id="iSalesItemList" class="default">
<thead>
<tr>
<td><?= $this->getHtml('Number'); ?>
<td class="wf-100"><?= $this->getHtml('Name'); ?>
<td><?= $this->getHtml('Net'); ?>
<td><?= $this->getHtml('Date'); ?>
<tbody>
<?php foreach ($newestInvoices as $invoice) :
$url = UriFactory::build('{/prefix}purchase/bill?{?}&id=' . $invoice->getId());
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $invoice->getNumber(); ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->billTo; ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->net->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->createdAt->format('Y-m-d'); ?></a>
<?php endforeach; ?>
</table>
</section>
</div>
</div>
@ -204,8 +227,86 @@ echo $this->getData('nav')->render();
<div class="col-xs-12 col-md-6">
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Sales'); ?></div>
<div class="portlet-body"></div>
<div class="portlet-head"><?= $this->getHtml('Purchase'); ?></div>
<div class="portlet-body">
<canvas id="purchase-region" data-chart='{
"type": "bar",
"data": {
"labels": [
<?php
$temp = [];
foreach ($monthlyPurchaseCosts as $monthly) {
$temp[] = $monthly['month'] . '/' . \substr((string) $monthly['year'], -2);
}
?>
<?= '"' . \implode('", "', $temp) . '"'; ?>
],
"datasets": [
{
"label": "<?= $this->getHtml('Margin'); ?>",
"type": "line",
"data": [
<?php
$temp = [];
foreach ($monthlyPurchaseCosts as $monthly) {
$temp[] = \round(((((int) $monthly['net_purchase']) - ((int) $monthly['net_costs'])) / ((int) $monthly['net_purchase'])) * 100, 2);
}
?>
<?= \implode(',', $temp); ?>
],
"yAxisID": "axis-2",
"fill": false,
"borderColor": "rgb(255, 99, 132)",
"backgroundColor": "rgb(255, 99, 132)"
},
{
"label": "<?= $this->getHtml('Purchase'); ?>",
"type": "bar",
"data": [
<?php
$temp = [];
foreach ($monthlyPurchaseCosts as $monthly) {
$temp[] = ((int) $monthly['net_purchase']) / 1000;
}
?>
<?= \implode(',', $temp); ?>
],
"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": "<?= $this->getHtml('Margin'); ?> %"
},
"gridLines": {
"display": false
},
"beginAtZero": true,
"ticks": {
"min": 0,
"max": 100,
"stepSize": 10
}
}
]
}
}
}'></canvas>
</div>
</section>
</div>
</div>