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

Improves the code be expanding the scope of the volunteer benefits object, and providing correct calculations in Stand Time so that the stand time transaction is properly rendered on select change.

This commit is contained in:
Jonathan Rosenbaum 2017-08-07 22:42:55 +00:00
parent 609078a60d
commit 6bd1742c54

View File

@ -819,6 +819,7 @@ $(function() {
sold_to.change(function() { sold_to.change(function() {
var membership_obj; //reuse this object
if (this.value !== "no_selection") { if (this.value !== "no_selection") {
var expiration_date; var expiration_date;
@ -826,18 +827,19 @@ $(function() {
// Determine membership benefits of current transaction // Determine membership benefits of current transaction
$.post("json/transaction.php", { membership_benefits: 1, contact_id: this.value }, function (data) { $.post("json/transaction.php", { membership_benefits: 1, contact_id: this.value }, function (data) {
var obj = $.parseJSON(data); membership_obj = $.parseJSON(data);
var title = obj.normal_full_name + "\r\n" + var title = membership_obj.normal_full_name + "\r\n" +
obj.email + "\r\n" + membership_obj.email + "\r\n" +
obj.phone + "\r\n" + membership_obj.phone + "\r\n" +
"expiration: " + obj.expiration_date; "expiration: " + membership_obj.expiration_date;
$("#membership_discount").empty(); $("#membership_discount").empty();
amount.val(""); amount.val("");
if (typeof obj.expiration_date && obj.expiration_date !== undefined) { if (membership_transaction === true) { // if membership transaction
if (typeof membership_obj.expiration_date && membership_obj.expiration_date !== undefined) {
var exp = obj.expiration_date; var exp = membership_obj.expiration_date;
expiration_date = new Date(exp.split("-").toString()); expiration_date = new Date(exp.split("-").toString());
if (d >= expiration_date) { if (d >= expiration_date) {
amount.on("input", function () { amount.on("input", function () {
@ -853,22 +855,28 @@ $(function() {
} else if (d < expiration_date) { } else if (d < expiration_date) {
if ($("#paid_member").length === 1) { if ($("#paid_member").length === 1) {
$("#paid_member").prop("title",title).html("Paid Member"); $("#paid_member").prop("title",title).html("Paid Member");
amount.on("input", function () { amount.on("input", function () {
var discount = (price * (obj.membership_discount / 100).toFixed(2)).toFixed(2); var discount = (price * (membership_obj.membership_discount / 100).toFixed(2)).toFixed(2);
var discount_price = (price - discount).toFixed(2); var discount_price = (price - discount).toFixed(2);
//console.log("original " + price + " discount " + discount + " discounted " + discount_price); //console.log("original " + price + " discount " + discount + " discounted " + discount_price);
if ( $("#transaction_type").val() !== "Stand Time" ) {
$("#membership_discount").text("Member pays $" + discount_price).show(); $("#membership_discount").text("Member pays $" + discount_price).show();
} else {
$("#membership_discount").empty();
}
}); });
} else { } else {
$("#expired_membership").prop("id","paid_member").prop("title",title).html("Paid Member"); $("#expired_membership").prop("id","paid_member").prop("title",title).html("Paid Member");
amount.on("input", function () { amount.on("input", function () {
var discount = (price * (obj.membership_discount / 100).toFixed(2)).toFixed(2); var discount = (price * (membership_obj.membership_discount / 100).toFixed(2)).toFixed(2);
var discount_price = (price - discount).toFixed(2); var discount_price = (price - discount).toFixed(2);
//console.log("original " + price + " discount " + discount + " discounted " + discount_price); //console.log("original " + price + " discount " + discount + " discounted " + discount_price);
if ( $("#transaction_type").val() !== "Stand Time" ) {
$("#membership_discount").text("Member pays $" + discount_price).show(); $("#membership_discount").text("Member pays $" + discount_price).show();
} else {
$("#membership_discount").empty();
}
}); });
} }
} }
@ -882,24 +890,47 @@ $(function() {
$("#expired_membership").empty(); $("#expired_membership").empty();
} }
} }
} // if membership transaction
}); // end Is this a paid member }); // end Is this a paid member
// Stand Time - if a paid member, nothing is owed // Stand Time - if a paid member, nothing is owed
if ( $("#transaction_type").val() === "Stand Time" ) { if ( $("#transaction_type").val() === "Stand Time" ) {
$.post("json/transaction.php", { stand_time: 1, contact_id: this.value, shop_id: shop_id }, function (data) { $.post("json/transaction.php", { stand_time: 1, contact_id: this.value, shop_id: shop_id }, function (data) {
$("#stand_time_total").empty();
if (data) { if (data) {
var obj = $.parseJSON(data); var obj = $.parseJSON(data);
var current_membership, expiration_date;
amount.val(""); amount.val("");
if(!obj.membership || expiration_date) { if (membership_obj.expiration_date) {
var exp = membership_obj.expiration_date;
var expiration_date = new Date(exp.split("-").toString());
if (d >= expiration_date) {
current_membership = false;
} else if (d < expiration_date) {
current_membership = true;
}
} else {
current_membership = false;
}
// transaction has membership benefits
if (membership_transaction) {
amount.val("");
$("#stand_time_total").empty();
$(".ui-spinner").hide();
// not a member or an expired membership
if(current_membership === false) {
amount.val(obj.total + ".00"); // should improve this for amount values with digits amount.val(obj.total + ".00"); // should improve this for amount values with digits
price = obj.total; price = obj.total;
}
$("#stand_time_total").text(obj.hours + " hours " + obj.minutes + " minutes"); $("#stand_time_total").text(obj.hours + " hours " + obj.minutes + " minutes");
}
} else { } else {
amount.val(data); amount.val(data);
$("#stand_time_total").empty(); $("#stand_time_total").empty();
$(".ui-spinner").hide(); $(".ui-spinner").hide();
} }
}
}); // stand time pos }); // stand time pos
} }
@ -1031,21 +1062,11 @@ $(function() {
$("#redeemable_hours").spinner("disable"); $("#redeemable_hours").spinner("disable");
} }
// Membership benefits
/*
if ( obj.transactions_with_membership_benefits[$("#transaction_type").val()] === true ) {
if ($("#redeemable_hours").data("ui-spinner"))
} else {
if ($("#redeemable_hours").data("ui-spinner"))
}
*/
}); });
// control spinner behavior of transaction_type "Stand Time" // control spinner behavior of transaction_type "Stand Time"
if ($("#transaction_type").val() === "Stand Time" && $("#stand_time_total").is(":empty")) { if ($("#transaction_type").val() === "Stand Time" && $("#stand_time_total").is(":empty")) {
if ($("#redeemable_hours").data("ui-spinner"))
$("#redeemable_hours").spinner("disable"); $("#redeemable_hours").spinner("disable");
} else if ($("#transaction_type").val() === "Stand Time") { } else if ($("#transaction_type").val() === "Stand Time") {
if ($("#redeemable_hours").data("ui-spinner")) if ($("#redeemable_hours").data("ui-spinner"))
@ -1069,11 +1090,11 @@ $(function() {
var obj = $.parseJSON(data); var obj = $.parseJSON(data);
if (obj) { if (obj) {
var most_recent_bike_purchase = obj[obj.length -1]; var most_recent_bike_purchase = obj[obj.length -1];
console.log(most_recent_bike_purchase); //console.log(most_recent_bike_purchase);
var now = new Date(); var now = new Date();
var end = new Date(most_recent_bike_purchase.free_stand_time_period); var end = new Date(most_recent_bike_purchase.free_stand_time_period);
if ( now.getTime() <= end.getTime() ) { if ( now.getTime() <= end.getTime() ) {
console.log("Free Stand Time is still good"); //console.log("Free Stand Time is still good");
if ($("#redeemable_hours").data("ui-spinner")) { if ($("#redeemable_hours").data("ui-spinner")) {
$("#redeemable_hours").spinner("disable"); $("#redeemable_hours").spinner("disable");
} }
@ -1082,7 +1103,7 @@ $(function() {
$("#stand_time_total").text("Free Stand Time is good until " + end.toDateString()); $("#stand_time_total").text("Free Stand Time is good until " + end.toDateString());
} }
} else if ( now.getTime() > end.getTime() ) { } else if ( now.getTime() > end.getTime() ) {
console.log("Free Stand Time is now over"); //console.log("Free Stand Time is now over");
} }
} // end Free stand time } // end Free stand time