jpc_cross_tab.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. let JV = require('./jpc_value_define');
  2. let JpcFieldHelper = require('./helper/jpc_helper_field');
  3. let JpcBandHelper = require('./helper/jpc_helper_band');
  4. let JpcBand = require('./jpc_band');
  5. let JpcFlowTabHelper = require('./helper/jpc_helper_flow_tab');
  6. let JpcCrossTabHelper = require('./helper/jpc_helper_cross_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 JpcCrossTabSrv = function(){};
  13. JpcCrossTabSrv.prototype.createNew = function(){
  14. function private_addTabValue(tabValuedIdxLst, sortedSequence, segIdx, preRec, nextRec, dispSerialIdxLst, sorted_sum_value_Lst, rst_sum_value_Lst) {
  15. if (tabValuedIdxLst) {
  16. let serial1stTier = null;
  17. if (dispSerialIdxLst) serial1stTier = [];
  18. let pgseg1stTier = [];
  19. let sumVal = [];
  20. let sumValL = 1;
  21. if (sortedSequence) {
  22. let arrDupVals = sortedSequence[segIdx];
  23. let arrDupSumVals = null;
  24. if (sorted_sum_value_Lst != null) {
  25. arrDupSumVals = sorted_sum_value_Lst[segIdx];
  26. sumValL = arrDupSumVals[0].length;
  27. }
  28. for (let i = 0; i < nextRec; i++) {
  29. if (arrDupVals.length <= preRec + i) {
  30. pgseg1stTier[i] = JV.BLANK_VALUE_INDEX;
  31. sumVal[i] = [];
  32. for (let ei = 0; ei < sumValL; ei++) {
  33. sumVal[i][ei] = null;
  34. }
  35. if (serial1stTier != null) {
  36. serial1stTier[i] = JV.BLANK_VALUE_INDEX;
  37. }
  38. continue;
  39. }
  40. let duplicateValueArr = arrDupVals[preRec + i];
  41. pgseg1stTier[i] = duplicateValueArr[0];
  42. if (arrDupSumVals != null) sumVal[i] = arrDupSumVals[preRec + i];
  43. if (serial1stTier != null) {
  44. serial1stTier[i] = preRec + i;
  45. }
  46. }
  47. tabValuedIdxLst.push(pgseg1stTier);
  48. if (dispSerialIdxLst != null) {
  49. dispSerialIdxLst.push(serial1stTier);
  50. }
  51. if (sorted_sum_value_Lst != null && rst_sum_value_Lst != null) {
  52. rst_sum_value_Lst.push(sumVal);
  53. }
  54. } else {
  55. //should push blank value index rather than null
  56. for (let i = 0; i < nextRec; i++) {
  57. pgseg1stTier[i] = JV.BLANK_VALUE_INDEX;
  58. sumVal[i] = null;
  59. if (serial1stTier != null) {
  60. serial1stTier[i] = JV.BLANK_VALUE_INDEX;
  61. }
  62. }
  63. tabValuedIdxLst.push(pgseg1stTier);
  64. if (dispSerialIdxLst != null) {
  65. dispSerialIdxLst.push(serial1stTier);
  66. }
  67. if (sorted_sum_value_Lst != null && rst_sum_value_Lst != null) {
  68. rst_sum_value_Lst.push(sumVal);
  69. }
  70. }
  71. }
  72. }
  73. function private_addContentValue(dispValueIdxLst_Content, sortedContentSequence, segIdx, counterRowRec, maxRowRec, counterColRec, maxColRec, page_seg_map, pageIdx) {
  74. if (dispValueIdxLst_Content != null) {
  75. page_seg_map.push([pageIdx,segIdx]);
  76. let arrContents = [];
  77. if (sortedContentSequence != null) {
  78. let arrAllContent = sortedContentSequence[segIdx];
  79. for (let i = 0; i < maxRowRec; i++) {
  80. arrContents.push([]);
  81. for (let j = 0; j < maxColRec; j++) {
  82. if (arrAllContent.length <= counterRowRec + i || arrAllContent[counterRowRec + i].length <= counterColRec + j) {
  83. arrContents[i][j] = JV.BLANK_VALUE_INDEX;
  84. } else {
  85. arrContents[i][j] = arrAllContent[counterRowRec + i][counterColRec + j];
  86. }
  87. }
  88. }
  89. dispValueIdxLst_Content.push(arrContents);
  90. } else {
  91. //should push blank value index rather than null
  92. for (let i = 0; i < maxRowRec; i++) {
  93. arrContents.push([]);
  94. for (let j = 0; j < maxColRec; j++) {
  95. arrContents[i][j] = JV.BLANK_VALUE_INDEX;
  96. }
  97. }
  98. dispValueIdxLst_Content.push(arrContents);
  99. }
  100. }
  101. }
  102. function private_SortAndOptimize(rptTpl, dataObj, dataSeq, sortTab, rstFieldsIdx) {
  103. let result = [];
  104. let tab = rptTpl[JV.NODE_CROSS_INFO][sortTab];
  105. if (tab) {
  106. let sIDX = 0;
  107. //1. prepare and sort by tab-field
  108. let fields = [];
  109. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, tab[JV.TAB_CROSS_FIELDS], fields, rstFieldsIdx);
  110. let data_details = dataObj[JV.DATA_DETAIL_DATA];
  111. JpcCrossTabHelper.sortTabFields(fields, rstFieldsIdx, data_details, dataSeq);
  112. //2. distinguish sort tab fields value
  113. let b1 = false;
  114. for (let i = 0; i < dataSeq.length; i++) {
  115. sIDX = 0;
  116. let segArr = [];
  117. if (dataSeq[i].length == 1) {
  118. JpcCrossTabHelper.pushToSeg(segArr, dataSeq, i, 0, 1);
  119. } else {
  120. for (let j = 1; j < dataSeq[i].length; j++) {
  121. b1 = false;
  122. for (let k = 0; k < rstFieldsIdx.length; k++) {
  123. if (data_details[rstFieldsIdx[k]][dataSeq[i][j - 1]] != data_details[rstFieldsIdx[k]][dataSeq[i][j]]) {
  124. b1 = true;
  125. break;
  126. }
  127. }
  128. if (b1) {
  129. JpcCrossTabHelper.pushToSeg(segArr, dataSeq, i, sIDX, j);
  130. sIDX = j;
  131. if (j == dataSeq[i].length - 1) {
  132. JpcCrossTabHelper.pushToSeg(segArr, dataSeq, i, j, dataSeq[i].length);
  133. }
  134. } else if (j == dataSeq[i].length - 1) {
  135. JpcCrossTabHelper.pushToSeg(segArr, dataSeq, i, sIDX, dataSeq[i].length);
  136. }
  137. }
  138. }
  139. if (segArr.length > 0) result.push(segArr);
  140. }
  141. }
  142. return result;
  143. }
  144. function private_SortForDisplayContent(rptTpl, rowSeq, colSeq, rstFieldsIdx){
  145. let result = [];
  146. let tab = rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT];
  147. if (tab) {
  148. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, tab[JV.TAB_CROSS_FIELDS], null, rstFieldsIdx);
  149. }
  150. for (let i = 0; i < rowSeq.length; i++) {
  151. let rl = rowSeq[i], cl = colSeq[i];
  152. let ds = [];
  153. //1. initialize to blank value index
  154. for (let j = 0; j < rl.length; j++) {
  155. ds.push([]);
  156. for (let k = 0; k < cl.length; k++) {
  157. ds[j].push(JV.BLANK_VALUE_INDEX);
  158. }
  159. }
  160. //2. then fill up the right index
  161. for (let j = 0; j < rl.length; j++) {
  162. let ra = rl[j];
  163. for (let k = 0; k < ra.length; k++) {
  164. let colIdx = JpcCrossTabHelper.getColIDX(cl, ra[k]);
  165. if (colIdx >= 0) {
  166. ds[j][colIdx] = ra[k];
  167. }
  168. }
  169. }
  170. result.push(ds);
  171. }
  172. return result;
  173. }
  174. let JpcCrossTabResult = {};
  175. JpcCrossTabResult.initialize = function() {
  176. let me = this;
  177. me.dispValueIdxLst_Row = [];
  178. me.dispValueIdxLst_Col = [];
  179. me.dispValueIdxLst_Content = [];
  180. me.dispSerialIdxLst_Row = [];
  181. me.col_sum_fields_idx = [];
  182. me.col_sum_fields_value_total = [];
  183. me.dispSumValueLst_Col = [];
  184. me.page_seg_map = [];
  185. me.row_fields_idx = [];
  186. me.col_fields_idx = [];
  187. me.content_fields_idx = [];
  188. me.row_extension_fields_idx = [];
  189. me.row_sum_extension_fields_idx = [];
  190. me.crsOrient = JV.PAGE_ORIENTATION_V_FIRST;
  191. me.pageStatusLst = [];
  192. };
  193. JpcCrossTabResult.sorting = function(rptTpl, dataObj, dataSeq) {
  194. let me = this;
  195. //IMPORTANT: the data should be sorted in SQL/NoSQL level!
  196. me.sortedRowSequence = private_SortAndOptimize(rptTpl, dataObj, dataSeq, JV.NODE_CROSS_ROW, me.row_fields_idx);
  197. me.sortedColSequence = private_SortAndOptimize(rptTpl, dataObj, dataSeq, JV.NODE_CROSS_COL, me.col_fields_idx);
  198. me.sortedContentSequence = private_SortForDisplayContent(rptTpl, me.sortedRowSequence, me.sortedColSequence, me.content_fields_idx);
  199. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM][JV.TAB_CROSS_FIELDS], null, me.col_sum_fields_idx);
  200. //pre-sum the data(for col sum display)
  201. let data_details = dataObj[JV.DATA_DETAIL_DATA],
  202. data_fields = [];
  203. for (let i = 0; i < me.col_sum_fields_idx.length; i++) {
  204. let data_field = data_details[me.col_sum_fields_idx[i]];
  205. data_fields.push(data_field);
  206. }
  207. for (let i = 0; i < me.sortedRowSequence.length; i++) { //seg level
  208. if (me.sortedRowSequence[i].length > 0) {
  209. me.col_sum_fields_value_total.push([]);
  210. for (let j = 0; j < me.sortedRowSequence[i].length; j++) {
  211. let rowGrandTotal = [];
  212. for (let di = 0; di < data_fields.length; di++) {
  213. rowGrandTotal.push(0.0);
  214. for (let k = 0; k < me.sortedRowSequence[i][j].length; k++) {
  215. //3. start to sum
  216. rowGrandTotal[di] = rowGrandTotal[di] + 1.0 * JpcFieldHelper.getValue(data_fields[di], me.sortedRowSequence[i][j][k]);
  217. }
  218. }
  219. me.col_sum_fields_value_total[i].push(rowGrandTotal);
  220. }
  221. }
  222. }
  223. };
  224. JpcCrossTabResult.preSetupPages = function(rptTpl, defProperties, option) {
  225. let rst = 0, me = this, dftPagingOption = option||JV.PAGING_OPTION_NORMAL;
  226. //1. original initialize
  227. let maxRowRec = 1, maxColRec = 1, counterRowRec = 0, counterColRec = 0, pageIdx = 0, segCnt = me.sortedContentSequence.length;
  228. let pageStatus = [true, true, false, true, false, false, false, false];
  229. //2. calculate the page info one by one
  230. let bands = JpcBand.createNew(rptTpl, defProperties);
  231. function private_resetBandArea() {
  232. JpcBandHelper.setBandArea(bands, rptTpl, pageStatus);
  233. maxRowRec = JpcCrossTabHelper.getMaxRowsPerPage(bands, rptTpl);
  234. maxColRec = JpcCrossTabHelper.getMaxColsPerPage(bands, rptTpl);
  235. }
  236. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT][JV.TAB_CROSS_FIELDS], null, me.row_extension_fields_idx);
  237. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT][JV.TAB_CROSS_FIELDS], null, me.row_sum_extension_fields_idx);
  238. for (let segIdx = 0; segIdx < segCnt; segIdx++) {
  239. //2.1. seg level initialize
  240. private_resetBandArea();
  241. let orgMaxRowRec = maxRowRec, orgMaxColRec = maxColRec;
  242. let rowSplitCnt = Math.ceil(1.0 * me.sortedRowSequence[segIdx].length / maxRowRec);
  243. let colSplitCnt = Math.ceil(1.0 * me.sortedColSequence[segIdx].length / maxColRec);
  244. pageStatus[JV.STATUS_CROSS_ROW_END] = true;
  245. private_resetBandArea();
  246. let hasAdHocRow = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_ROW_SUM, rptTpl, bands, me.sortedRowSequence, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
  247. if (hasAdHocRow) {
  248. hasAdHocRow = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_ROW_EXT, rptTpl, bands, me.sortedRowSequence, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
  249. }
  250. pageStatus[JV.STATUS_CROSS_ROW_END] = false;
  251. pageStatus[JV.STATUS_CROSS_COL_END] = true;
  252. private_resetBandArea();
  253. let hasAdHocCol = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_COL_SUM, rptTpl, bands, me.sortedColSequence, segIdx, (colSplitCnt - 1) * orgMaxColRec, maxColRec);
  254. pageStatus[JV.STATUS_CROSS_COL_END] = false;
  255. private_resetBandArea();
  256. if (hasAdHocRow) rowSplitCnt++;
  257. if (hasAdHocCol) colSplitCnt++;
  258. //2.2
  259. for (let colIdx = 0; colIdx < colSplitCnt; colIdx++) {
  260. pageStatus[JV.STATUS_CROSS_COL_END] = colIdx == (colSplitCnt - 1)?true:false;
  261. private_resetBandArea();
  262. counterColRec = orgMaxColRec * colIdx;
  263. let currentSortedContentSequence = me.sortedContentSequence;
  264. let currentSortedColSequence = me.sortedColSequence;
  265. if (hasAdHocCol && colIdx == (colSplitCnt - 1)) {
  266. currentSortedColSequence = null;
  267. currentSortedContentSequence = null;
  268. counterColRec = 0;
  269. }
  270. for (let rowIdx = 0; rowIdx < rowSplitCnt; rowIdx++) {
  271. pageStatus[JV.STATUS_CROSS_ROW_END] = rowIdx == (rowSplitCnt - 1)?true:false;
  272. private_resetBandArea();
  273. me.pageStatusLst.push(pageStatus.slice(0));
  274. pageIdx++;
  275. counterRowRec = orgMaxRowRec * rowIdx;
  276. let currentSortedRowSequence = me.sortedRowSequence;
  277. if (hasAdHocRow && rowIdx == (rowSplitCnt - 1)) {
  278. currentSortedRowSequence = null;
  279. currentSortedContentSequence = null;
  280. counterRowRec = 0;
  281. }
  282. private_addTabValue(me.dispValueIdxLst_Row, currentSortedRowSequence, segIdx, counterRowRec, maxRowRec, me.dispSerialIdxLst_Row, me.col_sum_fields_value_total, me.dispSumValueLst_Col);
  283. private_addTabValue(me.dispValueIdxLst_Col, currentSortedColSequence, segIdx, counterColRec, maxColRec, null, null, null);
  284. private_addContentValue(me.dispValueIdxLst_Content, currentSortedContentSequence, segIdx, counterRowRec, maxRowRec, counterColRec, maxColRec, me.page_seg_map, pageIdx);
  285. }
  286. }
  287. JpcCrossTabHelper.initialPageStatus(pageStatus);
  288. }
  289. bands = null;
  290. //3. set pageSeq and return the result
  291. rst = pageIdx;
  292. return rst;
  293. };
  294. JpcCrossTabResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, page, bands, controls, $CURRENT_RPT) {
  295. let me = this, rst = [], tabRstLst = [];
  296. let segIdx = JpcCommonHelper.getSegIdxByPageIdx(page, me.page_seg_map);
  297. //1 calculate the band position
  298. JpcBandHelper.setBandArea(bands, rptTpl, me.pageStatusLst[page - 1]);
  299. //2. start to output detail-part
  300. let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  301. //2.1 Row-Tab
  302. tabRstLst.push(me.outputRowTab(rptTpl, dataObj, page, bands, unitFactor, controls));
  303. //2.2 Col-Tab
  304. tabRstLst.push(me.outputColTab(rptTpl, dataObj, page, bands, unitFactor, controls));
  305. //2.3 Content-Tab
  306. tabRstLst.push(me.outputContent(rptTpl, dataObj, page, bands, unitFactor, controls));
  307. //2.4 Sum-Tab Row
  308. //2.4 Sum-tab Col
  309. tabRstLst.push(me.outputTabSum(rptTpl, dataObj, page, bands, unitFactor, JV.NODE_CROSS_COL_SUM, controls));
  310. //2.x row tab ext
  311. tabRstLst.push(me.outputTabExt(rptTpl, dataObj, page, bands, unitFactor, controls));
  312. tabRstLst.push(me.outputSumTabExt(rptTpl, dataObj, page, bands, unitFactor, segIdx, controls));
  313. //2.5 Discrete
  314. tabRstLst.push(JpcDiscreteHelper.outputDiscreteInfo(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[page - 1], segIdx, 1, 0, $CURRENT_RPT));
  315. for (let i = 0; i < tabRstLst.length; i++) {
  316. rst = rst.concat(tabRstLst[i]);
  317. tabRstLst[i] = null;
  318. }
  319. return rst;
  320. };
  321. JpcCrossTabResult.outputRowTab = function(rptTpl, dataObj, page, bands, unitFactor, controls) {
  322. let me = this, rst = [];
  323. let tab = rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW];
  324. let band = bands[tab[JV.PROP_BAND_NAME]];
  325. if (band) {
  326. let pageStatus = me.pageStatusLst[page - 1];
  327. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  328. let tab_fields = tab[JV.TAB_CROSS_FIELDS];
  329. let data_details = dataObj[JV.DATA_DETAIL_DATA];
  330. let valuesIdx = me.dispValueIdxLst_Row[page - 1];
  331. let serialsIdx = me.dispSerialIdxLst_Row[page - 1];
  332. for (let i = 0; i < me.row_fields_idx.length; i++) {
  333. let tab_field = tab_fields[i];
  334. let data_field = data_details[me.row_fields_idx[i]];
  335. if (!(tab_field[JV.PROP_HIDDEN])) {
  336. let rows = valuesIdx.length;
  337. for (let rowIdx = 0; rowIdx < rows; rowIdx++) {
  338. rst.push(me.outputTabField(band, tab_field, data_field, valuesIdx[rowIdx], serialsIdx[rowIdx], rows, rowIdx, 1, 0, unitFactor, true, controls));
  339. }
  340. }
  341. }
  342. }
  343. }
  344. return rst;
  345. };
  346. JpcCrossTabResult.outputColTab = function(rptTpl, dataObj, page, bands, unitFactor, controls) {
  347. let me = this, rst = [], firstTextOutput = true;
  348. let tab = rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL];
  349. let band = bands[tab[JV.PROP_BAND_NAME]];
  350. if (band) {
  351. let pageStatus = me.pageStatusLst[page - 1];
  352. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  353. let tab_fields = tab[JV.TAB_CROSS_FIELDS];
  354. let data_details = dataObj[JV.DATA_DETAIL_DATA];
  355. let valuesIdx = me.dispValueIdxLst_Col[page - 1];
  356. for (let i = 0; i < me.col_fields_idx.length; i++) {
  357. let tab_field = tab_fields[i];
  358. let data_field = data_details[me.col_fields_idx[i]];
  359. if (!(tab_field[JV.PROP_HIDDEN])) {
  360. let cols = valuesIdx.length;
  361. for (let colIdx = 0; colIdx < cols; colIdx++) {
  362. rst.push(me.outputTabField(band, tab_field, data_field, valuesIdx[colIdx], -1, 1, 0, cols, colIdx, unitFactor, false, controls));
  363. //2. output texts
  364. if (firstTextOutput) {
  365. if (tab[JV.PROP_TEXT]) {
  366. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, cols, colIdx, 1, 0));
  367. }
  368. if (tab[JV.PROP_TEXTS]) {
  369. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  370. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, cols, colIdx, 1, 0));
  371. }
  372. }
  373. }
  374. }
  375. firstTextOutput = false;
  376. }
  377. }
  378. }
  379. }
  380. return rst;
  381. };
  382. JpcCrossTabResult.outputContent = function (rptTpl, dataObj, page, bands, unitFactor, controls) {
  383. let me = this, rst = [];
  384. let tab = rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT];
  385. let band = bands[tab[JV.PROP_BAND_NAME]];
  386. if (band) {
  387. let pageStatus = me.pageStatusLst[page - 1];
  388. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  389. let tab_fields = tab[JV.TAB_CROSS_FIELDS];
  390. let data_details = dataObj[JV.DATA_DETAIL_DATA];
  391. let contentValuesIdx = me.dispValueIdxLst_Content[page - 1];
  392. for (let i = 0; i < tab_fields.length; i++) {
  393. let tab_field = tab_fields[i];
  394. let data_field = data_details[me.content_fields_idx[i]];
  395. if (!(tab_field[JV.PROP_HIDDEN])) {
  396. let rows = contentValuesIdx.length;
  397. for (let rowIdx = 0; rowIdx < rows; rowIdx++) {
  398. let cols = contentValuesIdx[rowIdx].length;
  399. for (let colIdx = 0; colIdx < cols; colIdx++) {
  400. rst.push(me.outputTabField(band, tab_field, data_field, contentValuesIdx[rowIdx][colIdx], -1, rows, rowIdx, cols, colIdx, unitFactor, true, controls));
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. return rst;
  408. };
  409. JpcCrossTabResult.outputTabSum = function (rptTpl, dataObj, page, bands, unitFactor, tabNodeName, controls) {
  410. let me = this, rst = [],
  411. tab = rptTpl[JV.NODE_CROSS_INFO][tabNodeName],
  412. band = bands[tab[JV.PROP_BAND_NAME]];
  413. if (band) {
  414. let pageStatus = me.pageStatusLst[page - 1];
  415. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  416. let tab_fields = tab[JV.TAB_CROSS_FIELDS];
  417. for (let i = 0; i < me.dispSumValueLst_Col[page - 1].length; i++) {
  418. if (me.dispSumValueLst_Col[page - 1][i] != null) {
  419. for (let j = 0; j < me.dispSumValueLst_Col[page - 1][i].length; j++) {
  420. let tab_field = tab_fields[j];
  421. let val = me.dispSumValueLst_Col[page - 1][i][j];
  422. let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_field, val, controls);
  423. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, me.dispSumValueLst_Col[page - 1].length, i, 1, 0, 1, 0, true, false);
  424. rst.push(cellItem);
  425. }
  426. } else {
  427. let sumL = 1;
  428. for (let si = 0; si < me.dispSumValueLst_Col.length; si++) {
  429. if (me.dispSumValueLst_Col[si][0] != null) {
  430. sumL = me.dispSumValueLst_Col[si][0].length;
  431. break;
  432. }
  433. }
  434. for (let j = 0; j < sumL; j++) {
  435. let tab_field = tab_fields[j];
  436. let val = null;
  437. let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_field, val, controls);
  438. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, me.dispSumValueLst_Col[page - 1].length, i, 1, 0, 1, 0, true, false);
  439. rst.push(cellItem);
  440. }
  441. }
  442. }
  443. }
  444. }
  445. return rst;
  446. };
  447. JpcCrossTabResult.outputTabExt = function (rptTpl, dataObj, page, bands, unitFactor, controls) {
  448. let me = this, rst = [], firstTextOutput = true,
  449. tab = rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT];
  450. let band = bands[tab[JV.PROP_BAND_NAME]];
  451. if (band) {
  452. let pageStatus = me.pageStatusLst[page - 1];
  453. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
  454. let tab_fields = tab[JV.TAB_CROSS_FIELDS],
  455. data_details = dataObj[JV.DATA_DETAIL_DATA],
  456. valuesIdx = me.dispValueIdxLst_Col[page - 1];
  457. for (let i = 0; i < me.row_extension_fields_idx.length; i++) {
  458. let tab_field = tab_fields[i];
  459. let data_field = data_details[me.row_extension_fields_idx[i]];
  460. if (!(tab_field[JV.PROP_HIDDEN])) {
  461. let cols = valuesIdx.length;
  462. for (let colIdx = 0; colIdx < cols; colIdx++) {
  463. rst.push(me.outputTabField(band, tab_field, data_field, valuesIdx[colIdx], -1, 1, 0, cols, colIdx, unitFactor, false, controls));
  464. //2. output texts if has
  465. if (firstTextOutput) {
  466. if (tab[JV.PROP_TEXT]) {
  467. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, cols, colIdx, 1, 0));
  468. }
  469. if (tab[JV.PROP_TEXTS]) {
  470. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  471. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, cols, colIdx, 1, 0));
  472. }
  473. }
  474. }
  475. }
  476. firstTextOutput = false;
  477. }
  478. }
  479. }
  480. }
  481. return rst;
  482. };
  483. JpcCrossTabResult.outputSumTabExt = function (rptTpl, dataObj, page, bands, unitFactor, segIdx, controls) {
  484. let me = this, rst = [],
  485. tab = rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT];
  486. let band = bands[tab[JV.PROP_BAND_NAME]];
  487. if (band) {
  488. let pageStatus = me.pageStatusLst[page - 1];
  489. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true && pageStatus[JV.STATUS_CROSS_ROW_END] === true) {
  490. let tab_fields = tab[JV.TAB_CROSS_FIELDS],
  491. data_details = dataObj[JV.DATA_DETAIL_DATA],
  492. data_fields = [];
  493. for (let i = 0; i < me.row_sum_extension_fields_idx.length; i++) {
  494. let data_field = data_details[me.row_sum_extension_fields_idx[i]];
  495. data_fields.push(data_field);
  496. }
  497. //2. initialize grand total value
  498. let rowGrandTotal = [];
  499. for (let di = 0; di < data_fields.length; di++) {
  500. rowGrandTotal[di] = 0.0;
  501. //3. start to sum
  502. for (let i = 0; i < me.sortedColSequence[segIdx].length; i++) {
  503. //me.sortedColSequence[segIdx][i][0] //this is the data field value index!
  504. rowGrandTotal[di] = rowGrandTotal[di] + 1.0 * JpcFieldHelper.getValue(data_fields[di], me.sortedColSequence[segIdx][i][0]);
  505. }
  506. }
  507. //4. output
  508. for (let di = 0; di < tab_fields.length; di++) {
  509. let tab_field = tab_fields[di];
  510. if (!tab_field[JV.PROP_HIDDEN]) {
  511. let val = rowGrandTotal[di];
  512. let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_field, val, controls);
  513. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  514. rst.push(cellItem);
  515. }
  516. }
  517. //output texts if has
  518. if (tab[JV.PROP_TEXT]) {
  519. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  520. }
  521. if (tab[JV.PROP_TEXTS]) {
  522. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  523. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  524. }
  525. }
  526. }
  527. }
  528. return rst;
  529. };
  530. JpcCrossTabResult.outputTabField = function (band, tab_field, data_field, valueIdx, serialIdx, rows, rowIdx, cols, colIdx, unitFactor, isRow, controls) {
  531. let me = this, rst = null;
  532. if (isRow == true && tab_field[JV.PROP_IS_SERIAL] && tab_field[JV.PROP_IS_SERIAL] == true) {
  533. if (serialIdx >= 0) rst = JpcCommonOutputHelper.createCommonOutput(tab_field, serialIdx + 1)
  534. else rst = JpcCommonOutputHelper.createCommonOutput(tab_field, "", controls);
  535. } else {
  536. rst = JpcCommonOutputHelper.createCommonOutput(tab_field, JpcFieldHelper.getValue(data_field, valueIdx), controls);
  537. }
  538. //position
  539. if (isRow == true) {
  540. rst[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, rows, rowIdx, cols, colIdx, 1, 0, true, false);
  541. } else {
  542. rst[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, rows, rowIdx, cols, colIdx, 1, 0, false, false);
  543. }
  544. return rst;
  545. }
  546. return JpcCrossTabResult;
  547. }
  548. module.exports = new JpcCrossTabSrv();