Browse Source

有负变更的清单,不可修改单价

MaiXinRong 3 years ago
parent
commit
7af23969da

+ 5 - 2
app/controller/revise_controller.js

@@ -435,15 +435,18 @@ module.exports = app => {
                                 p.used = usedPrePos.indexOf(p.id) >= 0;
                                 p.used = usedPrePos.indexOf(p.id) >= 0;
                             }
                             }
                         } else {
                         } else {
+                            const minusChange = await this.ctx.service.stageChange.getStageMinusChange(lastStage);
                             const usedPreBills = lastStage.order > 1 ? await ctx.service.stageBillsFinal.getUsedBills(ctx.tender.id, lastStage.order - 1) : [];
                             const usedPreBills = lastStage.order > 1 ? await ctx.service.stageBillsFinal.getUsedBills(ctx.tender.id, lastStage.order - 1) : [];
                             const usedCurBills = await ctx.service.stageBills.getStageUsedBills(ctx.tender.id, lastStage.id);
                             const usedCurBills = await ctx.service.stageBills.getStageUsedBills(ctx.tender.id, lastStage.id);
+                            const minusChangeBills = minusChange.map(x => {return x.qty < 0 ? x.lid : undefined});
                             for (const b of reviseBills) {
                             for (const b of reviseBills) {
-                                b.used = usedPreBills.indexOf(b.id) >= 0 || usedCurBills.indexOf(b.id) >= 0;
+                                b.used = usedPreBills.indexOf(b.id) >= 0 || usedCurBills.indexOf(b.id) >= 0 || minusChangeBills.indexOf(b.id) >= 0;
                             }
                             }
                             const usedPrePos = lastStage.order > 1 ? await ctx.service.stagePosFinal.getUsedPos(ctx.tender.id, lastStage.order - 1) : [];
                             const usedPrePos = lastStage.order > 1 ? await ctx.service.stagePosFinal.getUsedPos(ctx.tender.id, lastStage.order - 1) : [];
                             const usedCurPos = await ctx.service.stagePos.getStageUsedPos(ctx.tender.id, lastStage.id);
                             const usedCurPos = await ctx.service.stagePos.getStageUsedPos(ctx.tender.id, lastStage.id);
+                            const minusChangePos = minusChange.map(x => {return x.qty < 0 ? x.pid : undefined});
                             for (const p of revisePos) {
                             for (const p of revisePos) {
-                                p.used = usedPrePos.indexOf(p.id) >= 0 || usedCurPos.indexOf(p.id) >= 0;
+                                p.used = usedPrePos.indexOf(p.id) >= 0 || usedCurPos.indexOf(p.id) >= 0 || minusChangePos.indexOf(p.id) >= 0 ;
                             }
                             }
                         }
                         }
                     }
                     }

+ 39 - 43
app/service/stage_bills_final.js

@@ -75,54 +75,50 @@ module.exports = app => {
             if (!transaction || !tender || !stage) {
             if (!transaction || !tender || !stage) {
                 throw '数据错误';
                 throw '数据错误';
             }
             }
-            if (stage.order > 1) {
-                const cur = await this.ctx.service.stageBills.getLastestStageData2(tender.id, stage.id);
-                const pre = await this.getFinalData(tender, stage.order - 1);
-                if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
-                for (const c of cur) {
-                    delete c.id;
-                    delete c.said;
-                    delete c.times;
-                    delete c.order;
-                    delete c.postil;
-                    c.sorder = stage.order;
-                    const p = this.ctx.helper._.find(pre, function (x) {
-                        return x.lid === c.lid;
-                    });
-                    if (p) {
-                        c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
-                        c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
-                        c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
-                        c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
-                        c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
-                            || !this.ctx.helper.checkZero(c.contract_tp) || !this.ctx.helper.checkZero(c.qc_tp);
-                        pre.splice(pre.indexOf(p), 1);
+            const cur = await this.ctx.service.stageBills.getLastestStageData2(tender.id, stage.id);
+            const pre = await this.getFinalData(tender, stage.order - 1);
+            const minusChange = await this.ctx.service.stageChange.getStageMinusChange(stage);
+            if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
+            for (const c of cur) {
+                delete c.id;
+                delete c.said;
+                delete c.times;
+                delete c.order;
+                delete c.postil;
+                c.sorder = stage.order;
+                const p = this.ctx.helper._.find(pre, function (x) {
+                    return x.lid === c.lid;
+                });
+                if (p) {
+                    c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
+                    c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
+                    c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
+                    c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
+                    if (p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
+                        || !this.ctx.helper.checkZero(c.contract_tp)) {
+                        c.used = true;
                     } else {
                     } else {
-                        c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
-                            || !this.ctx.helper.checkZero(c.contract_tp) || !this.ctx.helper.checkZero(c.qc_tp);
+                        const mc = minusChange.find(x => { return x.lid === c.lid && x.qty < 0 });
+                        c.used = !!mc;
+                    }
+                    pre.splice(pre.indexOf(p), 1);
+                } else {
+                    if (!this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
+                        || !this.ctx.helper.checkZero(c.contract_tp)) {
+                        c.used = true;
+                    } else {
+                        const mc = minusChange.find(x => { return x.lid === c.lid && x.qty < 0 });
+                        c.used = !!mc;
                     }
                     }
                 }
                 }
+            }
 
 
-                for (const p of pre) {
-                    if (p.id !== undefined) delete p.id;
-                    p.sid = stage.id;
-                    p.sorder = stage.order;
-                }
-                await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
-            } else {
-                const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp, used)' +
-                    '  SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp,' +
-                    '    IF(IFNULL(b.contract_qty, 0) <> 0 or IFNULL(b.contract_tp, 0) <> 0 or IFNULL(b.qc_qty, 0) <> 0 or IFNULL(b.qc_tp, 0) <> 0, 1, 0) As used' +
-                    '  FROM ' + this.ctx.service.stageBills.tableName + ' AS b' +
-                    '  INNER JOIN(' +
-                    '    SELECT Max(`times` * ' + timesLen + ' + `order`) As `flow`, `lid` FROM ' + this.ctx.service.stageBills.tableName +
-                    '    WHERE `sid` = ?' +
-                    '    GROUP By `lid`) As MF' +
-                    '  ON (b.times * ' + timesLen + ' + b.order) = MF.flow AND b.lid = MF.lid' +
-                    '  WHERE b.sid = ?';
-                const sqlParam = [this.tableName, stage.order, stage.id, stage.id];
-                await transaction.query(sql, sqlParam);
+            for (const p of pre) {
+                if (p.id !== undefined) delete p.id;
+                p.sid = stage.id;
+                p.sorder = stage.order;
             }
             }
