Browse Source

membership_benefits now just one call as desired for issue #46

* now need to do the same thing for volunteer_benefits
devel
Jonathan Rosenbaum 7 years ago
parent
commit
f59020a823
  1. 114
      js/shop.js
  2. 8
      js/transaction.js
  3. 15
      json/transaction.php
  4. 2
      shop_log_iframe.php

114
js/shop.js

@ -91,7 +91,32 @@ $(function(){
// could have done this in php, but this separates out the view logic
var d = new Date();
volunteer_status();
membership_status();
var membership_ids;
var last_index = $("#shop_log tr").length;
if (last_index) {
last_index = last_index -1;
$.each($("#shop_log tr"), function(index) {
if (this.id) {
var id = this.id;
// 2 tr for first created login
if (last_index <= 2) {
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 ";
}
}
});
}
membership_status(membership_ids);
// volunteer status
function volunteer_status() {
@ -200,60 +225,63 @@ $(function(){
// Is this a paid member?
function membership_status() {
function membership_status(contacts) {
var expiration_date;
var membership_obj; //reuse this object
var all_members_obj; //reuse this object
var membership_transaction;
$.each($("#shop_log tr"), function() {
//$.each($("#shop_log tr"), function() {
if (this.id) {
var id = this.id;
if (contacts) {
$.post("json/transaction.php", { membership_benefits: 1, contact_id: this.id }, function (data) {
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contacts }, function (data) {
membership_obj = $.parseJSON(data);
var title = membership_obj.normal_full_name + "\r\n" +
"expiration: " + membership_obj.expiration_date;
all_members_obj = $.parseJSON(data);
$.each(all_members_obj, function() {
var membership_obj = this;
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) {
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());
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", textDecoration: "none"}).prop("title",title);
// expired membership
if (d >= expiration_date) {
$(".paid_membership_" + membership_obj.contact_id).html("Expired").
parent().css({backgroundColor: "red", textAlign: "center", cursor: "cell", textDecoration: "none"}).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
} 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
}
} // paid membership
// never been a member
} else {
$(".paid_membership_" + id).parent().css({cursor: "not-allowed"});
} // never been a member
}); // each all_members_obj
}); // end if this a paid member
} // if this.id
}); // each
// never been a member
$(".paid_membership:not([title])").parent().css({cursor: "not-allowed"});
} // if contacts
} // function membership status
});

8
js/transaction.js

@ -879,9 +879,11 @@ $(function() {
// Is this a paid member?
// Determine membership benefits of current transaction
$.post("json/transaction.php", { membership_benefits: 1, contact_id: this.value }, function (data) {
membership_obj = $.parseJSON(data);
var contact_id = "contact_id=" + this.value;
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contact_id }, function (data) {
var membership_objs = $.parseJSON(data);
membership_obj = membership_objs[0];
var title = membership_obj.normal_full_name + "\r\n" +
membership_obj.email + "\r\n" +
membership_obj.phone + "\r\n" +

15
json/transaction.php

@ -667,7 +667,7 @@ $membership_discount = MEMBERSHIP_DISCOUNT;
} // End Deposit Calculator
function membership_benefits($contact_id, $membership_discount) {
function membership_benefits($contact_id, $membership_discount) {
global $database_YBDB, $YBDB;
mysql_select_db($database_YBDB, $YBDB);
@ -677,14 +677,19 @@ $membership_discount = MEMBERSHIP_DISCOUNT;
transaction_log.date AS membership_start, SUBSTRING_INDEX(DATE_ADD(date, INTERVAL 365 DAY), ' ', 1) AS expiration_date
FROM transaction_log LEFT JOIN contacts ON transaction_log.sold_to = contacts.contact_id
WHERE SUBSTRING_INDEX(date, ' ', 1) <= DATE_ADD(date, INTERVAL 365 DAY)
AND (transaction_type='Memberships' AND paid=1) AND contact_id=" .
AND (transaction_type='Memberships' AND paid=1) AND " .
$contact_id .
" ORDER by membership_start DESC;";
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
$result['membership_discount'] = $membership_discount;
return $result;
$members = [];
while ( $result = mysql_fetch_assoc($sql) ) {
$result['membership_discount'] = $membership_discount;
$members[] = $result;
}
return $members;
} // end membership_benefits

2
shop_log_iframe.php

@ -269,7 +269,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
<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 class="volunteer_hours_<?php echo $row_Recordset1['contact_id']; ?>"></span></td>
<td><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>
<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