MaiXinRong 1 день назад
Родитель
Сommit
fc833df946
1 измененных файлов с 83 добавлено и 0 удалено
  1. 83 0
      app/service/cost_stage_analysis.js

+ 83 - 0
app/service/cost_stage_analysis.js

@@ -196,6 +196,89 @@ module.exports = app => {
 
 
             await transaction.insert(this.tableName, insertData);
             await transaction.insert(this.tableName, insertData);
         }
         }
+        // 以下为新增时,根据上一期导入的数据,自动导入明细等数据
+        // todo 暂未进行任何测试 -- 未考虑利润与利润率计算问题(待核实)
+        // async initByPre(stage, preStage, transaction) {
+        //     if (!stage || !preStage || !transaction) throw '成本分析数据错误';
+        //     const insertData = [], insertDetailData = [];
+        //     if (!stage.calcTemplate) stage.calcTemplate = await this.service.calcTmpl.getTemplate(stage.calc_template);
+        //
+        //     const costStageLedger = await this.getCostStageData(stage.relaStage);
+        //
+        //     const preBills = await this.getReadData(preStage);
+        //     const preLedger = new Ledger.baseTree(this.ctx, {
+        //         id: 'tree_id', pid: 'tree_pid', order: 'tree_order',
+        //         level: 'tree_level', isLeaf: 'tree_is_leaf', fullPath: 'tree_full_path',
+        //         rootId: -1, calcField: [],
+        //     });
+        //     preLedger.loadDatas(preBills);
+        //     const preDetails = await this.ctx.service.costStageAnalysisDetail.getReadData(preStage);
+        //     for (const pl of preLedger.nodes) {
+        //         if (pl.tree_is_leaf) pl.detail = preDetails.filter(x => { return x.ledger_id === pl.id; });
+        //         const idata = {};
+        //         this._getDefaultData(idata, stage);
+        //         idata.cost_id = pl.cost_id;
+        //         idata.node_type = pl.node_type;
+        //         idata.calc_type = pl.calc_type;
+        //         idata.has_detail = pl.has_detail && pl.detail.length > 0;
+        //         idata.import_cost_id = pl.import_cost_id;
+        //         if (!idata.has_detail) {
+        //             for (const prop of costFields.preCopyFields) {
+        //                 idata[prop] = pl[prop];
+        //             }
+        //         }
+        //         insertData.push(idata);
+        //         if (idata.import_cost_id) {
+        //             const cost_id = idata.import_cost_id.split(',');
+        //             const nodes = costStageLedger.nodes.filter(x => { return cost_id.indexOf(x.cost_id) >= 0; });
+        //             if (nodes.length > 0) {
+        //                 if (nodes[0].detail.length > 0) {
+        //                     const insertDetails = [];
+        //                     const preDetail = await this.ctx.service.costStageAnalysisDetail.getAllDataByCondition({ where: { stage_id: preStage.id, cost_id: select.cost_id } });
+        //                     for (const node of nodes) {
+        //                         for (const d of node.detail) {
+        //                             let id = insertDetails.find(x => { return x.source_id === d.source_cid && x.is_deal === d.is_deal; });
+        //                             if (!id) {
+        //                                 id = {
+        //                                     id: this.uuid.v4(), tender_id: stage.tid, stage_id: stage.id,
+        //                                     add_user_id: userId, update_user_id: userId,
+        //                                     ledger_id: select.id, cost_id: select.cost_id, source_id: d.source_cid, is_deal: d.is_deal,
+        //                                     d_order: insertDetails.length + 1,
+        //                                     code: d.code, name: d.name, party_b: d.party_b || '', tax: d.tax || 0,
+        //                                 };
+        //                                 insertDetails.push(id);
+        //                             }
+        //                             id.yf_excl_tax_tp = this.ctx.helper.add(id.yf_excl_tax_tp, d.yf_excl_tax_tp || 0);
+        //                             id.sf_excl_tax_tp = this.ctx.helper.add(id.sf_excl_tax_tp, d.sf_excl_tax_tp || 0);
+        //                             id.in_excl_tax_tp = this.ctx.helper.add(id.in_excl_tax_tp, d.in_excl_tax_tp || 0);
+        //                         }
+        //                     }
+        //                     for (const id of insertDetails) {
+        //                         const sourceDetail = preDetail.find(x => { return x.source_id === id.source_id && x.is_deal === id.is_deal; });
+        //                         for (const prop of costFields.selfCalcFields) {
+        //                             id[prop] = sourceDetail ? sourceDetail[prop] || 0 : 0;
+        //                         }
+        //                         this.ctx.service.calcTmpl.calcByTemplate(id, id, id, stage.calcTemplate.calc_expr);
+        //                         for (const prop of costFields.sumFields) {
+        //                             idata[prop] = this.ctx.helper.add(idata[prop], id[prop]);
+        //                         }
+        //                     }
+        //                     insertDetailData.push(...insertDetails);
+        //                 } else {
+        //                     for (const node of nodes) {
+        //                         idata.yf_excl_tax_tp = this.ctx.helper.add(idata.yf_excl_tax_tp, node.end_yf_excl_tax_tp || 0);
+        //                         idata.sf_excl_tax_tp = this.ctx.helper.add(idata.sf_excl_tax_tp, node.end_sf_excl_tax_tp || 0);
+        //                         idata.in_excl_tax_tp = this.ctx.helper.add(idata.in_excl_tax_tp, node.end_in_excl_tax_tp || 0);
+        //                     }
+        //                 }
+        //             }
+        //             this.ctx.service.calcTmpl.calcByTemplate(idata, idata, select, stage.calcTemplate.calc_expr);
+        //         }
+        //     }
+        //
+        //     await transaction.insert(this.tableName, insertData);
+        //     if (insertDetailData.length > 0) await transaction.insert(this.tableName, insertDetailData);
+        // }
         async initStageData(transaction, stage, preStage) {
         async initStageData(transaction, stage, preStage) {
             try {
             try {
                 if (preStage) {
                 if (preStage) {