Browse Source

This adds more detail (title) for volunteers in the member metric report.

* Could be modifed further.
* Currently shows color when all hours redeemed.
devel
Jonathan Rosenbaum 6 years ago
parent
commit
85011402a5
  1. 116
      js/stats.js
  2. 38
      stats/members.php

116
js/stats.js

@ -68,4 +68,120 @@ $(function(){
e.preventDefault();
});
var volunteer_ids;
var last_index = $("tr[id]").length;
if (last_index) {
last_index = last_index - 1;
$.each($("tr[id]"), function(index) {
if (this.id) {
var id = this.id;
if (last_index < 1) {
volunteer_ids = "contacts.contact_id=" + id;
}
else if (!volunteer_ids) {
volunteer_ids = "(contacts.contact_id=" + id + " OR ";
} else if ( index === last_index) {
volunteer_ids += "contacts.contact_id=" + id + ")";
} else {
volunteer_ids += "contacts.contact_id=" + id + " OR ";
}
}
});
}
var d = new Date();
volunteer_status(volunteer_ids);
// volunteer status
// Essentially, the same function (but with modifications) as in shop.js and transaction.js
function volunteer_status(contacts) {
var all_members_obj; //reuse this object
var year = d.getFullYear();
if (contacts) {
$.post("../json/transaction.php", { volunteer_benefits: 1, contact_id: contacts }, function (data) {
all_members_obj = $.parseJSON(data);
$.each(all_members_obj, function() {
var bikes_earned = 0;
var volunteer_hours_redeemed = 0;
var obj = this;
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
if (obj.volunteer) {
volunteer = $.parseJSON(obj.volunteer);
if (volunteer.hasOwnProperty(year)) {
remaining = obj.current_year_volunteer_hours - volunteer[year].volunteer_hours_redeemed;
vhr = volunteer[year].volunteer_hours_redeemed;
max_bikes_earned = volunteer[year].max_bike_earned;
}
} else {
vhr = 0;
}
var title = obj.normal_full_name + "\r\n" +
"Volunteer Hours for last 365 days: " + obj.volunteer_hours + "\r\n" +
"Volunteer Hours \(" + year + "\): " + obj.current_year_volunteer_hours + "\r\n" +
"Volunteer Hours Redeemed: " + vhr + "\r\n" +
"Volunteer Hours Remaining: " + remaining + "\r\n" +
"Max Bikes Earned: " + max_bikes_earned;
var volunteer_with_redeemed_hours_at_zero = obj.current_year_volunteer_hours - vhr;
if (obj.contact_id) {
if (obj.volunteer_hours && obj.volunteer_hours !== '0') {
if (volunteer_with_redeemed_hours_at_zero !== 0) {
$("#" + obj.contact_id + " td").first().
css({textAlign: "center", cursor: "cell"}).
prop("title",title).css({textAlign: "center"});
} else {
$("#" + obj.contact_id + " td").first().
css({backgroundColor: "rgb(216, 198, 39)", textAlign: "center", cursor: "cell"}).
prop("title",title).css({textAlign: "center"});
}
} else {
title = obj.normal_full_name + "\r\n" +
"Volunteer Hours for last 365 days: None" + "\r\n";
$("#" + obj.contact_id + " td").first().
css({backgroundColor: "rgb(190, 199, 204)", textAlign: "center", cursor: "cell"}).
prop("title",title).css({textAlign: "center"});
}
} else {
var name = $("#" + id + " td a[href*='individual']").text();
var name_obj = name.trim().split(", ");
name = name_obj[1] + " " + name_obj[0];
title = name + "\r\n" +
"Volunteer Hours for last 365 days: None" + "\r\n";
$("#" + obj.contact_id + " td").first().
css({backgroundColor: "rgb(190, 199, 204)", textAlign: "center", cursor: "cell"}).
prop("title",title).css({textAlign: "center"});
}
}); // each all_members_obj
}); // post volunteer benefits
} // if this is a volunteer
} // function volunteer_status
});

38
stats/members.php

@ -39,36 +39,6 @@ if (isset($_POST['range1'])) {
$today = $range2;
}
/*
SELECT contact_id, full_name, email, phone, sort_visits, sort_hours FROM
(SELECT contacts.contact_id, CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name,
contacts.email AS email, contacts.phone AS phone,
COUNT(shop_hours.contact_id) as sort_visits,
ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS sort_hours
FROM shop_hours
LEFT JOIN contacts ON shop_hours.contact_id = contacts.contact_id
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id
WHERE (time_in > DATE_SUB(CURDATE(),INTERVAL 12 MONTH))
AND shop_user_roles.volunteer = 1 GROUP BY contact_id) AS members
WHERE sort_hours >= 8 AND sort_visits >= 2
GROUP by contact_id ORDER by sort_hours DESC, sort_visits DESC;
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 sort_hours
FROM transaction_log
LEFT JOIN contacts ON transaction_log.sold_to = contacts.contact_id
WHERE (SUBSTRING_INDEX(date, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY)
AND SUBSTRING_INDEX(date, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY))
AND (transaction_type="Memberships" AND paid=1);
*/
// Membership via volunteering
$query = "SELECT contact_id, full_name, normal_full_name, email, phone, sort_visits, sort_hours FROM
(SELECT contacts.contact_id, CONCAT(last_name, ', ', first_name, ' ',middle_initial) AS full_name,
@ -127,11 +97,11 @@ while ($result = mysql_fetch_assoc($purchased_membership)) {
while ($result = mysql_fetch_assoc($members)) {
//do {
?>
<tr>
<?php if( isset($purchased_membership_dictionary[$result['contact_id']]) ) { ?>
<td class="yb_standardRIGHTred"><a href="<?php echo "{$page_individual_history_log}?contact_id=" . $result['contact_id']; ?>"><?php echo $result['full_name']; ?></a><br \>(paid until <?php echo $purchased_membership_dictionary[$result['contact_id']]['expiration_date']; ?>)</td>
<tr id="<?php echo $result['contact_id']; ?>">
<?php if( isset($purchased_membership_dictionary[$result['contact_id']]) ) { ?>
<td class="yb_standardRIGHTred"><a style="text-decoration:none" href="<?php echo "{$page_individual_history_log}?contact_id=" . $result['contact_id']; ?>"><?php echo $result['full_name']; ?></a><br \>(paid until <?php echo $purchased_membership_dictionary[$result['contact_id']]['expiration_date']; ?>)</td>
<?php } else { ?>
<td class="yb_standardRIGHTred"><a href="<?php echo "{$page_individual_history_log}?contact_id=" . $result['contact_id']; ?>"><?php echo $result['full_name']; ?></a></td>
<td class="yb_standardRIGHTred"><a style="text-decoration:none" href="<?php echo "{$page_individual_history_log}?contact_id=" . $result['contact_id']; ?>"><?php echo $result['full_name']; ?></a></td>
<?php } ?>
<td class="yb_standardRIGHT"><?php echo number_format($result['sort_visits'],0); ?></td>
<td class="yb_standardRIGHT"><?php echo number_format($result['sort_hours'],0); ?></td>

Loading…
Cancel
Save