<?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/remove_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/remove_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"); 

$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 = "Remove 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_Remove_No'])) {            
    $trans_no = $_GET['Processed_IOU_Remove_No'];
    $message = get_session_variable('remove_i_owe_you_message');
    clear_session_variable('remove_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["REMOVE_FROM_BATCH"])) {
    $msg = handle_remove_i_owe_you($iou_no);   
        if ($msg["success"] !== true) {   
            display_error($msg['message']);
        } else {
            set_session_variable('remove_i_owe_you_message', $msg['message']);
            meta_forward($_SERVER['PHP_SELF'], "Processed_IOU_Remove_No=$iou_no");
        }
}


    start_form();
    
        hidden('iou_no', $iou_no);
        
        display_remove_i_owe_you($iou_no);
        
        submit_center_first('REMOVE_FROM_BATCH', _("Remove IOU From Batch"), '', 'default');        br(3);

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

?>