123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const RptMemBase = require('./base');
- const bindData = {};
- const ledger = require('../ledger');
- class rptMemPaymentSafe extends RptMemBase {
- constructor(ctx) {
- super(ctx, bindData);
- }
- async doCheckSubProj(id) {
- if (this.ctx.subProject) return;
- this.ctx.subProject = await this.ctx.service.subProject.getDataById(id);
- this.ctx.subProject.info = await this.ctx.service.subProjInfo.getInfo4Report(this.ctx.subProject.id);
- if (!this.ctx.budget) {
- this.ctx.budget = await this.ctx.service.budget.getCurBudget(this.ctx.subProject.budget_id);
- }
- }
- async doCheckBudget(id) {
- if (this.ctx.budget) return;
- this.ctx.budget = await this.ctx.service.budget.getCurBudget(id);
- if (!this.ctx.subProject) {
- this.ctx.subProject = await this.ctx.service.subProject.getDataByCondition({ budget_id: id });
- this.ctx.subProject.info = await this.ctx.service.subProjInfo.getInfo4Report(this.ctx.subProject.id);
- }
- }
- async doBeforeLoadReport(params) {
- await this.doCheckSubProj(params.sp_id);
- await this.doCheckBudget(params.budget_id);
- }
- async budgetGai(bid, showLevel = false) {
- const gai = await this.ctx.service.budgetGai.getAllDataByCondition({ where: { bid } });
- const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
- tree.loadDatas(gai);
- tree.calculateAll();
- // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
- return tree.getDefaultDatas();
- }
- async budgetYu(bid, showLevel = false) {
- const yu = await this.ctx.service.budgetYu.getAllDataByCondition({ where: { bid } });
- const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
- tree.loadDatas(yu);
- tree.calculateAll();
- // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
- return tree.getDefaultDatas();
- }
- async budgetGu(bid, showLevel = false) {
- const gu = await this.ctx.service.budgetGu.getAllDataByCondition({ where: { bid } });
- const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
- tree.loadDatas(gu);
- tree.calculateAll();
- // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
- return tree.getDefaultDatas();
- }
- async budgetZb(bid, showLevel = false) {
- const zb = await this.ctx.service.budgetZb.getAllDataByCondition({ where: { bid } });
- const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] });
- tree.loadDatas(zb);
- tree.calculateAll();
- // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
- return tree.getDefaultDatas();
- }
- async budgetFinal(bid, showLevel = false) {
- const budget = this.ctx.budget && this.ctx.budget.id === bid
- ? this.ctx.budget
- : await this.ctx.service.budget.getDataById(bid);
- if (!budget.final_id) return [];
- const final = await this.ctx.service.budgetFinal.getAllDataByCondition({ where: { final_id: budget.final_id } });
- const tree = new ledger.billsTree(this.ctx, { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
- tree.loadDatas(final);
- // return showLevel ? tree.getDefaultDatasByLevel(this.ctx.tender.rpt_show_level) : tree.getDefaultDatas();
- return tree.getDefaultDatas();
- }
- getCommonData(params, tableName, fields, customDefine, customSelect) {
- switch (tableName) {
- case 'mem_info':
- return [this.ctx.subProject.info];
- case 'mem_qty_info':
- return [...this.ctx.subProject.info.main_quantity, ...this.ctx.subProject.info.gcl_quantity];
- case 'mem_budget_gu':
- return this.budgetGu(this.ctx.budget.id);
- case 'mem_budget_gai':
- return this.budgetGai(this.ctx.budget.id);
- case 'mem_budget_yu':
- return this.budgetYu(this.ctx.budget.id);
- case 'mem_budget_zb':
- return this.budgetZb(this.ctx.budget.id);
- case 'mem_budget_final':
- return this.budgetFinal(this.ctx.budget.id);
- case 'mem_budget_gu_filter':
- return this.budgetGu(this.ctx.budget.id, true);
- case 'mem_budget_gai_filter':
- return this.budgetGai(this.ctx.budget.id, true);
- case 'mem_budget_yu_filter':
- return this.budgetYu(this.ctx.budget.id, true);
- case 'mem_budget_zb_filter':
- return this.budgetZb(this.ctx.budget.id, true);
- case 'mem_budget_final_filter':
- return this.budgetFinal(this.ctx.budget.id, true);
- default:
- return [];
- }
- }
- }
- module.exports = rptMemPaymentSafe;
|