mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2025-02-22 08:53:23 -05:00
Adds performance improvements for volunteer_benefits closing #46
* Major changes, will test more, but appears to be working very well.
This commit is contained in:
parent
33c5e60969
commit
d0028b5779
155
js/shop.js
155
js/shop.js
@ -89,49 +89,57 @@ $(function(){
|
|||||||
|
|
||||||
|
|
||||||
// could have done this in php, but this separates out the view logic
|
// could have done this in php, but this separates out the view logic
|
||||||
var d = new Date();
|
var membership_ids, volunteer_ids;
|
||||||
volunteer_status();
|
var last_index = $("#shop_log tr[id]").length;
|
||||||
|
|
||||||
var membership_ids;
|
|
||||||
var last_index = $("#shop_log tr").length;
|
|
||||||
if (last_index) {
|
if (last_index) {
|
||||||
last_index = last_index -1;
|
last_index = last_index - 1;
|
||||||
$.each($("#shop_log tr"), function(index) {
|
$.each($("#shop_log tr[id]"), function(index) {
|
||||||
|
|
||||||
if (this.id) {
|
if (this.id) {
|
||||||
|
|
||||||
var id = this.id;
|
var id = this.id;
|
||||||
|
|
||||||
// 2 tr for first created login
|
if (last_index <= 1) {
|
||||||
if (last_index <= 2) {
|
membership_ids = "contact_id=" + id;
|
||||||
membership_ids = "contact_id=" + id;
|
|
||||||
}
|
|
||||||
else if (!membership_ids) {
|
|
||||||
membership_ids = "(contact_id=" + id + " OR ";
|
|
||||||
} else if ( index === last_index) {
|
|
||||||
membership_ids += "contact_id=" + id + ")";
|
|
||||||
} else {
|
|
||||||
membership_ids += "contact_id=" + id + " OR ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (!membership_ids) {
|
||||||
|
membership_ids = "(contact_id=" + id + " OR ";
|
||||||
|
} else if ( index === last_index) {
|
||||||
|
membership_ids += "contact_id=" + id + ")";
|
||||||
|
} else {
|
||||||
|
membership_ids += "contact_id=" + id + " OR ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (membership_ids) {
|
||||||
|
volunteer_ids = membership_ids.replace(/contact_id/g,"contacts.contact_id");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var d = new Date();
|
||||||
|
volunteer_status(volunteer_ids);
|
||||||
membership_status(membership_ids);
|
membership_status(membership_ids);
|
||||||
|
|
||||||
// volunteer status
|
// volunteer status
|
||||||
function volunteer_status() {
|
function volunteer_status(contacts) {
|
||||||
|
|
||||||
$.each($("#shop_log tr"), function() {
|
var all_members_obj; //reuse this object
|
||||||
|
|
||||||
if (this.id) {
|
if (contacts) {
|
||||||
var id = this.id;
|
|
||||||
|
|
||||||
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: this.id }, function (data) {
|
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: contacts }, function (data) {
|
||||||
|
|
||||||
|
all_members_obj = $.parseJSON(data);
|
||||||
|
|
||||||
|
$.each(all_members_obj, function() {
|
||||||
|
|
||||||
var year = d.getFullYear();
|
var year = d.getFullYear();
|
||||||
var bikes_earned = 0;
|
var bikes_earned = 0;
|
||||||
var volunteer_hours_redeemed = 0;
|
var volunteer_hours_redeemed = 0;
|
||||||
var obj = $.parseJSON(data);
|
var obj = this;
|
||||||
|
|
||||||
|
|
||||||
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
|
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
|
||||||
if (obj.volunteer) {
|
if (obj.volunteer) {
|
||||||
@ -217,9 +225,34 @@ $(function(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}); // post volunteer benefits
|
}); // each all_members_obj
|
||||||
} // if id
|
}); // post volunteer benefits
|
||||||
}); // each tr
|
} // if this is a volunteer
|
||||||
|
|
||||||
|
// not a current volunteer within the last 365 days, or never has been a volunteer
|
||||||
|
$(".volunteer_hours:not([title])").prevAll(".existing_shop_user")
|
||||||
|
.children().each( function() {
|
||||||
|
|
||||||
|
var name = $(this).text();
|
||||||
|
var name_obj = name.trim().split(", ");
|
||||||
|
name = name_obj[1] + " " + name_obj[0];
|
||||||
|
|
||||||
|
var id = this.href.split("=")[1];
|
||||||
|
|
||||||
|
var title = name + "\r\n" +
|
||||||
|
"Volunteer Hours for last 365 days: None" + "\r\n";
|
||||||
|
|
||||||
|
$(".volunteer_hours_" + id).
|
||||||
|
html("<span class='update_interests'><a href='./contact_add_edit_select.php?contact_id=" +
|
||||||
|
id +
|
||||||
|
"'>Update Interests</a></span>").
|
||||||
|
parent().css({backgroundColor: "rgb(190, 199, 204)", textAlign: "center", cursor: "cell"}).
|
||||||
|
prop("title",title).css({textAlign: "center"});
|
||||||
|
|
||||||
|
$('.update_interests a').css({color: "#1b691e", textDecoration: "none", cursor: "crosshair"});
|
||||||
|
$('.update_interests a').hover( function(e){ $(this).css("color",e.type === "mouseenter"?"blue":"#1b691e");});
|
||||||
|
|
||||||
|
}); // .each not a current volunteer
|
||||||
|
|
||||||
} // function volunteer_status
|
} // function volunteer_status
|
||||||
|
|
||||||
@ -232,56 +265,54 @@ $(function(){
|
|||||||
var membership_transaction;
|
var membership_transaction;
|
||||||
|
|
||||||
|
|
||||||
//$.each($("#shop_log tr"), function() {
|
if (contacts) {
|
||||||
|
|
||||||
if (contacts) {
|
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contacts }, function (data) {
|
||||||
|
|
||||||
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contacts }, function (data) {
|
all_members_obj = $.parseJSON(data);
|
||||||
|
|
||||||
all_members_obj = $.parseJSON(data);
|
$.each(all_members_obj, function() {
|
||||||
|
|
||||||
$.each(all_members_obj, function() {
|
var membership_obj = this;
|
||||||
|
|
||||||
var membership_obj = this;
|
var title = membership_obj.normal_full_name + "\r\n" +
|
||||||
|
"expiration: " + membership_obj.expiration_date;
|
||||||
var title = membership_obj.normal_full_name + "\r\n" +
|
|
||||||
"expiration: " + membership_obj.expiration_date;
|
|
||||||
|
|
||||||
|
|
||||||
if (membership_obj.expiration_date) {
|
if (membership_obj.expiration_date) {
|
||||||
var exp = membership_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) {
|
||||||
membership_transaction = true;
|
membership_transaction = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof membership_obj.expiration_date && membership_obj.expiration_date !== undefined) {
|
if (typeof membership_obj.expiration_date && membership_obj.expiration_date !== undefined) {
|
||||||
|
|
||||||
var exp = membership_obj.expiration_date;
|
var exp = membership_obj.expiration_date;
|
||||||
expiration_date = new Date(exp.split("-").toString());
|
expiration_date = new Date(exp.split("-").toString());
|
||||||
|
|
||||||
// expired membership
|
// expired membership
|
||||||
if (d >= expiration_date) {
|
if (d >= expiration_date) {
|
||||||
$(".paid_membership_" + membership_obj.contact_id).html("Expired").
|
$(".paid_membership_" + membership_obj.contact_id).html("Expired").
|
||||||
parent().css({backgroundColor: "red", textAlign: "center", cursor: "cell", textDecoration: "none"}).prop("title",title);
|
parent().css({backgroundColor: "red", textAlign: "center", cursor: "cell", textDecoration: "none"}).prop("title",title);
|
||||||
|
|
||||||
// paid membership
|
// paid membership
|
||||||
} else if (d < expiration_date) {
|
} else if (d < expiration_date) {
|
||||||
$(".paid_membership_" + membership_obj.contact_id).html("Current").
|
$(".paid_membership_" + membership_obj.contact_id).html("Current").
|
||||||
parent().css({backgroundColor: "green", textAlign: "center", cursor: "cell"}).prop("title",title).css({textAlign: "center"});
|
parent().css({backgroundColor: "green", textAlign: "center", cursor: "cell"}).prop("title",title).css({textAlign: "center"});
|
||||||
|
|
||||||
} // paid membership
|
} // paid membership
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}); // each all_members_obj
|
}); // each all_members_obj
|
||||||
}); // end if this a paid member
|
}); // end if this a paid member
|
||||||
|
|
||||||
// never been a member
|
// never been a member
|
||||||
$(".paid_membership:not([title])").css({cursor: "not-allowed"});
|
$(".paid_membership:not([title])").css({cursor: "not-allowed"});
|
||||||
|
|
||||||
} // if contacts
|
} // if contacts
|
||||||
} // function membership status
|
} // function membership status
|
||||||
|
|
||||||
});
|
});
|
@ -874,6 +874,7 @@ $(function() {
|
|||||||
|
|
||||||
amount.prop("disabled","");
|
amount.prop("disabled","");
|
||||||
var membership_obj; //reuse this object
|
var membership_obj; //reuse this object
|
||||||
|
|
||||||
if (this.value !== "no_selection") {
|
if (this.value !== "no_selection") {
|
||||||
var expiration_date;
|
var expiration_date;
|
||||||
|
|
||||||
@ -883,11 +884,18 @@ $(function() {
|
|||||||
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contact_id }, function (data) {
|
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contact_id }, function (data) {
|
||||||
|
|
||||||
var membership_objs = $.parseJSON(data);
|
var membership_objs = $.parseJSON(data);
|
||||||
membership_obj = membership_objs[0];
|
|
||||||
|
/*
|
||||||
|
Weird hack, before improving performance #46, there was always a property for membership_obj,
|
||||||
|
membership_discount:10, which just allowed the code to work, now it is empty when a patron
|
||||||
|
actually is not a paid member, so this creates that obj & property if that is the case.
|
||||||
|
*/
|
||||||
|
membership_obj = membership_objs[0] || { membership_discount: 10 };
|
||||||
|
|
||||||
var title = membership_obj.normal_full_name + "\r\n" +
|
var title = membership_obj.normal_full_name + "\r\n" +
|
||||||
membership_obj.email + "\r\n" +
|
membership_obj.email + "\r\n" +
|
||||||
membership_obj.phone + "\r\n" +
|
membership_obj.phone + "\r\n" +
|
||||||
"expiration: " + membership_obj.expiration_date;
|
"expiration: " + membership_obj.expiration_date;
|
||||||
|
|
||||||
$("#membership_discount").empty();
|
$("#membership_discount").empty();
|
||||||
$("#membership_discount_price").empty();
|
$("#membership_discount_price").empty();
|
||||||
@ -1024,12 +1032,15 @@ $(function() {
|
|||||||
|
|
||||||
// How many hours does this volunteer have?
|
// How many hours does this volunteer have?
|
||||||
$("#redeemable_hours").val("");
|
$("#redeemable_hours").val("");
|
||||||
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: this.value }, function (data) {
|
var contact_id = "contacts.contact_id=" + this.value;
|
||||||
|
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: contact_id }, function (data) {
|
||||||
|
|
||||||
var year = d.getFullYear();
|
var year = d.getFullYear();
|
||||||
var bikes_earned = 0;
|
var bikes_earned = 0;
|
||||||
var volunteer_hours_redeemed = 0;
|
var volunteer_hours_redeemed = 0;
|
||||||
var obj = $.parseJSON(data);
|
|
||||||
|
var volunteer_objs = $.parseJSON(data);
|
||||||
|
var obj = volunteer_objs[0];
|
||||||
|
|
||||||
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
|
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
|
||||||
if (obj.volunteer) {
|
if (obj.volunteer) {
|
||||||
|
@ -122,7 +122,7 @@ $membership_discount = MEMBERSHIP_DISCOUNT;
|
|||||||
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id
|
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id
|
||||||
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY)
|
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY)
|
||||||
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY))
|
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY))
|
||||||
AND shop_user_roles.volunteer = 1 AND contacts.contact_id=" .
|
AND shop_user_roles.volunteer = 1 AND " .
|
||||||
$_POST['contact_id'] .
|
$_POST['contact_id'] .
|
||||||
" GROUP BY contact_id) AS firstset
|
" GROUP BY contact_id) AS firstset
|
||||||
INNER JOIN
|
INNER JOIN
|
||||||
@ -135,28 +135,32 @@ $membership_discount = MEMBERSHIP_DISCOUNT;
|
|||||||
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= CONCAT(YEAR(CURDATE()),'-01-01')
|
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= CONCAT(YEAR(CURDATE()),'-01-01')
|
||||||
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_ADD(CONCAT(YEAR(CURDATE()),'-01-01'),INTERVAL DAYOFYEAR(CONCAT(YEAR(CURDATE()),'-12-31')) - 1 DAY))
|
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_ADD(CONCAT(YEAR(CURDATE()),'-01-01'),INTERVAL DAYOFYEAR(CONCAT(YEAR(CURDATE()),'-12-31')) - 1 DAY))
|
||||||
AND shop_user_roles.volunteer = 1
|
AND shop_user_roles.volunteer = 1
|
||||||
AND contacts.contact_id=" .
|
AND " .
|
||||||
$_POST['contact_id'] .
|
$_POST['contact_id'] .
|
||||||
") AS secondset;";
|
") AS secondset;";
|
||||||
|
|
||||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||||
$result = mysql_fetch_assoc($sql);
|
|
||||||
|
|
||||||
|
|
||||||
// update volunteer_benefits either on sold_to.change (initialize) or redeem.change in separate callback
|
// update volunteer_benefits either on sold_to.change (initialize) or redeem.change in separate callback
|
||||||
// zero out if new year
|
// zero out if new year
|
||||||
|
|
||||||
$result3["max_bike_earned"] = $max_bike_earned;
|
$volunteers = [];
|
||||||
$result3["volunteer_hour_value"] = $volunteer_hour_value;
|
while ( $result = mysql_fetch_assoc($sql) ) {
|
||||||
$result3["sweat_equity_limit"] = $sweat_equity_limit;
|
$result["max_bike_earned"] = $max_bike_earned;
|
||||||
$result3["volunteer_discount"] = $volunteer_discount;
|
$result["volunteer_hour_value"] = $volunteer_hour_value;
|
||||||
$result3["special_volunteer_hours_qualification"] = $special_volunteer_hours_qualification;
|
$result["sweat_equity_limit"] = $sweat_equity_limit;
|
||||||
$result3["special_volunteer_discount"] = $special_volunteer_discount;
|
$result["volunteer_discount"] = $volunteer_discount;
|
||||||
$result3["stand_time_value"] = $stand_time_value;
|
$result["special_volunteer_hours_qualification"] = $special_volunteer_hours_qualification;
|
||||||
$result3["redeem_one_to_one"] = $redeem_one_to_one;
|
$result["special_volunteer_discount"] = $special_volunteer_discount;
|
||||||
|
$result["stand_time_value"] = $stand_time_value;
|
||||||
|
$result["redeem_one_to_one"] = $redeem_one_to_one;
|
||||||
|
$volunteers[] = $result;
|
||||||
|
}
|
||||||
|
|
||||||
$result = (object)array_merge((array)$result,(array)$result3);
|
//return $volunteers;
|
||||||
echo json_encode($result);
|
|
||||||
|
//$result = (object)array_merge((array)$result,(array)$result3);
|
||||||
|
echo json_encode($volunteers);
|
||||||
|
|
||||||
} // end Volunteer Benefits
|
} // end Volunteer Benefits
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ if($_GET['new_user_id']>0){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// does this work?
|
// does this work?
|
||||||
$("#shop_log_iframe").contents().find("#sign_in_button").on("click keypress", function(e){
|
$("#shop_log_iframe").contents().find("#sign_in_button").on("click keypress", function(e){
|
||||||
|
|
||||||
@ -78,7 +79,6 @@ if($_GET['new_user_id']>0){
|
|||||||
|
|
||||||
if ( $("#epframeshop_log_pad").length ) {
|
if ( $("#epframeshop_log_pad").length ) {
|
||||||
|
|
||||||
|
|
||||||
var body_margin = $("#shop_log_iframe").contents().find("body").css("margin");
|
var body_margin = $("#shop_log_iframe").contents().find("body").css("margin");
|
||||||
body_margin = body_margin.replace("px","");
|
body_margin = body_margin.replace("px","");
|
||||||
body_margin = body_margin * 4;
|
body_margin = body_margin * 4;
|
||||||
@ -89,7 +89,7 @@ if($_GET['new_user_id']>0){
|
|||||||
|
|
||||||
$("#shop_log_iframe").contents().find("#shop_log_link").attr("href","/shop_log_iframe.php");
|
$("#shop_log_iframe").contents().find("#shop_log_link").attr("href","/shop_log_iframe.php");
|
||||||
|
|
||||||
// does this work?
|
// does this work? - the first time it is completely loaded
|
||||||
$("#shop_log_iframe").contents().find("#sign_in_button").on("click keypress", function(e){
|
$("#shop_log_iframe").contents().find("#sign_in_button").on("click keypress", function(e){
|
||||||
|
|
||||||
var body_margin = $("#shop_log_iframe").contents().find("body").css("margin");
|
var body_margin = $("#shop_log_iframe").contents().find("body").css("margin");
|
||||||
|
@ -262,13 +262,13 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
|
|||||||
<?php } else { //This section executes if it is not the visit_id selected NOT FOR EDIT ?>
|
<?php } else { //This section executes if it is not the visit_id selected NOT FOR EDIT ?>
|
||||||
<form method="post" name="FormUpdate_<?php echo $row_Recordset1['shop_visit_id']; ?>" action="<?php echo $editFormAction; ?>">
|
<form method="post" name="FormUpdate_<?php echo $row_Recordset1['shop_visit_id']; ?>" action="<?php echo $editFormAction; ?>">
|
||||||
<tr bordercolor="#CCCCCC" id="<?php echo $row_Recordset1['contact_id']; ?>">
|
<tr bordercolor="#CCCCCC" id="<?php echo $row_Recordset1['contact_id']; ?>">
|
||||||
<td><a href="<?php echo "{$page_individual_history_log}?contact_id=" . $row_Recordset1['contact_id']; ?>" target="_parent"><?php echo $row_Recordset1['full_name']; ?></a></td>
|
<td class="existing_shop_user"><a href="<?php echo "{$page_individual_history_log}?contact_id=" . $row_Recordset1['contact_id']; ?>" target="_parent"><?php echo $row_Recordset1['full_name']; ?></a></td>
|
||||||
<td class="shop_user_role"><?php echo $row_Recordset1['shop_user_role']; ?></td>
|
<td class="shop_user_role"><?php echo $row_Recordset1['shop_user_role']; ?></td>
|
||||||
<td><?php echo date_to_time($row_Recordset1['time_in']); ?></td>
|
<td><?php echo date_to_time($row_Recordset1['time_in']); ?></td>
|
||||||
<td><?php echo list_time($row_Recordset1['time_in'],$row_Recordset1['time_out'],'time_out',0,1,'none', $shop_hours_length, $row_Recordset1['et']); ?></td>
|
<td><?php echo list_time($row_Recordset1['time_in'],$row_Recordset1['time_out'],'time_out',0,1,'none', $shop_hours_length, $row_Recordset1['et']); ?></td>
|
||||||
<td><?php sign_out($row_Recordset1['time_out'], $row_Recordset1['first_name']); ?> </td>
|
<td><?php sign_out($row_Recordset1['time_out'], $row_Recordset1['first_name']); ?> </td>
|
||||||
<td><?php if($shop_CanEdit == 1) {echo "<a href=\"{$_SERVER['PHP_SELF']}?shop_id={$shop_id}&visit_id={$row_Recordset1['shop_visit_id']}\">edit</a>";} else {echo " ";} ?></td>
|
<td><?php if($shop_CanEdit == 1) {echo "<a href=\"{$_SERVER['PHP_SELF']}?shop_id={$shop_id}&visit_id={$row_Recordset1['shop_visit_id']}\">edit</a>";} else {echo " ";} ?></td>
|
||||||
<td><span class="volunteer_hours_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
|
<td class="volunteer_hours"><span class="volunteer_hours_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
|
||||||
<td class="paid_membership"><span class="paid_membership_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
|
<td class="paid_membership"><span class="paid_membership_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
|
||||||
</tr>
|
</tr>
|
||||||
<input type="hidden" name="MM_insert" value="FormUpdate">
|
<input type="hidden" name="MM_insert" value="FormUpdate">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user