From 9e908450373bf588b8043a9598b5f558fc6130b1 Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Fri, 21 Dec 2018 16:22:17 +0100 Subject: [PATCH] fix chart --- entity/Turnover_entity/Turnover_entity.aod | 3 +- .../recordcontainers/jdito/contentProcess.js | 18 ++ process/Chart_lib/process.js | 206 ++++++++---------- 3 files changed, 112 insertions(+), 115 deletions(-) diff --git a/entity/Turnover_entity/Turnover_entity.aod b/entity/Turnover_entity/Turnover_entity.aod index 9d4bbb0ec7..cbc8b66c2b 100644 --- a/entity/Turnover_entity/Turnover_entity.aod +++ b/entity/Turnover_entity/Turnover_entity.aod @@ -28,8 +28,7 @@ <entityField> <name>X</name> <title>Year</title> - <contentType>NUMBER</contentType> - <outputFormat>0.00#.##</outputFormat> + <contentType>TEXT</contentType> </entityField> </entityFields> <recordContainers> diff --git a/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js b/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js index bae3bd0c71..cd12703571 100644 --- a/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js @@ -92,3 +92,21 @@ function _addMonthRows(pYear) _addRow([year.toString(), 'turnover', 0, turnoverYearSum]); _addRow([year.toString(), 'forecast', 0, forecastYearSum]); } + + +/* + * + * import("system.datetime"); +import("system.db"); +import("system.result"); +import("system.translate"); +import("Chart_lib"); +// [[id, x, y, ...], [x, y, ...]] +var sumOfMonthTurnover = db.table("select year(SALESORDERDATE) yearNum, sum(NET + VAT) from SALESORDER where year(SALESORDERDATE) <> 2017 group by year(SALESORDERDATE) order by yearNum"); +var sumOfMonthForecast = db.table("select year(DATE_START) yearNum, sum(VOLUME) from SALESPROJECT_FORECAST group by year(DATE_START) order by yearNum"); + +var chart = MultiDataChart.begin(); + +chart.addDataSource(translate.text("Turnover"), sumOfMonthTurnover) + .addDataSource(translate.text("Forecast"), sumOfMonthForecast) + */ \ No newline at end of file diff --git a/process/Chart_lib/process.js b/process/Chart_lib/process.js index ea4a62f24d..8cc26ccc21 100644 --- a/process/Chart_lib/process.js +++ b/process/Chart_lib/process.js @@ -1,116 +1,13 @@ +import("system.logging"); import("system.util"); -import("system.report"); -import("system.neon"); -import("system.vars"); - - - - -var sumOfMonthTurnover = db.table("select year(SALESORDERDATE) yearNum, 'turnover', month(SALESORDERDATE) monthNum, sum(NET + VAT) from SALESORDER group by year(SALESORDERDATE), month(SALESORDERDATE) order by yearNum, monthNum"); -var sumOfMonthForecast = db.table("select year(DATE_START) yearNum, 'forecast', month(DATE_START) monthNum, sum(VOLUME) from SALESPROJECT_FORECAST group by year(DATE_START), month(DATE_START) order by yearNum, monthNum"); - - -var chartData = []; - -var turnoverSkippedCount = 0; -var forecastSkippedCount = 0; - -for (let i = 0; i < 4; i++) -{ - var year = i + 2016; - - _addMonthRows(year); -} - -result.object(chartData); - -function _addRow(pRow) -{ - //logging.log(pRow.toSource()) - // month = 0 --> sum of the whole year - var parent = ""; - var dateDisplay = pRow[0]; - - if (pRow[2] != 0) - { - parent = pRow[0] + "0" + pRow[1].trim(); - - var rowDate = new Date(pRow[0], pRow[2]-1); - dateDisplay = datetime.toDate(rowDate.getTime(), "MMM yyyy", "UTC") - } - - chartData.push([pRow[0] + pRow[2] + pRow[1].trim(), parent, - ((pRow[1].trim() == "turnover") ? translate.text("Turnover") : translate.text("Forecast")), parseFloat(pRow[3]), dateDisplay]); -} - -function _addMonthRows(pYear) -{ - var turnoverSkippedCount = 0; - // var turnoverNotCorrectYearCount = 0; - - var forecastSkippedCount = 0; - var forecastNotCorrectYearCount = 0; - - var turnoverYearSum = 0; - var forecastYearSum = 0; - - var filteredTurnover = sumOfMonthTurnover.filter(function(row) - { - return row[0] == pYear - }); - - var filteredForecast = sumOfMonthForecast.filter(function(row) - { - return row[0] == pYear - }); - - for (let i = 1; i <= 12; i++) - { - var turnoverSum = filteredTurnover[i - turnoverSkippedCount - 1]; - var forecastSum = filteredForecast[i - forecastSkippedCount - 1]; - - if (turnoverSum != undefined && turnoverSum[0] == pYear && turnoverSum[2] == i.toString()) - { - _addRow(turnoverSum); - turnoverYearSum += turnoverSum[3]; - } - else - { - _addRow([year.toString(), 'turnover', i, 0.0]); - - turnoverSkippedCount++; - } - - if (forecastSum != undefined && forecastSum[0] == pYear && forecastSum[2] == i) - { - _addRow(forecastSum); - forecastYearSum += forecastSum[3]; - } - else - { - _addRow([year.toString(), 'forecast', i, 0.0]); - - forecastSkippedCount++; - } - } - - _addRow([year.toString(), 'turnover', 0, turnoverYearSum]); - _addRow([year.toString(), 'forecast', 0, forecastYearSum]); -} - - - - /** * * @class */ function MultiDataChart() { - this._ID = 0; - this._GROUP = 1; - this._X = 2; - this._Y = 3; + this._X = 0; + this._Y = 1; this.dataSources = {}; this.drilldowns = {}; @@ -125,13 +22,15 @@ MultiDataChart.begin = function() /** * Add a new datasource - * Has to be an array with [[id, x, y, ...], [id, x, y, ...]] + * Has to be an array with [[x, y, ...], [x, y, ...]] * ... means you can add additional columns, used as identification and naming of drilldowns */ -MultiDataChart.prototype.addDataSource = function(pName, pData) +MultiDataChart.prototype.addDataSource = function(pName, pData, pFixedXValues) { - this.dataSources[pName] = pData; - + this.dataSources[pName] = { + data: pData, + fixedValues: pFixedXValues + } return this; } @@ -149,7 +48,7 @@ MultiDataChart.prototype.addCumulativeDrillDown = function(pDataSourceName, pGet } else { - throw Error("MultiDataChart::addCumulativeDrillDown: Data source " + pDataSourceName + " doesn't exist!"); + throw new Error("MultiDataChart::addCumulativeDrillDown: Data source " + pDataSourceName + " doesn't exist!"); } return this; @@ -162,17 +61,98 @@ MultiDataChart.prototype.build = function() { for (dataSource in this.dataSources) { - for (let i = 0; i < dataSources[dataSource].length; i++) + + + + for (let i = 0; i < this.dataSources[dataSource].data.length; i++) { - var dataRow = dataSources[dataSource][i]; + var dataRow = this.dataSources[dataSource].data[i]; var rowId = util.getNewUUID(); // id, parent, group, x, y this._resultData.push([rowId, "", dataSource, dataRow[this._X], dataRow[this._Y]]); } } + logging.log(this._resultData.toSource()) + return this._resultData; +} + +/** + * check if all X-Values exist. If not, create empty values. + * + * + * TODO!!!!!!!!!!!!! + * + */ +MultiDataChart.prototype._normalize = function(pDataSource) +{ + var fixed = pDataSource.fixedValues; + var data = pDataSource.data; + var found = {}; + + var resultData = []; + + for (let i = 0; i < data.length; i++) + { + + if (found[data[i][this._X]] == undefined) + { + if (fixed.indexOf(data[i][this._X]) >= 0) + { + + } + else + { + throw new Error("The X-Value " + data[i][this._X] + " is not in the fixed values of the dataSource!"); + } + } + + found[data[i][this._X]] = true; + + resultData.push(data[i]); + } + + return resultData; +} + + + + + + + + + + + + + + + + + + for (drilldown in this.drilldowns) + { + if (drilldown.type == "cumulative") + { + this._processCumulativeDrilldown(drilldown); + } + } } + + + + + + + + + + + + + MultiDataChart.prototype._processDrilldowns = function() { for (drilldown in this.drilldowns) -- GitLab