change.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const RptMemBase = require('./base');
  10. const bindData = {};
  11. const changeConst = require('../../const/change');
  12. class rptMemChange extends RptMemBase {
  13. constructor(ctx) {
  14. super(ctx, bindData);
  15. }
  16. _getChangeConstName(define, value) {
  17. for (const prop in define) {
  18. if (define[prop].value === value) {
  19. return define[prop].name;
  20. }
  21. }
  22. return '';
  23. }
  24. async _anaylisChange(change) {
  25. const self = this;
  26. const types = this.ctx.helper._.map(change.type.split(','), function (t) {
  27. return self._getChangeConstName(changeConst.type, self.ctx.helper._.toInteger(t));
  28. });
  29. change.type = types.join(';');
  30. change.class = this._getChangeConstName(changeConst.class, change.class);
  31. change.quality = this._getChangeConstName(changeConst.quality, change.quality);
  32. change.charge = this._getChangeConstName(changeConst.charge, change.charge);
  33. }
  34. async doCheckChange(changeId) {
  35. if (this.ctx.change) return;
  36. this.ctx.change = await this.ctx.service.change.getDataByCondition({ cid: changeId });
  37. this._anaylisChange(this.ctx.change);
  38. }
  39. async doCheckTender(tenderId) {
  40. if (this.ctx.tender) return;
  41. this.ctx.tender = { id: tenderId };
  42. this.ctx.tender.data = await this.ctx.service.tender.getTender(tenderId);
  43. this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
  44. }
  45. async doBeforeLoadReport(params) {
  46. await this.doCheckChange(params.change_id);
  47. await this.doCheckTender(this.ctx.change.tid);
  48. }
  49. async _getChangeBills() {
  50. const decimal = this.ctx.tender.info.decimal;
  51. const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: this.ctx.change.cid} });
  52. for (const d of changeBills) {
  53. d.o_qty = d.oamount;
  54. d.o_tp = this.ctx.helper.mul(d.o_qty, d.unit_price, decimal.tp);
  55. d.o_qty2 = d.oamount2;
  56. d.o_tp2 = this.ctx.helper.mul(d.o_qty2, d.unit_price, decimal.tp);
  57. d.c_qty = d.camount;
  58. d.c_tp = this.ctx.helper.mul(d.c_qty, d.unit_price, decimal.tp);
  59. d.s_qty = d.samount ? parseFloat(d.samount) : 0;
  60. d.s_tp = this.ctx.helper.mul(d.s_qty, d.unit_price, decimal.tp);
  61. d.sp_qty = d.spamount;
  62. d.sp_tp = this.ctx.helper.mul(d.sp_qty, d.unit_price, decimal.tp);
  63. const auditAmount = d.audit_amount ? d.audit_amount.split(',') : [];
  64. const relaChange = this.ctx.helper._.find(this.ctx.change, {cid: d.cid});
  65. for (const [i, aa] of auditAmount.entries()) {
  66. const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
  67. d[amountField] = aa ? parseFloat(aa) : 0;
  68. d[tpField] = this.ctx.helper.mul(d[amountField], d.unit_price, decimal.tp);
  69. if (relaChange) {
  70. relaChange[tpField] = this.ctx.helper.add(relaChange[tpField], d[tpField]);
  71. }
  72. }
  73. }
  74. return changeBills;
  75. }
  76. getCommonData(params, tableName, fields, customDefine, customSelect) {
  77. switch (tableName) {
  78. case 'mem_change':
  79. return [this.ctx.change];
  80. case 'mem_change_bills':
  81. return this._getChangeBills();
  82. case 'mem_change_audit':
  83. return this.ctx.service.changeAudit.getListGroupByTimes(this.ctx.change.cid, this.ctx.change.times);
  84. case 'mem_change_att':
  85. return this.ctx.service.changeAtt.getChangeAttachment(this.ctx.change.cid);
  86. case 'mem_project':
  87. return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
  88. case 'mem_tender':
  89. return [this.ctx.tender.data];
  90. case 'mem_tender_info':
  91. return [this.ctx.tender.info];
  92. default:
  93. return [];
  94. }
  95. }
  96. }
  97. module.exports = rptMemChange;