Pārlūkot izejas kodu

调差清单右键数量变更不参与调差功能

ellisran 1 gadu atpakaļ
vecāks
revīzija
7bf88ae1b0

+ 4 - 4
app/controller/material_controller.js

@@ -912,19 +912,19 @@ module.exports = app => {
                         break;
                     case 'change':
                     case 'join':
-                        await ctx.service.materialListNotjoin.del(data.select.id, data.gather_qty, data.ms_id);
+                        await ctx.service.materialListNotjoin.del(data.select.id, data.ms_id);
                         break;
                     case 'notjoin':
-                        responseData.data = await ctx.service.materialListNotjoin.add(data.select, data.gather_qty, data.ms_id);
+                        responseData.data = await ctx.service.materialListNotjoin.add(data.select, data.ms_id);
                         break;
                     case 'notchange':
-                        responseData.data = await ctx.service.materialListNotjoin.addChange(data.select, data.gather_qty, data.ms_id);
+                        responseData.data = await ctx.service.materialListNotjoin.addChange(data.select, data.ms_id);
                         break;
                     case 'self':
                         responseData.data = await ctx.service.materialListSelf.add(data.select);
                         break;
                     case 'noself':
-                        responseData.data = await ctx.service.materialListSelf.del(data.select.id, data.ms_id, data.select.gather_qty);
+                        responseData.data = await ctx.service.materialListSelf.del(data.select.id, data.ms_id, data.select);
                         break;
                     case 'paste':
                         await ctx.service.materialList.saveDatas(data.updateData, data.ms_id);

+ 4 - 1
app/extend/helper.js

@@ -1656,7 +1656,7 @@ module.exports = {
             console.log(err);
         }
     },
