diff --git a/css/transactions.css b/css/transactions.css index d61b285..335ac9a 100644 --- a/css/transactions.css +++ b/css/transactions.css @@ -91,4 +91,13 @@ input[value=Save]:focus, input[value=Close]:focus { padding: 0px 10px 0px 10px; } +/* for memberships */ +#expired_membership { + color: orchid; +} + +#paid_member { + color: blue; +} + diff --git a/js/transaction.js b/js/transaction.js index 418151f..b069e71 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -652,6 +652,48 @@ $(function() { var check_number_error = $("#check_number_error"); //var check_number = $("#check_number").on("input"); + // Things to do before pressing the save / close button + + // Membership and Volunteer Benefits + var d = new Date(); + + sold_to.change(function() { + + if (this.value !== "no_selection") { + + // Is this a paid member? + $.post("json/transaction.php", { membership_and_volunteer_benefits: 1, contact_id: this.value }, function (data) { + + var obj = $.parseJSON(data); + if (typeof obj.expiration_date && obj.expiration_date !== undefined) { + var exp = obj.expiration_date; + var expiration_date = new Date(exp.split("-").toString()); + if (d >= expiration_date) { + if ($("#expired_membership").length === 1) { + $("#expired_membership").html("Expired Membership"); + } else { + $("#paid_member").prop("id","expired_membership").html("Expired Membership"); + } + } else if (d < expiration_date) { + if ($("#paid_member").length === 1) { + $("#paid_member").html("Paid Member"); + } else { + $("#expired_membership").prop("id","paid_member").html("Paid Member"); + } + } + } else { + if ($("#paid_member").length === 1) { + $("#paid_member").empty(); + } else { + $("#expired_membership").empty(); + } + } + }); // post + + } // if not no_selection + + }); // sold_to.change + // note: it is possible to close with all error conditions being satisfied, // however, it is no biggy. save_or_close($("#close_transaction"), "Close"); diff --git a/json/transaction.php b/json/transaction.php index 876414a..6f813d4 100644 --- a/json/transaction.php +++ b/json/transaction.php @@ -14,8 +14,8 @@ $csv_directory = CSV_DIRECTORY; } else { echo "no_shop"; } - } - + } + // update whether paid or not if(isset($_POST['paid'])) { if ($_POST['paid'] == 1) { @@ -76,6 +76,22 @@ $csv_directory = CSV_DIRECTORY; echo json_encode($result); } + // Membership and Volunteer Benefits + if (isset($_POST['membership_and_volunteer_benefits'])) { + + $query = "SELECT contacts.contact_id, CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name, + CONCAT(first_name, ' ', last_name) AS normal_full_name, contacts.email AS email, contacts.phone AS phone, + transaction_log.date AS membership_start, SUBSTRING_INDEX(DATE_ADD(date, INTERVAL 365 DAY), ' ', 1) AS expiration_date + FROM transaction_log LEFT JOIN contacts ON transaction_log.sold_to = contacts.contact_id + WHERE SUBSTRING_INDEX(date, ' ', 1) <= DATE_ADD(date, INTERVAL 365 DAY) + AND (transaction_type='Memberships' AND paid=1) AND contact_id=" . + $_POST['contact_id'] . ";"; + + $sql = mysql_query($query, $YBDB) or die(mysql_error()); + $result = mysql_fetch_assoc($sql); + echo json_encode($result); + } + // Anonymous transaction - save and communicate back settings if(isset($_POST['anonymous'])) { @@ -103,7 +119,7 @@ $csv_directory = CSV_DIRECTORY; echo $history_result; } } - + // Transaction history - update transaction history // Note: This could easily be turned into its own table with a foreign key // referencing transaction_log.transaction_id, but most transactions