contract.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. getCommonData(params, tableName, fields, customDefine, customSelect) {
  52. switch (tableName) {
  53. case 'sp_contract_tree_1':
  54. return this.getSpContractTree(1);
  55. case 'sp_contract_1':
  56. return this.getSpContract(1);
  57. case 'sp_contract_pay_1':
  58. return this.getSpContractPay(1);
  59. case 'sp_contract_tree_2':
  60. return this.getSpContractTree(2);
  61. case 'sp_contract_2':
  62. return this.getSpContract(2);
  63. case 'sp_contract_pay_2':
  64. return this.getSpContractPay(2);
  65. default:
  66. return [];
  67. }
  68. }
  69. }
  70. module.exports = rptMemContract;