Browse Source

Adds initial Volunteer Hour logic and displays in transactions with title.

devel
Jonathan Rosenbaum 7 years ago
parent
commit
787fff74d6
  1. 9
      css/transactions.css
  2. 33
      js/transaction.js
  3. 36
      json/transaction.php

9
css/transactions.css

@ -94,10 +94,19 @@ input[value=Save]:focus, input[value=Close]:focus {
/* for memberships */
#expired_membership {
color: orchid;
margin-left: 10px;
}
#paid_member {
color: blue;
margin-left: 10px;
}
/* for volunteers */
#volunteer_hours {
color: blueviolet;
margin-left: 10px;
}

33
js/transaction.js

@ -662,16 +662,13 @@ $(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) {
$.post("json/transaction.php", { membership_benefits: 1, contact_id: this.value }, function (data) {
var obj = $.parseJSON(data);
var title = obj.normal_full_name + "\r\n" +
obj.email + "\r\n" +
obj.phone + "\r\n" +
"expiration: " + obj.expiration_date;
//"normal_full_name":"Carol Barnes","email":"msbarnes@rocketmail.com","phone":"(304) 864-4403","membership_start":"2017-07-16 21:45:51","expiration_date":"2018-07-16"}
if (typeof obj.expiration_date && obj.expiration_date !== undefined) {
var exp = obj.expiration_date;
@ -696,7 +693,33 @@ $(function() {
$("#expired_membership").empty();
}
}
}); // post
}); // membership post
// How many hours does this volunteer have?
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: this.value }, function (data) {
var obj = $.parseJSON(data);
var title = obj.normal_full_name + "\r\n" +
obj.email + "\r\n" +
obj.phone + "\r\n" +
"volunteer hours for last 365 day: " + obj.volunteer_hours + "\r\n" +
"volunteer hours redeemed " + "\r\n" +
"volunteer hours remaining";
$("#volunteer_hours").prop("title","").empty();
if (obj) {
var volunteer_hours = obj.volunteer_hours;
if (volunteer_hours.length) {
$("#volunteer_hours").prop("title","").empty();
$("#volunteer_hours").prop("title",title).html("Volunteer Hours");
} else {
$("#volunteer_hours").prop("title","").empty();
}
}
}); // volunteers post
} // if not no_selection

36
json/transaction.php

@ -76,8 +76,8 @@ $csv_directory = CSV_DIRECTORY;
echo json_encode($result);
}
// Membership and Volunteer Benefits
if (isset($_POST['membership_and_volunteer_benefits'])) {
// Membership Benefits
if (isset($_POST['membership_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,
@ -91,7 +91,37 @@ $csv_directory = CSV_DIRECTORY;
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
echo json_encode($result);
}
// SELECT contact_id, full_name, normal_full_name, email, phone, visits, volunteer_hours FROM (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, COUNT(shop_hours.contact_id) as visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS volunteer_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 (SUBSTRING_INDEX(time_in, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY) AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY)) AND shop_user_roles.volunteer = 1 GROUP BY contact_id) AS members;
} // Membership Benefits
// Volunteer Benefits
if (isset($_POST['volunteer_benefits'])) {
$query = "SELECT contact_id, full_name, normal_full_name, email, phone, visits, volunteer_hours
FROM (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,
COUNT(shop_hours.contact_id) AS visits,
ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS volunteer_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 (SUBSTRING_INDEX(time_in, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY)
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY))
AND shop_user_roles.volunteer = 1 AND contacts.contact_id=" .
$_POST['contact_id'] .
" GROUP BY contact_id) AS members;";
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
echo json_encode($result);
} // Volunteer Benefits
// Anonymous transaction - save and communicate back settings
if(isset($_POST['anonymous'])) {

Loading…
Cancel
Save