Forráskód Böngészése

调差数量变更不参与调差功能

ellisran 1 éve
szülő
commit
8e9e1d4c6f

+ 9 - 4
app/controller/material_controller.js

@@ -570,7 +570,8 @@ module.exports = app => {
                 const responseData = { err: 0, msg: '', data: {} };
                 // 取所有已被调用的工料清单表
                 responseData.data.materialListData = await ctx.service.materialList.getMaterialData(ctx.tender.id, ctx.material.id);
-                responseData.data.materialNotJoinListData = await ctx.service.materialListNotjoin.getAllDataByCondition({ where: { tid: ctx.tender.id, mid: ctx.material.id } });
+                responseData.data.materialNotJoinListData = await ctx.service.materialListNotjoin.getAllDataByCondition({ where: { tid: ctx.tender.id, mid: ctx.material.id, type: 1 } });
+                responseData.data.materialNotChangeListData = await ctx.service.materialListNotjoin.getAllDataByCondition({ where: { tid: ctx.tender.id, mid: ctx.material.id, type: 2 } });
                 responseData.data.materialSelfListData = await ctx.service.materialListSelf.getAllDataByCondition({ where: { tid: ctx.tender.id, mid: ctx.material.id } });
                 // 获取清单数据
                 responseData.data.ledger = await ctx.service.ledger.getData(ctx.tender.id);
@@ -871,7 +872,7 @@ module.exports = app => {
                     msg: '',
                     data: {},
                 };
-                const notControlList = ['join', 'notjoin', 'self', 'noself', 'useOther', 'add', 'del', 'update', 'paste'];
+                const notControlList = ['join', 'notjoin', 'change', 'notchange', 'self', 'noself', 'useOther', 'add', 'del', 'update', 'paste'];
                 if (ctx.session.sessionProject.page_show.openMaterialChecklist && ctx.app._.indexOf(notControlList, data.type) === -1) {
                     throw '清单设置功能已启动,请前往清单设置页操作清单内容';
                 }
@@ -899,11 +900,15 @@ module.exports = app => {
                     case 'useOther':
                         responseData.data = await ctx.service.materialList.addOther(data.postData);
                         break;
+                    case 'change':
                     case 'join':
-                        await ctx.service.materialListNotjoin.del(data.select.id, data.ms_id);
+                        await ctx.service.materialListNotjoin.del(data.select.id, data.gather_qty, data.ms_id);
                         break;
                     case 'notjoin':
-                        responseData.data = await ctx.service.materialListNotjoin.add(data.select, data.ms_id);
+                        responseData.data = await ctx.service.materialListNotjoin.add(data.select, data.gather_qty, data.ms_id);
+                        break;
+                    case 'notchange':
+                        responseData.data = await ctx.service.materialListNotjoin.addChange(data.select, data.gather_qty, data.ms_id);
                         break;
                     case 'self':
                         responseData.data = await ctx.service.materialListSelf.add(data.select);

+ 20 - 4
app/public/js/material_checklist.js

@@ -23,6 +23,17 @@ function findNotJoinLeafXmj(x, type = '') {
     });
 }
 
