<?php

$page_security = 'SA_GENERATE_FI_ENTRIES';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$path_to_root = "..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/gl/includes/fi/db/generate_fi_accounting_entries_db.inc");
include_once($path_to_root . "/gl/includes/fi/ui/generate_fi_accounting_entries_ui.inc");
include_once($path_to_root . "/gl/includes/fi/ui/fi_generate_project_accounting_entries_ui.inc");
include_once($path_to_root . "/gl/includes/fi/ui/check_fi_accounting_entries_ui.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");

fi_include_files($path_to_root);


$js = '';
if ($SysPrefs->use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}

page(_($help_context = "Generate Financial Integration Accounting Entries"),false,false,"",$js);

//---------------------------------------------------------------------------------------------------

//check_db_has_projects(_("There are no projects defined in the system."));

simple_page_mode(true);
//---------------------------------------------------------------------------------------------------
$input_error = 0;


if(isset($_POST['GenerateFIAccountingEntries'])){
    $cutoff_date_ = $_POST['cutoff_date'];
    $batch_size = input_num('batch_size');

    
    if(!($batch_size >= 1)){
        $batch_size = 0;
    }

        $cg_msg = can_generate_fi_entries($cutoff_date_, $batch_size);
        if($cg_msg['success'] !== true){
            set_focus($cg_msg["focus"]);
            display_error($cg_msg["message"]);
        }else{
            $msg = generate_fi_entries($cutoff_date_, $batch_size); 
            if($msg["success"] !== true){
                display_error($msg['message']);            
            } 
            else{
                display_notification($msg['message']);      
            }
        }
    
}


start_form();


start_table(TABLESTYLE);

date_row("Cutoff Date: :", 'cutoff_date');
amount_row("Transactions Per Type", "batch_size", null, null, null, 0);

end_table(1);

start_table(TABLESTYLE_NOBORDER);
    start_row();
        submit_cells('CheckNewEntries', _("Check New Transactions"));
    end_row();
end_table(1);

display_fi_transaction_types();



start_table(TABLESTYLE_NOBORDER);
    start_row();
        submit_cells('GenerateFIAccountingEntries', _("Generate Accounting Entries"));
    end_row();
end_table();


	
br(2);
    
//display_task_groups_summary($filetering_group_id, $project_id);

//display_task_groups($_POST['project_id'], $_POST['filtering_group_id']);
//------------------------------------------------------------------------------------------------

if(get_post('task_group_id') > 0){
    $selected_id = get_post('task_group_id');
    $Mode = 'Edit';
}
else{
    $selected_id = -1;
}

//display_edit_controls($Mode, $selected_id, $project_id);

//br();
//
//
//submit_center('CalculateProjectBudgetCosts', _("Calculate"), true, '',  'default');
//
//br(2);
//
//submit_center('CalculateForEntireProject', _("Calculate For Entire Project"), true, '',  'default');

br(2);

if (!@$_GET['popup'])
{
	end_form();
	end_page(@$_GET['popup'], false, false);
}	


?>
