kivitendo/js/kivi.CustomerVendorTurnover.js @ bc928a5a
58e28ca0 | Werner Hahn | namespace('kivi.CustomerVendorTurnover', function(ns) {
|
||
ns.show_dun_stat = function(period) {
|
||||
if (period === 'y') {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/count_open_items_by_year&id=' + $('#cv_id').val();
|
||||
$('#duns').load(url);
|
||||
} else {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/count_open_items_by_month&id=' + $('#cv_id').val();
|
||||
$('#duns').load(url);
|
||||
}
|
||||
};
|
||||
ns.get_invoices = function() {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/get_invoices&id=' + $('#cv_id').val() + '&db=' + $('#db').val();
|
||||
$('#invoices').load(url);
|
||||
};
|
||||
ns.get_sales_quotations = function() {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/get_orders&id=' + $('#cv_id').val() + '&db=' + $('#db').val() + '&type=quotation';
|
||||
$('#quotations').load(url);
|
||||
};
|
||||
ns.get_orders = function() {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/get_orders&id=' + $('#cv_id').val() + '&db=' + $('#db').val() + '&type=order';
|
||||
$('#orders').load(url);
|
||||
};
|
||||
ns.get_letters = function() {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/get_letters&id=' + $('#cv_id').val() + '&db=' + $('#db').val();;
|
||||
$('#letters').load(url);
|
||||
};
|
||||
ns.get_mails = function() {
|
||||
var url = 'controller.pl?action=CustomerVendorTurnover/get_mails&id=' + $('#cv_id').val() + '&db=' + $('#db').val();;
|
||||
$('#mails').load(url);
|
||||
};
|
||||
fe51b1d2 | Bernd Bleßmann | ns.show_turnover = function(period, year_for_month) {
|
||
ns.show_turnover_chart(period, year_for_month);
|
||||
ns.show_turnover_stat(period);
|
||||
};
|
||||
58e28ca0 | Werner Hahn | ns.show_turnover_stat = function(period) {
|
||
b3aa9c06 | Bernd Bleßmann | let mode = 'year';
|
||
if (period === 'm') mode = 'month';
|
||||
const url = 'controller.pl?action=CustomerVendorTurnover/turnover&id=' + $('#cv_id').val() + '&db=' + $('#db').val() + '&mode=' + mode;
|
||||
$('#turnovers').load(url);
|
||||
58e28ca0 | Werner Hahn | };
|
||
bfcc4c7a | Bernd Bleßmann | ns.show_turnover_chart = function(period, year_for_month) {
|
||
e92b48eb | Bernd Bleßmann | let mode = "month";
|
||
if (period === 'y') {
|
||||
mode = "year";
|
||||
bfcc4c7a | Bernd Bleßmann | year_for_month = undefined;
|
||
e92b48eb | Bernd Bleßmann | } else if (period === 'm') {
|
||
mode = "month";
|
||||
}
|
||||
const data = { action: 'CustomerVendorTurnover/turnover.json',
|
||||
id: $('#cv_id').val(),
|
||||
db: $('#db').val(),
|
||||
bfcc4c7a | Bernd Bleßmann | mode: mode,
|
||
year: year_for_month
|
||||
e92b48eb | Bernd Bleßmann | };
|
||
$.getJSON('controller.pl', data, function( returned_data ) {
|
||||
fe51b1d2 | Bernd Bleßmann | const html = '<canvas id="turnovers_chart" height="70vH"></canvas>';
|
||
2be5630a | Bernd Bleßmann | $('#turnovers_chart_container').html(html);
|
||
e92b48eb | Bernd Bleßmann | ns.draw_chart(returned_data);
|
||
});
|
||||
};
|
||||
ns.draw_chart = function(data) {
|
||||
$(data).each(function(idx, elt) {
|
||||
elt.date_part = '' + elt.date_part;
|
||||
});
|
||||
ns.chart(data);
|
||||
};
|
||||
f9cc8974 | Bernd Bleßmann | ns.background_colors = function() { return [
|
||
'rgba(255, 0, 0, 0.2)',
|
||||
'rgba(191, 0, 0, 0.2)',
|
||||
'rgba(127, 0, 0, 0.2)',
|
||||
'rgba(63, 0, 0, 0.2)',
|
||||
'rgba(0, 255, 0, 0.2)',
|
||||
'rgba(0, 191, 0, 0.2)',
|
||||
'rgba(0, 127, 0, 0.2)',
|
||||
'rgba(0, 63, 0, 0.2)',
|
||||
'rgba(0, 0, 255, 0.2)',
|
||||
'rgba(0, 0, 191, 0.2)',
|
||||
'rgba(0, 0, 127, 0.2)',
|
||||
'rgba(0, 0, 63, 0.2)'
|
||||
]};
|
||||
ns.border_colors = function() { return [
|
||||
'rgba(255, 0, 0, 1)',
|
||||
'rgba(191, 0, 0, 1)',
|
||||
'rgba(127, 0, 0, 1)',
|
||||
'rgba(63, 0, 0, 1)',
|
||||
'rgba(0, 255, 0, 1)',
|
||||
'rgba(0, 191, 0, 1)',
|
||||
'rgba(0, 127, 0, 1)',
|
||||
'rgba(0, 63, 0, 1)',
|
||||
'rgba(0, 0, 255, 1)',
|
||||
'rgba(0, 0, 191, 1)',
|
||||
'rgba(0, 0, 127, 1)',
|
||||
'rgba(0, 0, 63, 1)'
|
||||
]};
|
||||
e92b48eb | Bernd Bleßmann | ns.chart = function(data) {
|
||
2be5630a | Bernd Bleßmann | const ctx = 'turnovers_chart';
|
||
bfcc4c7a | Bernd Bleßmann | const chart = new Chart(ctx, {
|
||
e92b48eb | Bernd Bleßmann | type: 'bar',
|
||
data: {
|
||||
datasets: [{
|
||||
label: kivi.t8('Net.Turnover'),
|
||||
data: data,
|
||||
f9cc8974 | Bernd Bleßmann | backgroundColor: ns.background_colors,
|
||
borderColor: ns.border_colors,
|
||||
e92b48eb | Bernd Bleßmann | borderWidth: 1
|
||
f9e1fa33 | Bernd Bleßmann | },
|
||
{
|
||||
label: kivi.t8('Overall Net.Turnover'),
|
||||
data: data,
|
||||
type: 'line',
|
||||
backgroundColor: 'black',
|
||||
e92b48eb | Bernd Bleßmann | }]
|
||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
},
|
||||
parsing: {
|
||||
xAxisKey: 'date_part',
|
||||
f9e1fa33 | Bernd Bleßmann | yAxisKey: ['netamount', 'overall_netamount']
|
||
bfcc4c7a | Bernd Bleßmann | },
|
||
onClick: (e) => {
|
||||
const canvasPosition = Chart.helpers.getRelativePosition(e, chart);
|
||||
// Substitute the appropriate scale IDs
|
||||
const dataX = chart.scales.x.getValueForPixel(canvasPosition.x);
|
||||
const dataY = chart.scales.y.getValueForPixel(canvasPosition.y);
|
||||
if ((data[dataX].date_part || "").match(/^\d{1,4}$/)) {
|
||||
fe51b1d2 | Bernd Bleßmann | ns.show_turnover('m', data[dataX].date_part);
|
||
bfcc4c7a | Bernd Bleßmann | } else {
|
||
fe51b1d2 | Bernd Bleßmann | ns.show_turnover('y');
|
||
bfcc4c7a | Bernd Bleßmann | }
|
||
e92b48eb | Bernd Bleßmann | }
|
||
}
|
||||
});
|
||||
};
|
||||
baa54321 | Bernd Bleßmann | ns.cv_tabs_init = function () {
|
||
$("#customer_vendor_tabs").on('tabsbeforeactivate', function(event, ui){
|
||||
if (ui.newPanel.attr('id') == 'quotations') {
|
||||
ns.get_sales_quotations();
|
||||
}
|
||||
2be5630a | Bernd Bleßmann | if (ui.newPanel.attr('id') == 'turnover_stat') {
|
||
fe51b1d2 | Bernd Bleßmann | ns.show_turnover("y");
|
||
2be5630a | Bernd Bleßmann | }
|
||
baa54321 | Bernd Bleßmann | return 1;
|
||
});
|
||||
$("#customer_vendor_tabs").on('tabscreate', function(event, ui){
|
||||
if (ui.panel.attr('id') == 'quotations') {
|
||||
ns.get_sales_quotations();
|
||||
}
|
||||
2be5630a | Bernd Bleßmann | if (ui.panel.attr('id') == 'turnover_stat') {
|
||
fe51b1d2 | Bernd Bleßmann | ns.show_turnover("y");
|
||
2be5630a | Bernd Bleßmann | }
|
||
baa54321 | Bernd Bleßmann | return 1;
|
||
});
|
||||
};
|
||||
$(function(){
|
||||
ns.cv_tabs_init();
|
||||
});
|
||||
58e28ca0 | Werner Hahn | });
|