<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PETTY_CASH_FLOAT_REIMBURSEMENT';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/petty_cash/includes/ui/petty_cash_ui.inc");
include_once($path_to_root . "/includes/approval_functions.inc");
include_once($path_to_root . "/petty_cash/includes/db/petty_cash_float_reimbursement_db.inc");
include_once($path_to_root . "/petty_cash/includes/ui/petty_cash_float_reimbursement_ui.inc");

include_once($path_to_root . "/petty_cash/includes/db/petty_cash_float_adjustments_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_expenses_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/petty_cash_payments_db.inc");

include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/petty_cash_floats_db.inc");
include_once($path_to_root . "/gl/includes/db/gl_db_bank_accounts.inc");
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_advances_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/project_advance_batches_db.inc");
include_once($path_to_root . "/purchasing/includes/db/supp_trans_db.inc");


include_once($path_to_root . "/reporting/includes/reporting.inc");


$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 = "Petty Cash Float Reimbursement "), false, false, "", $js);
simple_page_mode(true);


 if(isset($_POST['float_id']))
{
    $float_id = $_POST['float_id'];

}

if (isset($_GET['Added_ID'])) 
{
	//return;
        
    $trans_no = $_GET['Added_ID'];
	$trans_type = ST_PETTY_CASH_FLOAT_REIMBUR;

	display_notification_centered("Float Reimbursement $trans_no has been created.");
        
	display_note(print_document_link($trans_no, _("&Print this Float Reimbursement"), true, $trans_type), 0, 0);

	hyperlink_no_params("$path_to_root/petty_cash/petty_cash_float_reimbursement.php", _("Create another &Float Reimbursement"));

//	hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), "filterType=$trans_type&trans_no=$trans_no");

	display_footer_exit();
}


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






if(isset($_POST['recalculate']))
{
//    if(isset($_POST['float_id'])){
//        $float_id = $_POST['float_id'];
//        display_transactions_for_float_reimbursement($float_id, $_POST['from_date'], $_POST['to_date']);
//    }
}

if(isset($_POST['create_petty_cash_reimbursement']))
{ 
    create_float_reimbursement($float_id, $_POST['from_date'], $_POST['to_date']);
}


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

if (!@$_GET['popup'])
start_form();
start_table(TABLESTYLE2);
petty_cash_floats_list_row('Petty Cash Float:', 'float_id', null, 'Select Float', true);
end_table();
br();

if(isset($_POST['float_id']))
{
    $float_id = $_POST['float_id'];

}


start_table(TABLESTYLE_NOBORDER);
start_row();
    date_cells(_("from:"), 'from_date', '', null, -7);
    date_cells(_("to:"), 'to_date');
    submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
end_row();
end_table();

br();

display_transactions_for_float_reimbursement($float_id, $_POST['from_date'], $_POST['to_date']);
 
global $Ajax;

$Ajax->activate('float_reim');
display_float_reimbursement_controles($float_id);


submit_center_first('recalculate', _("Calcualte"), '', 'default');

submit('create_petty_cash_reimbursement', _("Create Petty Cash Reimbursement"), true, false, 'default');
br();

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


?>
