From 121da1d27b2c5c803c6d3d997c99f10e72ec8b42 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Fri, 7 Sep 2012 09:36:12 -0400 Subject: [PATCH] BUG 7070 "Sum function not calculating properly" SOLVED - SUM and AVG functions does not work correctly in Grids - No one takes into account the attribute "Decimal Separator" - Problem solved, SUM and AVG functions now take into account the attribute "Decimal Separator" * Available from version 2.0.44 --- gulliver/js/form/core/form.js | 39 ++++++++++++++++++++++------------- gulliver/js/grid/core/grid.js | 17 +++++++++------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/gulliver/js/form/core/form.js b/gulliver/js/form/core/form.js index 7f4581bec..138ff32e3 100755 --- a/gulliver/js/form/core/form.js +++ b/gulliver/js/form/core/form.js @@ -2215,21 +2215,32 @@ function G() }; //Gets number without mask - this.getValue = function(masked_num){ - var __DECIMAL_SEP = '.'; - var xNum = masked_num.split(''); - _num = ''; - for (u=0; u < xNum.length; u++){ - switch(xNum[u]){ - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case __DECIMAL_SEP: - _num += xNum[u]; - break; - } - } - return _num; - }; + this.getValue = function (elem) { + var arrayNum = elem.value().split(""); + var num = ""; + for (var i = 0; i <= arrayNum.length - 1; i++) { + switch (arrayNum[i]) { + case "0": + case "1": + case "2": + case "3": + case "4": + case "5": + case "6": + case "7": + case "8": + case "9": + num = num + arrayNum[i]; + break; + case elem.comma_separator: + num = num + "."; + break; + } + } + + return num; + }; //DEPRECATED this.toMask2 = function (num, mask, cursor) diff --git a/gulliver/js/grid/core/grid.js b/gulliver/js/grid/core/grid.js index c7290eeef..114feb6f5 100755 --- a/gulliver/js/grid/core/grid.js +++ b/gulliver/js/grid/core/grid.js @@ -932,10 +932,12 @@ var G_Grid = function(oForm, sGridName){ if (aAux[2] == nnName[2] && j <= (this.oGrid.rows.length-2)){ oAux=this.getElementByName(j, nnName[2]); var oAux2 = oAux.value().replace(/[$|a-zA-Z\s]/g,''); - if ( (oAux != null) && (oAux.value().trim() != '') && (oAux2)) { - fTotal += parseFloat(G.getValue(oAux.value())); + + if ((oAux != null) && (oAux.value().trim() != "") && (oAux2)) { + fTotal = fTotal + parseFloat(G.getValue(oAux)); } - j++; + + j = j + 1; } } /* @@ -964,13 +966,16 @@ var G_Grid = function(oForm, sGridName){ i = 1; fTotal = 0; aAux[2] = aAux[2].replace(']', ''); + while ((oAux = this.getElementByName(i, aAux[2]))) { - if ( oAux.value() != "" ) { - fTotal += parseFloat(G.getValue(oAux.value().trim() )); + if (oAux.value().trim() != "") { + fTotal = fTotal + parseFloat(G.getValue(oAux)); } + sMask = oAux.mask; - i++; + i = i + 1; } + i--; if (fTotal > 0) { fTotal = (fTotal / i).toFixed(2);