change_apply.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 doCheckChangeApply(id) {
  16. if (this.ctx.change_apply) return;
  17. this.ctx.change_apply = await this.ctx.service.changeApply.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.getTender(tenderId);
  23. this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
  24. }
  25. async doBeforeLoadReport(params) {
  26. await this.doCheckChangeApply(params.change_apply_id);
  27. await this.doCheckTender(this.ctx.change_apply.tid);
  28. }
  29. async _getChangeApplyBills() {
  30. const helper = this.ctx.helper;
  31. const decimal = this.ctx.tender.info.decimal;
  32. const apply = this.ctx.change_apply;
  33. const bills = await this.ctx.service.changeApplyList.getAllDataByCondition({ where: { caid: apply.id} });
  34. bills.forEach(x => {
  35. const a_decimal = apply.decimal ? JSON.stringify(apply.decimal) : { tp: decimal.tp, up: decimal.up };
  36. x.o_tp = helper.mul(x.oamount, x.unit_price, a_decimal.tp);
  37. x.c_tp = helper.mul(x.camount, x.unit_price, a_decimal.tp);
  38. });
  39. bills.sort(function(a, b ) {
  40. return helper.compareCode(a.code, b.code);
  41. });
  42. return bills;
  43. }
  44. async _getChangeApplyAudit() {
  45. const changeAudit = await this.ctx.service.changeApplyAudit.getAllDataByCondition({ where: { caid: this.ctx.change_apply.id, times: this.ctx.change_apply.times }});
  46. return this.ctx.helper.filterLastestData(changeAudit, ['aid']);
  47. }
  48. getCommonData(params, tableName, fields, customDefine, customSelect) {
  49. switch (tableName) {
  50. case 'mem_change_apply':
  51. return [this.ctx.change_apply];
  52. case 'mem_change_apply_bills':
  53. return this._getChangeApplyBills();
  54. case 'mem_change_apply_audit':
  55. return this._getChangeApplyAudit();
  56. case 'mem_change_apply_att':
  57. return this.ctx.service.changeApplyAtt.getChangeAttachment(this.ctx.change_apply.id);
  58. case 'mem_project':
  59. return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
  60. case 'mem_tender':
  61. return [this.ctx.tender.data];
  62. case 'mem_tender_info':
  63. return [this.ctx.tender.info];
  64. default:
  65. return [];
  66. }
  67. }
  68. }
  69. module.exports = rptMemChange;