+function findNotChangeLeafXmj(x, type = '') {
+    if (type === 'index') {
+        return notChangeList.findIndex(function (item) {
+            return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
+        });
+    }
+    return notChangeList.find(function (item) {
+        return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
+    });
+}
+
 function getPasteHint (str, row = '') {
     let returnObj = str;
     if (row) {
@@ -132,6 +143,7 @@ $(document).ready(() => {
         curPosData = result.curPosData;
         // materialListData = result.materialListData;
         notJoinList = result.materialNotJoinListData;
+        notChangeList = result.materialNotChangeListData;
         materialChecklistData = result.materialChecklistData;
         gclList = result.gclList;
         if (isStageSelf) {
@@ -427,11 +439,12 @@ $(document).ready(() => {
         const datas = [];
         for (const xmj of gcl) {
             const notx = findNotJoinLeafXmj(xmj);
+            const notx2 = findNotChangeLeafXmj(xmj);
             const data = {
                 xmj_id: xmj.id,
                 gcl_id: xmj.gcl_id,
                 mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
-                gather_qty: xmj.gather_qty,
+                gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                 is_join: notx === undefined ? 1 : 0,
             };
             if (ms_id) data.ms_id = ms_id;
@@ -447,11 +460,12 @@ $(document).ready(() => {
                         const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
                         for (const xmj of leafXmjs) {
                             const notx = findNotJoinLeafXmj(xmj);
+                            const notx2 = findNotChangeLeafXmj(xmj);
                             const data = {
                                 xmj_id: xmj.id,
                                 gcl_id: xmj.gcl_id,
                                 mx_id: xmj.mx_id ? xmj.mx_id : '',
-                                gather_qty: xmj.gather_qty,
+                                gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                                 is_join: notx === undefined ? 1 : 0,
                                 ms_id: ms.id,
                             };
@@ -1348,11 +1362,12 @@ $(document).ready(() => {
                 const datas = [];
                 for (const xmj of gcl) {
                     const notx = findNotJoinLeafXmj(xmj);
+                    const notx2 = findNotChangeLeafXmj(xmj);
                     const data = {
                         xmj_id: xmj.id,
                         gcl_id: xmj.gcl_id,
                         mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
-                        gather_qty: xmj.gather_qty,
+                        gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                         is_join: notx === undefined ? 1 : 0,
                     };
                     if (ms_id) data.ms_id = ms_id;
@@ -1371,11 +1386,12 @@ $(document).ready(() => {
                                 const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
                                 for (const xmj of leafXmjs) {
                                     const notx = findNotJoinLeafXmj(xmj);
+                                    const notx2 = findNotChangeLeafXmj(xmj);
                                     const data = {
                                         xmj_id: xmj.id,
                                         gcl_id: xmj.gcl_id,
                                         mx_id: xmj.mx_id ? xmj.mx_id : '',
-                                        gather_qty: xmj.gather_qty,
+                                        gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                                         is_join: notx === undefined ? 1 : 0,
                                         ms_id: ms.id,
                                     };

+ 112 - 9
app/public/js/material_list.js

@@ -23,6 +23,17 @@ function findNotJoinLeafXmj(x, type = '') {
     });
 }
 
+function findNotChangeLeafXmj(x, type = '') {
+    if (type === 'index') {
+        return notChangeList.findIndex(function (item) {
+            return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
+        });
+    }
+    return notChangeList.find(function (item) {
+        return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
+    });
+}
+
 function findSelfLeafXmj(x, type = '') {
     if (type === 'index') {
         return selfList.findIndex(function (item) {
@@ -57,8 +68,15 @@ function calcOneBQJC(xmj) {
     const notx = findNotJoinLeafXmj(xmj);
     if (notx === undefined) {
         const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
-        for (const l of list) {
-            jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
+        const notx2 = findNotChangeLeafXmj(xmj);
+        if (notx2 !== undefined) {
+            for (const l of list) {
+                jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.contract_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
+            }
+        } else {
+            for (const l of list) {
+                jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
+            }
         }
     }
     return ZhCalc.round(jiacha, materialDecimal.tp);
@@ -264,6 +282,7 @@ $(document).ready(() => {
                 materialListData = result.materialListData;
                 gclList = result.gclList;
                 notJoinList = result.materialNotJoinListData;
+                notChangeList = result.materialNotChangeListData;
                 selfList = result.materialSelfListData;
                 materialChecklistData = result.materialChecklistData;
                 if (isStageSelf) {
@@ -473,8 +492,8 @@ $(document).ready(() => {
             selfSheet.suspendPaint();
             selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
             selfSheet.resumePaint();
-            checkNotJoinMaterialData();
             ledgerSpread.getActiveSheet().setSelection(0, 0, 1, 1);
+            checkNotJoinMaterialData();
         }
     }
 
@@ -684,7 +703,7 @@ $(document).ready(() => {
     // sheet.suspendPaint();
     // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
     // sheet.resumePaint();
-    // 不参与调差数据值变灰
+    // 不参与调差数据值变灰, 数量变更不参与调差数据值变黄
     function checkNotJoinMaterialData() {
         const sheet = ledgerSpread.getActiveSheet();
         const select = SpreadJsObj.getSelectObject(sheet);
@@ -698,6 +717,9 @@ $(document).ready(() => {
                 const notx = findNotJoinLeafXmj(x);
                 const color = notx === undefined ? '' : '#d6d8db';
                 leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
+                const notx2 = findNotChangeLeafXmj(x);
+                const color2 = notx2 === undefined ? '' : '#FFE699';
+                leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color2);
             }
         }
     }
@@ -745,11 +767,12 @@ $(document).ready(() => {
             const datas = [];
             for (const xmj of gcl) {
                 const notx = findNotJoinLeafXmj(xmj);
+                const notx2 = findNotChangeLeafXmj(xmj);
                 const data = {
                     xmj_id: xmj.id,
                     gcl_id: xmj.gcl_id,
                     mx_id: xmj.mx_id ? xmj.mx_id : '',
-                    gather_qty: xmj.gather_qty,
+                    gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                     is_join: notx === undefined ? 1 : 0,
                 };
                 if (ms_id) data.ms_id = ms_id;
@@ -765,11 +788,12 @@ $(document).ready(() => {
                             const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
                             for (const xmj of leafXmjs) {
                                 const notx = findNotJoinLeafXmj(xmj);
+                                const notx2 = findNotChangeLeafXmj(xmj);
                                 const data = {
                                     xmj_id: xmj.id,
                                     gcl_id: xmj.gcl_id,
                                     mx_id: xmj.mx_id ? xmj.mx_id : '',
-                                    gather_qty: xmj.gather_qty,
+                                    gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                                     is_join: notx === undefined ? 1 : 0,
                                     ms_id: ms.id,
                                 };
@@ -805,12 +829,13 @@ $(document).ready(() => {
             const leafXmjIndex = gcl.indexOf(leafXmjSelect);
             const xmj = gcl[leafXmjIndex];
             const notx = findNotJoinLeafXmj(xmj);
+            const notx2 = findNotChangeLeafXmj(xmj);
             const data = {
                 xmj_id: xmj.id,
                 gcl_id: xmj.gcl_id,
                 mx_id: xmj.mx_id ? xmj.mx_id : '',
                 mb_id: mb_id,
-                gather_qty: xmj.gather_qty,
+                gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
                 is_join: notx === undefined ? 1 : 0,
             };
             console.log(data);
@@ -844,6 +869,7 @@ $(document).ready(() => {
             const data = {
                 type: type,
                 select: type === 'join' ? findNotJoinLeafXmj(select) : select,
+                gather_qty: select.gather_qty,
                 ms_id: $('#myTab').find('.active').data('msid') || null,
             };
             // 添加到
@@ -853,6 +879,33 @@ $(document).ready(() => {
                     notJoinList.splice(index, 1);
                 } else {
                     notJoinList.push(result);
+                    const index = findNotChangeLeafXmj(select, 'index');
+                    notChangeList.splice(index, 1);
+                }
+                gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
+                calculateJiaCha(gclGatherData, iGclRow);
+                SpreadJsObj.reLoadRowData(sheet, nRow);
+                sheet.getRange(nRow, -1, 1, -1).backColor(color);
+                loadMaterialData(iGclRow);
+                SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
+            });
+        },
+        checkChangeMaterial: function (type) {
+            const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
+            const color = type === 'change' ? '' : '#FFE699';
+            const data = {
+                type: type,
+                select: type === 'change' ? findNotChangeLeafXmj(select) : select,
+                gather_qty: type === 'change' ? select.gather_qty : select.contract_qty,
+                ms_id: $('#myTab').find('.active').data('msid') || null,
+            };
+            // 添加到
+            postData(window.location.pathname + '/save', data, function (result) {
+                if (type === 'change') {
+                    const index = findNotChangeLeafXmj(select, 'index');
+                    notChangeList.splice(index, 1);
+                } else {
+                    notChangeList.push(result);
                 }
                 gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
                 calculateJiaCha(gclGatherData, iGclRow);
@@ -926,7 +979,7 @@ $(document).ready(() => {
                 },
                 items: {
                     'stop': {
-                        name: '不参与调差',
+                        name: '当前节点不参与调差',
                         icon: 'fa-remove',
                         callback: function (key, opt) {
                             leafXmjSpreadObj.checkJoinMaterial('notjoin');
@@ -947,7 +1000,7 @@ $(document).ready(() => {
                         }
                     },
                     'start': {
-                        name: '参与调差',
+                        name: '当前节点参与调差',
                         icon: 'fa-sign-in',
                         callback: function (key, opt) {
                             leafXmjSpreadObj.checkJoinMaterial('join');
@@ -967,6 +1020,56 @@ $(document).ready(() => {
                             }
                         },
                     },
+                    'stop2': {
+                        name: '数量变更不参与调差',
+                        icon: 'fa-remove',
+                        callback: function (key, opt) {
+                            leafXmjSpreadObj.checkChangeMaterial('notchange');
+                        },
+                        visible: function (key, opt) {
+                            const sheet = leafXmjSpread.getActiveSheet();
+                            const select = SpreadJsObj.getSelectObject(sheet);
+                            const sel = sheet.getSelections()[0];
+                            if (!select || sel.rowCount !== 1) {
+                                return false;
+                            }
+                            const notx = findNotJoinLeafXmj(select);
+                            if (!(!readOnly && select && notx === undefined)) {
+                                return false;
+                            }
+                            const notx2 = findNotChangeLeafXmj(select);
+                            if (!readOnly && select && notx2 === undefined) {
+                                return true;
+                            } else {
+                                return false;
+                            }
+                        }
+                    },
+                    'start2': {
+                        name: '数量变更参与调差',
+                        icon: 'fa-sign-in',
+                        callback: function (key, opt) {
+                            leafXmjSpreadObj.checkChangeMaterial('change');
+                        },
+                        visible: function (key, opt) {
+                            const sheet = leafXmjSpread.getActiveSheet();
+                            const select = SpreadJsObj.getSelectObject(sheet);
+                            const sel = sheet.getSelections()[0];
+                            if (!select || sel.rowCount !== 1) {
+                                return false;
+                            }
+                            const notx = findNotJoinLeafXmj(select);
+                            if (!(!readOnly && select && notx === undefined)) {
+                                return false;
+                            }
+                            const notx2 = findNotChangeLeafXmj(select);
+                            if (!readOnly && select && notx2 === undefined) {
+                                return false;
+                            } else {
+                                return true;
+                            }
+                        },
+                    },
                     'self': {
                         name: '单独添加工料',
                         icon: 'fa-sign-in',

+ 4 - 0
app/public/js/measure_material.js

@@ -342,6 +342,7 @@ $(function () {
                                             mx_id: xmj.mx_id ? xmj.mx_id : '',
                                             xmj_id: xmj.id ? xmj.id : null,
                                             gather_qty: xmj.gather_qty,
+                                            contract_qty: xmj.contract_qty,
                                             quantity: bill.quantity,
                                             expr: bill.expr,
                                             mb_id: bill.mb_id,
@@ -357,6 +358,7 @@ $(function () {
                                             mx_id: xmj.mx_id ? xmj.mx_id : '',
                                             xmj_id: xmj.id ? xmj.id : null,
                                             gather_qty: xmj.gather_qty,
+                                            contract_qty: xmj.contract_qty,
                                             quantity: bill.quantity,
                                             expr: bill.expr,
                                             mb_id: bill.mb_id,
@@ -425,6 +427,7 @@ $(function () {
                                         mx_id: xmj.mx_id ? xmj.mx_id : '',
                                         xmj_id: xmj.id ? xmj.id : null,
                                         gather_qty: xmj.gather_qty,
+                                        contract_qty: xmj.contract_qty,
                                         quantity: bill.quantity,
                                         expr: bill.expr,
                                         mb_id: bill.mb_id,
@@ -439,6 +442,7 @@ $(function () {
                                         mx_id: xmj.mx_id ? xmj.mx_id : '',
                                         xmj_id: xmj.id ? xmj.id : null,
                                         gather_qty: xmj.gather_qty,
+                                        contract_qty: xmj.contract_qty,
                                         quantity: bill.quantity,
                                         expr: bill.expr,
                                         mb_id: bill.mb_id,

+ 1 - 1
app/service/material.js

@@ -197,7 +197,7 @@ module.exports = app => {
                     if (!auditResult) {
                         throw '复制上一期审批流程失败';
                     }
-                    // 复制不参与调差清单
+                    // 复制不参与调差或不计算数量变更清单
                     const preNotJoinList = await this.ctx.service.materialListNotjoin.getAllDataByCondition({ where: { tid: this.ctx.tender.id, mid: preMaterial.id } });
                     await this.ctx.service.materialListNotjoin.copyNewStageNotJoinList(transaction, preNotJoinList, newMaterial.id);
                     // 复制单独计量调差清单

+ 6 - 4
app/service/material_list.js

@@ -480,7 +480,8 @@ module.exports = app => {
             if (materialListData && materialListData.length > 0) {
                 const copyMLArray = [];
                 for (const ml of materialListData) {
-                    const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
+                    const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id, type: 1 });
+                    const is_change = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id, type: 2 });
                     const newMaterialList = {
                         tid: newMaterial.tid,
                         order: ml.order,
@@ -489,7 +490,7 @@ module.exports = app => {
                         gcl_id: ml.gcl_id,
                         xmj_id: ml.xmj_id,
                         mx_id: ml.mx_id,
-                        gather_qty: ml.gather_qty,
+                        gather_qty: is_change ? ml.contract_qty : ml.gather_qty,
                         quantity: ml.quantity ? ml.quantity : 0,
                         expr: ml.expr ? ml.expr : '',
                         is_join: is_join ? 0 : 1,
@@ -506,7 +507,8 @@ module.exports = app => {
             if (materialSelfListData && materialSelfListData.length > 0) {
                 const copyMLArray2 = [];
                 for (const ml of materialSelfListData) {
-                    const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
+                    const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id, type: 1 });
+                    const is_change = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id, type: 2 });
                     const newMaterialList = {
                         tid: newMaterial.tid,
                         order: ml.order,
@@ -515,7 +517,7 @@ module.exports = app => {
                         gcl_id: ml.gcl_id,
                         xmj_id: ml.xmj_id,
                         mx_id: ml.mx_id,
-                        gather_qty: ml.gather_qty,
+                        gather_qty: is_change ? ml.contract_qty : ml.gather_qty,
                         quantity: ml.quantity ? ml.quantity : 0,
                         expr: ml.expr ? ml.expr : '',
                         is_join: is_join ? 0 : 1,

+ 56 - 6
app/service/material_list_notjoin.js

@@ -26,7 +26,7 @@ module.exports = app => {
          * 添加不参与调差的清单
          * @return {void}
          */
-        async add(data, ms_id = null) {
+        async add(data, gather_qty, ms_id = null) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
@@ -38,11 +38,21 @@ module.exports = app => {
                     gcl_id: data.gcl_id,
                     xmj_id: data.id,
                     mx_id: data.mx_id ? data.mx_id : '',
+                    type: 1,
                     in_time: new Date(),
                 };
+                // 如果存在数量变更不参与调差,需要删除
+                await transaction.delete(this.tableName, {
+                    tid: this.ctx.tender.id,
+                    mid: this.ctx.material.id,
+                    gcl_id: data.gcl_id,
+                    xmj_id: data.id,
+                    mx_id: data.mx_id ? data.mx_id : '',
+                    type: 2,
+                });
                 data.xmj_id = data.id;
                 data.mx_id = data.mx_id ? data.mx_id : '';
-                await this.updateAllMaterials(transaction, data, 'add', ms_id);
+                await this.updateAllMaterials(transaction, data, 'add', gather_qty, ms_id);
                 // 新增不参与调差清单
                 const result = await transaction.insert(this.tableName, newListNotJoin);
                 if (result.affectedRows === 0) {
@@ -57,18 +67,53 @@ module.exports = app => {
         }
 
         /**
+         * 添加数量变更不计量的清单
+         * @return {void}
+         */
+        async addChange(data, gather_qty, ms_id = null) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            const transaction = await this.db.beginTransaction();
+            try {
+                const newListNotChange = {
+                    tid: this.ctx.tender.id,
+                    mid: this.ctx.material.id,
+                    gcl_id: data.gcl_id,
+                    xmj_id: data.id,
+                    mx_id: data.mx_id ? data.mx_id : '',
+                    type: 2,
+                    in_time: new Date(),
+                };
+                data.xmj_id = data.id;
+                data.mx_id = data.mx_id ? data.mx_id : '';
+                await this.updateAllMaterials(transaction, data, 'change', gather_qty, ms_id);
+                // 新增不参与调差清单
+                const result = await transaction.insert(this.tableName, newListNotChange);
+                if (result.affectedRows === 0) {
+                    throw '新增数量变更不计量不参与调差数据失败';
+                }
+                await transaction.commit();
+                return await this.getDataById(result.insertId);
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        /**
          * 删除不参与调差的清单
          * @param {int} id 工料id
          * @return {void}
          */
-        async del(id, ms_id = null) {
+        async del(id, gather_qty, ms_id = null) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
             const transaction = await this.db.beginTransaction();
             try {
                 const notJoinInfo = await this.getDataById(id);
-                await this.updateAllMaterials(transaction, notJoinInfo, 'del', ms_id);
+                await this.updateAllMaterials(transaction, notJoinInfo, 'del', gather_qty, ms_id);
                 // 判断是否可删
                 const result = await transaction.delete(this.tableName, { id });
                 await transaction.commit();
@@ -84,7 +129,7 @@ module.exports = app => {
          * @param transaction
          * @returns {Promise<void>}
          */
-        async updateAllMaterials(transaction, data, type, ms_id = null) {
+        async updateAllMaterials(transaction, data, type, gather_qty = null, ms_id = null) {
             // 先判断material_list是否存在值并quantity不为null
             const searchSql = {
                 mid: this.ctx.material.id,
@@ -103,16 +148,19 @@ module.exports = app => {
             if (materialListData && materialListData.length !== 0) {
                 // 对应修改更新本期应耗数量值和总的本期金额计算
                 const mbIdList = [];
+                const updateList = [];
                 for (const ml of materialListData) {
                     const updateData = {
                         id: ml.id,
+                        gather_qty,
                         is_join: type === 'add' ? 0 : 1,
                     };
                     if (mbIdList.indexOf(ml.mb_id) === -1) {
                         mbIdList.push(ml.mb_id);
                     }
-                    await transaction.update(this.ctx.service.materialList.tableName, updateData);
+                    updateList.push(updateData);
                 }
+                if (updateList.length > 0) await transaction.updateRows(this.ctx.service.materialList.tableName, updateList);
                 // 重新计算金额
                 for (const mb_id of mbIdList) {
                     await this.service.materialList.calcQuantityByML(transaction, mb_id, ms_id, 'all');
@@ -139,6 +187,7 @@ module.exports = app => {
                     gcl_id: mb.gcl_id,
                     xmj_id: mb.xmj_id,
                     mx_id: mb.mx_id,
+                    type: mb.type,
                     in_time: new Date(),
                 };
                 notJoinlist.push(newLists);
@@ -154,6 +203,7 @@ module.exports = app => {
                 gcl_id: datas.gcl_id,
                 xmj_id: datas.xmj_id,
                 mx_id: datas.mx_id,
+                type: 1,
             };
             const info = await transaction.get(this.tableName, searchData);
             if (info) {

+ 1 - 1
app/view/material/checklist.ejs

@@ -75,5 +75,5 @@
     const stage_order = <%- material.order %>;
     const materialID = <%- material.id %>;
     const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));
-    let materialChecklistData, notJoinList, ledger, curLedgerData, pos, curPosData, gclGatherData, gclList, gclGatherListData;
+    let materialChecklistData, notJoinList, notChangeList, ledger, curLedgerData, pos, curPosData, gclGatherData, gclList, gclGatherListData;
 </script>

+ 1 - 1
app/view/material/list.ejs

@@ -111,5 +111,5 @@
     const tenderID = <%- tender.id %>;
     const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));
     const openMaterialChecklist = parseInt(<%- ctx.session.sessionProject.page_show.openMaterialChecklist %>);
-    let materialListData, materialChecklistData, notJoinList, ledger, curLedgerData, pos, curPosData, gclGatherData, gclList, selfList, gclGatherListData;
+    let materialListData, materialChecklistData, notJoinList, notChangeList, ledger, curLedgerData, pos, curPosData, gclGatherData, gclList, selfList, gclGatherListData;
 </script>

+ 4 - 1
sql/update.sql

@@ -31,4 +31,7 @@ CREATE TABLE `zh_budget_zb` (
   KEY `idx_tree_pid` (`tree_pid`),
   KEY `idx_level` (`level`),
   KEY `idx_full_path` (`bid`,`full_path`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='招标预算数据';
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='招标预算数据';
+
+ALTER TABLE `zh_material_list_notjoin`
+ADD COLUMN `type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1为本期不参与调差,2为数量变更不参与调差' AFTER `mx_id`;