Browse Source

Adds Volunteer Hours and Paid Membership Columns to shop log:

* shows Summary for Volunteer hours
* show whether membership is current or not
* a little css magic in shop.js
devel
Jonathan Rosenbaum 7 years ago
parent
commit
c356cb9aaf
  1. 149
      js/shop.js
  2. 8
      shop_log.php

149
js/shop.js

@ -1,6 +1,8 @@
$(function(){
"use strict";
$.ajaxSetup({async:false});
// sensible defaults
$("#shop_date").mask("0000-00-00", {placeholder: "yyyy-mm-dd" });
@ -35,4 +37,151 @@ $(function(){
} // end error_handling function
function sign_out() {
// Deferred Promise, since we don't know when the click will be made,
// it is an asynchronous function, and we need to know the returned result.
// Provides a clean separation of code.
var dfd = $.Deferred();
$(".sign_out").on("click keypress", function(e){
//$.post("json/shop.php", {sign_out: 1});
dfd.resolve("Success");
//event.preventDefault();
});
return dfd.promise();
} // end sign_out
//sign_out();
// A function to provide a json string to provide apps with information on state of the current shop
sign_out().done(function(success) {
if (success === "Success") {
$.post("json/shop.php", {sign_out: 1});
}
} );
// could have done this in php, but this separates out the view logic
var d = new Date();
volunteer_status();
membership_status();
// volunteer status
function volunteer_status() {
$.each($("#shop_log tr"), function() {
if (this.id) {
var id = this.id;
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: this.id }, function (data) {
var year = d.getFullYear();
var bikes_earned = 0;
var volunteer_hours_redeemed = 0;
var obj = $.parseJSON(data);
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
if (obj.volunteer) {
volunteer = $.parseJSON(obj.volunteer);
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;
if (obj.contact_id) {
$("#volunteer_hours_" + obj.contact_id).html("Summary").
parent().css({backgroundColor: "#19a0cc", textAlign: "center", cursor: "cell"}).
prop("title",title).css({textAlign: "center"});
} else {
$("#volunteer_hours_" + id).parent().css({cursor: "not-allowed"});
}
}); // post volunteer benefits
} // if id
}); // each tr
} // function volunteer_status
// Is this a paid member?
function membership_status() {
var expiration_date;
var membership_obj; //reuse this object
var membership_transaction;
$.each($("#shop_log tr"), function() {
if (this.id) {
var id = this.id;
$.post("json/transaction.php", { membership_benefits: 1, contact_id: this.id }, function (data) {
membership_obj = $.parseJSON(data);
var title = membership_obj.normal_full_name + "\r\n" +
"expiration: " + membership_obj.expiration_date;
if (membership_obj.expiration_date) {
var exp = membership_obj.expiration_date;
expiration_date = new Date(exp.split("-").toString());
if (d < expiration_date) {
membership_transaction = true;
}
}
if (typeof membership_obj.expiration_date && membership_obj.expiration_date !== undefined) {
var exp = membership_obj.expiration_date;
expiration_date = new Date(exp.split("-").toString());
// expired membership
if (d >= expiration_date) {
$("#paid_membership_" + membership_obj.contact_id).html("Expired").
parent().css({backgroundColor: "red", textAlign: "center", cursor: "cell"}).prop("title",title);
// paid membership
} else if (d < expiration_date) {
$("#paid_membership_" + membership_obj.contact_id).html("Current").
parent().css({backgroundColor: "green", textAlign: "center", cursor: "cell"}).prop("title",title).css({textAlign: "center"});
} // paid membership
// never been a member
} else {
$("#paid_membership_" + id).parent().css({cursor: "not-allowed"});
} // never been a member
}); // end if this a paid member
} // if this.id
}); // each
} // function membership status
});

8
shop_log.php

@ -190,7 +190,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
<br /><br />
<table id="shop_log" width="relative" style="margin-left:170px" border="1" cellpadding="1" cellspacing="0" bordercolor="#CCCCCC">
<tbody
<tbody>
<tr valign="bottom" bordercolor="#CCCCCC">
<td height="25" colspan="1" bgcolor="#99CC33">Existing Shop Users</td>
<td height="25" colspan="1" bgcolor="#99CC33">Status</td>
@ -198,6 +198,8 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
<td height="25" colspan="1" bgcolor="#99CC33">Time Out</td>
<td height="25" colspan="1" bgcolor="#99CC33">Update Hours</td>
<td height="25" colspan="1" bgcolor="#99CC33">Edit</td>
<td height="25" colspan="1" bgcolor="#99CC33">Volunteer Hours</td>
<td height="25" colspan="1" bgcolor="#99CC33">Paid Membership</td>
</tr>
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { //do {
if($visit_id == $row_Recordset1['shop_visit_id']) {?>
@ -241,13 +243,15 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
</form>
<?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; ?>">
<tr bordercolor="#CCCCCC">
<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']; ?>"><?php echo $row_Recordset1['full_name']; ?></a></td>
<td><?php echo $row_Recordset1['shop_user_role']; ?></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 sign_out($row_Recordset1['time_out'], $row_Recordset1['first_name']); ?>&nbsp</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 "&nbsp";} ?></td>
<td><span id="volunteer_hours_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
<td><span id="paid_membership_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
</tr>
<input type="hidden" name="MM_insert" value="FormUpdate">
<input type="hidden" name="shop_visit_id" value="<?php echo $row_Recordset1['shop_visit_id']; ?>">

Loading…
Cancel
Save