From c084780757bc3948872889fea063b5c7f645530e Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Tue, 17 Sep 2019 11:01:34 +0200
Subject: [PATCH] fix turnover chart - Months & Documentation

---
 .../recordcontainers/jdito/contentProcess.js   | 18 ++++++++++++++----
 .../recordcontainers/jdito/contentProcess.js   |  3 +--
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/entity/TurnoverTree_entity/recordcontainers/jdito/contentProcess.js b/entity/TurnoverTree_entity/recordcontainers/jdito/contentProcess.js
index d12d20da8e..3493235775 100644
--- a/entity/TurnoverTree_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/TurnoverTree_entity/recordcontainers/jdito/contentProcess.js
@@ -8,6 +8,19 @@ import("KeywordRegistry_basic");
 import("Keyword_lib");
 import("system.translate");
 
+/**
+ * This content process is similar to the Turnover_entity content process.
+ * It is modified for the tree table. This means
+ *  - months with no forecast or turnover are not added explicitely
+ *  - the _addCount function adds the layerIndex to the countData, which is used...
+ *  - ... to sort the table so that all parents are added before the childs (as the treetable needs it in this order)
+ *  - the sort function also sorts the data by year, month and productgroup name (using TreeUtils.treeOrderBy)
+ *  - the _addCount is modified specially for THIS tree. 
+ *    TODO: make more generic and use for both: the tree and the chart
+ *    
+ * See Turnover_entity content process for more documentation
+ */
+
 var turnoverCategory = translate.text('Turnover');
 var forecastCategory = translate.text('Forecast');
 
@@ -41,15 +54,12 @@ var columns = {
     groupcodeName: 8
 };
 
-// combine both data sources
-
-
 var treeData = [];
 var countData = {};
 
 turnover.forEach(function(row) 
 {    
-    var monthDate = new Date(row[columns.year], row[columns.month]-1);
+    var monthDate = new Date(row[columns.year], row[columns.month]);
     monthDate = datetime.toDate(monthDate.getTime(), "MMM yyyy", "UTC");
     _addCount([row[columns.year], [row[columns.month], monthDate], [row[columns.groupcodeId], row[columns.groupcodeName]]], row[columns.type], row[columns.year], row[columns.month],
         MoneyUtils.getGross(
diff --git a/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js b/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js
index 02befbe14c..bd20eceda6 100644
--- a/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Turnover_entity/recordcontainers/jdito/contentProcess.js
@@ -58,7 +58,6 @@ var chartData = [];
 var countData = {}
 
 var monthDate;
-    
 /**
  * 2. Special treatment for some layers
  * Some data needs special treatment. You may ommit these if you don't need it.
@@ -99,7 +98,7 @@ for (let y = minYear; y <= maxYear; y++)
 data.forEach(function(row) 
 {    
     // load the display value for the months
-    monthDate = new Date(row[columns.year], row[columns.month]);
+    monthDate = new Date(row[columns.year], row[columns.month]-1);
     monthDate = datetime.toDate(monthDate.getTime(), "MMM yyyy", "UTC");
     
     switch(row[columns.type])
-- 
GitLab