|  | @@ -77,30 +77,40 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      for (const p of datas.parent_ledger) {
 | 
	
		
			
				|  |  |                          await transaction.delete(this.ctx.service.scheduleLedgerMonth.tableName, { tid: this.ctx.tender.id, lid: p });
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    const mode = scheduleInfo.mode;
 | 
	
		
			
				|  |  | -                    const slmUpdateOption = [];
 | 
	
		
			
				|  |  | -                    for (const u of datas.under_ledger) {
 | 
	
		
			
				|  |  | -                        const dgn_price = this.ctx.helper.round(this.ctx.helper.div(u.tp, u.gcl), 2);
 | 
	
		
			
				|  |  | -                        if (dgn_price && dgn_price !== 0) {
 | 
	
		
			
				|  |  | -                            const sql = 'SELECT * FROM ?? WHERE tid = ? and lid = ?';
 | 
	
		
			
				|  |  | -                            const sqlParam = [this.ctx.service.scheduleLedgerMonth.tableName, this.ctx.tender.id, u.ledger_id];
 | 
	
		
			
				|  |  | -                            const lidList = await transaction.query(sql, sqlParam);
 | 
	
		
			
				|  |  | -                            if (lidList > 0) {
 | 
	
		
			
				|  |  | -                                for (const l of lidList) {
 | 
	
		
			
				|  |  | -                                    if (mode === scheduleConst.plan_mode.tp) {
 | 
	
		
			
				|  |  | -                                        const new_plan_gcl = l.plan_tp ? this.ctx.helper.round(this.ctx.helper.div(l.plan_tp, dgn_price), 3) : null;
 | 
	
		
			
				|  |  | -                                        const new_sj_gcl = l.sj_tp ? this.ctx.helper.round(this.ctx.helper.div(l.sj_tp, dgn_price), 3) : null;
 | 
	
		
			
				|  |  | -                                        slmUpdateOption.push({ id: l.id, plan_gcl: new_plan_gcl, sj_gcl: new_sj_gcl });
 | 
	
		
			
				|  |  | -                                    } else if (mode === scheduleConst.plan_mode.gcl) {
 | 
	
		
			
				|  |  | -                                        const new_plan_tp = l.plan_gcl ? this.ctx.helper.round(this.ctx.helper.div(l.plan_gcl, dgn_price), 0) : null;
 | 
	
		
			
				|  |  | -                                        const new_sj_tp = l.sj_gcl ? this.ctx.helper.round(this.ctx.helper.div(l.sj_gcl, dgn_price), 0) : null;
 | 
	
		
			
				|  |  | -                                        slmUpdateOption.push({ id: l.id, plan_tp: new_plan_tp, sj_tp: new_sj_tp });
 | 
	
		
			
				|  |  | +                    if (datas.type === 'xz') {
 | 
	
		
			
				|  |  | +                        const slmUpdateOption = [];
 | 
	
		
			
				|  |  | +                        const mode = scheduleInfo.mode;
 | 
	
		
			
				|  |  | +                        for (const u of datas.under_ledger) {
 | 
	
		
			
				|  |  | +                            const dgn_price = this.ctx.helper.round(this.ctx.helper.div(u.tp, u.gcl), 2);
 | 
	
		
			
				|  |  | +                            if (dgn_price && dgn_price !== 0) {
 | 
	
		
			
				|  |  | +                                const sql = 'SELECT * FROM ?? WHERE tid = ? and lid = ?';
 | 
	
		
			
				|  |  | +                                const sqlParam = [this.ctx.service.scheduleLedgerMonth.tableName, this.ctx.tender.id, u.ledger_id];
 | 
	
		
			
				|  |  | +                                const lidList = await transaction.query(sql, sqlParam);
 | 
	
		
			
				|  |  | +                                if (lidList.length > 0) {
 | 
	
		
			
				|  |  | +                                    for (const l of lidList) {
 | 
	
		
			
				|  |  | +                                        if (mode === scheduleConst.plan_mode.tp) {
 | 
	
		
			
				|  |  | +                                            const new_plan_gcl = l.plan_tp ? this.ctx.helper.round(this.ctx.helper.div(l.plan_tp, dgn_price), 3) : null;
 | 
	
		
			
				|  |  | +                                            const new_sj_gcl = l.sj_tp ? this.ctx.helper.round(this.ctx.helper.div(l.sj_tp, dgn_price), 3) : null;
 | 
	
		
			
				|  |  | +                                            slmUpdateOption.push({ id: l.id, plan_gcl: new_plan_gcl, sj_gcl: new_sj_gcl });
 | 
	
		
			
				|  |  | +                                        } else if (mode === scheduleConst.plan_mode.gcl) {
 | 
	
		
			
				|  |  | +                                            const new_plan_tp = l.plan_gcl ? this.ctx.helper.round(this.ctx.helper.div(l.plan_gcl, dgn_price), 0) : null;
 | 
	
		
			
				|  |  | +                                            const new_sj_tp = l.sj_gcl ? this.ctx.helper.round(this.ctx.helper.div(l.sj_gcl, dgn_price), 0) : null;
 | 
	
		
			
				|  |  | +                                            slmUpdateOption.push({ id: l.id, plan_tp: new_plan_tp, sj_tp: new_sj_tp });
 | 
	
		
			
				|  |  | +                                        }
 | 
	
		
			
				|  |  |                                      }
 | 
	
		
			
				|  |  |                                  }
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | +                        if (slmUpdateOption.length > 0) await transaction.updateRows(this.ctx.service.scheduleLedgerMonth.tableName, slmUpdateOption);
 | 
	
		
			
				|  |  | +                        // scheduleLedgerHistory更新到最新版台账
 | 
	
		
			
				|  |  | +                        const ledgerData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | +                        const insertDatas = [];
 | 
	
		
			
				|  |  | +                        for (const le of ledgerData) {
 | 
	
		
			
				|  |  | +                            insertDatas.push({ tid: this.ctx.tender.id, ledger_id: le.ledger_id });
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        await transaction.delete(this.ctx.service.scheduleLedgerHistory.tableName, { tid: this.ctx.tender.id });
 | 
	
		
			
				|  |  | +                        await transaction.insert(this.ctx.service.scheduleLedgerHistory.tableName, insertDatas);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    if (slmUpdateOption.length > 0) await transaction.updateRows(this.ctx.service.scheduleLedgerMonth.tableName, slmUpdateOption);
 | 
	
		
			
				|  |  |                      for (const sm of smList) {
 | 
	
		
			
				|  |  |                          await this.ctx.service.scheduleLedgerMonth.calcMonthPlan(transaction, this.ctx.tender.id, sm.yearmonth);
 | 
	
		
			
				|  |  |                          await this.ctx.service.scheduleLedgerMonth.calcMonthSj(transaction, this.ctx.tender.id, sm.yearmonth);
 |