From e37a0ec2f7c1622d540027cb4229236ed99ed983 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Wed, 9 Aug 2017 05:25:23 +0000 Subject: [PATCH] Redeemable now properly adds discount when there has been previous transactions . * some fun math! --- js/transaction.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/js/transaction.js b/js/transaction.js index f5908cd..f6c49fc 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -630,15 +630,21 @@ $(function() { } // figure out remaining hours that can be redeemed if volunteer hours have been redeemed. - var remaining, year = d.getFullYear(), exceeded_sweat_equity_limit = false; + var remaining, year = d.getFullYear(), exceeded_sweat_equity_limit = false, price_after_redeeming, spinner_difference; if (volunteer) { - var vhr = obj.volunteer_hour_value * volunteer[year].volunteer_hours_redeemed; - remaining = obj.current_year_volunteer_hours - volunteer[year].volunteer_hours_redeemed; + var vhr = obj.volunteer_hour_value * volunteer[year].volunteer_hours_redeemed + (spinner_value * obj.volunteer_hour_value); + console.log(obj.volunteer_hour_value + " * " + volunteer[year].volunteer_hours_redeemed + " = " + vhr ); + remaining = obj.current_year_volunteer_hours - volunteer[year].volunteer_hours_redeemed; + //console.log(obj.current_year_volunteer_hours + " - " + volunteer[year].volunteer_hours_redeemed + " = " + remaining ); if (vhr > obj.sweat_equity_limit) { - exceeded_sweat_equity_limit = true; + exceeded_sweat_equity_limit = true; + price_after_redeeming = price - (obj.volunteer_hour_value * ((obj.sweat_equity_limit / obj.volunteer_hour_value) - volunteer[year].volunteer_hours_redeemed)); + spinner_difference = (obj.sweat_equity_limit / obj.volunteer_hour_value) - volunteer[year].volunteer_hours_redeemed; + console.log(spinner_difference); } - } - + } + + // no volunteer_hours_redeemed or still less than the allowable sweat_equity_hours // if running volunteer_hours >= special_volunteer_hours_qualification the special_discount kicks in @@ -649,7 +655,7 @@ $(function() { if (price >= redeemable_value) { // discount is now applied if transaction is over special_volunteer_hours_qualification - if (redeemable_value > obj.sweat_equity_limit && $("#transaction_type").val() !== "Stand Time") { + if (redeemable_value > obj.sweat_equity_limit && $("#transaction_type").val() !== "Stand Time" && !price_after_redeeming) { var value_to_apply_discount, difference, hours_applied_with_value; @@ -664,12 +670,12 @@ $(function() { if (price > max_discount_price) { max_discount_price_difference = price - max_discount_price; - //console.log("we have to do things differently " + max_discount_price_difference); + console.log("we have to do things differently " + max_discount_price_difference); value_to_apply_discount = (price - max_discount_price_difference) - redeemable_value; difference = (price - max_discount_price_difference) - obj.sweat_equity_limit; hours_applied_with_value = difference - value_to_apply_discount; - //console.log("(" + max_discount_price_difference + " + " + difference + ") - (" + hours_applied_with_value + " * ." + discount + ")"); + console.log("(" + max_discount_price_difference + " + " + difference + ") - (" + hours_applied_with_value + " * ." + discount + ")"); redeemable_value = (max_discount_price_difference + difference) - (hours_applied_with_value * (discount / 100).toFixed(2)); } else { @@ -677,7 +683,7 @@ $(function() { value_to_apply_discount = price - redeemable_value; hours_applied_with_value = difference - value_to_apply_discount; - //console.log(difference + " - (" + hours_applied_with_value + " * ." + discount + ")"); + console.log(difference + " - (" + hours_applied_with_value + " * ." + discount + ")"); redeemable_value = difference - (hours_applied_with_value * (discount / 100).toFixed(2)); } @@ -686,7 +692,13 @@ $(function() { // volunteer hours redeemed if the redeemable_value <= obj.sweat_equity_limit } else { if (exceeded_sweat_equity_limit === true) { - amount.val(price - (redeemable_value * (discount / 100).toFixed(2))); + console.log(exceeded_sweat_equity_limit); + if (price_after_redeeming) { + amount.val(price_after_redeeming - (((spinner_value - spinner_difference) * obj.volunteer_hour_value) * (discount / 100).toFixed(2))); + } else { + amount.val(price - (redeemable_value * (discount / 100).toFixed(2))); + } + console.log(price_after_redeeming + " - " + redeemable_value + " * ." + discount); } else { amount.val(price - redeemable_value); }