mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2025-02-22 00:53:22 -05:00
Cleans up the code, and allows proper behavior.
1. async:false because mysql can be slow 2. improved a regexp causing weird behavior with edit button
This commit is contained in:
parent
511dc81471
commit
d40dfca931
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
$.ajaxSetup({async:false}); // best to do this in $.ajax,
|
||||||
|
// but all ajax needs to be synchronous in this program because of the use of mysql
|
||||||
|
|
||||||
$("select[name='transaction_type']").attr("tabindex",1);
|
$("select[name='transaction_type']").attr("tabindex",1);
|
||||||
$("select[name='transaction_type']").focus();
|
$("select[name='transaction_type']").focus();
|
||||||
$("input[value='Create Transaction']").attr("tabindex",2);
|
$("input[value='Create Transaction']").attr("tabindex",2);
|
||||||
@ -12,58 +15,52 @@ $(function() {
|
|||||||
$(":checked").parent("td").prev().children().hide();
|
$(":checked").parent("td").prev().children().hide();
|
||||||
$(".paid").click(function() {
|
$(".paid").click(function() {
|
||||||
|
|
||||||
$.ajaxSetup({async:false});
|
|
||||||
|
|
||||||
if ($(this).prop("checked")) {
|
if ($(this).prop("checked")) {
|
||||||
|
|
||||||
$(this).closest("tr").css("background-color","#E6E7E6");
|
$(this).closest("tr").css("background-color","#E6E7E6");
|
||||||
$('[href*="' + this.name + '"]').hide();
|
$('[href*="trans_id=' + this.name + '"]').hide();
|
||||||
$.post("json/transaction.php",{ paid: 1, transaction_id: this.name } );
|
$.post("json/transaction.php",{ paid: 1, transaction_id: this.name } );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$(this).closest("tr").css("background-color","transparent");
|
$(this).closest("tr").css("background-color","transparent");
|
||||||
$('[href*="' + this.name + '"]').show();
|
$('[href*="trans_id=' + this.name + '"]').show();
|
||||||
$.post("json/transaction.php",{ paid: 0, transaction_id: this.name } );
|
$.post("json/transaction.php",{ paid: 0, transaction_id: this.name } );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deposit Calculator
|
// Deposit Calculator for clicks
|
||||||
|
deposit_calculator();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Deposit Calculator on page reload
|
||||||
|
if ( $(".paid").length ) { // any transactions?
|
||||||
|
|
||||||
|
deposit_calculator();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deposit Calculator function
|
||||||
|
function deposit_calculator() {
|
||||||
|
|
||||||
var deposit = {};
|
var deposit = {};
|
||||||
$(".deposit input").each(function(count){
|
$(".deposit input").each(function(count){
|
||||||
deposit[count] = this.name;
|
deposit[count] = this.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$.post("json/transaction.php",{"deposit": deposit}, function(data) {
|
$.post("json/transaction.php",{"deposit": deposit}, function(data) {
|
||||||
var obj = $.parseJSON(data);
|
var obj = $.parseJSON(data);
|
||||||
$.each(obj,function(k,v){
|
$.each(obj,function(k,v){
|
||||||
//console.log(k + "= Cash: " + v.cash + " Check: " + v.check + " Credit: " + v.credit + "\n");
|
//console.log(k + "= Cash: " + v.cash + " Check: " + v.check + " Credit: " + v.credit + "\n");
|
||||||
$("#" + k + "_cash span").text("$" + v.cash);
|
$("#" + k + "_cash span").text("$" + v.cash);
|
||||||
$("#" + k + "_check span").text("$" + v.check);
|
$("#" + k + "_check span").text("$" + v.check);
|
||||||
$("#" + k + "_credit span").text("$" + v.credit);
|
$("#" + k + "_credit span").text("$" + v.credit);
|
||||||
|
var sum = Number(v.check) + Number(v.cash);
|
||||||
|
$("#" + k + "_sum span").text("$" + sum);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
$.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}, 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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,9 @@ mysql_select_db($database_YBDB, $YBDB);
|
|||||||
$result = mysql_fetch_assoc($sql);
|
$result = mysql_fetch_assoc($sql);
|
||||||
|
|
||||||
|
|
||||||
if ( $visible_count == $result["count"] ) { // 1 or more deposits, and all deposits are visible
|
if ( $visible_count == $result["count"] ) { // 1 or more deposits, and all deposits are visible
|
||||||
|
|
||||||
|
|
||||||
foreach ( $deposit as $key => $value ) {
|
foreach ( $deposit as $key => $value ) {
|
||||||
if ( $c > $key ) {
|
if ( $c > $key ) {
|
||||||
$query = 'SELECT SUM(IF(payment_type="check", amount, 0)) AS "check",
|
$query = 'SELECT SUM(IF(payment_type="check", amount, 0)) AS "check",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user