change.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.c_qty = d.camount;
  56. d.c_tp = this.ctx.helper.mul(d.c_qty, d.unit_price, decimal.tp);
  57. d.s_qty = d.samount ? parseFloat(d.samount) : 0;
  58. d.s_tp = this.ctx.helper.mul(d.s_qty, d.unit_price, decimal.tp);
  59. d.sp_qty = d.spamount;
  60. d.sp_tp = this.ctx.helper.mul(d.sp_qty, d.unit_price, decimal.tp);
  61. const auditAmount = d.audit_amount ? d.audit_amount.split(',') : [];
  62. const relaChange = this.ctx.helper._.find(this.ctx.change, {cid: d.cid});
  63. for (const [i, aa] of auditAmount.entries()) {
  64. const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
  65. d[amountField] = aa ? parseFloat(aa) : 0;
  66. d[tpField] = this.ctx.helper.mul(d[amountField], d.unit_price, decimal.tp);
  67. if (relaChange) {
  68. relaChange[tpField] = this.ctx.helper.add(relaChange[tpField], d[tpField]);
  69. }
  70. }
  71. }
  72. return changeBills;
  73. }
  74. getCommonData(params, tableName, fields, customDefine, customSelect) {
  75. switch (tableName) {
  76. case 'mem_change':
  77. return [this.ctx.change];
  78. case 'mem_change_bills':
  79. return this._getChangeBills();
  80. case 'mem_change_audit':
  81. return this.ctx.service.changeAudit.getListGroupByTimes(this.ctx.change.cid, this.ctx.change.times);
  82. case 'mem_change_att':
  83. return this.ctx.service.changeAtt.getChangeAttachment(this.ctx.change.cid);
  84. case 'mem_project':
  85. return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
  86. case 'mem_tender':
  87. return [this.ctx.tender.data];
  88. case 'mem_tender_info':
  89. return [this.ctx.tender.info];
  90. default:
  91. return [];
  92. }
  93. }
  94. }
  95. module.exports = rptMemChange;