budget.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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(this.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(this.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 budgetZb(bid, showLevel = false) {
  61. const zb = await this.ctx.service.budgetZb.getAllDataByCondition({ where: { bid } });
  62. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  63. tree.loadDatas(zb);
  64. tree.calculateAll();
  65. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  66. return tree.getDefaultDatas();
  67. }
  68. async budgetFinal(bid, showLevel = false) {
  69. const budget = this.ctx.budget && this.ctx.budget.id === bid
  70. ? this.ctx.budget
  71. : await this.ctx.service.budget.getDataById(bid);
  72. if (!budget.final_id) return [];
  73. const final = await this.ctx.service.budgetFinal.getAllDataByCondition({ where: { final_id: budget.final_id } });
  74. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
  75. tree.loadDatas(final);
  76. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  77. return tree.getDefaultDatas();
  78. }
  79. getCommonData(params, tableName, fields, customDefine, customSelect) {
  80. switch (tableName) {
  81. case 'mem_info':
  82. return [this.ctx.subProject.info];
  83. case 'mem_qty_info':
  84. return [...this.ctx.subProject.info.main_quantity, ...this.ctx.subProject.info.gcl_quantity];
  85. case 'mem_budget_gu':
  86. return this.budgetGu(this.ctx.budget.id);
  87. case 'mem_budget_gai':
  88. return this.budgetGai(this.ctx.budget.id);
  89. case 'mem_budget_yu':
  90. return this.budgetYu(this.ctx.budget.id);
  91. case 'mem_budget_zb':
  92. return this.budgetZb(this.ctx.budget.id);
  93. case 'mem_budget_final':
  94. return this.budgetFinal(this.ctx.budget.id);
  95. case 'mem_budget_gu_filter':
  96. return this.budgetGu(this.ctx.budget.id, true);
  97. case 'mem_budget_gai_filter':
  98. return this.budgetGai(this.ctx.budget.id, true);
  99. case 'mem_budget_yu_filter':
  100. return this.budgetYu(this.ctx.budget.id, true);
  101. case 'mem_budget_zb_filter':
  102. return this.budgetZb(this.ctx.budget.id, true);
  103. case 'mem_budget_final_filter':
  104. return this.budgetFinal(this.ctx.budget.id, true);
  105. default:
  106. return [];
  107. }
  108. }
  109. }
  110. module.exports = rptMemPaymentSafe;