jpc_flow_tab.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. let JV = require('./jpc_value_define');
  2. let JE = require('./jpc_rte');
  3. let JpcFieldHelper = require('./helper/jpc_helper_field');
  4. let JpcBandHelper = require('./helper/jpc_helper_band');
  5. let JpcBand = require('./jpc_band');
  6. let JpcFlowTabHelper = require('./helper/jpc_helper_flow_tab');
  7. let JpcCommonHelper = require('./helper/jpc_helper_common');
  8. let JpcDiscreteHelper = require('./helper/jpc_helper_discrete');
  9. let JpcTextHelper = require('./helper/jpc_helper_text');
  10. let JpcCommonOutputHelper = require('./helper/jpc_helper_common_output');
  11. let JpcAreaHelper = require('./helper/jpc_helper_area');
  12. let JpcFlowTabSrv = function(){};
  13. JpcFlowTabSrv.prototype.createNew = function(){
  14. function private_addPageValue(ValuedIdxLst, sortedSequence, preRec, nextRec,page_seg_map, segIdx, pageIdx) {
  15. let vIdx = [];
  16. for (let vi = 0; vi < nextRec; vi++) {
  17. if (sortedSequence.length > preRec + vi) {
  18. vIdx.push(sortedSequence[preRec + vi]);
  19. } else {
  20. vIdx.push(JV.BLANK_VALUE_INDEX);
  21. }
  22. }
  23. page_seg_map.push([pageIdx, segIdx]);
  24. ValuedIdxLst.push(vIdx);
  25. }
  26. let JpcFlowTabResult = {};
  27. JpcFlowTabResult.initialize = function(isEx) {
  28. let me = this;
  29. me.isEx = isEx;
  30. me.segments = [];
  31. me.dispValueIdxLst = [];
  32. me.page_seg_map = [];
  33. me.disp_fields_idx = [];
  34. me.seg_sum_fields_idx = [];
  35. me.seg_sum_tab_fields = [];
  36. me.page_sum_fields_idx = [];
  37. me.group_fields_idx = [];
  38. me.pageStatusLst = [];
  39. me.groupSumValLst = [];
  40. me.segSumValLst = [];
  41. me.multiCols = 1;
  42. me.pagesAmt = 0;
  43. };
  44. JpcFlowTabResult.sorting = function(rptTpl, dataObj, dataSeq) {
  45. let me = this;
  46. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  47. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS], me.seg_sum_tab_fields, me.seg_sum_fields_idx, me.isEx);
  48. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS], null, me.page_sum_fields_idx, me.isEx);
  49. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_FIELDS], null, me.group_fields_idx, me.isEx);
  50. for (let si = 0; si < dataSeq.length; si++) {
  51. me.segments.push(dataSeq[si].slice(0));
  52. }
  53. //pre-sum the data(for seg sum display)
  54. let data_details = me.isEx?dataObj[JV.DATA_DETAIL_DATA_EX]:dataObj[JV.DATA_DETAIL_DATA],
  55. data_fields = [];
  56. for (let i = 0; i < me.seg_sum_fields_idx.length; i++) {
  57. let data_field = data_details[me.seg_sum_fields_idx[i]];
  58. data_fields.push(data_field);
  59. }
  60. for (let i = 0; i < me.segments.length; i++) { //seg level
  61. if (me.segments[i].length > 0) {
  62. let rowGrandTotal = [];
  63. for (let di = 0; di < data_fields.length; di++) {
  64. rowGrandTotal.push(0.0);
  65. for (let j = 0; j < me.segments[i].length; j++) {
  66. //3. start to sum
  67. rowGrandTotal[di] = rowGrandTotal[di] + 1.0 * JpcFieldHelper.getValue(data_fields[di], me.segments[i][j]);
  68. }
  69. }
  70. me.segSumValLst.push(rowGrandTotal);
  71. }
  72. }
  73. };
  74. JpcFlowTabResult.preSetupPages = function (rptTpl, dataOjb, defProperties) {
  75. let rst = 0, me = this, counterRowRec = 0, maxRowRec = 1, pageIdx = 0;
  76. let CURRENT_FLOW_INFO = (me.isEx)?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  77. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[CURRENT_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], null, me.disp_fields_idx, me.isEx);
  78. let bands = JpcBand.createNew(rptTpl, defProperties);
  79. let pageStatus = [true, true, false, false, false, false, false, false];
  80. if (me.isEx) {
  81. pageStatus[JV.STATUS_REPORT_START] = false;
  82. }
  83. if (rptTpl[CURRENT_FLOW_INFO][JV.PROP_MULTI_COLUMN]) {
  84. me.multiCols = 1 * rptTpl[CURRENT_FLOW_INFO][JV.PROP_MULTI_COLUMN];
  85. }
  86. function private_resetBandArea() {
  87. JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, !me.isEx, me.isEx);
  88. maxRowRec = JpcFlowTabHelper.getMaxRowsPerPage(bands, rptTpl);
  89. }
  90. for (let segIdx = 0; segIdx < me.segments.length; segIdx++) {
  91. private_resetBandArea();
  92. let orgMaxRowRec = maxRowRec;
  93. let rowSplitCnt = Math.ceil(1.0 * me.segments[segIdx].length / orgMaxRowRec);
  94. pageStatus[JV.STATUS_SEGMENT_END] = true;
  95. private_resetBandArea();
  96. let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, me.segments, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
  97. if (hasAdHocRow) rowSplitCnt++;
  98. if (rowSplitCnt % me.multiCols > 0) {
  99. rowSplitCnt++
  100. }
  101. for (let rowIdx = 0; rowIdx < rowSplitCnt; rowIdx++) {
  102. pageStatus[JV.STATUS_SEGMENT_END] = rowIdx == (rowSplitCnt - 1)?true:false;
  103. if (pageIdx > 0) pageStatus[JV.STATUS_REPORT_START] = false;
  104. private_resetBandArea();
  105. me.pageStatusLst.push(pageStatus.slice(0));
  106. pageIdx++;
  107. counterRowRec = orgMaxRowRec * rowIdx;
  108. private_addPageValue(me.dispValueIdxLst, me.segments[segIdx], counterRowRec, maxRowRec,me.page_seg_map, segIdx, pageIdx);
  109. }
  110. pageStatus[JV.STATUS_SEGMENT_END] = false;
  111. pageStatus[JV.STATUS_REPORT_START] = false;
  112. }
  113. rst = Math.ceil(1.0 * pageIdx / me.multiCols);
  114. me.pagesAmt = rst;
  115. return rst;
  116. };
  117. JpcFlowTabResult.outputAsSimpleJSONPage = function (rptTpl, dataObj, page, bands, controls, $CURRENT_RPT) {
  118. let me = this, rst = [], tabRstLst = [];
  119. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  120. let segIdx = JpcCommonHelper.getSegIdxByPageIdx(page, me.page_seg_map);
  121. //1 calculate the band position
  122. JpcBandHelper.setBandArea(bands, rptTpl, me.pageStatusLst[page - 1], !me.isEx, me.isEx);
  123. //2. start to output detail-part
  124. let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  125. for (let pi = 0; pi < me.multiCols; pi++) {
  126. let actualPage = (page - 1) * me.multiCols + pi + 1;
  127. //2.1 Content-Tab
  128. tabRstLst.push(me.outputContent(rptTpl, dataObj, actualPage, bands, unitFactor, controls, pi, $CURRENT_RPT));
  129. //2.2 Column tab
  130. tabRstLst.push(me.outputColumn(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, pi));
  131. //2.3 Sum Seg
  132. tabRstLst.push(me.outputSegSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls));
  133. //2.4 Sum Page
  134. //2.5 Discrete
  135. if (pi == 0) {
  136. tabRstLst.push(JpcDiscreteHelper.outputDiscreteInfo(rptTpl[FLOW_NODE_STR][JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[actualPage - 1], segIdx, 1, pi, $CURRENT_RPT));
  137. }
  138. }
  139. for (let i = 0; i < tabRstLst.length; i++) {
  140. rst = rst.concat(tabRstLst[i]);
  141. tabRstLst[i] = null;
  142. }
  143. return rst;
  144. };
  145. JpcFlowTabResult.outputContent = function(rptTpl, dataObj, page, bands, unitFactor, controls, multiColIdx, $CURRENT_RPT) {
  146. let me = this, rst = [];
  147. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  148. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT];
  149. let band = bands[tab[JV.PROP_BAND_NAME]];
  150. if (band) {
  151. let pageStatus = me.pageStatusLst[page - 1];
  152. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  153. let tab_fields = tab[JV.PROP_FLOW_FIELDS];
  154. let data_details = me.isEx?dataObj[JV.DATA_DETAIL_DATA_EX]:dataObj[JV.DATA_DETAIL_DATA];
  155. let contentValuesIdx = me.dispValueIdxLst[page - 1];
  156. for (let i = 0; i < tab_fields.length; i++) {
  157. let tab_field = tab_fields[i];
  158. let data_field = null;
  159. if (me.disp_fields_idx[i] != JV.BLANK_FIELD_INDEX) {
  160. data_field = data_details[me.disp_fields_idx[i]];
  161. } else {
  162. data_field = JE.F(tab_field[JV.PROP_FIELD_ID], $CURRENT_RPT);
  163. if (data_field) {
  164. data_field = data_field[JV.PROP_AD_HOC_DATA];
  165. }
  166. }
  167. if (!(tab_field[JV.PROP_HIDDEN])) {
  168. for (let rowIdx = 0; rowIdx < contentValuesIdx.length; rowIdx++) {
  169. rst.push(me.outputTabField(band, tab_field, data_field, contentValuesIdx[rowIdx], -1, contentValuesIdx.length, rowIdx, 1, 0, unitFactor, true, controls, multiColIdx));
  170. }
  171. }
  172. }
  173. }
  174. }
  175. return rst;
  176. };
  177. JpcFlowTabResult.outputColumn = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, multiColIdx) {
  178. let me = this, rst = [];
  179. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  180. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_COLUMN];
  181. let band = bands[tab[JV.PROP_BAND_NAME]];
  182. if (band) {
  183. let pageStatus = me.pageStatusLst[page - 1];
  184. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  185. if (tab[JV.PROP_TEXT]) {
  186. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, me.multiCols, multiColIdx));
  187. }
  188. if (tab[JV.PROP_TEXTS]) {
  189. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  190. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, me.multiCols, multiColIdx));
  191. }
  192. }
  193. if (tab[JV.NODE_DISCRETE_INFO]) {
  194. rst = rst.concat(JpcDiscreteHelper.outputDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[page - 1], segIdx, me.multiCols, multiColIdx));
  195. }
  196. }
  197. }
  198. return rst;
  199. };
  200. JpcFlowTabResult.outputSegSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls) {
  201. let me = this, rst = [];
  202. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  203. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_SEG_SUM];
  204. let band = bands[tab[JV.PROP_BAND_NAME]];
  205. if (band) {
  206. let pageStatus = me.pageStatusLst[page - 1];
  207. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  208. let tab_fields = me.seg_sum_tab_fields;
  209. for (let i = 0; i < tab_fields.length; i++) {
  210. let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_fields[i], me.segSumValLst[segIdx][i], controls);
  211. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_fields[i][JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0, true, false);
  212. rst.push(cellItem);
  213. }
  214. if (tab[JV.PROP_TEXT]) {
  215. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0));
  216. }
  217. if (tab[JV.PROP_TEXTS]) {
  218. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  219. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0));
  220. }
  221. }
  222. if (tab[JV.NODE_DISCRETE_INFO]) {
  223. rst = rst.concat(JpcDiscreteHelper.outputDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[page - 1], segIdx, me.multiCols, 0));
  224. }
  225. }
  226. }
  227. return rst;
  228. };
  229. JpcFlowTabResult.outputTabField = function (band, tab_field, data_field, valueIdx, serialIdx, rows, rowIdx, cols, colIdx, unitFactor, isRow, controls, multiColIdx) {
  230. let me = this, rst = null;
  231. rst = JpcCommonOutputHelper.createCommonOutput(tab_field, JpcFieldHelper.getValue(data_field, valueIdx), controls);
  232. rst[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx, true, false);
  233. return rst;
  234. }
  235. return JpcFlowTabResult;
  236. }
  237. module.exports = new JpcFlowTabSrv();