ckdoublenecks
Programmer
The below code works except that the calcs for "if the amptaid >= totOwed" don't work. I know it has to do with the
statement
"var totOwed = parseInt(rentdue.value) + parseInt(prevbal.value) + parseInt(secdep.value) + parseInt(damage.value) + parseInt(latechg.value) + parseInt(courtcost.value) +
parseInt(nsf.value) - parseInt(hudpay.value);"
but I don't know enough to make it work.
<script>
function $_(IDS) { return document.getElementById(IDS); }
function calculate_paid() {
var amtpaid = document.getElementById("amtpaid");
var rentdue = document.getElementById("rentdue");
var prevbal = document.getElementById("prevbal");
var hudpay = document.getElementById("hudpay");
var tentpay = document.getElementById("tentpay");
var datepaid = document.getElementById("datepaid");
var late = document.getElementById("late");
var damage = document.getElementById("damage");
var courtcost = document.getElementById("courtcost");
var nsf = document.getElementById("nsf");
var latechg = document.getElementById("latechg");
var secdep = document.getElementById("secdep");
var paidsum = document.getElementById("paidsum");
var dateNow = new Date();
var dayNow = dateNow.getDate();
var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
datepaid.value = datePaid;
paidsum.value = parseInt(paidsum.value) + parseInt(amtpaid.value);
tentpay.value = parseInt(tentpay.value) + parseInt(amtpaid.value) - parseInt(hudpay.value);
// *********************************************************
var totOwed = parseInt(rentdue.value) + parseInt(prevbal.value) + parseInt(secdep.value) + parseInt(damage.value) + parseInt(latechg.value) + parseInt(courtcost.value) +
parseInt(nsf.value) - parseInt(hudpay.value);
if(dayNow > 5) { late.value = "L"; totOwed = totOwed.value + 10; }
var excess = parseInt(amtpaid.value - rentdue.value);
if (amtpaid.value >= totOwed) { prevbal.value = totOwed - amtpaid.value ;
excess = 0 ; secdep.value = 0 ; damage.value = 0 ; latechg.value = 0 ;
courtcost.value = 0 ; nsf.value = 0; }
// *********************************************************
if (excess < prevbal.value && amtpaid.value > rentdue.value) { prevbal.value = prevbal.value - excess; excess = 0}
if (excess >= prevbal.value) { excess = excess - prevbal.value; prevbal.value = 0 ; }
if (excess < secdep.value && amtpaid.value > rentdue.value) { secdep.value = secdep.value - excess; excess = 0}
if (excess >= secdep.value) { excess = excess - secdep.value; secdep.value = 0 ; }
if (excess < damage.value && amtpaid.value > rentdue.value) { damage.value = damage.value - excess; excess = 0}
if (excess >= damage.value) { excess = excess - damage.value; damage.value = 0 ; }
if (excess < latechg.value && amtpaid.value > rentdue.value) { latechg.value = latechg.value - excess; excess = 0}
if (excess >= latechg.value) { excess = excess - latechg.value; latechg.value = 0 ; }
if (excess < courtcost.value && amtpaid.value > rentdue.value) { courtcost.value = courtcost.value - excess; excess = 0}
if (excess >= courtcost.value) { excess = excess - courtcost.value; courtcost.value = 0 ; }
if (excess < nsf.value && amtpaid.value > rentdue.value) { nsf.value = nsf.value - excess; excess = 0}
if (excess >= nsf.value) { excess = excess - nsf.value; nsf.value = 0 ; }
}
statement
"var totOwed = parseInt(rentdue.value) + parseInt(prevbal.value) + parseInt(secdep.value) + parseInt(damage.value) + parseInt(latechg.value) + parseInt(courtcost.value) +
parseInt(nsf.value) - parseInt(hudpay.value);"
but I don't know enough to make it work.
<script>
function $_(IDS) { return document.getElementById(IDS); }
function calculate_paid() {
var amtpaid = document.getElementById("amtpaid");
var rentdue = document.getElementById("rentdue");
var prevbal = document.getElementById("prevbal");
var hudpay = document.getElementById("hudpay");
var tentpay = document.getElementById("tentpay");
var datepaid = document.getElementById("datepaid");
var late = document.getElementById("late");
var damage = document.getElementById("damage");
var courtcost = document.getElementById("courtcost");
var nsf = document.getElementById("nsf");
var latechg = document.getElementById("latechg");
var secdep = document.getElementById("secdep");
var paidsum = document.getElementById("paidsum");
var dateNow = new Date();
var dayNow = dateNow.getDate();
var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
datepaid.value = datePaid;
paidsum.value = parseInt(paidsum.value) + parseInt(amtpaid.value);
tentpay.value = parseInt(tentpay.value) + parseInt(amtpaid.value) - parseInt(hudpay.value);
// *********************************************************
var totOwed = parseInt(rentdue.value) + parseInt(prevbal.value) + parseInt(secdep.value) + parseInt(damage.value) + parseInt(latechg.value) + parseInt(courtcost.value) +
parseInt(nsf.value) - parseInt(hudpay.value);
if(dayNow > 5) { late.value = "L"; totOwed = totOwed.value + 10; }
var excess = parseInt(amtpaid.value - rentdue.value);
if (amtpaid.value >= totOwed) { prevbal.value = totOwed - amtpaid.value ;
excess = 0 ; secdep.value = 0 ; damage.value = 0 ; latechg.value = 0 ;
courtcost.value = 0 ; nsf.value = 0; }
// *********************************************************
if (excess < prevbal.value && amtpaid.value > rentdue.value) { prevbal.value = prevbal.value - excess; excess = 0}
if (excess >= prevbal.value) { excess = excess - prevbal.value; prevbal.value = 0 ; }
if (excess < secdep.value && amtpaid.value > rentdue.value) { secdep.value = secdep.value - excess; excess = 0}
if (excess >= secdep.value) { excess = excess - secdep.value; secdep.value = 0 ; }
if (excess < damage.value && amtpaid.value > rentdue.value) { damage.value = damage.value - excess; excess = 0}
if (excess >= damage.value) { excess = excess - damage.value; damage.value = 0 ; }
if (excess < latechg.value && amtpaid.value > rentdue.value) { latechg.value = latechg.value - excess; excess = 0}
if (excess >= latechg.value) { excess = excess - latechg.value; latechg.value = 0 ; }
if (excess < courtcost.value && amtpaid.value > rentdue.value) { courtcost.value = courtcost.value - excess; excess = 0}
if (excess >= courtcost.value) { excess = excess - courtcost.value; courtcost.value = 0 ; }
if (excess < nsf.value && amtpaid.value > rentdue.value) { nsf.value = nsf.value - excess; excess = 0}
if (excess >= nsf.value) { excess = excess - nsf.value; nsf.value = 0 ; }
}