Bladeren bron

负变更,不记入本期数量变更

MaiXinRong 3 jaren geleden
bovenliggende
commit
2607394e3c

+ 4 - 0
app/controller/stage_controller.js

@@ -2077,6 +2077,8 @@ module.exports = app => {
 
                 const data = JSON.parse(ctx.request.body.data);
                 await ctx.service.stageStash.recover(ctx.stage, data.id);
+                await ctx.service.stage.updateCheckCalcFlag(ctx.stage, true);
+                await ctx.service.stage.updateCacheTime(ctx.stage.id);
                 ctx.body = { err: 0, msg: '', data: null };
             } catch (err) {
                 ctx.log(err);
@@ -2102,6 +2104,8 @@ module.exports = app => {
                 const compressData = ctx.request.body.data;
                 const data = JSON.parse(LzString.decompressFromUTF16(compressData));
 
+                await ctx.service.stage.updateCheckCalcFlag(ctx.stage, true);
+                await ctx.service.stage.updateCacheTime(ctx.stage.id);
             } catch (err) {
                 ctx.log(err);
                 ctx.ajaxErrorBody(err, '导入计量台账数据错误');

+ 1 - 1
app/public/js/stage.js

@@ -502,7 +502,7 @@ $(document).ready(() => {
                             return;
                         }
 
-                        data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
+                        data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount, minus: c.bamount < 0 });
                     }
                 }
                 // 提交数据到后端

+ 35 - 33
app/service/stage_change.js

@@ -131,17 +131,13 @@ module.exports = app => {
          */
         async billsChange(bills, changes) {
             const self = this;
-            function getNewChange(cid, cbid, times, order, qty) {
+            function getNewChange(cid, cbid, times, order, qty, minus) {
                 return {
-                    tid: self.ctx.tender.id,
-                    sid: self.ctx.stage.id,
-                    lid: bills.id,
-                    pid: -1,
-                    cid,
-                    cbid,
-                    stimes: times,
-                    sorder: order,
-                    qty,
+                    tid: self.ctx.tender.id, sid: self.ctx.stage.id,
+                    lid: bills.id, pid: -1,
+                    cid, cbid,
+                    stimes: times, sorder: order,
+                    qty, minus
                 };
             }
             const ledgerBills = await this.ctx.service.ledger.getDataById(bills.id);
@@ -159,8 +155,10 @@ module.exports = app => {
                 const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
                 if (!nc || nc.qty !== oc.qty) {
                     const qty = nc ? this.round(nc.qty, precision.value) : null;
-                    const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty);
-                    billsQty = this.ctx.helper.add(billsQty, change.qty);
+                    const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc.minus);
+                    if (!change.minus) {
+                        billsQty = this.ctx.helper.add(billsQty, change.qty);
+                    }
                     if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
                         change.id = oc.id;
                         updateChanges.push(change);
@@ -168,14 +166,18 @@ module.exports = app => {
                         newChanges.push(change);
                     }
                 } else {
-                    billsQty = this.ctx.helper.add(billsQty, oc.qty);
+                    if (!oc.minus) {
+                        billsQty = this.ctx.helper.add(billsQty, oc.qty);
+                    }
                 }
             }
             for (const c of changes) {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 if (!nc) {
-                    const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
-                    billsQty = this.ctx.helper.add(billsQty, change.qty);
+                    const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus);
+                    if (!change.minus) {
+                        billsQty = this.ctx.helper.add(billsQty, change.qty);
+                    }
                     newChanges.push(change);
                 }
             }
@@ -208,17 +210,13 @@ module.exports = app => {
          */
         async posChange(pos, changes) {
             const self = this;
-            function getNewChange(cid, cbid, times, order, qty) {
+            function getNewChange(cid, cbid, times, order, qty, minus) {
                 return {
-                    tid: self.ctx.tender.id,
-                    sid: self.ctx.stage.id,
-                    lid: pos.lid,
-                    pid: pos.id,
-                    cid,
-                    cbid,
-                    stimes: times,
-                    sorder: order,
-                    qty,
+                    tid: self.ctx.tender.id, sid: self.ctx.stage.id,
+                    lid: pos.lid, pid: pos.id,
+                    cid, cbid,
+                    stimes: times, sorder: order,
+                    qty, minus
                 };
             }
             const ledgerBills = await this.ctx.service.ledger.getDataById(pos.lid);
@@ -235,23 +233,27 @@ module.exports = app => {
                 const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
                 if (!nc || nc.qty !== oc.qty) {
                     const qty = nc ? this.round(nc.qty, precision.value) : null;
-                    const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty);
-                    posQty = this.ctx.helper.add(posQty, change.qty);
+                    const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc.minus);
+                    if (!change.minus) {
+                        posQty = this.ctx.helper.add(posQty, change.qty);
+                    }
                     if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
                         change.id = oc.id;
                         updateChanges.push(change);
-                    } else {
-                        newChanges.push(change);
                     }
                 } else {
-                    posQty = this.ctx.helper.add(posQty, oc.qty);
+                    if (!oc.minus) {
+                        posQty = this.ctx.helper.add(posQty, oc.qty);
+                    }
                 }
             }
             for (const c of changes) {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 if (!nc) {
-                    const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
-                    posQty = this.ctx.helper.add(posQty, change.qty);
+                    const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus);
+                    if (!change.minus) {
+                        posQty = this.ctx.helper.add(posQty, change.qty);
+                    }
                     newChanges.push(change);
                 }
             }
