rpt_gather_memory.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const Ledger = require('../lib/ledger');
  10. const PayCalculator = require('../lib/pay_calc');
  11. const auditConst = require('../const/audit');
  12. const payConst = require('../const/deal_pay');
  13. const moment = require('moment');
  14. const indexPre = 'id_';
  15. const normalPrefix = 't_', sumPrefix = 's_', specPrefix = 'ts_';
  16. const gatherUtils = {
  17. completeGatherData: function (datas, completeDatas) {
  18. for (const data of datas) {
  19. for (const cd of completeDatas) {
  20. data[cd.prefix + 'id'] = cd.id;
  21. data[cd.prefix + 'name'] = cd.name;
  22. }
  23. }
  24. },
  25. gatherStage: function (tender, gatherNode, sourceNode, prefix, helper) {
  26. gatherNode[prefix + 'id'] = tender.id;
  27. gatherNode[prefix + 'name'] = tender.name;
  28. gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
  29. gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
  30. gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
  31. gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
  32. gatherNode[prefix + "contract_qty"] = helper.add(gatherNode[prefix + "contract_qty"], sourceNode.contract_qty);
  33. gatherNode[prefix + "contract_tp"] = helper.add(gatherNode[prefix + "contract_tp"], sourceNode.contract_tp);
  34. gatherNode[prefix + "qc_qty"] = helper.add(gatherNode[prefix + "qc_qty"], sourceNode.qc_qty);
  35. gatherNode[prefix + "qc_tp"] = helper.add(gatherNode[prefix + "qc_tp"], sourceNode.qc_tp);
  36. gatherNode[prefix + "gather_qty"] = helper.add(gatherNode[prefix + "gather_qty"], sourceNode.gather_qty);
  37. gatherNode[prefix + "gather_tp"] = helper.add(gatherNode[prefix + "gather_tp"], sourceNode.gather_tp);
  38. gatherNode[prefix + "pre_contract_qty"] = helper.add(gatherNode[prefix + "pre_contract_qty"], sourceNode.pre_contract_qty);
  39. gatherNode[prefix + "pre_contract_tp"] = helper.add(gatherNode[prefix + "pre_contract_tp"], sourceNode.pre_contract_tp);
  40. gatherNode[prefix + "pre_qc_qty"] = helper.add(gatherNode[prefix + "pre_qc_qty"], sourceNode.pre_qc_qty);
  41. gatherNode[prefix + "pre_qc_tp"] = helper.add(gatherNode[prefix + "pre_qc_tp"], sourceNode.pre_qc_tp);
  42. gatherNode[prefix + "pre_gather_qty"] = helper.add(gatherNode[prefix + "pre_gather_qty"], sourceNode.pre_gather_qty);
  43. gatherNode[prefix + "pre_gather_tp"] = helper.add(gatherNode[prefix + "pre_gather_tp"], sourceNode.pre_gather_tp);
  44. gatherNode[prefix + "end_contract_qty"] = helper.add(gatherNode[prefix + "end_contract_qty"], sourceNode.end_contract_qty);
  45. gatherNode[prefix + "end_contract_tp"] = helper.add(gatherNode[prefix + "end_contract_tp"], sourceNode.end_contract_tp);
  46. gatherNode[prefix + "end_qc_qty"] = helper.add(gatherNode[prefix + "end_qc_qty"], sourceNode.end_qc_qty);
  47. gatherNode[prefix + "end_qc_tp"] = helper.add(gatherNode[prefix + "end_qc_tp"], sourceNode.end_qc_tp);
  48. gatherNode[prefix + "end_gather_qty"] = helper.add(gatherNode[prefix + "end_gather_qty"], sourceNode.end_gather_qty);
  49. gatherNode[prefix + "end_gather_tp"] = helper.add(gatherNode[prefix + "end_gather_tp"], sourceNode.end_gather_tp);
  50. gatherNode[prefix + "deal_dgn_qty1"] = helper.add(gatherNode[prefix + "deal_dgn_qty1"], sourceNode.deal_dgn_qty1);
  51. gatherNode[prefix + "deal_dgn_qty2"] = helper.add(gatherNode[prefix + "deal_dgn_qty2"], sourceNode.deal_dgn_qty2);
  52. gatherNode[prefix + "c_dgn_qty1"] = helper.add(gatherNode[prefix + "c_dgn_qty1"], sourceNode.c_dgn_qty1);
  53. gatherNode[prefix + "c_dgn_qty2"] = helper.add(gatherNode[prefix + "c_dgn_qty2"], sourceNode.c_dgn_qty2);
  54. gatherNode['s_' + "qty"] = helper.add(gatherNode['s_' + "qty"], sourceNode.quantity);
  55. gatherNode['s_' + "tp"] = helper.add(gatherNode['s_' + "tp"], sourceNode.total_price);
  56. gatherNode['s_' + "dgn_qty1"] = helper.add(gatherNode['s_' + "dgn_qty1"], sourceNode.dgn_qty1);
  57. gatherNode['s_' + "dgn_qty2"] = helper.add(gatherNode['s_' + "dgn_qty2"], sourceNode.dgn_qty2);
  58. gatherNode['s_' + "contract_qty"] = helper.add(gatherNode['s_' + "contract_qty"], sourceNode.contract_qty);
  59. gatherNode['s_' + "contract_tp"] = helper.add(gatherNode['s_' + "contract_tp"], sourceNode.contract_tp);
  60. gatherNode['s_' + "qc_qty"] = helper.add(gatherNode['s_' + "qc_qty"], sourceNode.qc_qty);
  61. gatherNode['s_' + "qc_tp"] = helper.add(gatherNode['s_' + "qc_tp"], sourceNode.qc_tp);
  62. gatherNode['s_' + "gather_qty"] = helper.add(gatherNode['s_' + "gather_qty"], sourceNode.gather_qty);
  63. gatherNode['s_' + "gather_tp"] = helper.add(gatherNode['s_' + "gather_tp"], sourceNode.gather_tp);
  64. gatherNode['s_' + "pre_contract_qty"] = helper.add(gatherNode['s_' + "pre_contract_qty"], sourceNode.pre_contract_qty);
  65. gatherNode['s_' + "pre_contract_tp"] = helper.add(gatherNode['s_' + "pre_contract_tp"], sourceNode.pre_contract_tp);
  66. gatherNode['s_' + "pre_qc_qty"] = helper.add(gatherNode['s_' + "pre_qc_qty"], sourceNode.pre_qc_qty);
  67. gatherNode['s_' + "pre_qc_tp"] = helper.add(gatherNode['s_' + "pre_qc_tp"], sourceNode.pre_qc_tp);
  68. gatherNode['s_' + "pre_gather_qty"] = helper.add(gatherNode['s_' + "pre_gather_qty"], sourceNode.pre_gather_qty);
  69. gatherNode['s_' + "pre_gather_tp"] = helper.add(gatherNode['s_' + "pre_gather_tp"], sourceNode.pre_gather_tp);
  70. gatherNode['s_' + "end_contract_qty"] = helper.add(gatherNode['s_' + "end_contract_qty"], sourceNode.end_contract_qty);
  71. gatherNode['s_' + "end_contract_tp"] = helper.add(gatherNode['s_' + "end_contract_tp"], sourceNode.end_contract_tp);
  72. gatherNode['s_' + "end_qc_qty"] = helper.add(gatherNode['s_' + "end_qc_qty"], sourceNode.end_qc_qty);
  73. gatherNode['s_' + "end_qc_tp"] = helper.add(gatherNode['s_' + "end_qc_tp"], sourceNode.end_qc_tp);
  74. gatherNode['s_' + "end_gather_qty"] = helper.add(gatherNode['s_' + "end_gather_qty"], sourceNode.end_gather_qty);
  75. gatherNode['s_' + "end_gather_tp"] = helper.add(gatherNode['s_' + "end_gather_tp"], sourceNode.end_gather_tp);
  76. gatherNode['s_' + "deal_dgn_qty1"] = helper.add(gatherNode['s_' + "deal_dgn_qty1"], sourceNode.deal_dgn_qty1);
  77. gatherNode['s_' + "deal_dgn_qty2"] = helper.add(gatherNode['s_' + "deal_dgn_qty2"], sourceNode.deal_dgn_qty2);
  78. gatherNode['s_' + "c_dgn_qty1"] = helper.add(gatherNode['s_' + "c_dgn_qty1"], sourceNode.c_dgn_qty1);
  79. gatherNode['s_' + "c_dgn_qty2"] = helper.add(gatherNode['s_' + "c_dgn_qty2"], sourceNode.c_dgn_qty2);
  80. },
  81. gatherZone: function (tender, gatherNode, sourceNode, prefix, helper) {
  82. gatherNode[prefix + 'id'] = tender.id;
  83. gatherNode[prefix + 'name'] = tender.name;
  84. gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
  85. gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
  86. gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
  87. gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
  88. gatherNode[prefix + "contract_qty"] = helper.add(gatherNode[prefix + "contract_qty"], sourceNode.contract_qty);
  89. gatherNode[prefix + "contract_tp"] = helper.add(gatherNode[prefix + "contract_tp"], sourceNode.contract_tp);
  90. gatherNode[prefix + "qc_qty"] = helper.add(gatherNode[prefix + "qc_qty"], sourceNode.qc_qty);
  91. gatherNode[prefix + "qc_tp"] = helper.add(gatherNode[prefix + "qc_tp"], sourceNode.qc_tp);
  92. gatherNode[prefix + "gather_qty"] = helper.add(gatherNode[prefix + "gather_qty"], sourceNode.gather_qty);
  93. gatherNode[prefix + "gather_tp"] = helper.add(gatherNode[prefix + "gather_tp"], sourceNode.gather_tp);
  94. gatherNode[prefix + "deal_dgn_qty1"] = helper.add(gatherNode[prefix + "deal_dgn_qty1"], sourceNode.deal_dgn_qty1);
  95. gatherNode[prefix + "deal_dgn_qty2"] = helper.add(gatherNode[prefix + "deal_dgn_qty2"], sourceNode.deal_dgn_qty2);
  96. gatherNode[prefix + "c_dgn_qty1"] = helper.add(gatherNode[prefix + "c_dgn_qty1"], sourceNode.c_dgn_qty1);
  97. gatherNode[prefix + "c_dgn_qty2"] = helper.add(gatherNode[prefix + "c_dgn_qty2"], sourceNode.c_dgn_qty2);
  98. gatherNode['s_' + "qty"] = helper.add(gatherNode['s_' + "qty"], sourceNode.quantity);
  99. gatherNode['s_' + "tp"] = helper.add(gatherNode['s_' + "tp"], sourceNode.total_price);
  100. gatherNode['s_' + "contract_qty"] = helper.add(gatherNode['s_' + "contract_qty"], sourceNode.contract_qty);
  101. gatherNode['s_' + "contract_tp"] = helper.add(gatherNode['s_' + "contract_tp"], sourceNode.contract_tp);
  102. gatherNode['s_' + "qc_qty"] = helper.add(gatherNode['s_' + "qc_qty"], sourceNode.qc_qty);
  103. gatherNode['s_' + "qc_tp"] = helper.add(gatherNode['s_' + "qc_tp"], sourceNode.qc_tp);
  104. gatherNode['s_' + "gather_qty"] = helper.add(gatherNode['s_' + "gather_qty"], sourceNode.gather_qty);
  105. gatherNode['s_' + "gather_tp"] = helper.add(gatherNode['s_' + "gather_tp"], sourceNode.gather_tp);
  106. },
  107. gatherLedger: function (tender, gatherNode, sourceNode, prefix, helper) {
  108. gatherNode[prefix + 'id'] = tender.id;
  109. gatherNode[prefix + 'name'] = tender.name;
  110. gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
  111. gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
  112. gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
  113. gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
  114. gatherNode['s_' + "qty"] = helper.add(gatherNode['s_' + "qty"], sourceNode.quantity);
  115. gatherNode['s_' + "tp"] = helper.add(gatherNode['s_' + "tp"], sourceNode.total_price);
  116. },
  117. gatherSpecial: function (gatherNode, sourceNode, prefix, helper) {
  118. gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
  119. gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
  120. gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
  121. gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
  122. },
  123. };
  124. module.exports = app => {
  125. class RptGatherMemory extends app.BaseService {
  126. /**
  127. * 构造函数
  128. *
  129. * @param {Object} ctx - egg全局context
  130. * @return {void}
  131. */
  132. constructor(ctx) {
  133. super(ctx);
  134. this.resultTree = new Ledger.gatherTree(ctx, {
  135. id: 'id',
  136. pid: 'pid',
  137. order: 'order',
  138. level: 'level',
  139. rootId: -1
  140. });
  141. this.resultTenderInfo = [];
  142. this.resultDealPay = [];
  143. this.resultDealBills = [];
  144. }
  145. async _getValidStages(tenderId) {
  146. const stages = await this.db.select(this.ctx.service.stage.tableName, {
  147. where: { tid: tenderId },
  148. orders: [['order', 'desc']],
  149. });
  150. if (stages.length !== 0) {
  151. const lastStage = stages[0];
  152. if (lastStage.status === auditConst.stage.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
  153. stages.splice(0, 1);
  154. }
  155. }
  156. return stages;
  157. }
  158. async _getCheckedStages(tenderId) {
  159. const stages = await this.db.select(this.ctx.service.stage.tableName, {
  160. where: { tid: tenderId },
  161. orders: [['order', 'desc']],
  162. });
  163. if (stages.length !== 0) {
  164. const lastStage = stages[0];
  165. if (lastStage.status !== auditConst.stage.status.checked) {
  166. stages.splice(0, 1);
  167. }
  168. }
  169. return stages;
  170. }
  171. _checkSpecialTender(tender, special) {
  172. if (special) {
  173. for (const spec of special) {
  174. if (tender[spec.key] === true) return spec.key;
  175. }
  176. }
  177. return '';
  178. }
  179. async _getTimeZoneStages(tender, zone) {
  180. const times = zone.split(' - ');
  181. if (times.length !== 2) throw '选择的汇总周期无效';
  182. const beginTime = moment(times[0], 'YYYY-MM');
  183. const endTime = moment(times[1], 'YYYY-MM');
  184. const stages = await this._getValidStages(tender.id), validStages = [];
  185. for (const stage of stages) {
  186. const sTime = moment(stage.s_time, 'YYYY-MM');
  187. if (sTime.isBetween(beginTime, endTime, null, '[]')) {
  188. validStages.push(stage);
  189. }
  190. }
  191. return validStages;
  192. }
  193. async _getOrderZoneStages (tender, zone) {
  194. let [iBegin, iEnd] = zone.split(':');
  195. iBegin = this.ctx.helper._.toInteger(iBegin) || 0;
  196. iEnd = this.ctx.helper._.toInteger(iEnd) || 0;
  197. const stages = await this._getValidStages(tender.id), validStages = [];
  198. for (const stage of stages) {
  199. if (stage.order < iBegin || stage.order > iEnd) continue;
  200. validStages.push(stage);
  201. }
  202. return validStages;
  203. }
  204. /**
  205. * 台账数据
  206. */
  207. async _gatherStageData(completeData, tender, stage, hasPre) {
  208. const helper = this.ctx.helper;
  209. completeData.id = tender.id;
  210. completeData.name = tender.name;
  211. const billsTree = new Ledger.billsTree(this.ctx, {
  212. id: 'ledger_id',
  213. pid: 'ledger_pid',
  214. order: 'order',
  215. level: 'level',
  216. rootId: -1,
  217. keys: ['id', 'tender_id', 'ledger_id'],
  218. stageId: 'id',
  219. calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
  220. calc: function (node) {
  221. if (node.children && node.children.length === 0) {
  222. node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
  223. node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
  224. node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty);
  225. node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
  226. node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty);
  227. }
  228. node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
  229. node.gather_tp = helper.add(node.contract_tp, node.qc_tp);
  230. node.end_contract_tp = helper.add(node.pre_contract_tp, node.contract_tp);
  231. node.end_qc_tp = helper.add(node.pre_qc_tp, node.qc_tp);
  232. node.end_gather_tp = helper.add(node.pre_gather_tp, node.gather_tp);
  233. }
  234. });
  235. const billsData = await this.ctx.service.ledger.getData(tender.id);
  236. const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(tender.id);
  237. for (const d of dgnData) {
  238. const l = this.ctx.helper._.find(billsData, {id: d.id});
  239. this.ctx.helper._.assignIn(l, d);
  240. }
  241. if (stage) {
  242. await this.ctx.service.stage.doCheckStage(stage);
  243. if (stage.readOnly) {
  244. const curStage = await this.ctx.service.stageBills.getAuditorStageData(tender.id,
  245. stage.id, stage.curTimes, stage.curOrder);
  246. this.ctx.helper.assignRelaData(billsData, [
  247. {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
  248. ]);
  249. } else {
  250. const curStage = await this.ctx.service.stageBills.getLastestStageData(tender.id, stage.id);
  251. this.ctx.helper.assignRelaData(billsData, [
  252. {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
  253. ]);
  254. }
  255. if (hasPre) {
  256. const preStage = stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(tender, stage.order - 1) : [];
  257. this.ctx.helper.assignRelaData(billsData, [
  258. {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
  259. ]);
  260. }
  261. }
  262. billsTree.loadDatas(billsData);
  263. billsTree.calculateAll();
  264. this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
  265. gatherUtils.gatherStage(tender, gatherNode, sourceNode, completeData.prefix, helper);
  266. });
  267. }
  268. async _gatherStagesData(completeData, tender, stages) {
  269. const helper = this.ctx.helper;
  270. completeData.id = tender.id;
  271. completeData.name = tender.name;
  272. /**
  273. * 汇总并合并 相关数据
  274. * @param {Array} index - 主数据
  275. * @param {Array[]}rela - 相关数据 {data, fields, prefix, relaId}
  276. */
  277. const sumAssignRelaData = function (index, rela) {
  278. const loadFields = function (datas, fields, prefix, relaId) {
  279. for (const d of datas) {
  280. const key = indexPre + d[relaId];
  281. const m = index[key];
  282. if (m) {
  283. for (const f of fields) {
  284. if (d[f] !== undefined) {
  285. m[prefix + f] = helper.add(m[prefix + f], d[f]);
  286. }
  287. }
  288. }
  289. }
  290. };
  291. for (const r of rela) {
  292. loadFields(r.data, r.fields, r.prefix, r.relaId);
  293. }
  294. };
  295. const billsTree = new Ledger.billsTree(this.ctx, {
  296. id: 'ledger_id',
  297. pid: 'ledger_pid',
  298. order: 'order',
  299. level: 'level',
  300. rootId: -1,
  301. keys: ['id', 'tender_id', 'ledger_id'],
  302. stageId: 'id',
  303. calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp'],
  304. calc: function (node) {
  305. if (node.children && node.children.length === 0) {
  306. node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
  307. }
  308. node.gather_tp = helper.add(node.contract_tp, node.qc_tp);
  309. }
  310. });
  311. const billsData = await this.ctx.service.ledger.getData(tender.id);
  312. const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(tender.id);
  313. for (const d of dgnData) {
  314. const l = this.ctx.helper._.find(billsData, {id: d.id});
  315. this.ctx.helper._.assignIn(l, d);
  316. }
  317. let billsIndexData = {};
  318. for (const bd of billsData) {
  319. billsIndexData[indexPre + bd.id] = bd;
  320. }
  321. for (const stage of stages) {
  322. await this.ctx.service.stage.doCheckStage(stage);
  323. if (stage.readOnly) {
  324. const curStage = await this.ctx.service.stageBills.getAuditorStageData(tender.id,
  325. stage.id, stage.curTimes, stage.curOrder);
  326. sumAssignRelaData(billsIndexData, [
  327. {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
  328. ]);
  329. } else {
  330. const curStage = await this.ctx.service.stageBills.getLastestStageData(tender.id, stage.id);
  331. sumAssignRelaData(billsIndexData, [
  332. {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
  333. ]);
  334. }
  335. }
  336. billsTree.loadDatas(billsData);
  337. billsTree.calculateAll();
  338. this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
  339. gatherUtils.gatherZone(tender, gatherNode, sourceNode, completeData.prefix, helper);
  340. });
  341. }
  342. async _gatherMonthData(sTender, completeData, month, hasPre) {
  343. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  344. const stages = await this._getValidStages(tender.id);
  345. const stage = this.ctx.helper._.find(stages, {s_time: month});
  346. await this._gatherStageData(completeData, tender, stage, hasPre);
  347. }
  348. async _gatherIndexData(sTender, completeData, index, hasPre) {
  349. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  350. const stages = await this._getValidStages(tender.id);
  351. const stage = this.ctx.helper._.find(stages, {order: index});
  352. await this._gatherStageData(completeData, tender, stage, hasPre);
  353. }
  354. async _gatherZoneData(sTender, completeData, zone) {
  355. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  356. const stages = await this._getTimeZoneStages(tender, zone);
  357. await this._gatherStagesData(completeData, tender, stages);
  358. }
  359. async _gatherIndexZoneData(sTender, completeData, stageZone) {
  360. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  361. const stages = await this._getOrderZoneStages(tender, stageZone);
  362. await this._gatherStagesData(completeData, tender, stages);
  363. }
  364. async _gatherFinalData(sTender, completeData, hasPre) {
  365. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  366. const stages = await this._getValidStages(tender.id);
  367. await this._gatherStageData(completeData, tender, stages[0], hasPre);
  368. }
  369. async _gatherCheckedFinalData(sTender, completeData, hasPre) {
  370. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  371. const stages = await this._getCheckedStages(tender.id);
  372. await this._gatherStageData(completeData, tender, stages[0], hasPre);
  373. }
  374. async _gatherLedgerData(sTender, completeData) {
  375. const helper = this.ctx.helper;
  376. const billsTree = new Ledger.billsTree(this.ctx, {
  377. id: 'ledger_id',
  378. pid: 'ledger_pid',
  379. order: 'order',
  380. level: 'level',
  381. rootId: -1,
  382. keys: ['id', 'tender_id', 'ledger_id'],
  383. stageId: 'id',
  384. calcFields: ['deal_tp', 'total_price'],
  385. });
  386. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  387. const billsData = await this.ctx.service.ledger.getData(tender.id);
  388. billsTree.loadDatas(billsData);
  389. billsTree.calculateAll();
  390. this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
  391. gatherUtils.gatherLedger(tender, gatherNode, sourceNode, completeData.prefix, helper);
  392. })
  393. }
  394. async _gatherSpecialData(sTender, sKey) {
  395. const helper = this.ctx.helper;
  396. const billsTree = new Ledger.billsTree(this.ctx, {
  397. id: 'ledger_id',
  398. pid: 'ledger_pid',
  399. order: 'order',
  400. level: 'level',
  401. rootId: -1,
  402. keys: ['id', 'tender_id', 'ledger_id'],
  403. stageId: 'id',
  404. calcFields: ['deal_tp', 'total_price'],
  405. });
  406. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  407. const billsData = await this.ctx.service.ledger.getData(tender.id);
  408. billsTree.loadDatas(billsData);
  409. billsTree.calculateAll();
  410. this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
  411. gatherUtils.gatherSpecial(gatherNode, sourceNode, 'ts_' + sKey + '_', helper);
  412. })
  413. }
  414. async getGatherStageBills(memFieldKeys, gsDefine, gsCustom) {
  415. if (!gsDefine || !gsDefine.enable) return [];
  416. if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
  417. const gsSetting = JSON.parse(gsDefine.setting);
  418. let commonIndex = 0;
  419. const completeDatas = [];
  420. for (const tender of gsCustom.tenders) {
  421. const specialKey = this._checkSpecialTender(tender, gsSetting.special);
  422. if (specialKey === '') {
  423. const completeData = {
  424. prefix: 't_' + commonIndex + '_',
  425. };
  426. completeDatas.push(completeData);
  427. switch (gsSetting.type) {
  428. case 'month':
  429. await this._gatherMonthData(tender, completeData, gsCustom.month, gsSetting.hasPre);
  430. break;
  431. case 'zone':
  432. await this._gatherZoneData(tender, completeData, gsCustom.zone);
  433. break;
  434. case 'final':
  435. await this._gatherFinalData(tender, completeData, gsSetting.hasPre);
  436. break;
  437. case 'checked-final':
  438. await this._gatherCheckedFinalData(tender, completeData, gsSetting.hasPre);
  439. break;
  440. case 'ledger':
  441. await this._gatherLedgerData(tender, completeData);
  442. break;
  443. case 'stage':
  444. await this._gatherIndexData(tender, completeData, gsCustom.stage, gsSetting.hasPre);
  445. break;
  446. case 'stage-zone':
  447. await this._gatherIndexZoneData(tender, completeData, gsCustom.stage_zone);
  448. break;
  449. }
  450. commonIndex++;
  451. } else {
  452. await this._gatherSpecialData(tender, specialKey);
  453. }
  454. }
  455. this.resultTree.generateSortNodes();
  456. gatherUtils.completeGatherData(this.resultTree.nodes, completeDatas);
  457. return this.resultTree.getDefaultDatas();
  458. }
  459. /**
  460. * 标段信息
  461. */
  462. async _getBaseTenderInfo(tender) {
  463. const info = {
  464. id: tender.id,
  465. name: tender.name,
  466. deal_tp: tender.deal_tp,
  467. tp: tender.total_price
  468. };
  469. const deal_bills_sum = await this.ctx.service.dealBills.getSum(tender.id);
  470. info.deal_bills_tp = deal_bills_sum ? deal_bills_sum.total_price : 0;
  471. if (tender.ledger_status === auditConst.ledger.status.uncheck || tender.ledger_status === auditConst.ledger.status.checkNo) {
  472. const sum = await this.ctx.service.ledger.addUp({tender_id: tender.id/*, is_leaf: true*/});
  473. info.tp = sum.total_price;
  474. info.deal_tp = sum.deal_tp;
  475. }
  476. info.deal_info = tender.info.deal_info;
  477. info.construction_unit = tender.info.construction_unit;
  478. info.tech_param = tender.info.tech_param;
  479. info.deal_param = tender.info.deal_param;
  480. info.pay_account = tender.info.pay_account;
  481. info.deal_param.contractPriceWithoutZL = this.ctx.helper.sub(info.deal_param.contractPrice,
  482. info.deal_param.zanLiePrice);
  483. info.bid_info = tender.info.bid_info;
  484. return info;
  485. }
  486. async _getStageTenderInfo(stage, info) {
  487. if (stage) {
  488. const helper = this.ctx.helper;
  489. await this.ctx.service.stage.doCheckStage(stage);
  490. await this.ctx.service.stage.checkStageGatherData(stage);
  491. info.pre_contract_tp = stage.pre_contract_tp;
  492. info.pre_qc_tp = stage.pre_qc_tp;
  493. info.pre_gather_tp = helper.add(info.pre_contract_tp, info.pre_qc_tp);
  494. info.contract_tp = stage.contract_tp;
  495. info.qc_tp = stage.qc_tp;
  496. info.gather_tp = helper.add(info.contract_tp, info.qc_tp);
  497. info.end_contract_tp = helper.add(info.pre_contract_tp, info.contract_tp);
  498. info.end_qc_tp = helper.add(info.pre_qc_tp, info.qc_tp);
  499. info.end_gather_tp = helper.add(info.pre_gather_tp, info.gather_tp);
  500. info.yf_tp = stage.yf_tp;
  501. info.pre_yf_tp = stage.pre_yf_tp;
  502. info.end_yf_tp = helper.add(stage.yf_tp, stage.pre_yf_tp);
  503. }
  504. }
  505. async _getStagesTenderInfo(stages, info) {
  506. const helper = this.ctx.helper;
  507. for (const stage of stages) {
  508. await this.ctx.service.stage.doCheckStage(stage);
  509. await this.ctx.service.stage.checkStageGatherData(stage);
  510. info.contract_tp = helper.add(info.contract_tp, stage.contract_tp);
  511. info.qc_tp = helper.add(info.qc_tp, stage.qc_tp);
  512. info.yf_tp = helper.add(info.yf_tp, stage.yf_tp);
  513. }
  514. info.gather_tp = helper.add(info.contract_tp, info.qc_tp);
  515. }
  516. async _gatherMonthTenderInfo(sTender, index, month, hasPre) {
  517. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  518. const info = await this._getBaseTenderInfo(tender);
  519. const stages = await this._getValidStages(tender.id);
  520. const stage = this.ctx.helper._.find(stages, {s_time: month});
  521. await this._getStageTenderInfo(stage, info);
  522. this.resultTenderInfo.push(info);
  523. }
  524. async _gatherOrderTenderInfo(sTender, index, order, hasPre) {
  525. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  526. const info = await this._getBaseTenderInfo(tender);
  527. const stages = await this._getValidStages(tender.id);
  528. const stage = this.ctx.helper._.find(stages, {order: order});
  529. await this._getStageTenderInfo(stage, info);
  530. this.resultTenderInfo.push(info);
  531. }
  532. async _gatherZoneTenderInfo(sTender, index, zone) {
  533. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  534. const info = await this._getBaseTenderInfo(tender);
  535. const stages = await this._getTimeZoneStages(tender, zone);
  536. await this._getStagesTenderInfo(stages, info);
  537. this.resultTenderInfo.push(info);
  538. }
  539. async _gatherOrderZoneTenderInfo(sTender, index, stageZone) {
  540. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  541. const info = await this._getBaseTenderInfo(tender);
  542. const stages = await this._getOrderZoneStages(tender, stageZone);
  543. await this._getStagesTenderInfo(stages, info);
  544. this.resultTenderInfo.push(info);
  545. }
  546. async _gatherFinalTenderInfo(sTender, index, hasPre) {
  547. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  548. const info = await this._getBaseTenderInfo(tender);
  549. const stages = await this._getValidStages(tender.id);
  550. await this._getStageTenderInfo(stages[0], info);
  551. this.resultTenderInfo.push(info);
  552. }
  553. async _gatherCheckedFinalTenderInfo(sTender, index, hasPre) {
  554. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  555. const info = await this._getBaseTenderInfo(tender);
  556. const stages = await this._getCheckedStages(tender.id);
  557. await this._getStageTenderInfo(stages[0], info);
  558. this.resultTenderInfo.push(info);
  559. }
  560. async _gatherLedgerTenderInfo(sTender, index) {
  561. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  562. const info = await this._getBaseTenderInfo(tender);
  563. this.resultTenderInfo.push(info);
  564. }
  565. async _gatherSpecialTenderInfo(sTender, sKey) {
  566. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  567. const info = await this._getBaseTenderInfo(tender);
  568. info.spec = sKey;
  569. this.resultTenderInfo.push(info);
  570. }
  571. async getGatherTenderInfo(memFieldKeys, gsDefine, gsCustom) {
  572. if (!gsDefine || !gsDefine.enable) return [];
  573. if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
  574. this.resultTenderInfo = [];
  575. const gsSetting = JSON.parse(gsDefine.setting);
  576. let commonIndex = 0;
  577. for (const tender of gsCustom.tenders) {
  578. const specialKey = this._checkSpecialTender(tender, gsSetting.special);
  579. if (specialKey === '') {
  580. switch (gsSetting.type) {
  581. case 'month':
  582. await this._gatherMonthTenderInfo(tender, commonIndex, gsCustom.month, gsSetting.hasPre);
  583. break;
  584. case 'zone':
  585. await this._gatherZoneTenderInfo(tender, commonIndex, gsCustom.zone);
  586. break;
  587. case 'final':
  588. await this._gatherFinalTenderInfo(tender, commonIndex, gsSetting.hasPre);
  589. break;
  590. case 'checked-final':
  591. await this._gatherCheckedFinalTenderInfo(tender, commonIndex, gsSetting.hasPre);
  592. break;
  593. case 'ledger':
  594. await this._gatherLedgerTenderInfo(tender, commonIndex);
  595. break;
  596. case 'stage':
  597. await this._gatherOrderTenderInfo(tender, commonIndex, gsCustom.stage, gsSetting.hasPre);
  598. break;
  599. case 'stage-zone':
  600. await this._gatherOrderZoneTenderInfo(tender, commonIndex, gsCustom.stage_zone);
  601. break;
  602. }
  603. commonIndex++;
  604. } else {
  605. await this._gatherSpecialTenderInfo(tender, specialKey);
  606. }
  607. }
  608. return this.resultTenderInfo;
  609. }
  610. /**
  611. * 合同支付
  612. */
  613. _gatherPayRecord(dealPay, fun) {
  614. let rdp;
  615. if (dealPay.ptype !== payConst.payType.normal) {
  616. rdp = this.ctx.helper._.find(this.resultDealPay, {ptype: dealPay.ptype});
  617. } else {
  618. rdp = this.ctx.helper._.find(this.resultDealPay, {
  619. name: dealPay.name,
  620. minus: dealPay.minus ? true : false,
  621. is_yf: dealPay.is_yf ? true : false,
  622. });
  623. }
  624. if (!rdp) {
  625. rdp = {
  626. ptype: dealPay.ptype,
  627. name: dealPay.name,
  628. minus: dealPay.minus ? true : false,
  629. is_yf: dealPay.is_yf ? true : false,
  630. };
  631. this.resultDealPay.push(rdp);
  632. }
  633. if (fun) fun(rdp, dealPay);
  634. }
  635. async _checkStagePayCalc(tender, stage, dealPay) {
  636. if (!stage.readOnly) {
  637. // 计算 本期金额
  638. const payCalculator = new PayCalculator(this.ctx, stage, tender.info);
  639. await payCalculator.calculateAll(dealPay);
  640. }
  641. }
  642. async _gatherStagePay(completeData, tender, stage, hasPre) {
  643. if (stage) {
  644. completeData.id = tender.id;
  645. completeData.name = tender.name;
  646. const helper = this.ctx.helper;
  647. await this.ctx.service.stage.doCheckStage(stage);
  648. const dealPay = await this.ctx.service.stagePay.getStagePays(stage);
  649. await this._checkStagePayCalc(tender, stage, dealPay);
  650. for (const dp of dealPay) {
  651. dp.end_tp = helper.add(dp.pre_tp, dp.tp);
  652. this._gatherPayRecord(dp, function (gatherData, sourceData) {
  653. gatherData[completeData.prefix + 'id'] = tender.id;
  654. gatherData[completeData.prefix + 'name'] = tender.name;
  655. gatherData[completeData.prefix + 'tp'] = helper.add(gatherData[completeData.prefix + 'tp'], sourceData.tp);
  656. gatherData[completeData.prefix + 'pre_tp'] = helper.add(gatherData[completeData.prefix + 'pre_tp'], sourceData.pre_tp);
  657. gatherData[completeData.prefix + 'end_tp'] = helper.add(gatherData[completeData.prefix + 'end_tp'], sourceData.end_tp);
  658. gatherData['s_' + 'tp'] = helper.add(gatherData['s_' + 'tp'], sourceData.tp);
  659. gatherData['s_' + 'pre_tp'] = helper.add(gatherData['s_' + 'pre_tp'], sourceData.pre_tp);
  660. gatherData['s_' + 'end_tp'] = helper.add(gatherData['s_' + 'end_tp'], sourceData.end_tp);
  661. });
  662. }
  663. }
  664. }
  665. async _gatherStagesPay(completeData, tender, stages) {
  666. const helper = this.ctx.helper;
  667. completeData.id = tender.id;
  668. completeData.name = tender.name;
  669. for (const stage of stages) {
  670. await this.ctx.service.stage.doCheckStage(stage);
  671. const dealPay = await this.ctx.service.stagePay.getStagePays(stage);
  672. await this._checkStagePayCalc(tender, stage, dealPay);
  673. for (const dp of dealPay) {
  674. dp.end_tp = helper.add(dp.pre_tp, dp.tp);
  675. this._gatherPayRecord(dp, function (gatherData, sourceData) {
  676. gatherData[completeData.prefix + 'id'] = tender.id;
  677. gatherData[completeData.prefix + 'name'] = tender.name;
  678. gatherData[completeData.prefix + 'tp'] = helper.add(gatherData[completeData.prefix + 'tp'], sourceData.tp);
  679. gatherData['s_' + 'tp'] = helper.add(gatherData['s_' + 'tp'], sourceData.tp);
  680. });
  681. }
  682. }
  683. }
  684. async _gatherMonthStagePay(sTender, completeData, month, hasPre) {
  685. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  686. const stages = await this._getValidStages(tender.id);
  687. const stage = this.ctx.helper._.find(stages, {s_time: month});
  688. await this._gatherStagePay(completeData, tender, stage, hasPre);
  689. }
  690. async _gatherOrderStagePay(sTender, completeData, order, hasPre) {
  691. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  692. const stages = await this._getValidStages(tender.id);
  693. const stage = this.ctx.helper._.find(stages, {order: order});
  694. await this._gatherStagePay(completeData, tender, stage, hasPre);
  695. }
  696. async _gatherZoneStagePay(sTender, completeData, zone) {
  697. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  698. const stages = await this._getTimeZoneStages(tender, zone);
  699. await this._gatherStagesPay(completeData, tender, stages);
  700. }
  701. async _gatherOrderZoneStagePay(sTender, completeData, stageZone) {
  702. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  703. const stages = await this._getOrderZoneStages(tender, stageZone)
  704. await this._gatherStagesPay(completeData, tender, stages);
  705. }
  706. async _gatherFinalStagePay(sTender, completeData, hasPre) {
  707. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  708. const stages = await this._getValidStages(tender.id);
  709. await this._gatherStagePay(completeData, tender, stages[0], hasPre);
  710. }
  711. async _gatherCheckedFinalStagePay(sTender, completeData, hasPre) {
  712. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  713. const stages = await this._getCheckedStages(tender.id);
  714. await this._gatherStagePay(completeData, tender, stages[0], hasPre);
  715. }
  716. async getGatherStagePay(memFieldKeys, gsDefine, gsCustom) {
  717. if (!gsDefine || !gsDefine.enable) return [];
  718. if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
  719. this.resultTenderInfo = [];
  720. const gsSetting = JSON.parse(gsDefine.setting);
  721. let commonIndex = 0;
  722. const completeDatas = [];
  723. for (const tender of gsCustom.tenders) {
  724. const specialKey = this._checkSpecialTender(tender, gsSetting.special);
  725. if (specialKey === '') {
  726. const completeData = {
  727. prefix: 't_' + commonIndex + '_',
  728. };
  729. completeDatas.push(completeData);
  730. switch (gsSetting.type) {
  731. case 'month':
  732. await this._gatherMonthStagePay(tender, completeData, gsCustom.month, gsSetting.hasPre);
  733. break;
  734. case 'zone':
  735. await this._gatherZoneStagePay(tender, completeData, gsCustom.zone);
  736. break;
  737. case 'final':
  738. await this._gatherFinalStagePay(tender, completeData, gsSetting.hasPre);
  739. break;
  740. case 'checked-final':
  741. await this._gatherCheckedFinalStagePay(tender, completeData, gsSetting.hasPre);
  742. break;
  743. case 'stage':
  744. await this._gatherOrderStagePay(tender, completeData, gsCustom.stage, gsSetting.hasPre);
  745. break;
  746. case 'stage-zone':
  747. await this._gatherOrderZoneStagePay(tender, completeData, gsCustom.stage_zone);
  748. break;
  749. }
  750. commonIndex++;
  751. }
  752. // 合同支付,只有在每一期中有数据,故特殊标段直接不汇总合同支付
  753. }
  754. gatherUtils.completeGatherData(this.resultDealPay, completeDatas);
  755. return this.resultDealPay;
  756. }
  757. /**
  758. * 签约清单
  759. */
  760. async _gatherDealBills(tender, fun) {
  761. const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({
  762. where: { tender_id: tender.id }
  763. });
  764. for (const db of dealBills) {
  765. let rdb = this.ctx.helper._.find(this.resultDealBills, {
  766. code: db.code,
  767. name: db.name,
  768. unit: db.unit,
  769. unit_price: db.unit_price ? db.unit_price: 0,
  770. });
  771. if (!rdb) {
  772. rdb = {
  773. code: db.code,
  774. name: db.name,
  775. unit: db.unit,
  776. unit_price: db.unit_price ? db.unit_price: 0,
  777. };
  778. this.resultDealBills.push(rdb);
  779. }
  780. if (fun) fun(rdb, db);
  781. }
  782. }
  783. async _gatherCommonDealBills(sTender, completeData) {
  784. const self = this;
  785. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  786. completeData.id = tender.id;
  787. completeData.name = tender.name;
  788. await this._gatherDealBills(tender, function (gatherData, sourceData) {
  789. gatherData[completeData.prefix + 'id'] = tender.id;
  790. gatherData[completeData.prefix + 'name'] = tender.name;
  791. gatherData[completeData.prefix + 'qty'] = sourceData.quantity;
  792. gatherData[completeData.prefix + 'tp'] = sourceData.total_price;
  793. gatherData['s_' + 'qty'] = self.ctx.helper.add(gatherData['s_' + 'qty'], sourceData.quantity);
  794. gatherData['s_' + 'tp'] = self.ctx.helper.add(gatherData['s_' + 'tp'], sourceData.total_price);
  795. });
  796. }
  797. async _gatherSpecialDealBills(sTender, sKey) {
  798. const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
  799. await this._gatherDealBills(tender, function (gatherData, sourceData) {
  800. const prefix = 'ts_' + sKey + '_';
  801. gatherData[prefix + 'qty'] = sourceData.quantity;
  802. gatherData[prefix + 'tp'] = sourceData.total_price;
  803. });
  804. }
  805. async getGatherDealBills(memFieldKeys, gsDefine, gsCustom) {
  806. if (!gsDefine || !gsDefine.enable) return [];
  807. if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
  808. this.resultTenderInfo = [];
  809. const gsSetting = JSON.parse(gsDefine.setting);
  810. let commonIndex = 0;
  811. const completeDatas = [];
  812. for (const tender of gsCustom.tenders) {
  813. const specialKey = this._checkSpecialTender(tender, gsSetting.special);
  814. if (specialKey === '') {
  815. const completeData = {
  816. prefix: 't_' + commonIndex + '_',
  817. };
  818. completeDatas.push(completeData);
  819. await this._gatherCommonDealBills(tender, completeData);
  820. commonIndex++;
  821. } else {
  822. await this._gatherSpecialDealBills(tender, specialKey);
  823. }
  824. }
  825. gatherUtils.completeGatherData(this.resultDealBills, completeDatas);
  826. return this.resultDealBills;
  827. }
  828. }
  829. return RptGatherMemory;
  830. };