budget.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. if (budget.final_id) {
  32. const finalInfo = await this.ctx.service.budgetFinalList.getDataById(budget.final_id);
  33. this.ctx.budget.final_uid = finalInfo.uid;
  34. this.ctx.budget.final_u_name = finalInfo.u_name;
  35. this.ctx.budget.final_u_role = finalInfo.u_role;
  36. this.ctx.budget.final_u_company = finalInfo.u_company;
  37. this.ctx.budget.final_u_mobile = finalInfo.u_mobile;
  38. this.ctx.budget.final_u_login = finalInfo.u_login;
  39. this.ctx.budget.final_create_time = finalInfo.create_time;
  40. this.ctx.budget.final_update_time = finalInfo.update_time;
  41. this.ctx.budget.final_tender_info = finalInfo.tender_info ? JSON.parse(finalInfo.tender_info) : [];
  42. }
  43. }
  44. async doBeforeLoadReport(params) {
  45. await this.doCheckSubProj(params.sp_id);
  46. await this.doCheckBudget(params.budget_id);
  47. }
  48. async budgetGai(bid, showLevel = false) {
  49. const gai = await this.ctx.service.budgetGai.getAllDataByCondition({ where: { bid } });
  50. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  51. tree.loadDatas(gai);
  52. tree.calculateAll();
  53. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  54. return tree.getDefaultDatas();
  55. }
  56. async budgetYu(bid, showLevel = false) {
  57. const yu = await this.ctx.service.budgetYu.getAllDataByCondition({ where: { bid } });
  58. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  59. tree.loadDatas(yu);
  60. tree.calculateAll();
  61. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  62. return tree.getDefaultDatas();
  63. }
  64. async budgetGu(bid, showLevel = false) {
  65. const gu = await this.ctx.service.budgetGu.getAllDataByCondition({ where: { bid } });
  66. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  67. tree.loadDatas(gu);
  68. tree.calculateAll();
  69. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  70. return tree.getDefaultDatas();
  71. }
  72. async budgetZb(bid, showLevel = false) {
  73. const zb = await this.ctx.service.budgetZb.getAllDataByCondition({ where: { bid } });
  74. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
  75. tree.loadDatas(zb);
  76. tree.calculateAll();
  77. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  78. return tree.getDefaultDatas();
  79. }
  80. async budgetFinalInfo(bid) {
  81. const budget = this.ctx.budget && this.ctx.budget.id === bid
  82. ? this.ctx.budget
  83. : await this.ctx.service.budget.getDataById(bid);
  84. return [finalInfo];
  85. }
  86. async budgetFinal(bid, showLevel = false) {
  87. const budget = this.ctx.budget && this.ctx.budget.id === bid
  88. ? this.ctx.budget
  89. : await this.ctx.service.budget.getDataById(bid);
  90. if (!budget.final_id) return [];
  91. const final = await this.ctx.service.budgetFinal.getAllDataByCondition({ where: { final_id: budget.final_id } });
  92. const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
  93. tree.loadDatas(final);
  94. // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
  95. return tree.getDefaultDatas();
  96. }
  97. getCommonData(params, tableName, fields, customDefine, customSelect) {
  98. switch (tableName) {
  99. case 'mem_info':
  100. return [this.ctx.subProject.info];
  101. case 'mem_qty_info':
  102. return [...this.ctx.subProject.info.main_quantity, ...this.ctx.subProject.info.gcl_quantity];
  103. case 'budget':
  104. return [this.ctx.budget];
  105. case 'mem_budget_gu':
  106. return this.budgetGu(this.ctx.budget.id);
  107. case 'mem_budget_gai':
  108. return this.budgetGai(this.ctx.budget.id);
  109. case 'mem_budget_yu':
  110. return this.budgetYu(this.ctx.budget.id);
  111. case 'mem_budget_zb':
  112. return this.budgetZb(this.ctx.budget.id);
  113. case 'mem_budget_final':
  114. return this.budgetFinal(this.ctx.budget.id);
  115. case 'mem_budget_gu_filter':
  116. return this.budgetGu(this.ctx.budget.id, true);
  117. case 'mem_budget_gai_filter':
  118. return this.budgetGai(this.ctx.budget.id, true);
  119. case 'mem_budget_yu_filter':
  120. return this.budgetYu(this.ctx.budget.id, true);
  121. case 'mem_budget_zb_filter':
  122. return this.budgetZb(this.ctx.budget.id, true);
  123. case 'mem_budget_final_filter':
  124. return this.budgetFinal(this.ctx.budget.id, true);
  125. default:
  126. return [];
  127. }
  128. }
  129. }
  130. module.exports = rptMemPaymentSafe;