فهرست منبع

暂存计量,不计价,正负变更统计相关

MaiXinRong 2 سال پیش
والد
کامیت
66427cfe08
1فایلهای تغییر یافته به همراه24 افزوده شده و 7 حذف شده
  1. 24 7
      app/service/stage_stash.js

+ 24 - 7
app/service/stage_stash.js

@@ -248,19 +248,27 @@ 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, minus: c.minus };
+                                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, no_value: c.no_value };
                                 const validQty = await this.ctx.service.stageChangeFinal.getChangeBillsValidQty(c.cbid);
-                                ncs.qty = validQty >= c.qty ? c.qty : validQty;
+                                ncs.qty = ncs.minus ? math.max(validQty, c.qty) : math.min(validQty, c.qty);
                                 insertChangeData.push(ncs);
-                                if (!ncs.minus) nps.qc_qty = await this.ctx.helper.add(nps.qc_qty, ncs.qty);
+                                if (!ncs.no_value) nps.qc_qty = await this.ctx.helper.add(nps.qc_qty, ncs.qty);
+                                if (ncs.minus) {
+                                    nps.negative_qc_qty = this.ctx.helper.add(nps.negative_qc_qty, ncs.qty);
+                                } else {
+                                    nps.positive_qc_qty = this.ctx.helper.add(nps.positive_qc_qty, ncs.qty);
+                                }
                             }
                         }
                         nbs.contract_qty = this.ctx.helper.add(nbs.contract_qty, nps.contract_qty);
                         nbs.qc_qty = this.ctx.helper.add(nbs.qc_qty, nps.qc_qty);
-
+                        nbs.positive_qc_qty = this.ctx.helper.add(nbs.positive_qc_qty, nps.qc_qty);
+                        nbs.negative_qc_qty = this.ctx.helper.add(nbs.negative_qc_qty, nps.qc_qty);
                     }
                     nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
                     nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
+                    nbs.positive_qc_tp = this.ctx.helper.mul(nbs.positive_qc_qty, b.unit_price, decimal.tp);
+                    nbs.negative_qc_tp = this.ctx.helper.mul(nbs.negative_qc_qty, b.unit_price, decimal.tp);
                 } else {
                     if (b.is_tp) {
                         nbs.contract_qty = 0;
@@ -271,17 +279,26 @@ module.exports = app => {
                         nbs.contract_qty = this.ctx.helper.round(d.contract_qty, decimal.qty);
                         nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
                         nbs.qc_qty = 0;
+                        nbs.positive_qc_qty = 0;
+                        nbs.negative_qc_qty = 0;
                         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, minus: c.minus };
+                                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, no_value: c.no_value };
                                 const validQty = await this.ctx.service.stageChangeFinal.getChangeBillsValidQty(c.cbid);
-                                ncs.qty = validQty >= c.qty ? c.qty : validQty;
+                                ncs.qty = ncs.minus ? math.max(validQty, c.qty) : math.min(validQty, c.qty);
                                 insertChangeData.push(ncs);
-                                if (!ncs.minus) nbs.qc_qty = await this.ctx.helper.add(nbs.qc_qty, ncs.qty);
+                                if (!ncs.no_value) nbs.qc_qty = this.ctx.helper.add(nbs.qc_qty, ncs.qty);
+                                if (ncs.minus) {
+                                    nbs.negative_qc_qty = this.ctx.helper.add(nbs.negative_qc_qty, ncs.qty);
+                                } else {
+                                    nbs.positive_qc_qty = this.ctx.helper.add(nbs.positive_qc_qty, ncs.qty);
+                                }
                             }
                         }
                         nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
+                        nbs.positive_qc_tp = this.ctx.helper.mul(nbs.positive_qc_qty, b.unit_price, decimal.tp);
+                        nbs.negative_qc_tp = this.ctx.helper.mul(nbs.negative_qc_qty, b.unit_price, decimal.tp);
                     }
                 }
                 insertBillsData.push(nbs);