laiguoran преди 4 години
родител
ревизия
ca2c1e8822
променени са 2 файла, в които са добавени 31 реда и са изтрити 21 реда
  1. 2 2
      app/public/js/schedule_ledger.js
  2. 29 19
      app/service/schedule_ledger.js

+ 2 - 2
app/public/js/schedule_ledger.js

@@ -201,7 +201,7 @@ $(function () {
         }
         $(this).attr('disabled', true);
         const [under_ledger, parent_ledger] = getPAndULedger(select_ledger);
-        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger } , function (result) {
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger, type: 'sz' } , function (result) {
             toastr.success('设置成功');
             setTimeout(function () {
                 window.location.reload();
@@ -231,7 +231,7 @@ $(function () {
         }
         $(this).attr('disabled', true);
         const [under_ledger, parent_ledger] = getPAndULedger(select_ledger);
-        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger } , function (result) {
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger, type: 'xz' } , function (result) {
             toastr.success('进度台账数据修正成功');
             setTimeout(function () {
                 window.location.reload();

+ 29 - 19
app/service/schedule_ledger.js

@@ -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);