-    getQtySource(qty_source) {
+    getQtySource(qty_source, no_qc_qty = 0) {
         let qty = '';
         switch (qty_source) {
             case qtySourceValueConst.gather_qty: qty = '`gather_qty`'; break;
@@ -1664,6 +1664,9 @@ module.exports = {
             case qtySourceValueConst.gather_minus_qty: qty = '(`gather_qty`+`qc_minus_qty`)'; break;
             default: throw '未配置计量来源出错';
         }
+        if (qty_source !== qtySourceValueConst.contract_qty && no_qc_qty) {
+            qty = '(' + qty + '-`qc_qty`)';
+        }
         return qty;
     },
     resetQtys(qtys) {

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

@@ -448,7 +448,7 @@ $(document).ready(() => {
                 qc_qty: xmj.qc_qty,
                 qc_minus_qty: xmj.qc_minus_qty,
                 gather_qty: xmj.gather_qty,
-                is_join: notx === undefined ? 1 : 0,
+                is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
             };
             if (ms_id) data.ms_id = ms_id;
             datas.push(data);
@@ -474,7 +474,7 @@ $(document).ready(() => {
                                 qc_qty: xmj.qc_qty,
                                 qc_minus_qty: xmj.qc_minus_qty,
                                 gather_qty: xmj.gather_qty,
-                                is_join: notx === undefined ? 1 : 0,
+                                is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
                                 ms_id: ms.id,
                             };
                             datas.push(data);
@@ -1388,7 +1388,7 @@ $(document).ready(() => {
                         qc_qty: xmj.qc_qty,
                         qc_minus_qty: xmj.qc_minus_qty,
                         gather_qty: xmj.gather_qty,
-                        is_join: notx === undefined ? 1 : 0,
+                        is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
                     };
                     if (ms_id) data.ms_id = ms_id;
                     datas.push(data);
@@ -1417,7 +1417,7 @@ $(document).ready(() => {
                                         qc_qty: xmj.qc_qty,
                                         qc_minus_qty: xmj.qc_minus_qty,
                                         gather_qty: xmj.gather_qty,
-                                        is_join: notx === undefined ? 1 : 0,
+                                        is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
                                         ms_id: ms.id,
                                     };
                                     datas.push(data);

+ 28 - 8
app/public/js/material_list.js

@@ -835,7 +835,7 @@ $(document).ready(() => {
                 const color = notx === undefined ? '' : '#d6d8db';
                 // leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
                 const notx2 = findNotChangeLeafXmj(x);
-                const color2 = notx2 === undefined ? color : '#FFE699';
+                const color2 = notx2 === undefined || materialQtySource === qtySourceValueConst.contract_qty ? color : '#FFE699';
                 leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color2);
             }
         }
@@ -893,7 +893,7 @@ $(document).ready(() => {
                     qc_qty: xmj.qc_qty,
                     qc_minus_qty: xmj.qc_minus_qty,
                     gather_qty: xmj.gather_qty,
-                    is_join: notx === undefined ? 1 : 0,
+                    is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
                 };
                 if (ms_id) data.ms_id = ms_id;
                 datas.push(data);
@@ -920,7 +920,7 @@ $(document).ready(() => {
                                     qc_qty: xmj.qc_qty,
                                     qc_minus_qty: xmj.qc_minus_qty,
                                     gather_qty: xmj.gather_qty,
-                                    is_join: notx === undefined ? 1 : 0,
+                                    is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
                                     ms_id: ms.id,
                                 };
                                 datas.push(data);
@@ -967,7 +967,7 @@ $(document).ready(() => {
                 qc_qty: xmj.qc_qty,
                 qc_minus_qty: xmj.qc_minus_qty,
                 gather_qty: xmj.gather_qty,
-                is_join: notx === undefined ? 1 : 0,
+                is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
             };
             console.log(data);
             postData(window.location.pathname + '/save', {type: 'add', postData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
@@ -1000,7 +1000,7 @@ $(document).ready(() => {
             const data = {
                 type: type,
                 select: type === 'join' ? findNotJoinLeafXmj(select) : select,
-                gather_qty: select.gather_qty,
+                // gather_qty: select.gather_qty,
                 ms_id: $('#myTab').find('.active').data('msid') || null,
             };
             // 添加到
@@ -1027,7 +1027,7 @@ $(document).ready(() => {
             const data = {
                 type: type,
                 select: type === 'change' ? findNotChangeLeafXmj(select) : select,
-                gather_qty: type === 'change' ? select.gather_qty : select.contract_qty,
+                // gather_qty: type === 'change' ? select.gather_qty : select.contract_qty,
                 ms_id: $('#myTab').find('.active').data('msid') || null,
             };
             // 添加到
@@ -1065,6 +1065,9 @@ $(document).ready(() => {
                     for (const [index, ms] of materialStageData.entries()) {
                         const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
                         let gather_qty = null;
+                        let contract_qty = null;
+                        let qc_qty = null;
+                        let qc_minus_qty = null;
                         if (gclOther) {
                             const leafXmjs = gclOther.leafXmjs.filter(item => {
                                 return item.qc_qty || item.contract_qty || item.qc_minus_qty
@@ -1072,12 +1075,23 @@ $(document).ready(() => {
                             const oneXmj = _.find(leafXmjs, function (item) {
                                 return item.gcl_id === select.gcl_id && item.id === select.id && (select.mx_id === undefined || item.mx_id === select.mx_id);
                             });
-                            if (oneXmj) gather_qty = oneXmj.gather_qty;
+                            if (oneXmj) {
+                                gather_qty = oneXmj.gather_qty;
+                                contract_qty = oneXmj.contract_qty;
+                                qc_qty = oneXmj.qc_qty;
+                                qc_minus_qty = oneXmj.qc_minus_qty ? oneXmj.qc_minus_qty : null;
+                            }
                         }
                         data.select.gather_qty['ms_id_' + ms.id] = gather_qty;
+                        data.select.contract_qty['ms_id_' + ms.id] = contract_qty;
+                        data.select.qc_qty['ms_id_' + ms.id] = qc_qty;
+                        data.select.qc_minus_qty['ms_id_' + ms.id] = qc_minus_qty;
                     }
                 } else {
                     data.select.gather_qty = select.gather_qty ? select.gather_qty : null;
+                    data.select.contract_qty = select.contract_qty ? select.contract_qty : null;
+                    data.select.qc_qty = select.qc_qty ? select.qc_qty : null;
+                    data.select.qc_minus_qty = select.qc_minus_qty ? select.qc_minus_qty : null;
                 }
             }
             console.log(data);
@@ -1166,12 +1180,15 @@ $(document).ready(() => {
                             if (!select || sel.rowCount !== 1) {
                                 return false;
                             }
+                            if (materialQtySource === qtySourceValueConst.contract_qty) {
+                                return false;
+                            }
                             const notx = findNotJoinLeafXmj(select);
                             if (!(!readOnly && select && notx === undefined)) {
                                 return false;
                             }
                             const notx2 = findNotChangeLeafXmj(select);
-                            if (!readOnly && select && notx2 === undefined && materialQtySource !== qtySourceValueConst.contract_qty) {
+                            if (!readOnly && select && notx2 === undefined) {
                                 return true;
                             } else {
                                 return false;
@@ -1191,6 +1208,9 @@ $(document).ready(() => {
                             if (!select || sel.rowCount !== 1) {
                                 return false;
                             }
+                            if (materialQtySource === qtySourceValueConst.contract_qty) {
+                                return false;
+                            }
                             const notx = findNotJoinLeafXmj(select);
                             if (!(!readOnly && select && notx === undefined)) {
                                 return false;

+ 5 - 22
app/service/material_bills.js

@@ -605,12 +605,7 @@ module.exports = app => {
         async calcQuantityByMB(transaction, mid, mb, materialCalculator, decimal, pre_is_stage_self, qty_source) {
             const [newmsg_spread, newm_spread] = await this.getSpread(mb, null, decimal.up);
             if (mb.t_type === materialConst.t_type[0].value) {
-                const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(qty_source) + '*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
-                const sqlParam = [mid, mb.id];
-                const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                console.log(mb_quantity);
-                // 取历史期记录获取截止上期调差金额,并清空本期单价和时间,来源地,重新计算价差和有效价差
-                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, decimal.qty);
+                const newQuantity = await this.ctx.service.materialList.getMbQuantity(transaction, mid, qty_source, decimal.qty, mb.id);
                 const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), decimal.tp);
                 const updateData = {
                     id: mb.id,
@@ -815,10 +810,7 @@ module.exports = app => {
                             // 通过管理重新算出quantity并保留小数位
                             if (mb.t_type === materialConst.t_type[0].value) {
                                 // 通过管理重新算出quantity并保留小数位
-                                const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(this.ctx.material.qty_source) + '*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `ms_id`=? AND `is_join`=1';
-                                const sqlParam = [this.ctx.material.id, mb.id, ms.id];
-                                const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, newDecimalQty);
+                                const newQuantity = await this.ctx.service.materialList.getMbQuantity(transaction, this.ctx.material.id, this.ctx.material.qty_source, newDecimalQty, mb.id, ms.id);
                                 if (newQuantity !== msb.quantity) {
                                     updateStageBillData.quantity = newQuantity;
                                     msb.quantity = newQuantity;
@@ -893,10 +885,7 @@ module.exports = app => {
                     if (newDecimalQty !== this.ctx.material.decimal.qty) {
                         // 通过管理重新算出quantity并保留小数位
                         if (mb.t_type === materialConst.t_type[0].value) {
-                            const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(this.ctx.material.qty_source) + '*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
-                            const sqlParam = [this.ctx.material.id, mb.id];
-                            const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, newDecimalQty);
+                            const newQuantity = await this.ctx.service.materialList.getMbQuantity(transaction, this.ctx.material.id, this.ctx.material.qty_source, newDecimalQty, mb.id);
                             mb.quantity = newQuantity;
                             updateData.quantity = newQuantity;
                         } else if (mb.t_type === materialConst.t_type[1].value) {
@@ -940,10 +929,7 @@ module.exports = app => {
                                 ms_id: ms.id,
                             });
                             // 通过管理重新算出quantity并保留小数位
-                            const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(newQtySource) + '*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `ms_id`=? AND `is_join`=1';
-                            const sqlParam = [this.ctx.material.id, mb.id, ms.id];
-                            const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+                            const newQuantity = await this.ctx.service.materialList.getMbQuantity(transaction, this.ctx.material.id, newQtySource, this.ctx.material.decimal.qty, mb.id, ms.id);
                             if (newQuantity !== msb.quantity) {
                                 const updateStageBillData = {
                                     id: msb.id,
@@ -964,10 +950,7 @@ module.exports = app => {
                         updateData.m_tax_tp = this.ctx.helper.round(tp.tax_total_price, this.ctx.material.decimal.tp);
                         updateList.push(updateData);
                     } else {
-                        const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(newQtySource) + '*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
-                        const sqlParam = [this.ctx.material.id, mb.id];
-                        const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                        const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+                        const newQuantity = await this.ctx.service.materialList.getMbQuantity(transaction, this.ctx.material.id, newQtySource, this.ctx.material.decimal.qty, mb.id);
                         if (newQuantity !== mb.quantity) {
                             mb.quantity = newQuantity;
                             updateData.quantity = newQuantity;

+ 18 - 21
app/service/material_list.js

@@ -223,12 +223,7 @@ module.exports = app => {
                 m_spread = msbInfo.m_spread;
                 updateId = msbInfo.id;
             }
-            const msSql = ms_id ? ' AND `ms_id` = ' + ms_id : '';
-            const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(this.ctx.material.qty_source) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=?' + msSql + ' AND `is_join`=1';
-            const sqlParam = [this.ctx.material.id, mb_id];
-            const mb_quantity = await transaction.queryOne(sql, sqlParam);
-            console.log(mb_quantity);
-            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+            const newQuantity = await this.getMbQuantity(transaction, this.ctx.material.id, this.ctx.material.qty_source, this.ctx.material.decimal.qty, mb_id, ms_id);
             const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, m_spread), this.ctx.material.decimal.tp);
             const updateData = {
                 id: updateId,
@@ -245,10 +240,7 @@ module.exports = app => {
                     const msbList = await transaction.select(this.ctx.service.materialStageBills.tableName, { where: { mid: this.ctx.material.id, mb_id } });
                     for (const msb of msbList) {
                         if (msb.ms_id !== parseInt(ms_id)) {
-                            const sql4 = 'SELECT SUM(' + this.ctx.helper.getQtySource(this.ctx.material.qty_source) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `ms_id`=? AND `is_join`=1';
-                            const sqlParam4 = [this.ctx.material.id, mb_id, msb.ms_id];
-                            const mb_quantity4 = await transaction.queryOne(sql4, sqlParam4);
-                            const newQuantity4 = this.ctx.helper.round(mb_quantity4.quantity, this.ctx.material.decimal.qty);
+                            const newQuantity4 = await this.getMbQuantity(transaction, this.ctx.material.id, this.ctx.material.qty_source, this.ctx.material.decimal.qty, mb_id, msb.ms_id);
                             const newTp4 = this.ctx.helper.round(this.ctx.helper.mul(newQuantity4, msb.m_spread), this.ctx.material.decimal.tp);
                             const updateData4 = {
                                 id: msb.id,
@@ -325,10 +317,7 @@ module.exports = app => {
                     const updateMsIds = [];
                     const msbList = await transaction.select(this.ctx.service.materialStageBills.tableName, { where: { mid: this.ctx.material.id, mb_id: mbInfo.id } });
                     for (const msb of msbList) {
-                        const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(this.ctx.material.qty_source) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `ms_id`=? AND `is_join`=1';
-                        const sqlParam = [this.ctx.material.id, mbInfo.id, msb.ms_id];
-                        const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                        const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+                        const newQuantity = await this.getMbQuantity(transaction, this.ctx.material.id, this.ctx.material.qty_source, this.ctx.material.decimal.qty, mbInfo.id, msb.ms_id);
                         const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, msb.m_spread), this.ctx.material.decimal.tp);
                         const updateData = {
                             id: msb.id,
@@ -356,11 +345,7 @@ module.exports = app => {
                     };
                     await transaction.update(this.ctx.service.materialBills.tableName, updateBillsData);
                 } else {
-                    const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(this.ctx.material.qty_source) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
-                    const sqlParam = [this.ctx.material.id, mbInfo.id];
-                    const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                    console.log(mb_quantity);
-                    const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+                    const newQuantity = await this.getMbQuantity(transaction, this.ctx.material.id, this.ctx.material.qty_source, this.ctx.material.decimal.qty, mbInfo.id);
                     const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, mbInfo.m_spread), this.ctx.material.decimal.tp);
                     const updateData = {
                         id: mbInfo.id,
@@ -499,7 +484,7 @@ module.exports = app => {
                         gather_qty: ml.gather_qty,
                         quantity: ml.quantity ? ml.quantity : 0,
                         expr: ml.expr ? ml.expr : '',
-                        is_join: is_join ? 0 : 1,
+                        is_join: is_join ? 0 : is_change ? 2 : 1,
                         in_time: new Date(),
                     };
                     if (ml.sid) {
@@ -529,7 +514,7 @@ module.exports = app => {
                         gather_qty: ml.gather_qty,
                         quantity: ml.quantity ? ml.quantity : 0,
                         expr: ml.expr ? ml.expr : '',
-                        is_join: is_join ? 0 : 1,
+                        is_join: is_join ? 0 : is_change ? 2 : 1,
                         is_self: 1,
                         in_time: new Date(),
                     };
@@ -847,6 +832,18 @@ module.exports = app => {
                 throw err;
             }
         }
+
+        async getMbQuantity(transaction, mid, qty_source, qty_decimal, mb_id, ms_id = null, needRound = 1) {
+            const msSql = ms_id ? ' AND `ms_id` = ' + ms_id : '';
+            const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(qty_source) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=?' + msSql + ' AND `is_join`=1';
+            const sqlParam = [mid, mb_id];
+            const mb_quantity = await transaction.queryOne(sql, sqlParam);
+            const sql2 = 'SELECT SUM(' + this.ctx.helper.getQtySource(qty_source, 1) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=?' + msSql + ' AND `is_join`=2';
+            const sqlParam2 = [mid, mb_id];
+            const mb_quantity2 = await transaction.queryOne(sql2, sqlParam2);
+            const newQuantity = this.ctx.helper.add(mb_quantity.quantity, mb_quantity2.quantity);
+            return needRound ? this.ctx.helper.round(newQuantity, qty_decimal) : newQuantity;
+        }
     }
     return MaterialList;
 };

+ 9 - 11
app/service/material_list_notjoin.js

@@ -26,7 +26,7 @@ module.exports = app => {
          * 添加不参与调差的清单
          * @return {void}
          */
-        async add(data, gather_qty, ms_id = null) {
+        async add(data, ms_id = null) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
@@ -52,7 +52,7 @@ module.exports = app => {
                 });
                 data.xmj_id = data.id;
                 data.mx_id = data.mx_id ? data.mx_id : '';
-                await this.updateAllMaterials(transaction, data, 'add', gather_qty, ms_id);
+                await this.updateAllMaterials(transaction, data, 'add', ms_id);
                 // 新增不参与调差清单
                 const result = await transaction.insert(this.tableName, newListNotJoin);
                 if (result.affectedRows === 0) {
@@ -70,7 +70,7 @@ module.exports = app => {
          * 添加数量变更不计量的清单
          * @return {void}
          */
-        async addChange(data, gather_qty, ms_id = null) {
+        async addChange(data, ms_id = null) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
@@ -87,7 +87,7 @@ module.exports = app => {
                 };
                 data.xmj_id = data.id;
                 data.mx_id = data.mx_id ? data.mx_id : '';
-                await this.updateAllMaterials(transaction, data, 'change', gather_qty, ms_id);
+                await this.updateAllMaterials(transaction, data, 'change', ms_id);
                 // 新增不参与调差清单
                 const result = await transaction.insert(this.tableName, newListNotChange);
                 if (result.affectedRows === 0) {
@@ -106,14 +106,14 @@ module.exports = app => {
          * @param {int} id 工料id
          * @return {void}
          */
-        async del(id, gather_qty, ms_id = null) {
+        async del(id, 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', gather_qty, ms_id);
+                await this.updateAllMaterials(transaction, notJoinInfo, 'del', ms_id);
                 // 判断是否可删
                 const result = await transaction.delete(this.tableName, { id });
                 await transaction.commit();
@@ -129,7 +129,7 @@ module.exports = app => {
          * @param transaction
          * @returns {Promise<void>}
          */
-        async updateAllMaterials(transaction, data, type, gather_qty = null, ms_id = null) {
+        async updateAllMaterials(transaction, data, type, ms_id = null) {
             // 先判断material_list是否存在值并quantity不为null
             const searchSql = {
                 mid: this.ctx.material.id,
@@ -152,8 +152,7 @@ module.exports = app => {
                 for (const ml of materialListData) {
                     const updateData = {
                         id: ml.id,
-                        gather_qty,
-                        is_join: type === 'add' ? 0 : 1,
+                        is_join: type === 'add' ? 0 : type === 'change' ? 2 : 1,
                     };
                     if (mbIdList.indexOf(ml.mb_id) === -1) {
                         mbIdList.push(ml.mb_id);
@@ -203,11 +202,10 @@ 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) {
-                return 0;
+                return info.type === 1 ? 0 : info.type === 2 ? 2 : 0;
             }
             return 1;
         }

+ 12 - 3
app/service/material_list_self.js

@@ -71,14 +71,17 @@ module.exports = app => {
          * @param {int} id 工料id
          * @return {void}
          */
-        async del(id, ms_id = null, gather_qty = null) {
+        async del(id, ms_id = null, qtys = null) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
             const transaction = await this.db.beginTransaction();
             try {
                 const selfInfo = await this.getDataById(id);
-                selfInfo.gather_qty = gather_qty;
+                selfInfo.contract_qty = qtys.contract_qty ? qtys.contract_qty : null;
+                selfInfo.qc_qty = qtys.gather_qty ? qtys.qc_qty : null;
+                selfInfo.qc_minus_qty = qtys.qc_minus_qty ? qtys.qc_minus_qty : null;
+                selfInfo.gather_qty = qtys.gather_qty ? qtys.gather_qty : null;
                 await this.updateAllMaterials(transaction, selfInfo, ms_id);
                 // 判断是否可删
                 const result = await transaction.delete(this.tableName, { id });
@@ -135,7 +138,7 @@ module.exports = app => {
                     // const oneML = this._.filter(materialListData, { ms_id: ms.id });
                     // const gather_qty = oneML[0].gather_qty;
                     // const is_join = oneML[0].is_join;
-                    if (data.gather_qty['ms_id_' + ms.id] !== null) {
+                    if (data.contract_qty['ms_id_' + ms.id] !== null || data.qc_qty['ms_id_' + ms.id] !== null || data.qc_minus_qty['ms_id_' + ms.id] !== null || data.gather_qty['ms_id_' + ms.id] !== null) {
                         for (const m of materialListGclData) {
                             insertList.push({
                                 tid: this.ctx.tender.id,
@@ -146,6 +149,9 @@ module.exports = app => {
                                 xmj_id: data.xmj_id,
                                 mx_id: data.mx_id,
                                 ms_id: ms.id,
+                                contract_qty: data.contract_qty['ms_id_' + ms.id],
+                                qc_qty: data.qc_qty['ms_id_' + ms.id],
+                                qc_minus_qty: data.qc_minus_qty['ms_id_' + ms.id],
                                 gather_qty: data.gather_qty['ms_id_' + ms.id],
                                 quantity: m.quantity,
                                 expr: m.expr,
@@ -168,6 +174,9 @@ module.exports = app => {
                         gcl_id: data.gcl_id,
                         xmj_id: data.xmj_id,
                         mx_id: data.mx_id,
+                        contract_qty: data.contract_qty,
+                        qc_qty: data.qc_qty,
+                        qc_minus_qty: data.qc_minus_qty,
                         gather_qty: data.gather_qty,
                         quantity: m.quantity,
                         expr: m.expr,

+ 3 - 8
app/service/material_stage_bills.js

@@ -223,13 +223,8 @@ module.exports = app => {
         async calcQuantityByMB(transaction, mid, mb, msb, materialCalculator, decimal, pre_is_stage_self, qty_source) {
             const [newmsg_spread, newm_spread] = await this.getSpread(mb, null, decimal.up);
             if (mb.t_type === materialConst.t_type[0].value) {
-                const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(qty_source) + '*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `ms_id`=? AND `mb_id`=? AND `is_join`=1';
-                const sqlParam = [mid, msb.ms_id, mb.id];
-                const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                console.log(mb_quantity);
-                // 取历史期记录获取截止上期调差金额,并清空本期单价和时间,来源地,重新计算价差和有效价差
-                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, decimal.qty);
-                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), decimal.tp);
+                const newQuantity = await this.ctx.service.materialList.getMbQuantity(transaction, mid, qty_source, decimal.qty, mb.id, null, 0);
+                const newTp = this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(newQuantity, decimal.qty), newm_spread), decimal.tp);
                 msb.quantity = newQuantity;
                 msb.msg_spread = newmsg_spread;
                 msb.m_spread = newm_spread;
@@ -249,7 +244,7 @@ module.exports = app => {
                 //     tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp) : mb.tax_pre_tp,
                 // };
                 // await transaction.update(this.tableName, updateData);
-                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), decimal.tp) : 0;
+                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), decimal.tp) : 0;
                 const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp);
                 return [m_tp, m_tax_tp];
             } else if (mb.t_type === materialConst.t_type[1].value) {