1
0
mirror of https://github.com/fspc/Yellow-Bike-Database.git synced 2025-02-22 08:53:23 -05:00

Yeah, working mysql/json logic is in place!

This commit is contained in:
Jonathan Rosenbaum 2015-01-03 07:50:48 +00:00
parent d8b74b7a79
commit 890b8f1b15
3 changed files with 69 additions and 46 deletions

View File

@ -14,14 +14,14 @@ $(function() {
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*="' + this.name + '"]').hide();
console.log(this.name); console.log(this.name);
$.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*="' + this.name + '"]').show();
$.post("json/transaction.php",{ paid: 0, transaction_id: this.name } ); $.post("json/transaction.php",{ paid: 0, transaction_id: this.name } );
} }
}); });

View File

@ -31,48 +31,67 @@ mysql_select_db($database_YBDB, $YBDB);
// Deposit Calculator // Deposit Calculator
if (isset($_POST['deposit'])) { if (isset($_POST['deposit'])) {
print_r($_POST);
}
/* $visible_count = count($_POST['deposit']);
transaction_id, date_startstorage, date,transaction_type, amount, description, sold_to, sold_by, quantity, shop_id, paid $c = $visible_count - 1;
$deposit = $_POST['deposit'];
Always do transactions from the first visible Deposit to the next Deposit. $query = 'SELECT COUNT(transaction_type) AS "count" FROM transaction_log WHERE transaction_type="Deposit";';
Variations: $sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
Based on the results of ..
SELECT COUNT(transaction_type) FROM transaction_log WHERE transaction_type="Deposit";
However, if there are no invisible deposits go to the end from the last visible deposit, so do a comparison with if ( $visible_count == $result["count"] ) { // 1 or more deposits, and all deposits are visible
visible deposits, to find out if there is 1 unique non-visible deposit.
COUNT == 1 foreach ( $deposit as $key => $value ) {
1. Just beginning to use YBDB: Calculation for 1 visible Deposit all the way to the first existing transaction if ( $c > $key ) {
$query = 'SELECT SUM(IF(payment_type="check", amount, 0)) AS "check",
SUM(IF(payment_type="credit", amount, 0)) AS "credit",
SUM(IF(payment_type="cash", amount, 0)) AS "cash"
FROM transaction_log WHERE paid=1 AND transaction_id <' . $deposit[$key] . ' AND transaction_id >'
. $deposit[$key + 1] . ';';
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
} else {
$query = 'SELECT SUM(IF(payment_type="check", amount, 0)) AS "check",
SUM(IF(payment_type="credit", amount, 0)) AS "credit",
SUM(IF(payment_type="cash", amount, 0)) AS "cash"
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);
SELECT SUM(IF(payment_type="check", amount, 0.00)) AS "Check", }
SUM(IF(payment_type="credit", amount, 0.00)) AS "Credit",
SUM(IF(payment_type="cash", amount, 0.00)) AS "Cash"
FROM transaction_log WHERE paid=1 AND transaction_id < 74;
(return sum)
COUNT > 1 echo json_encode($result);
2. Calculation for 1 or more visible Deposits to next non-visible Deposit or no non-visible Deposit
If no hidden, loop for visible deposits (#2)) ($v) with last one to end (#1 logic, except use $v variable); else;
loop for visible deposits to the next hidden deposit (#2).
foreach ( my $v in @visible_deposits ) {
SELECT SUM(IF(payment_type="check", amount, 0.00)) AS "Check",
SUM(IF(payment_type="credit", amount, 0.00)) AS "Credit",
SUM(IF(payment_type="cash", amount, 0.00)) AS "Cash"
FROM transaction_log WHERE paid=1 AND transaction_id < $v AND transaction_id >
(SELECT transaction_id FROM transaction_log WHERE transaction_type="Deposit" ORDER BY transaction_id LIMIT 1);
push @sum, answer;
} }
} else { // more deposits than visible
*/ $limit = $visible_count + 1;
$query = 'SELECT transaction_id FROM transaction_log
WHERE transaction_type="Deposit" ORDER BY transaction_id DESC LIMIT ' . $limit . ';';
$sql = mysql_query($query, $YBDB) or die(mysql_error());
while ( $result = mysql_fetch_assoc($sql) ) {
$transaction_id[] = $result['transaction_id'];
}
foreach ( $transaction_id as $key => $value ) {
if ($key <= $c) {
$query = 'SELECT SUM(IF(payment_type="check", amount, 0)) AS "check",
SUM(IF(payment_type="credit", amount, 0)) AS "credit",
SUM(IF(payment_type="cash", amount, 0)) AS "cash"
FROM transaction_log WHERE paid=1 AND transaction_id <' . $transaction_id[$key] . ' AND transaction_id >'
. $transaction_id[$key + 1] . ';';
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
echo json_encode($result);
}
} // foreach
} // end else for invisibles
}
?> ?>

View File

@ -64,7 +64,8 @@ if($_GET['trans_type']=='all_types'){
if($_GET['record_count']>0){ if($_GET['record_count']>0){
$record_count = $_GET['record_count']; $record_count = $_GET['record_count'];
} else { } else {
$record_count = $number_of_transactions;} $record_count = $number_of_transactions;
}
// This is the recordset for the list of logged transactions // This is the recordset for the list of logged transactions
@ -130,6 +131,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormNew")) {
$totalRows_Recordset4 = mysql_num_rows($Recordset4); $totalRows_Recordset4 = mysql_num_rows($Recordset4);
$newtrans = $row_Recordset4['newtrans']; //This field is used to set edit box preferences $newtrans = $row_Recordset4['newtrans']; //This field is used to set edit box preferences
$LoadPage = $_SERVER['PHP_SELF'] . "?trans_id={$newtrans}"; $LoadPage = $_SERVER['PHP_SELF'] . "?trans_id={$newtrans}";
header(sprintf("Location: %s", $LoadPage)); header(sprintf("Location: %s", $LoadPage));
} // end Form Submit New Transaction } // end Form Submit New Transaction
@ -163,6 +165,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit") && ($_PO
mysql_select_db($database_YBDB, $YBDB); mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error()); $Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
$trans_id = $_POST['transaction_id']; $trans_id = $_POST['transaction_id'];
header(sprintf("Location: %s",$editFormAction . "?trans_id={$trans_id}" )); //$editFormAction header(sprintf("Location: %s",$editFormAction . "?trans_id={$trans_id}" )); //$editFormAction
} }
@ -456,6 +459,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
} else { } else {
echo "<a href=\"{$_SERVER['PHP_SELF']}?trans_id={$record_trans_id}\">edit</a></td>"; echo "<a href=\"{$_SERVER['PHP_SELF']}?trans_id={$record_trans_id}\">edit</a></td>";
} }
$trans_url = "";
?> ?>
<td><input class="paid" type="checkbox" name="<?php $ti = $row_Recordset1['transaction_id']; echo $ti; ?>" <td><input class="paid" type="checkbox" name="<?php $ti = $row_Recordset1['transaction_id']; echo $ti; ?>"
value="<?php echo $row_Recordset1['paid'];?>" value="<?php echo $row_Recordset1['paid'];?>"