From e6630066985caee1ddb3a215b89bbff9e6d58307 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Thu, 27 Jul 2017 18:01:53 +0000 Subject: [PATCH] Some experimentation making sure the spinner is working. * Need to improve the css * Need to link everything togther, the fun part! --- js/transaction.js | 13 +++++++++++-- json/transaction.php | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/js/transaction.js b/js/transaction.js index 09146d4..cda75ca 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -713,15 +713,24 @@ $(function() { "Volunteer Hours Redeemed: " + "\r\n" + "Volunteer Hours Remaining:"; - $("#volunteer_hours").prop("title","").empty(); + $("#volunteer_hours").prop("title","").empty(); + $("#redeemable_hours").hide(); if (obj) { var volunteer_hours = obj.volunteer_hours; if (volunteer_hours && volunteer_hours.length) { $("#volunteer_hours").prop("title",title).html("Volunteer Hours"); + + + $( "#redeemable_hours" ).spinner({ + step: 0.10, + numberFormat: "n" + }).show(); + + //$("#redeemable_hours").html(obj.redeemable_hours); } else { $("#volunteer_hours").prop("title","").empty(); - + $("#redeemable_hours").hide(); } } diff --git a/json/transaction.php b/json/transaction.php index 5d010f6..1685d4b 100644 --- a/json/transaction.php +++ b/json/transaction.php @@ -15,6 +15,9 @@ $csv_directory = CSV_DIRECTORY; $stand_time_hourly_rate = STAND_TIME_HOURLY_RATE; $stand_time_grace_period = STAND_TIME_GRACE_PERIOD; $timezone = TIMEZONE; +$sweat_equity_limit = SWEAT_EQUITY_LIMIT; +$max_bike_earned = MAX_BIKE_EARNED; +$volunteer_hour_value = VOLUNTEER_HOUR_VALUE; // Is there a current shop? if(isset($_POST['shop_exist'])) { @@ -95,13 +98,16 @@ $timezone = TIMEZONE; // Volunteer Benefits if (isset($_POST['volunteer_benefits'])) { - $query = "SELECT contact_id, full_name, normal_full_name, email, phone, visits, volunteer_hours + $query = "SELECT contact_id, full_name, normal_full_name, email, phone, visits, volunteer_hours, sweat_equity_redeemed, max_bike_earned, year 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, + COUNT(shop_hours.contact_id) AS visits, + contacts.sweat_equity_redeemed AS sweat_equity_redeemed, + contacts.max_bike_earned AS max_bike_earned, + contacts.year AS year, 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 @@ -134,9 +140,30 @@ $timezone = TIMEZONE; $sql = mysql_query($query, $YBDB) or die(mysql_error()); $result2 = mysql_fetch_assoc($sql); - $result = (object)array_merge((array)$result, (array)$result2); - echo json_encode($result); + + // update volunteer_benefits either on sold_to.change (initialize) or redeem.change in separate callback + // zero out if new year + + //$handler->debug($result["sweat_equity_redeemed"]); + + if($result["sweat_equity_redeemed"] == 0) { + $redeemable_hours_amount = $result2["current_year_volunteer_hours"] * $volunteer_hour_value; + $remaining_redeemable_hours_amount_available = $sweat_equity_limit - $redeemable_hours_amount; + } else { + $remaining_redeemable_hours_amount_available = $sweat_equity_limit - $result["sweat_equity_redeemed"]; + } + + $result3["max_bike_earned"] = $max_bike_earned; + if($remaining_redeemable_hours_amount_available >= 0) { + //$handler->debug("$redeemable_hours_amount $remaining_redeemable_hours_amount_available"); + $result3["redeemable_hours"] = $redeemable_hours_amount; + } else { + $result3["redeemable_hours"] = $sweat_equity_limit; + } + + $result = (object)array_merge((array)$result, (array)$result2, (array)$result3); + echo json_encode($result); } // Volunteer Benefits