From 511dc81471cff5d9cf0ad75668fa2ed9b0886204 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Sat, 3 Jan 2015 11:00:33 +0000 Subject: [PATCH] Added some human interaction with Deposit Calculator. --- js/transaction.js | 35 ++++++++++++++++++++++++++++++++--- json/transaction.php | 14 ++++++++------ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/js/transaction.js b/js/transaction.js index 1c93c1a..5a82106 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -11,11 +11,13 @@ $(function() { // paid or not? $(":checked").parent("td").prev().children().hide(); $(".paid").click(function() { + + $.ajaxSetup({async:false}); + if ($(this).prop("checked")) { $(this).closest("tr").css("background-color","#E6E7E6"); $('[href*="' + this.name + '"]').hide(); - console.log(this.name); $.post("json/transaction.php",{ paid: 1, transaction_id: this.name } ); } else { @@ -24,17 +26,44 @@ $(function() { $('[href*="' + this.name + '"]').show(); $.post("json/transaction.php",{ paid: 0, transaction_id: this.name } ); } + + // Deposit Calculator + var deposit = {}; + $(".deposit input").each(function(count){ + deposit[count] = this.name; + }); + + + $.post("json/transaction.php",{"deposit": deposit}, function(data) { + var obj = $.parseJSON(data); + $.each(obj,function(k,v){ + //console.log(k + "= Cash: " + v.cash + " Check: " + v.check + " Credit: " + v.credit + "\n"); + $("#" + k + "_cash span").text("$" + v.cash); + $("#" + k + "_check span").text("$" + v.check); + $("#" + k + "_credit span").text("$" + v.credit); + }); + }); + $.ajaxSetup({async:true}); + }); // Deposit Calculator if ( $(".paid").length ) { // any transactions? - + var deposit = {}; $(".deposit input").each(function(count){ deposit[count] = this.name; }); - $.post("json/transaction.php",{"deposit": deposit}); + $.post("json/transaction.php",{"deposit": deposit}, function(data) { + var obj = $.parseJSON(data); + $.each(obj,function(k,v){ + //console.log(k + "= Cash: " + v.cash + " Check: " + v.check + " Credit: " + v.credit + "\n"); + $("#" + k + "_cash span").text("$" + v.cash); + $("#" + k + "_check span").text("$" + v.check); + $("#" + k + "_credit span").text("$" + v.credit); + }); + }); } diff --git a/json/transaction.php b/json/transaction.php index 2548d02..b8c7fd3 100644 --- a/json/transaction.php +++ b/json/transaction.php @@ -52,6 +52,7 @@ mysql_select_db($database_YBDB, $YBDB); . $deposit[$key + 1] . ';'; $sql = mysql_query($query, $YBDB) or die(mysql_error()); $result = mysql_fetch_assoc($sql); + $result_obj[$deposit[$key]] = $result; } else { $query = 'SELECT SUM(IF(payment_type="check", amount, 0)) AS "check", SUM(IF(payment_type="credit", amount, 0)) AS "credit", @@ -59,12 +60,12 @@ mysql_select_db($database_YBDB, $YBDB); FROM transaction_log WHERE paid=1 AND transaction_id <' . $deposit[$key] . ';'; $sql = mysql_query($query, $YBDB) or die(mysql_error()); $result = mysql_fetch_assoc($sql); - + $result_obj[$deposit[$key]] = $result; } - - echo json_encode($result); } + echo json_encode($result_obj); + } else { // more deposits than visible $limit = $visible_count + 1; @@ -86,10 +87,11 @@ mysql_select_db($database_YBDB, $YBDB); . $transaction_id[$key + 1] . ';'; $sql = mysql_query($query, $YBDB) or die(mysql_error()); $result = mysql_fetch_assoc($sql); - echo json_encode($result); - } + $result_obj[$transaction_id[$key]] = $result; + } - } // foreach + } // foreach + echo json_encode($result_obj); } // end else for invisibles }