Explorar o código

本期合同计量数量,公式计算相关

MaiXinRong hai 1 ano
pai
achega
1f6a089932

+ 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.exprCacheFields = calcRela.exprCacheKey.map(x => { return getCalcField(x); });
         }
         }
         calcRela.errorMsg = setting.errorMsg || true;
         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 = []) {
     const checkExprValid = function(expr, invalidOrders = []) {
         if (!expr) return [true, ''];
         if (!expr) return [true, ''];
@@ -188,7 +199,8 @@ const TreeExprCalc = (function(){
     const addCache = function(expr) {
     const addCache = function(expr) {
         const cache = { id: expr.id };
         const cache = { id: expr.id };
         if (expr.calcField === 'qty') {
         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);
             cache[calcRela.calcField.tp] = ZhCalc.mul(cache[calcRela.calcField.qty], expr.unit_price, calcRela.decimal.tp);
         } else if (expr.calcField === 'tp') {
         } else if (expr.calcField === 'tp') {
             cache[calcRela.calcField.qty] = 0;
             cache[calcRela.calcField.qty] = 0;

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

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

+ 1 - 0
app/service/stage_change.js

@@ -789,6 +789,7 @@ module.exports = app => {
                 cbid.push(x.cbid);
                 cbid.push(x.cbid);
             });
             });
             const validChangeBills = await this.ctx.service.stageChangeFinal.getListChangeBillsValidQty(tender.id, cbid);
             const validChangeBills = await this.ctx.service.stageChangeFinal.getListChangeBillsValidQty(tender.id, cbid);
+            console.log(cbid, validChangeBills);
             validChangeBills.forEach(x => {
             validChangeBills.forEach(x => {
                 x.billsPos = data.find(y => { return x.id === y.cbid; });
                 x.billsPos = data.find(y => { return x.id === y.cbid; });
             });
             });

+ 2 - 2
app/service/stage_change_final.js

@@ -124,8 +124,8 @@ module.exports = app => {
 
 
             return changeBills.filter(cb => {
             return changeBills.filter(cb => {
                 cb.qty = parseFloat(cb.samount);
                 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);
                 cb.valid_qty = self.ctx.helper.sub(cb.limitQty, cb.used_qty);
                 return cb.valid_qty;
                 return cb.valid_qty;
             });
             });