开发者

php income breakdown report problems

I hav开发者_开发知识库e to create a report which breaksdown membership fees over the fiscal years.

Fiscal year starts on the 31 July membership length is 1 or 2 years.

I would like to pro-rate the membership to determine how much of their dues belong in which fiscal year.

for example, a 1 year membership depending on when the member started, would span 2 fiscal years.

Ie 365 days, 50 days in fiscal year 1 and 315 in the second fiscal year. So the total would be (Dues/365) x 50 for year 1 and (Dues/365) year 2.

How could I reflect that in my report?

Thanks!

Edit:

this is an actual example form the current membership. Fiscal year is on the 31 of July

Member 1, dues $50, received 09/10/2009, days 730, Breakdown Fy2010 20.82, fy2011 25.00, fy2012 4.18


Jon, Here's a routine to get the next invoice date - http://www.php.net/manual/en/function.date.php#103196 which you could modify to get the next two fiscal year end dates, since they always end on the same date, but different years.

Combine that with a date diff, such as the function here http://php.net/manual/en/function.date-diff.php and you should be able to calculate how much time is left in each fiscal year.


Thanks to Brian Hoover who led me to the proper information.

I wish to display the code for others to see just how you can pro-rate things (it is tricky!) If you have any suggestions on making the code cleaner, please advise. I am just a newbie.

<?php 

//setup of the dates and values to play with

$now = $row->Membership_Date;
$membership_date = strtotime($now);
$fy2010 = strtotime("2010-07-31");
$fy2011 = strtotime("2011-07-31");
$fy2012 = strtotime("2012-07-31");
$fy2013 = strtotime("2013-07-31");
$fy2014 = strtotime("2014-07-31");

//doing the math to determine time span in unix timecode

$datedifffy2010 = $fy2010 - $membership_date;
$datedifffy2011 = $fy2011 - $membership_date;
$datedifffy2012 = $fy2012 - $membership_date;
$datedifffy2013 = $fy2013 - $membership_date;
$datedifffy2014 = $fy2014 - $membership_date;

//doing the math to transform it into full days

$fulldays2010 = floor($datedifffy2010/(60*60*24));
$fulldays2011 = floor($datedifffy2011/(60*60*24));
$fulldays2012 = floor($datedifffy2012/(60*60*24));
$fulldays2013 = floor($datedifffy2013/(60*60*24));
$fulldays2014 = floor($datedifffy2014/(60*60*24));

//Some values come back as negative, so we are making those zero

if ($fulldays2010 <= 0)
{
    $fulldays2010 = 0;  
};

if ($fulldays2011 <= 0)
{
    $fulldays2011 = 0;  
};

if ($fulldays2012 <= 0)
{
    $fulldays2012 = 0;  
};

if ($fulldays2013 <= 0)
{
    $fulldays2013 = 0;  
};

if ($fulldays2014 <= 0)
{
    $fulldays2014 = 0;  
};

//arithmetic to determine how many days belong to which fiscal year

if ($row->Membership_Length == 2)
{
$fy11remainder = 730 - $fulldays2010;
if ($fy11remainder >= 365) $fy11remainder = 365;
$fy12remainder = 730 - $fy11remainder - $fulldays2010;
if ($fy12remainder >= 365) $fy12remainder = 365;
$fy13remainder = 730 - $fy12remainder - $fy11remainder - $fulldays2010;
if ($fy13remainder >= 365) $fy13remainder = 365;
$fy14remainder = 730 - $fy13remainder - $fy12remainder - $fy11remainder - $fulldays2010;
}
else
{
$fy11remainder = 365 - $fulldays2010;
if ($fy11remainder >= 365) $fy11remainder = 365;
$fy12remainder = 365 - $fy11remainder - $fulldays2010;
if ($fy12remainder >= 365) $fy12remainder = 365;
$fy13remainder = 365 - $fy12remainder - $fy11remainder - $fulldays2010;
if ($fy13remainder >= 365) $fy13remainder = 365;
$fy14remainder = 365 - $fy13remainder - $fy12remainder - $fy11remainder - $fulldays2010;

};

//determining the mill rate for days (our organization has discounts for 2 year memberships, and different types of memberships have different prices

if ($length == 2)
{
    $income = $row->Dues_Paid;
    $daily_income = $income / 730;
}
else
{
    $income = $row->Dues_Paid;
    $daily_income = $income / 365;
};

//Mutiplying days by the mill rate for that specific entry or member

$fy10inc = $fulldays2010 * $daily_income;
$fy11inc = $fy11remainder * $daily_income;
$fy12inc = $fy12remainder * $daily_income;
$fy13inc = $fy13remainder * $daily_income;
$fy14inc = $fy14remainder * $daily_income;

//display pro-rate for fiscal year

echo $fy10inc;


?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