Browse Source

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

laiguoran 3 years ago
parent
commit
b35e8e3c57
2 changed files with 11 additions and 13 deletions
  1. 5 3
      app/public/js/stage.js
  2. 6 10
      app/service/stage_change.js

+ 5 - 3
app/public/js/stage.js

@@ -391,9 +391,11 @@ $(document).ready(() => {
                 getColor: function (sheet, data, row, col, defaultColor) {
                     if (col.field === 'uamount') {
                         if (data.bamount > 0) {
-                            return data.uamount < 0 || data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
+                            const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
+                            return usedAmount < 0 || usedAmount > data.bamount ? '#ff6f5c' : defaultColor;
                         } else if (data.bamount < 0) {
-                            return data.uamount > 0 || data.uamount < data.vamount ? '#ff6f5c' : defaultColor;
+                            const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
+                            return usedAmount > 0 || usedAmount < data.bamount ? '#ff6f5c' : defaultColor;
                         } else {
                             return data.uamount ? '#ff6f5c' : defaultColor;
                         }
@@ -536,7 +538,7 @@ $(document).ready(() => {
                     c.uamount = uc.qty;
                     c.vamount = ZhCalc.add(c.vamount, uc.qty);
                 }
-                c.pre_amount = ZhCalc.sub(c.used_amount, c.uamount);
+                c.pre_amount = ZhCalc.sub(ZhCalc.add(c.used_amount, c.stage_used_amount), c.uamount);
             }
         }
         _loadChangeDetail(change) {

+ 6 - 10
app/service/stage_change.js

@@ -234,23 +234,21 @@ module.exports = app => {
                 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, nc ? nc.minus : oc.minus);
-                    if (!change.minus) {
-                        posQty = this.ctx.helper.add(posQty, change.qty);
-                    }
+                    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 {
-                    if (!oc.minus) {
-                        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), c.minus);
+                    const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
                     if (!change.minus) {
                         posQty = this.ctx.helper.add(posQty, change.qty);
                     }
@@ -261,9 +259,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 if (newChanges.length > 0) await transaction.insert(this.tableName, newChanges);
-                for (const c of updateChanges) {
-                    await transaction.update(this.tableName, c);
-                }
+                if (updateChanges.length > 0) await transaction.updateRows(this.tableName, c);
                 await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty);
                 await transaction.commit();
             } catch (err) {