Esempio n. 1
0
if (!module_finance::can_i('view', 'Finance Upcoming')) {
    redirect_browser(_BASE_HREF);
}
$module->page_title = 'Recurring';
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : array();
if (module_config::c('finance_recurring_show_finished', 0)) {
    $search['show_finished'] = true;
}
if (!isset($search['date_to'])) {
    $search['date_to'] = print_date(strtotime('+' . (int) module_config::c('finance_recurring_months', 6) . ' months'));
}
$balance = isset($_REQUEST['balance']) ? (double) $_REQUEST['balance'] : module_config::c('finance_recurring_start_balance', 0);
module_config::save_config('finance_recurring_start_balance', $balance);
$_SESSION['_finance_recurring_ids'] = array();
module_debug::log(array('title' => 'calling get_recurrings', 'data' => ''));
$upcoming_finances_unsorted = module_finance::get_recurrings($search);
module_debug::log(array('title' => 'finished calling get_recurrings', 'data' => 'count: ' . count($upcoming_finances_unsorted)));
$upcoming_finances = array();
$limit_timestamp = isset($search['date_to']) && !empty($search['date_to']) ? strtotime(input_date($search['date_to'])) : strtotime('+' . (int) module_config::c('finance_recurring_months', 6) . ' months');
$duplicate_limit = 30;
$upcoming_finance_key = 0;
foreach ($upcoming_finances_unsorted as $recurring) {
    $time = strtotime($recurring['next_due_date']);
    $original = true;
    $count = 0;
    while ($time < $limit_timestamp) {
        $next_time = 0;
        if ($count++ > $duplicate_limit) {
            break;
        }
        // we need a special case for the first one that hasn't had a last trasnaction
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename="cal.ics"');
ob_start();
$search = array();
// todo - pass any ical options through to search
// how many months in the future are we limitingi this output to?
$months = isset($options['months']) ? (int) $options['months'] : (int) module_config::c('calendar_recurring_months', 6);
$limit_timestamp = strtotime('+' . $months . ' months');
// don't show any transactions after our timestamp here.
$search['show_finished'] = false;
$upcoming_finances = module_finance::get_recurrings($search);
// loop over each upcoming finance
// calculate the iterations of upcoming transactions date for each finance.
// print out those dates as long as they are before our limiting timestamp.
echo 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Ultimate Client Manager/Calendar Plugin v1.0//EN
CALSCALE:GREGORIAN
X-WR-CALNAME:Recurring ' . (isset($options['credit']) && $options['credit'] ? _l('Credit') . ' ' : '') . (isset($options['debit']) && $options['debit'] ? _l('Debit') . ' ' : '') . _l('Transactions') . '
X-WR-TIMEZONE:UTC
';
//$local_timezone_string = date('e');
//$local_timezone = new DateTimeZone($local_timezone_string);
//$local_time = new DateTime("now", $local_timezone);
$timezone_hours = module_config::c('timezone_hours', 0);
foreach ($upcoming_finances as $recurring) {