rpt_data_analysis.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const changeSort = {
  10. name: '变更令排序',
  11. hint: '默认的变更令排序,同时对变更令,变更清单进行排序\n' +
  12. '变更令排序勿需勾选任何预定义处理指标,但是在指标映射中,要添加"变更令(change)"和"变更清单(chang_audit_list)"下的指标',
  13. /**
  14. *
  15. * @param ctx - context常量
  16. * @param data - 全部数据源{Array}
  17. * @param fieldsKey - 计算字段
  18. */
  19. fun: function(ctx, data, fieldsKey) {
  20. if (!data.change || !data.change_audit_list) return;
  21. // 变更令排序
  22. data.change.sort(function (a, b) {
  23. return a.code.localeCompare(b.code);
  24. });
  25. data.change_audit_list.sort(function (a, b) {
  26. const aCIndex = data.change.findIndex(function (c) {
  27. return c.cid === a.cid;
  28. });
  29. const bCIndex = data.change.findIndex(function (c) {
  30. return c.cid === b.cid;
  31. });
  32. return aCIndex === bCIndex
  33. ? ctx.helper.compareCode(a.code, b.code)
  34. : aCIndex - bCIndex;
  35. });
  36. },
  37. };
  38. const gatherGcl = {
  39. name: '汇总工程量清单',
  40. hint: '请使用mem_stage_bills下指标,注意事项:\n' +
  41. '1. 以下字段,不管报表是否实际使用,均应添加至指标映射,且在此处应勾选(不要求顺序):\n' +
  42. ' 清单编号(b_code), 名称(name), 单位(unit), 单价(unit_price), 树结构-是否子项(is_leaf)\n' +
  43. '2. 汇总后,以下字段,均会失效, 请勿使用:\n' +
  44. ' 台账ID(id), 树结构-ID(ledger_id), 树结构父项-ID(ledger_pid),\n' +
  45. ' 树结构-层级(level), 树结构-同层排序(order), 树结构-完整路径(full_path),\n' +
  46. ' 图册号(drawing_code), 备注(memo), 节点类型(node_type), 总额计量(is_tp)\n' +
  47. '3. 如需汇总"未计入清单章节项",请勾选"章节编号(chapter)"字段\n',
  48. fun: function (ctx, data, fieldsKey) {
  49. const gatherFields = function(gcl, data, fields) {
  50. for (const f of fields) {
  51. if (data[f]) {
  52. gcl[f] = ctx.helper.add(gcl[f], data[f]);
  53. }
  54. }
  55. };
  56. if (!data.mem_stage_bills) return;
  57. const fields = ctx.helper._.map(fieldsKey, 'field');
  58. const needFields = ['b_code', 'name', 'unit', 'unit_price', 'is_leaf'];
  59. for (const nf of needFields) {
  60. if (fields.indexOf(nf) === -1) return;
  61. }
  62. const gatherOther = fields.indexOf('chapter') >= 0;
  63. ctx.helper._.pull(data.mem_stage_bills, 'is_leaf');
  64. const gclBills = [], other = {name: '未计入清单章节项', chapter: '100'};
  65. for (const b of data.mem_stage_bills) {
  66. if (b.b_code && b.b_code !== '') {
  67. let gcl = gclBills.find(function (g) {
  68. return g.b_code === b.b_code && g.name === b.name && g.unit === b.unit
  69. && ctx.helper.checkZero(ctx.helper.sub(g.unit_price, b.unit_price));
  70. });
  71. if (!gcl) {
  72. gcl = {
  73. b_code: b.b_code, name: b.name, unit: b.unit,
  74. unit_price: b.unit_price,
  75. qc_bgl_code: [],
  76. };
  77. gclBills.push(gcl);
  78. }
  79. gatherFields(gcl, b, [
  80. 'deal_qty', 'deal_tp',
  81. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  82. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp',
  83. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  84. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  85. 'final_tp'
  86. ]);
  87. if (b.qc_bgl_code && b.qc_bgl_code !== '') {
  88. gcl.qc_bgl_code = gcl.qc_bgl_code.concat(b.qc_bgl_code.split(';'));
  89. }
  90. } else if (gatherOther) {
  91. gatherFields(other, b, [
  92. 'deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price',
  93. 'contract_tp', 'qc_tp', 'gather_tp',
  94. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp',
  95. 'end_contract_tp', 'end_qc_tp', 'end_gather_tp',
  96. 'final_tp'
  97. ]);
  98. }
  99. }
  100. if (gatherOther) gclBills.push(other);
  101. for (const g of gclBills) {
  102. if (g.qc_bgl_code) g.qc_bgl_code = g.qc_bgl_code.join(';');
  103. g.final_ratio = ctx.helper.mul(ctx.helper.div(g.end_gather_tp, g.final_ratio), 100);
  104. }
  105. data.mem_stage_bills = gclBills;
  106. }
  107. };
  108. const sortGcl = {
  109. name: '工程量清单排序',
  110. hint: '只对一张表,进行工程量清单排序,排序哪张表,根据勾选的清单编号字段决定:\n' +
  111. 'e.g.1 要对mem_stage_bills排序,需要勾选mem_stage_bills下的"清单编号(b_code)"字段\n' +
  112. 'e.g.2 要对mem_stage_im_zl排序,需要勾选mem_stage_im_zl下的"中间计量总量信息_编号(code)"字段\n' +
  113. '特别的,如有"未计入清单章节项": \n' +
  114. ' 1. 默认"未计入清单章节项"排列在最后\n' +
  115. ' 2. 如须"未计入清单章节项"排在100章之后,请在清单编号字段后,依次勾选"章节编号(chapter)", "名称(name)"\n',
  116. fun: function (ctx, data, fieldsKey) {
  117. if (fieldsKey.length !== 1 && fieldsKey.length !== 3) return;
  118. const code = fieldsKey[0].field;
  119. const chapter = fieldsKey.length > 1 ? fieldsKey[1].field : '';
  120. const name = fieldsKey.length > 2 ? fieldsKey[2].field : '';
  121. const sortData = data[fieldsKey[0].table];
  122. if (!sortData) return;
  123. sortData.sort(function (a, b) {
  124. if (chapter !== '') {
  125. if (a[name] === '未计入清单章节项') {
  126. return b[chapter] === '100' ? 1 : -1;
  127. } else if (b[name] === '未计入清单章节项') {
  128. return a[chapter] === '100' ? -1 : 1
  129. } else {
  130. return ctx.helper.compareCode(a[code], b[code]);
  131. }
  132. } else {
  133. return ctx.helper.compareCode(a[code], b[code]);
  134. }
  135. });
  136. }
  137. };
  138. const analysisObj = {
  139. changeSort,
  140. gatherGcl,
  141. sortGcl
  142. };
  143. const analysisDefine = (function (obj) {
  144. const result = [];
  145. for (const o in obj) {
  146. const analysis = obj[o];
  147. if (analysis.name && analysis.hint && analysis.fun) {
  148. result.push({
  149. name: analysis.name,
  150. key: o,
  151. hint: analysis.hint,
  152. })
  153. }
  154. }
  155. return result;
  156. })(analysisObj);
  157. module.exports = {
  158. analysisObj,
  159. analysisDefine
  160. };