Players register at our events. I type their name in (#P1, #P2, etc.) and the function getCCCRexpire(ele) looks up their club expiration date. I want to modify function calcEntryFee to calculate the entrance fee. If the players expiration date is later than today, the fee (#E1, #E2, etc.) is $3. If the players expiration date is today or earlier, the fee is $5.
The problem is that the non-blank players with memberships expiring today or earlier don't get picked up. For example, NAME = "Jones, John" MEMBERSHIP_EXPIRES = "2017.01.12" should populate the fee with "$5" but it just leaves it blank.
A second problem is the unnecessary complexity of the function calcEntryFee. I've never seen anything this advanced or frankly obfuscated. I would sure be grateful in someone could rewrite this function and make it work correctly. I am clearly in over my head. I'm not even close to a solution.
HTML
function calcEntryFee(elem) {
var idx, member, exDate, today, fee;
elem = elem || {};
if (/^[PEMX](\d+)$/.test(elem.id)) {
idx = RegExp.$1;
} else {
return false;
}
member = getMemberData(jQuery('#P' + idx).val());
mmfee = parseFloat(jQuery('#M' + idx).val());
exDate = moment(member.cccrEXP, 'YYYY.MM.DD');
today = moment();
fee = '';
if (!member) {
fee = 0;
}
//if ( (exDate.isBefore( today ) || exDate == 0) && P1 > "") {fee = 5; } // my attempt to solve the issue.
if ((exDate.isBefore(today) || !member)) {
fee = 5;
}
if (exDate.isSameOrAfter(today)) {
fee = 3;
}
if (member.cccrEXP == "" && mmfee > 0) {
fee = 0;
}
// Updates the entry fee input value.
jQuery('#E' + idx).val(fee);
return fee;
}
function getCCCRexpire(ele) {
var i = null;
for (i = 0; cccr_mems.length > i; i++) {
if (cccr_mems[i].Name == ele.value) {
return cccr_mems[i].cccrEXP;
}
}
return;
}
for (let i = 0; i <= 48; i++) {
$("#P" + i).on("blur", function() {
$("#CCCR_X" + i).val(getCCCRexpire(this));
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.js"></script>
<div>
<div><input type="text" id="P1" onblur="calcEntryFee(this);" name="N1" /></div>
<div><input type="text" onblur="getCCCRexpire()" name="cccr_exp" id="CCCR_X1" /> </div>
<div><input type="text" name="ef-fee" id="E1" /></div>
</div>
<div>
<div><input type="text" id="P2" onblur="calcEntryFee(this);" name="N2" /></div>
<div><input type="text" onblur="getCCCRexpire()" name="cccr_exp" id="CCCR_X2" /> </div>
<div><input type="text" name="ef-fee" id="E2" /></div>
</div>
from calculate fee based on membership date
No comments:
Post a Comment