budget.js 4.6 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 ledger = require('../ledger');
  12. class rptMemPaymentSafe extends RptMemBase {
  13. constructor(ctx) {
  14. super(ctx, bindData);
  15. }
  16. async doCheckSubProj(id) {
  17. if (this.ctx.subProject) return;
  18. this.ctx.subProject = await this.ctx.service.subProject.getDataById(id);
  19. this.ctx.subProject.info = await this.ctx.service.subProjInfo.getInfo4Report(ctx.subProject.id);
  20. if (!this.ctx.budget) {
  21. this.ctx.budget = await this.ctx.service.budget.getCurBudget(this.ctx.subProject.budget_id);
  22. }
  23. }
  24. async doCheckBudget(id) {
  25. if (this.ctx.budget) return;
  26. this.ctx.budget = await this.ctx.service.budget.getCurBudget(id);
  27. if (!this.ctx.subProject) {
  28. this.ctx.subProject = await this.ctx.service.subProject.getDataByCondition({ budget_id: id });
  29. this.ctx.subProject.info = await this.ctx.service.subProjInfo.getInfo4Report(ctx.subProject.id);
  30. }
  31. }
  32. async doBeforeLoadReport(params) {
  33. await this.doCheckSubProj(params.sp_id);
  34. await this.doCheckBudget(params.budget_id);
  35. }
  36. async budgetGai(bid, showLevel = false) {
  37. const gai = await this.ctx.service.budgetGai.getAllDataByCondition({ where: { bid } });
  38. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  39. tree.loadDatas(gai);
  40. tree.calculateAll();
  41. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  42. return tree.getDefaultDatas();
  43. }
  44. async budgetYu(bid, showLevel = false) {
  45. const yu = await this.ctx.service.budgetYu.getAllDataByCondition({ where: { bid } });
  46. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  47. tree.loadDatas(yu);
  48. tree.calculateAll();
  49. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  50. return tree.getDefaultDatas();
  51. }
  52. async budgetGu(bid, showLevel = false) {
  53. const gu = await this.ctx.service.budgetGu.getAllDataByCondition({ where: { bid } });
  54. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  55. tree.loadDatas(gu);
  56. tree.calculateAll();
  57. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  58. return tree.getDefaultDatas();
  59. }
  60. async budgetFinal(bid, showLevel = false) {
  61. const budget = this.ctx.budget && this.ctx.budget.id === bid
  62. ? this.ctx.budget
  63. : await this.ctx.service.budget.getDataById(bid);
  64. if (!budget.final_id) return [];
  65. const final = await this.ctx.service.budgetFinal.getAllDataByCondition({ where: { final_id: budget.final_id } });
  66. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
  67. tree.loadDatas(final);
  68. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  69. return tree.getDefaultDatas();
  70. }
  71. getCommonData(params, tableName, fields, customDefine, customSelect) {
  72. switch (tableName) {
  73. case 'mem_info':
  74. return this.ctx.subProject.info;
  75. case 'mem_qty_info':
  76. return [...this.ctx.subProject.info.main_quantity, ...this.ctx.subProject.info.gcl_quantity];
  77. case 'mem_budget_gu':
  78. return this.budgetGu(this.ctx.budget.id);
  79. case 'mem_budget_gai':
  80. return this.budgetGai(this.ctx.budget.id);
  81. case 'mem_budget_yu':
  82. return this.budgetYu(this.ctx.budget.id);
  83. case 'mem_budget_final':
  84. return this.budgetFinal(this.ctx.budget.id);
  85. case 'mem_budget_gu_filter':
  86. return this.budgetGu(this.ctx.budget.id, true);
  87. case 'mem_budget_gai_filter':
  88. return this.budgetGai(this.ctx.budget.id, true);
  89. case 'mem_budget_yu_filter':
  90. return this.budgetYu(this.ctx.budget.id, true);
  91. case 'mem_budget_final_filter':
  92. return this.budgetFinal(this.ctx.budget.id, true);
  93. default:
  94. return [];
  95. }
  96. }
  97. }
  98. module.exports = rptMemPaymentSafe;