<?php

$page_security = 'SA_I_OWE_YOU_REQUESTS_ENTRY';

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 . "/petty_cash/includes/ui/petty_cash_ui.inc"); 
include_once($path_to_root . "/petty_cash/includes/ui/close_i_owe_you_ui.inc"); 
include_once($path_to_root . "/petty_cash/includes/ui/view_i_owe_you_ui.inc"); 
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/approve_i_owe_you_enties_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_advances_inquiry_db.inc"); 
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_expenses_db.inc"); 
include_once($path_to_root . "/inventory/includes/db/petty_cash_item_receive_db.inc"); 
include_once($path_to_root . "/transport/includes/db/vehicles_db.inc"); 
include_once($path_to_root . "/admin/db/list_values_db.inc"); 
include_once($path_to_root . "/includes/db/group_companies_db.inc");
include_once($path_to_root . "/includes/approval_functions.inc"); 
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_advances_db.inc"); 
include_once($path_to_root . "/includes/project_cost_functions.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 = "Close I Owe You"), false, false, "", $js);

simple_page_mode(true);

$iou_no = 0;

if (isset($_GET["iou_no"])) {
    $iou_no = $_GET["iou_no"];
} elseif (isset($_POST["iou_no"])) {
    $iou_no = $_POST["iou_no"];
}

if (isset($_GET['Processed_IOU_Close_No'])) {            
    $trans_no = $_GET['Processed_IOU_Close_No'];
    $message = get_session_variable('close_i_owe_you_message');
    clear_session_variable('close_i_owe_you_message');
    
    display_notification_centered($message);
    hyperlink_no_params("$path_to_root/petty_cash/inquiry/i_owe_you_inquiry.php", _("Process Another &I Owe You"));
    display_footer_exit();
}

if (isset($_POST["CLOSE_I_OWE_YOU"])) {
    $msg = handle_close_i_owe_you($iou_no);   
        if ($msg["success"] !== true) {   
            display_error($msg['message']);
        } else {
            set_session_variable('close_i_owe_you_message', $msg['message']);
            meta_forward($_SERVER['PHP_SELF'], "Processed_IOU_Close_No=$iou_no");
        }
}

    start_form();
    
        if ($iou_no > 0) {
            hidden('iou_no', $iou_no);
        }
    
        display_close_i_owe_you($iou_no);
        
        submit_center_first('CLOSE_I_OWE_YOU', _("Close I Owe You"), '', 'default');        br(3);

    end_form();
    
    end_page(@$_GET['popup'], false, false);

?>