I am very new to php, and am trying to create a simple dues calculator. All appears to work well when dues are within the minimum, tier 1, and above tier 4, but everything else doesn't seem to work. I've spent hours (because I am new), read through the FAQ, and am still puzzled.
Basically dues are calculated based on revenues. If revenue is say $2,000,000 then it is calculated as .35% on the first $1,000,000, and .15% on the remaining $1,000,000. If it were $6,000,000, then dues are .35% of the first $1M, .15% on the next $4M, and .01% on the final $1M.
The other caveat is that we have 2 membership types, and one pays 75% of the other.
Hopefully my code makes sense as to what I am trying to accomplish. But with the $6M example, I subtract the first $5M (which has a dues value of $9500) and add it back after the remaining dues are calculated. I've also added numbers to print with each "function" so that I can see which one is being calculated.
You can test the code here: http://www.amberandkevin.net/dues/index2.htm
Thanks in advance for your help!
note: of course I want to clean it up, but I want it to work first. If you could also give advice as to where I can find out how to add commas (to break up the long numbers) and round the final number to the nearest whole number, that would be wonderful!
My HTML page looks like this:
<form method="post" action="dues2.php">
Enter your consolidated revenues* <p>
<input type="text" name="rev" />
<p> Please select company type
<p><input type="radio" name="comp" value="coop" checked /> Cooperative
<p><input type="radio" name="comp" value="com" /> Commercial
<p>*Revenues include.... blah
<p><input type="submit" />
</form>
<?php
$comp = $_POST['comp'];
$rev = $_POST['rev'];
$min = 571428;
$tier1 = 1000000;
$tier2 = 5000000;
$teir3 = 10000000;
$tier4 = 20000000;
if ( $comp === "coop" && $rev <= $min ) {
echo "Your estimated dues are = 2000";
}
elseif ( $comp === "coop" && $rev <= $tier1 && $rev > $min ) {
echo " 1 Your estimated dues are = ";
echo $rev * .0035;
}
elseif ( $comp === "coop" && $rev > $tier1 && $rev <= $tier2 ) {
echo " 2 Your estimated dues are = ";
echo ($rev - $tier1) * .0015 + 3500 ;
}
elseif ( $comp === "coop" && $rev > $tier2 && $rev <= $tier3 ) {
echo " 3 Your estimated dues are = ";
echo ($rev - $tier2) * .001 + 9500 ;
}
elseif ( $comp === "coop" && $rev > $tier3 && $rev <= $tier4) {
echo " 4 Your estimated dues are = ";
echo ($rev - $tier3) * .0005 + 14500;
}
elseif ( $comp === "coop" && $rev > $tier4 ) {
echo " 5 Your estimated dues are = ";
echo ($rev - $tier4) * .0001 + 19500 ;
}
elseif ( $comp === "com" && $rev <= $min ) {
echo " 6 Your estimated dues are = 2000";
}
elseif ( $comp === "com" && $rev <= $tier1 && $rev > $min ) {
echo " 7 Your estimated dues are = ";
echo ($rev * .0035) * .75;
}
elseif ( $comp === "com" && $rev > $tier1 && $rev <= $tier2 ) {
echo " 8 Your estimated dues are = ";
echo (($rev - $tier1) * .0015 + 3500) *.75 ;
}
elseif ( $comp === "com" && $rev > $tier2 && $rev <= $tier3 ) {
echo " 9 Your estimated dues are = ";
echo (($rev - $tier2) * .001 + 9500) *.75 ;
}
elseif ( $comp === "com" && $rev > $tier3 && $rev <= $tier4) {
echo "10 Your estimated dues are = ";
echo (($rev - $tier3) * .0005 + 14500) *.75;
}
elseif ( $comp === "com" && $rev > $tier4 ) {
echo " 11 Your estimated dues are = ";
echo (($rev - $tier4) * .0001 + 19500) *.75 ;
}
else {
echo "I do not understand your input. Please try again with no special characters";
}
?>