contract.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 rptMemContract extends RptMemBase {
  13. constructor(ctx) {
  14. super(ctx, bindData);
  15. }
  16. async _getContractTree(condition) {
  17. const data = await this.ctx.service.contractTree.getAllDataByCondition({ where: condition });
  18. const contract_data = await this.ctx.service.contract.getAllDataByCondition({ where: condition });
  19. const tree = new Ledger.billsTree(this.ctx, {
  20. id: 'contract_id',
  21. pid: 'contract_pid',
  22. order: 'order',
  23. level: 'level',
  24. rootId: -1,
  25. calcFields: [ 'total_price', 'pay_price', 'debit_price', 'yf_price', 'sf_price'],
  26. calc: function (node, helper, decimal) {},
  27. });
  28. tree.loadDatas([...data, ...contract_data]);
  29. return tree.getDefaultDatas();
  30. }
  31. async _getContract(condition) {
  32. const data = await this.ctx.service.contract.getAllDataByCondition({ where: condition });
  33. return data;
  34. }
  35. async _getContractPay(condition) {
  36. const data = await this.ctx.service.contractPay.getAllDataByCondition({ where: condition, orders: [['cid', 'asc'], ['create_time', 'asc']] });
  37. return data;
  38. }
  39. async getSpContractTree(contract_type) {
  40. if (!this.ctx.subProject) return [];
  41. return await this._getContractTree({ spid: this.ctx.subProject.id, contract_type });
  42. }
  43. async getSpContract(contract_type) {
  44. if (!this.ctx.subProject) return [];
  45. return await this._getContract({ spid: this.ctx.subProject.id, contract_type });
  46. }
  47. async getSpContractPay(contract_type) {
  48. if (!this.ctx.subProject) return [];
  49. return await this._getContractPay({ spid: this.ctx.subProject.id, contract_type });
  50. }
  51. async getContractTree(tid, contract_type) {
  52. if (!this.ctx.subProject) return [];
  53. return await this._getContractTree({ tid, contract_type });
  54. }
  55. async getContract(tid, contract_type) {
  56. if (!this.ctx.subProject) return [];
  57. return await this._getContract({ tid, contract_type });
  58. }
  59. async getContractPay(tid, contract_type) {
  60. if (!this.ctx.subProject) return [];
  61. return await this._getContractPay({ tid, contract_type });
  62. }
  63. getCommonData(params, tableName, fields, customDefine, customSelect) {
  64. switch (tableName) {
  65. case 'sp_contract_tree_1':
  66. return this.getSpContractTree(1);
  67. case 'sp_contract_1':
  68. return this.getSpContract(1);
  69. case 'sp_contract_pay_1':
  70. return this.getSpContractPay(1);
  71. case 'sp_contract_tree_2':
  72. return this.getSpContractTree(2);
  73. case 'sp_contract_2':
  74. return this.getSpContract(2);
  75. case 'sp_contract_pay_2':
  76. return this.getSpContractPay(2);
  77. case 'contract_tree_1':
  78. return this.getContractTree(params.tender_id, 1);
  79. case 'contract_1':
  80. return this.getContract(params.tender_id, 1);
  81. case 'contract_pay_1':
  82. return this.getContractPay(params.tender_id, 1);
  83. case 'contract_tree_2':
  84. return this.getContractTree(params.tender_id, 2);
  85. case 'contract_2':
  86. return this.getContract(params.tender_id, 2);
  87. case 'contract_pay_2':
  88. return this.getContractPay(params.tender_id, 2);
  89. default:
  90. return [];
  91. }
  92. }
  93. }
  94. module.exports = rptMemContract;