Bläddra i källkod

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

Tony Kang 1 år sedan
förälder
incheckning
4e86acbc84

+ 9 - 33
app/lib/ledger.js

@@ -976,40 +976,13 @@ class checkData {
         }
     }
     _checkBillsOverRange(bills, posRange, isTz) {
-        // if (isTz && posRange.length > 0) {
-        //     for (const p of posRange) {
-        //         const end_contract_qty = this.add(p.pre_contract_qty, p.contract_qty);
-        //         if (end_contract_qty > p.quantity) return true;
-        //     }
-        //     return false;
-        // } else {
-        //     const end_qc_qty = this.add(bills.qc_qty, bills.pre_qc_qty);
-        //     const end_qc_tp = this.add(bills.qc_tp, bills.pre_qc_tp);
-        //     const end_gather_qty = this.sum([bills.contract_qty, bills.pre_contract_qty, end_qc_qty]);
-        //     const end_gather_tp = this.sum([bills.contract_tp, bills.pre_contract_tp, end_qc_tp]);
-        //     if (isTz) {
-        //         if (end_gather_qty) {
-        //             return !bills.quantity || Math.abs(end_gather_qty) > Math.abs(this.add(bills.quantity, end_qc_qty));
-        //         } else if (end_gather_tp) {
-        //             return !bills.total_price || Math.abs(end_gather_tp) > Math.abs(this.add(bills.total_price, end_qc_tp));
-        //         }
-        //     } else {
-        //         if (end_gather_qty) {
-        //             return !bills.deal_qty || Math.abs(end_gather_qty) > Math.abs(this.add(bills.deal_qty, end_qc_qty));
-        //         } else if (end_gather_tp) {
-        //             return !bills.deal_tp || Math.abs(end_gather_tp) > Math.abs(this.add(bills.deal_tp, end_qc_tp));
-        //         }
-        //     }
-        // }
         if (isTz && posRange.length > 0) {
             for (const p of posRange) {
                 const end_contract_qty = this.ctx.helper.add(p.pre_contract_qty, p.contract_qty);
                 if (!p.quantity && !!end_contract_qty) return true;
-                if (p.quantity > 0) {
-                    if (end_contract_qty > p.final_1_qty) return true;
-                } else {
-                    if (end_contract_qty < p.final_1_qty || end_contract_qty > 0) return true;
-                }
+                return p.quantity > 0
+                    ? end_contract_qty > p.quantity
+                    : (p.final_1_qty ? end_contract_qty > p.final_1_qty : end_contract_qty < p.final_1_qty || p.final_1_qty > 0);
             }
         }
         const end_contract_qty = this.ctx.helper.add(bills.contract_qty, bills.pre_contract_qty);
@@ -1019,9 +992,12 @@ class checkData {
             if (!compare_tp) return !!end_contract_tp;
             return compare_tp >= 0 ? end_contract_tp > compare_tp : end_contract_tp < compare_tp || end_contract_tp > 0;
         } else {
-            const compare_qty = isTz ? bills.final_1_qty : bills.deal_final_1_qty;
-            if (!compare_qty) return !!end_contract_qty;
-            return compare_qty >= 0 ? end_contract_qty > compare_qty : end_contract_qty < compare_qty || end_contract_qty > 0;
+            const compare_qty1 = isTz ? bills.quantity : bills.deal_qty;
+            const compare_qty2 = isTz ? bills.final_1_qty : bills.deal_final_1_qty;
+            if (!compare_qty1) return !!end_contract_qty;
+            return compare_qty1 > 0
+                ? end_contract_qty > compare_qty2
+                : (compare_qty2 > 0 ? end_contract_qty > compare_qty2 : end_contract_qty < compare_qty2 || end_contract_qty > 0);
         }
     }
     checkOverRange() {

+ 13 - 1
app/public/js/shares/tree_expr_calc.js

@@ -46,6 +46,17 @@ const TreeExprCalc = (function(){
             calcRela.exprCacheFields = calcRela.exprCacheKey.map(x => { return getCalcField(x); });
         }
         calcRela.errorMsg = setting.errorMsg || true;
+        calcRela.precision = setting.precision;
+    };
+    const findPrecision = function(list, unit) {
+        if (!unit) return list.other;
+
+        for (const p in list) {
+            if (list[p].unit && list[p].unit === unit) {
+                return list[p];
+            }
+        }
+        return list.other;
     };
     const checkExprValid = function(expr, invalidOrders = []) {
         if (!expr) return [true, ''];
@@ -188,7 +199,8 @@ const TreeExprCalc = (function(){
     const addCache = function(expr) {
         const cache = { id: expr.id };
         if (expr.calcField === 'qty') {
-            cache[calcRela.calcField.qty] = ZhCalc.round(expr.value, calcRela.decimal.qty);
+            const precision = findPrecision(calcRela.precision, expr.unit);
+            cache[calcRela.calcField.qty] = ZhCalc.round(expr.value, precision.value);
             cache[calcRela.calcField.tp] = ZhCalc.mul(cache[calcRela.calcField.qty], expr.unit_price, calcRela.decimal.tp);
         } else if (expr.calcField === 'tp') {
             cache[calcRela.calcField.qty] = 0;

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

@@ -1693,7 +1693,7 @@ $(document).ready(() => {
                         const posRange = stagePos.getLedgerPos(x.id);
                         if (posRange && posRange.length > 0) return false;
                         return !!x.calc_expr;
-                    }).map(x => { return { id: x.id, expr: x.calc_expr, unit_price: x.unit_price, calcField: x.is_tp ? 'tp' : 'qty' }});
+                    }).map(x => { return { id: x.id, expr: x.calc_expr, unit: x.unit, unit_price: x.unit_price, calcField: x.is_tp ? 'tp' : 'qty' }});
                     if (calcExpr.length === 0) {
                         toastr.warning('沒有可计算的公式');
                         return;
@@ -2332,6 +2332,7 @@ $(document).ready(() => {
         TreeExprCalc.init({
             tree: stageTree,
             decimal: tenderInfo.decimal,
+            precision: tenderInfo.precision,
             calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
             exprFieldsIndex: {
                 tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',

+ 2 - 2
app/service/stage_change_final.js

@@ -124,8 +124,8 @@ module.exports = app => {
 
             return changeBills.filter(cb => {
                 cb.qty = parseFloat(cb.samount);
-                const qtyDecimal = self.ctx.helper.findDecimal(changeBills.unit);
-                cb.limitQty = self.ctx.helper.mul(cb.qty, self.ctx.helper.div(changeBills.delimit, 100, 2), qtyDecimal);
+                const qtyDecimal = self.ctx.helper.findDecimal(cb.unit);
+                cb.limitQty = self.ctx.helper.mul(cb.qty, self.ctx.helper.div(cb.delimit, 100, 2), qtyDecimal);
                 cb.valid_qty = self.ctx.helper.sub(cb.limitQty, cb.used_qty);
                 return cb.valid_qty;
             });