@@ -401,7 +403,7 @@ module.exports = app => {
             data = helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
             const bqData = [];
             for (const d of data) {
-                if (!d.qty) continue;
+                if (!d.qty || d.minus) continue;
                 let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
                 if (!bd) {
                     const bills = await this.db.get(this.ctx.service.ledger.departTableName(tender.id), { id: d.lid });

+ 1 - 1
app/service/stage_change_final.js

@@ -64,7 +64,7 @@ module.exports = app => {
                 data.push({
                     tid: c.tid, sid: c.sid, sorder: stage.order,
                     lid: c.lid, pid: c.pid, cid: c.cid, cbid: c.cbid,
-                    qty: c.qty,
+                    qty: c.qty, minus: c.minus,
                 });
             }
             if (data.length > 0) await transaction.insert(this.tableName, data);

+ 4 - 4
app/service/stage_stash.js

@@ -110,11 +110,11 @@ module.exports = app => {
                         if (bp.change) {
                             for (const c of bp.change) {
                                 if (!c.qty) continue;
-                                const ncs = { tid: stage.tid, sid: stage.id, lid: b.id, pid: p.id, stimes: 1, sorder: 0, cid: c.cid, cbid: c.cbid };
+                                const ncs = { tid: stage.tid, sid: stage.id, lid: b.id, pid: p.id, stimes: 1, sorder: 0, cid: c.cid, cbid: c.cbid, minus: c.minus };
                                 const validQty = await this.ctx.service.stageChangeFinal.getChangeBillsValidQty(c.cbid);
                                 ncs.qty = validQty >= c.qty ? c.qty : validQty;
                                 insertChangeData.push(ncs);
-                                nps.qc_qty = await this.ctx.helper.add(nps.qc_qty, ncs.qty);
+                                if (!ncs.minus) nps.qc_qty = await this.ctx.helper.add(nps.qc_qty, ncs.qty);
                             }
                         }
                         nbs.contract_qty = this.ctx.helper.add(nbs.contract_qty, nps.contract_qty);
@@ -130,11 +130,11 @@ module.exports = app => {
                     if (d.change) {
                         for (const c of d.change) {
                             if (!c.qty) continue;
-                            const ncs = { tid: stage.tid, sid: stage.id, lid: d.id, pid: -1, stimes: 1, sorder: 0, cid: c.cid, cbid: c.cbid };
+                            const ncs = { tid: stage.tid, sid: stage.id, lid: d.id, pid: -1, stimes: 1, sorder: 0, cid: c.cid, cbid: c.cbid, minus: c.minus };
                             const validQty = await this.ctx.service.stageChangeFinal.getChangeBillsValidQty(c.cbid);
                             ncs.qty = validQty >= c.qty ? c.qty : validQty;
                             insertChangeData.push(ncs);
-                            nbs.qc_qty = await this.ctx.helper.add(nbs.qc_qty, ncs.qty);
+                            if (!ncs.minus) nbs.qc_qty = await this.ctx.helper.add(nbs.qc_qty, ncs.qty);
                         }
                     }
                     nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);

+ 5 - 0
sql/update.sql

@@ -99,3 +99,8 @@ Update zh_stage_change_final scf Join zh_stage s on scf.sid = s.id Set scf.sorde
 ALTER TABLE `zh_change` ADD `order_by` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '清单排序规则,默认按清单编号排(0),自定义排序(1)' AFTER `is_revise`;
 ALTER TABLE `zh_change_audit_list` ADD `order` INT NULL DEFAULT NULL COMMENT '排序序号(自定义规则时使用)' AFTER `spamount`;
 
+ALTER TABLE `zh_stage_change`
+ADD COLUMN `minus`  tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否负变更' AFTER `qty`;
+
+ALTER TABLE `zh_stage_change_final`
+ADD COLUMN `minus`  tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否负变更' AFTER `qty`;