Browse Source

The corrects a hereunto unknown very minor bug where data is not being check for value in the deposit calculator function.

devel
Jonathan Rosenbaum 8 years ago
parent
commit
7fb848f7d4
  1. 52
      js/transaction.js

52
js/transaction.js

@ -450,36 +450,38 @@ $(function() {
$.post("json/transaction.php",{"deposit": deposit}, function(data) { $.post("json/transaction.php",{"deposit": deposit}, function(data) {
var obj = $.parseJSON(data); if (data) {
var obj = $.parseJSON(data);
$.each(obj,function(k,v){
// Cash / Check / Credit $.each(obj,function(k,v){
$("#" + k + "_cash span").text("$" + payment_result(v.cash));
$("#" + k + "_check span").text("$" + payment_result(v.check)); // Cash / Check / Credit
$("#" + k + "_credit span").text("$" + payment_result(v.credit)); $("#" + k + "_cash span").text("$" + payment_result(v.cash));
$("#" + k + "_check span").text("$" + payment_result(v.check));
// Sum $("#" + k + "_credit span").text("$" + payment_result(v.credit));
var sum = Number(v.check) + Number(v.cash);
$("#" + k + "_sum span").text("$" + sum.toFixed(2)); // Sum
var sum = Number(v.check) + Number(v.cash);
// Difference (regexp - good up to 6 places and 2 digits) $("#" + k + "_sum span").text("$" + sum.toFixed(2));
var deposit_amount = $('input[name="' + k + '"]').parent().prev().prev().text().replace(/\$(\d*(?:,\d{3})*\.\d*)\s+/, "$1" );
deposit_amount = deposit_amount.replace(/,/, ""); // Difference (regexp - good up to 6 places and 2 digits)
if (deposit_amount != 0) { var deposit_amount = $('input[name="' + k + '"]').parent().prev().prev().text().replace(/\$(\d*(?:,\d{3})*\.\d*)\s+/, "$1" );
var diff = deposit_amount - sum; deposit_amount = deposit_amount.replace(/,/, "");
$("#" + k + "_difference span").text("$"+ diff.toFixed(2)); if (deposit_amount != 0) {
if ( diff == 0 ) { var diff = deposit_amount - sum;
$("#" + k + "_difference").css("color","green"); $("#" + k + "_difference span").text("$"+ diff.toFixed(2));
if ( diff == 0 ) {
$("#" + k + "_difference").css("color","green");
} else {
$("#" + k + "_difference").css("color","red");
}
} else { } else {
$("#" + k + "_difference").css("color","red"); $("#" + k + "_difference span").text("n/a");
} }
} else {
$("#" + k + "_difference span").text("n/a");
}
});
}); // each
} // if data
}); // end function }); // end function

Loading…
Cancel
Save