+            await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
         }
         }
 
 
         /**
         /**

+ 1 - 1
app/service/stage_change.js

@@ -486,7 +486,7 @@ module.exports = app => {
         }
         }
 
 
         async getStageMinusChange(stage) {
         async getStageMinusChange(stage) {
-            const data = this.getAllDataByCondition({ where: { sid: stage.id, minus: 1 } });
+            const data = await this.getAllDataByCondition({ where: { sid: stage.id, minus: 1 } });
             return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
             return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
         };
         };
 
 

+ 35 - 39
app/service/stage_pos_final.js

@@ -57,50 +57,46 @@ module.exports = app => {
             if (!transaction || !tender || !stage) {
             if (!transaction || !tender || !stage) {
                 throw '数据错误';
                 throw '数据错误';
             }
             }
-            if (stage.order > 1) {
-                const cur = await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
-                const pre = await this.getFinalData(tender, stage.order - 1);
-                if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
-                for (const c of cur) {
-                    delete c.id;
-                    delete c.said;
-                    delete c.times;
-                    delete c.order;
-                    delete c.postil;
-                    c.sorder = stage.order;
-                    const p = this.ctx.helper._.find(pre, function (x) {
-                        return x.pid === c.pid;
-                    });
-                    if (p) {
-                        c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
-                        c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
-                        c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
-                        pre.splice(pre.indexOf(p), 1);
+            const cur = await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
+            const pre = stage.order > 1 ? await this.getFinalData(tender, stage.order - 1) : [];
+            const minusChange = await this.ctx.service.stageChange.getStageMinusChange(stage);
+            if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
+            for (const c of cur) {
+                delete c.id;
+                delete c.said;
+                delete c.times;
+                delete c.order;
+                delete c.postil;
+                c.sorder = stage.order;
+                const p = this.ctx.helper._.find(pre, function (x) {
+                    return x.pid === c.pid;
+                });
+                if (p) {
+                    c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
+                    c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
+                    c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
+                    pre.splice(pre.indexOf(p), 1);
+                } else {
+                    if (!this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)) {
+                        c.used = true;
                     } else {
                     } else {
-                        c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
+                        const mc = minusChange.find(x => { return x.pid === c.pid && x.qty < 0});
+                        c.used = !!mc;
                     }
                     }
                 }
                 }
-                for (const p of pre) {
-                    if (p.id !== undefined) delete p.id;
-                    p.sid = stage.id;
-                    p.sorder = stage.order;
-                    p.used = p.used || !this.ctx.helper.checkZero(p.contract_qty) || !this.ctx.helper.checkZero(p.qc_qty);
+            }
+            for (const p of pre) {
+                if (p.id !== undefined) delete p.id;
+                p.sid = stage.id;
+                p.sorder = stage.order;
+                if (p.used || !this.ctx.helper.checkZero(p.contract_qty) || !this.ctx.helper.checkZero(p.qc_qty)) {
+                    p.used = true;
+                } else {
+                    const mc = minusChange.find(x => { return x.pid === p.pid && x.qty < 0});
+                    p.used = !!mc;
                 }
                 }
-                await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
-            } else {
-                const sql = 'Insert Into ??(tid, sid, lid, pid, sorder, contract_qty, qc_qty, used)' +
-                            '  SELECT p.tid, p.sid, p.lid, p.pid, ? As `sorder`, p.contract_qty, p.qc_qty,' +
-                            '    IF(IFNULL(p.contract_qty, 0) <> 0 or IFNULL(p.qc_qty, 0) <> 0, 1, 0) As used' +
-                            '  FROM ' + this.ctx.service.stagePos.tableName + ' AS p' +
-                            '  INNER JOIN(' +
-                            '    SELECT Max(`times` * ' + timesLen +' + `order`) As `flow`, `pid` FROM ' + this.ctx.service.stagePos.tableName +
-                            '    WHERE `sid` = ?' +
-                            '    GROUP By `pid`) As MF' +
-                            '  ON (p.times * ' + timesLen + ' + p.order) = MF.flow AND p.pid = MF.pid' +
-                            '  WHERE p.sid = ?';
-                const sqlParam = [this.tableName, stage.order, stage.id, stage.id];
-                await transaction.query(sql, sqlParam);
             }
             }
+            await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
         }
         }
 
 
         /**
         /**