change_plan.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. 'use strict';
  2. /**
  3. * 变更方案
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const RptMemBase = require('./base');
  10. const bindData = {};
  11. class rptMemChange extends RptMemBase {
  12. constructor(ctx) {
  13. super(ctx, bindData);
  14. }
  15. async doCheckChangePlan(id) {
  16. if (this.ctx.change_plan) return;
  17. this.ctx.change_plan = await this.ctx.service.changePlan.getDataById(id);
  18. }
  19. async doCheckTender(tenderId) {
  20. if (this.ctx.tender) return;
  21. this.ctx.tender = { id: tenderId };
  22. this.ctx.tender.data = await this.ctx.service.tender.getTender(tenderId);
  23. this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
  24. }
  25. async doBeforeLoadReport(params) {
  26. await this.doCheckChangePlan(params.change_plan_id);
  27. await this.doCheckTender(this.ctx.change_plan.tid);
  28. }
  29. async _getChangePlanBills() {
  30. const helper = this.ctx.helper;
  31. const decimal = this.ctx.tender.info.decimal;
  32. const plan = this.ctx.change_plan;
  33. const bills = await this.ctx.service.changePlanList.getAllDataByCondition({ where: { cpid: this.ctx.change_plan.id} });
  34. bills.forEach(x => {
  35. const p_decimal = plan.decimal ? JSON.parse(plan.decimal) : { tp: decimal.tp, up: decimal.up };
  36. x.o_tp = helper.mul(x.oamount, x.unit_price, p_decimal.tp);
  37. x.c_tp = helper.mul(x.camount, x.unit_price, p_decimal.tp);
  38. x.s_tp = helper.mul(x.samount, x.unit_price, p_decimal.tp);
  39. x.sp_tp = helper.mul(x.spamount, x.unit_price, p_decimal.tp);
  40. const auditAmount = x.audit_amount ? x.audit_amount.split(',') : [];
  41. for (const [i, aa] of auditAmount.entries()) {
  42. const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
  43. x[amountField] = aa ? parseFloat(aa) : 0;
  44. x[tpField] = helper.mul(x[amountField], x.unit_price, p_decimal.tp);
  45. if (plan) {
  46. plan[tpField] = helper.add(plan[tpField], x[tpField]);
  47. }
  48. }
  49. });
  50. bills.sort(function(a, b) {
  51. return helper.compareCode(a.code, b.code);
  52. });
  53. return bills;
  54. }
  55. async _getChangePlanAudit() {
  56. const changeAudit = await this.ctx.service.changePlanAudit.getAllDataByCondition({ where: { cpid: this.ctx.change_plan.id, times: this.ctx.change_plan.times }});
  57. return this.ctx.helper.filterLastestData(changeAudit, ['aid']);
  58. }
  59. getCommonData(params, tableName, fields, customDefine, customSelect) {
  60. switch (tableName) {
  61. case 'mem_change_plan':
  62. return [this.ctx.change_plan];
  63. case 'mem_change_plan_bills':
  64. return this._getChangePlanBills();
  65. case 'mem_change_plan_audit':
  66. return this._getChangePlanAudit();
  67. case 'mem_change_plan_att':
  68. return this.ctx.service.changePlanAtt.getAllChangePlanAtt(this.ctx.change_plan.tid, this.ctx.change_plan.id);
  69. case 'mem_project':
  70. return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
  71. case 'mem_tender':
  72. return [this.ctx.tender.data];
  73. case 'mem_tender_info':
  74. return [this.ctx.tender.info];
  75. default:
  76. return [];
  77. }
  78. }
  79. }
  80. module.exports = rptMemChange;