[eluser]Shaun Andrews[/eluser]
The method (get_budget_entries_for_current_cycle) grabs all entries that have the provided budget_id and where created after the cycle_start_date:
Code:
function get_budget_entries_for_current_cycle($budget_id, $cycle_start)
{
$this->db->select('description, amount, created_at')->where('budget', $budget_id)->where('created_at >', $cycle_start)->from('entries');
$query = $this->db->get();
return $query->result();
}
The cycle_start is based on the users account creation date (which can be manually reset if they desire). Here's the current formula:
Code:
# Find place in current monthly cycle:
# Start date is hard coded for now, but will pull from the users table.
$start_date = 1284076800;
# Find the difference (in s) between now and the start date.
$time_from_start_to_now = time() - $start_date;
# Divide the difference in time by 86,400s (a day) to find the number of days between start and current time.
$number_of_days_between = $time_from_start_to_now / 86400;
# Using the remainder (called 'mod' - %), find the current cycle day (based on a 28 day cycle) and week (based on a 7 day week).
$current_cycle_day = $number_of_days_between % 28;
$current_cylce_week = $current_cycle_day % 7;
# Take the current cycle day in seconds (86,400s = day) and subtract from the current time to find when the current cycle began.
$current_cylce_days_in_seconds = $current_cycle_day * 86400;
$current_cycle_start = time() - $current_cylce_days_in_seconds;