From e47498a00a36841e8d2f1fd473af6ea5711c409d Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Fri, 6 Feb 2015 09:50:57 +0000 Subject: [PATCH] Transaction history is now stored. 1). Next step, view history in the transaction when more than 1 transaction. --- js/transaction.js | 38 ++++++++++++++++++++++++++++++-------- json/transaction.php | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/js/transaction.js b/js/transaction.js index 8195aab..1ab57d9 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -456,7 +456,7 @@ $(function() { // On save (or close) check for errors - function save_or_close(button_choice) { + function save_or_close(button_choice, type_of_button) { //function error_handler(input,error_span,error,error_text,event) var err1 = 0, err2 = 0, err3 = 0, err4 = 0, err5 = 0, err6 = 0, err7 = 0, err8 = 0; @@ -526,7 +526,11 @@ $(function() { if ( !transaction_error.is(":visible") ) { transaction_error.show(); } - transaction_error.text("Correct errors below"); + if (type_of_button === "Save") { + transaction_error.text("Correct errors below"); + } else { + transaction_error.text("Correct errors below, and save before closing."); + } } else { transaction_error.hide(); } @@ -586,13 +590,16 @@ $(function() { var check_number_error = $("#check_number_error"); //var check_number = $("#check_number").on("input"); - var result = save_or_close($("#save_transaction")); - save_or_close($("#close_transaction")); // kind of a trick + var result = save_or_close($("#save_transaction"), "Save"); + // note: it is possible to close with all error conditions being satisfied, + // however, it is no biggy. + save_or_close($("#close_transaction"), "Close"); // Save history if (result === "Success") { - + transaction_id = $("input[name='transaction_id']").val(); + // store the transaction's history var transaction_history = []; var current_transaction = @@ -610,10 +617,25 @@ $(function() { check_number: $("#check_number").val(), anonymous: $("#anonymous").val() }; - //transaction_history[transaction_id].push(current_transaction); - console.dir(current_transaction); - } + // check for prior transactions + $.post("json/transaction.php",{ history_select: 1, transaction_id: transaction_id }, function(data) { + + if (data === "First Transaction") { + console.log(data); + transaction_history.push(current_transaction); + } else { + transaction_history = $.parseJSON(data); + transaction_history.push(current_transaction); + //var obj = $.parseJSON(data); + } + + } ); + + $.post("json/transaction.php",{ history_update: 1, transaction_id: transaction_id, history: transaction_history }); + + + } // End Save History diff --git a/json/transaction.php b/json/transaction.php index a40da25..bbfba48 100644 --- a/json/transaction.php +++ b/json/transaction.php @@ -89,6 +89,25 @@ $change_fund = CHANGE_FUND; } } + if(isset($_POST['history_select'])) { + $query = 'SELECT history FROM transaction_log WHERE transaction_id="' . $_POST['transaction_id'] . '";'; + $sql = mysql_query($query, $YBDB) or die(mysql_error()); + $result = mysql_fetch_assoc($sql); + if ($result['history'] == "") { + echo "First Transaction"; + } else { + echo $result['history']; + } + } + + if(isset($_POST['history_update'])) { + $json = json_encode($_POST['history']); + $query = "UPDATE transaction_log SET history='$json'" . + ' WHERE transaction_id="' . $_POST['transaction_id'] . '";'; + $result = mysql_query($query, $YBDB) or die(mysql_error()); + //echo ; + } + // check if start storage date has been changed since original shop date if(isset($_POST['date_startstorage'])) { $query = 'SELECT shops.date FROM transaction_log, shops WHERE transaction_id=' . $_POST['transaction_id'] .