فهرست منبع

修改正负变更值计算方式

ellisran 2 روز پیش
والد
کامیت
e59d65cb99
3فایلهای تغییر یافته به همراه54 افزوده شده و 23 حذف شده
  1. 17 6
      app/public/js/change_information.js
  2. 23 11
      app/service/change_audit_list.js
  3. 14 6
      db_script/change_valuation.js

+ 17 - 6
app/public/js/change_information.js

@@ -6400,7 +6400,13 @@ function calcChangePrice() {
             let unitPrice = 0;
             for (const c of list) {
                 if (c.spamount) {
-                    spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
+                    const amount = ZhCalc.round(c.spamount, findDecimal(c.unit));
+                    spamount = ZhCalc.add(spamount, amount);
+                    if (amount >= 0) {
+                        positive_amount = ZhCalc.add(positive_amount, amount);
+                    } else {
+                        negative_amount = ZhCalc.add(negative_amount, amount);
+                    }
                     unitPrice = c.unit_price;
                     if (c.is_valuation) {
                         valuation_amount = ZhCalc.add(valuation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
@@ -6416,16 +6422,21 @@ function calcChangePrice() {
                 }
             }
             const price = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit);
+            // 正负数量分别汇总后计算金额,避免相互抵消。
+            const positive_price = ZhCalc.round(ZhCalc.mul(positive_amount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit) || 0;
+            const negative_price = ZhCalc.round(ZhCalc.mul(negative_amount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit) || 0;
+            positive_tp = ZhCalc.add(positive_tp, positive_price);
+            negative_tp = ZhCalc.add(negative_tp, negative_price);
             const valuation_price = ZhCalc.round(ZhCalc.mul(valuation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
             const unvaluation_price = ZhCalc.round(ZhCalc.mul(unvaluation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
             valuation_tp = ZhCalc.add(valuation_tp, valuation_price);
             unvaluation_tp = ZhCalc.add(unvaluation_tp, unvaluation_price);
             new_tp = ZhCalc.add(new_tp, price);
-            if (price >= 0) {
-                positive_tp = ZhCalc.add(positive_tp, price);
-            } else {
-                negative_tp = ZhCalc.add(negative_tp, price);
-            }
+            // if (price >= 0) {
+            //     positive_tp = ZhCalc.add(positive_tp, price);
+            // } else {
+            //     negative_tp = ZhCalc.add(negative_tp, price);
+            // }
         } else {
             const list = _.filter(changeList, { gcl_id: g });
             for (const c of list) {

+ 23 - 11
app/service/change_audit_list.js

@@ -504,37 +504,49 @@ module.exports = app => {
                 if (g) {
                     const list = this._.filter(changeList, { gcl_id: g });
                     let spamount = 0;
+                    let positive_amount = 0;
+                    let negative_amount = 0;
                     let valuation_amount = 0;
                     let unvaluation_amount = 0;
                     let unitPrice = 0;
                     for (const cl of list) {
                         if (cl.spamount) {
                             spamount = this.ctx.helper.add(spamount, cl.spamount);
+                            if (cl.spamount >= 0) {
+                                positive_amount = this.ctx.helper.add(positive_amount, cl.spamount);
+                            } else {
+                                negative_amount = this.ctx.helper.add(negative_amount, cl.spamount);
+                            }
                             unitPrice = cl.unit_price;
                             if (cl.is_valuation) {
                                 valuation_amount = this.ctx.helper.add(valuation_amount, cl.spamount);
                             } else {
                                 unvaluation_amount = this.ctx.helper.add(unvaluation_amount, cl.spamount);
                             }
-                            // const posOrNePrice = this.ctx.helper.mul(cl.spamount, this.ctx.helper.round(cl.unit_price, up_decimal), tp_decimal);
-                            // if (posOrNePrice >= 0) {
-                            //     positive_tp = this.ctx.helper.add(positive_tp, posOrNePrice);
-                            // } else {
-                            //     negative_tp = this.ctx.helper.add(negative_tp, posOrNePrice);
-                            // }
+                            const posOrNePrice = this.ctx.helper.mul(cl.spamount, this.ctx.helper.round(cl.unit_price, up_decimal), tp_decimal);
+                            if (posOrNePrice >= 0) {
+                                positive_tp = this.ctx.helper.add(positive_tp, posOrNePrice);
+                            } else {
+                                negative_tp = this.ctx.helper.add(negative_tp, posOrNePrice);
+                            }
                         }
                     }
                     const price = this.ctx.helper.mul(spamount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal);
+                    // 正负数量分别汇总后计算金额,避免相互抵消。
+                    const positive_price = this.ctx.helper.mul(positive_amount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal) || 0;
+                    const negative_price = this.ctx.helper.mul(negative_amount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal) || 0;
+                    positive_tp = this.ctx.helper.add(positive_tp, positive_price);
+                    negative_tp = this.ctx.helper.add(negative_tp, negative_price);
                     const valuation_price = this.ctx.helper.mul(valuation_amount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal) || 0;
                     const unvaluation_price = this.ctx.helper.mul(unvaluation_amount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal) || 0;
                     valuation_tp = this.ctx.helper.add(valuation_tp, valuation_price);
                     unvaluation_tp = this.ctx.helper.add(unvaluation_tp, unvaluation_price);
                     total_price = this.ctx.helper.add(total_price, price);
-                    if (price >= 0) {
-                        positive_tp = this.ctx.helper.accAdd(positive_tp, price);
-                    } else {
-                        negative_tp = this.ctx.helper.accAdd(negative_tp, price);
-                    }
+                    // if (price >= 0) {
+                    //     positive_tp = this.ctx.helper.accAdd(positive_tp, price);
+                    // } else {
+                    //     negative_tp = this.ctx.helper.accAdd(negative_tp, price);
+                    // }
                 } else {
                     const list = this._.filter(changeList, { gcl_id: g });
                     for (const cl of list) {

+ 14 - 6
db_script/change_valuation.js

@@ -23,12 +23,20 @@ const checkChange = async function(change, decimal, precision = defaultInfo.defa
         if (g) {
             const list = _.filter(changeBills, { gcl_id: g });
             let spamount = 0;
+            let positive_amount = 0;
+            let negative_amount = 0;
             let valuation_amount = 0;
             let unvaluation_amount = 0;
             let unitPrice = 0;
             for (const c of list) {
                 if (c.spamount) {
-                    spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(c.unit, precision)));
+                    const amount = ZhCalc.round(c.spamount, findDecimal(c.unit, precision));
+                    spamount = ZhCalc.add(spamount, amount);
+                    if (amount >= 0) {
+                        positive_amount = ZhCalc.add(positive_amount, amount);
+                    } else {
+                        negative_amount = ZhCalc.add(negative_amount, amount);
+                    }
                     unitPrice = c.unit_price;
                     if (c.is_valuation) {
                         valuation_amount = ZhCalc.add(valuation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit, precision)));
@@ -38,11 +46,11 @@ const checkChange = async function(change, decimal, precision = defaultInfo.defa
                 }
             }
             const price = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit);
-            if (price >= 0) {
-                positive_tp = ZhCalc.add(positive_tp, price);
-            } else {
-                negative_tp = ZhCalc.add(negative_tp, price);
-            }
+            // 正负数量分别汇总后计算金额,避免相互抵消。
+            const positive_price = ZhCalc.round(ZhCalc.mul(positive_amount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit) || 0;
+            const negative_price = ZhCalc.round(ZhCalc.mul(negative_amount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit) || 0;
+            positive_tp = ZhCalc.add(positive_tp, positive_price);
+            negative_tp = ZhCalc.add(negative_tp, negative_price);
             const valuation_price = ZhCalc.round(ZhCalc.mul(valuation_amount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit) || 0;
             const unvaluation_price = ZhCalc.round(ZhCalc.mul(unvaluation_amount, ZhCalc.round(unitPrice, unitPriceUnit), totalPriceUnit), totalPriceUnit) || 0;
             valuation_tp = ZhCalc.add(valuation_tp, valuation_price);