<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_MATERIAL_REQ_TRANSFER';
$path_to_root = "..";

include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/purchasing/includes/ui/purchase_requisition_returns_ui.inc");
include_once($path_to_root . "/purchasing/includes/db/purchase_requisitions_db.inc");
include_once($path_to_root . "/includes/ui/ui_lists_group_companies.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");
include_once($path_to_root . "/admin/db/users_db.inc"); 
include_once($path_to_root . "/purchasing/includes/db/pr_issues_db.inc"); 
include_once($path_to_root . "/reporting/includes/reporting.inc"); 
include_once($path_to_root . "/purchasing/includes/db/pr_returns_db.inc"); 
include_once($path_to_root . "/includes/project_cost_functions.inc"); 
include_once($path_to_root . "/purchasing/includes/db/pr_returns_db.inc"); 
include_once($path_to_root . "/inventory/includes/db/items_adjust_db.inc"); 

$js = "";
if ($SysPrefs->use_popup_windows)
    $js .= get_js_open_window(800, 500);
if (user_use_date_picker())
    $js .= get_js_date_picker();


page(_($help_context = "Purchase Requisition Returns"), false, false, "", $js);

if (isset($_GET['Added_PRR_ID'])) {
    $prr_no = $_GET['Added_PRR_ID'];
    $trans_type = ST_PURCH_REQ;

    $message = get_session_variable('prr_messages');
    clear_session_variable('prr_messages');
    
	display_notification($message);
        
	display_note(print_document_link($prr_no, _("&Print this purchase requisition returns"), true, $trans_type), 0, 0);

	hyperlink_no_params("$path_to_root/purchasing/inquiry/pr_issues_inquiry.php", _("Process &Another Purchase Requisition Return"));

	display_footer_exit();
}


if (isset($_POST['Create_PRR'])) {
    create_prr_return();
} 

function check_item_data() {
	if (!check_num('tran_qty',0.01))
	{
            display_error(_("The quantity entered is negative or invalid."));
            set_focus('tran_qty');
            return false;
	}
   	return true;
}


if (isset($_GET['pri_no']) && $_GET['pri_no'] > 0) {
    if (! isset($_SESSION['prr_items'])) {
        handle_new_prr_order();
    }
    
    if ($_GET['pri_no'] != $_SESSION['prr_items']->order_id) {
        handle_new_prr_order();
    }
}

start_form();

    $guid = ST_PR_ISSUE;
    $_POST['guid'] = $guid;
    hidden("guid",$guid);

    display_purchase_requisition_return_header($_SESSION['prr_items']);

    start_outer_table(TABLESTYLE, "width=80%", 10);

        display_pr_return_items(_("Purchase Requisition Items"), $_SESSION['prr_items']);
        mrt_options_controls();

    end_outer_table(2, false);

    submit_center_first('Create_PRR', _("Create Purchase Requisition Return"), '', 'default');

end_form(4);
end_page();

?>