smplejohn Posted July 21, 2017 Share Posted July 21, 2017 I've been working on a script to figure out the yearly projected sales like the income forecast on the dashboard and since making it I've been having trouble getting the two numbers to match up. I feel my script is pretty encompassing and more thorough, so now I'm wondering if WHMCS' income forecast is correct. Here's the script I'm trying to use: // Total Annual Revenue $total = 0; $breakdown = array(); $stmt = $db->prepare('SELECT * FROM tblhosting WHERE domainstatus="Active" OR domainstatus="Suspended"'); $stmt->execute(); while($r = $stmt->fetch()){ $cycle = $r['billingcycle']; $amount = $r['amount']; switch($cycle){ case "Monthly": $yearly = $amount * 12; $breakdown['monthly'] = $breakdown['monthly'] + $amount; $breakdown['monthlycount'] = $breakdown['monthlycount'] + 1; break; case "Quarterly": $yearly = $amount * 4; $breakdown['quarterly'] = $breakdown['quarterly'] + $amount; $breakdown['quarterlycount'] = $breakdown['quarterlycount'] + 1; break; case "Semi-Annually": $yearly = $amount * 2; $breakdown['semiannually'] = $breakdown['semiannually'] + $amount; $breakdown['semiannuallycount'] = $breakdown['semiannuallycount'] + 1; break; case "Annually": $yearly = $amount; $breakdown['annually'] = $breakdown['annually'] + $amount; $breakdown['annuallycount'] = $breakdown['annuallycount'] + 1; break; case "Biennially": $yearly = $amount/2; $breakdown['biannually'] = $breakdown['biannually'] + $amount; $breakdown['biannuallycount'] = $breakdown['biannuallycount'] + 1; break; case "Triennially": $yearly = $amount/3; $breakdown['triannually'] = $breakdown['triannually'] + $amount; $breakdown['triannuallycount'] = $breakdown['triannuallycount'] + 1; break; default: $yearly = $amount; $breakdown['default'] = $breakdown['default'] + $amount; $breakdown['defaultcount'] = $breakdown['defaultcount'] + 1; break; } $total = $total + $yearly; } $stmt = $db->prepare('SELECT * FROM tblhostingaddons WHERE status="Active" OR status="Suspended"'); $stmt->execute(); while($r = $stmt->fetch()){ $cycle = $r['billingcycle']; $amount = $r['recurring']; switch($cycle){ case "Monthly": $yearly = $amount * 12; $breakdown['monthly'] = $breakdown['monthly'] + $amount; break; case "Quarterly": $yearly = $amount * 4; $breakdown['quarterly'] = $breakdown['quarterly'] + $amount; break; case "Semi-Annually": $yearly = $amount * 2; $breakdown['semiannually'] = $breakdown['semiannually'] + $amount; break; case "Annually": $yearly = $amount; $breakdown['annually'] = $breakdown['annually'] + $amount; break; case "Biennially": $yearly = $amount/2; $breakdown['biannually'] = $breakdown['biannually'] + $amount; break; case "Triennially": $yearly = $amount/3; $breakdown['triannually'] = $breakdown['triannually'] + $amount; break; default: $yearly = $amount; $breakdown['default'] = $breakdown['default'] + $amount; break; } $total = $total + $yearly; } $yearlyProducts = $total; $yearlyProductTotal = number_format($total,2); $total = 0; $stmt = $db->prepare('SELECT * FROM tbldomains WHERE status="Active"'); $stmt->execute(); while($r = $stmt->fetch()){ $amount = $r['recurringamount']; $cycle = $r['registrationperiod']; $yearly = $amount/$cycle; $breakdown['domains'] = $breakdown['domains'] + $amount; $breakdown['domainscount'] = $breakdown['domainscount'] + 1; $total = $total + $yearly; } $yearlyDomains = $total; $yearlyDomainTotal = number_format($total,2); $yearlyTotal = number_format($yearlyProducts + $yearlyDomains,2,".",","); echo "Monthly: $" . number_format($breakdown['monthly'],2,'.',',') . " (" . $breakdown['monthlycount'] . ")<br />"; echo "Quarterly: $" . number_format($breakdown['quarterly'],2,'.',',') . " (" . $breakdown['quarterlycount'] . ")<br />"; echo "Semi-Annually: $" . number_format($breakdown['semiannually'],2,'.',',') . " (" . $breakdown['semiannuallycount'] . ")<br />"; echo "Annually: $" . number_format($breakdown['annually'],2,'.',',') . " (" . $breakdown['annuallycount'] . ")<br />"; echo "Biennially: $" . number_format($breakdown['biannually'],2,'.',',') . " (" . $breakdown['biannuallycount'] . ")<br />"; echo "Triennially: $" . number_format($breakdown['triannually'],2,'.',',') . " (" . $breakdown['triannuallycount'] . ")<br />"; echo "One Time: $" . number_format($breakdown['default'],2,'.',',') . " (" . $breakdown['defaultcount'] . ")<br />"; echo "Domains: $" . number_format($breakdown['domains'],2,'.',',') . " (" . $breakdown['domainscount'] . ")<br />"; echo "Estimated Annual: $yearlyTotal"; exit(); And if you want to compare to WHMCS' queries you can look at the income_forecast.php file. I also have a ticket open because I believe WHMCS' file may be off. Any thoughts on what I may be missing here? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.