<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_MATERIAL_REQ_TRANSFER';
$path_to_root = "..";

include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/inventory/includes/material_transfer_receipts_ui.inc");
include_once($path_to_root . "/inventory/includes/db/material_transfer_receipts_db.inc");
include_once($path_to_root . "/inventory/includes/db/material_requisition_transfers_db.inc");
include_once($path_to_root . "/inventory/includes/db/material_transfer_requisitions_db.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/includes/project_cost_functions.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");
include_once($path_to_root . "/includes/data_checks.inc");
//include_once($path_to_root . "/projects/includes/db/tasks_db.inc"); 
include_once($path_to_root . "/includes/ui/ui_lists_group_companies.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 = "Material Transfer Receipts"), false, false, "", $js);

if (isset($_GET['AddedID'])) {
    $trans_no = $_GET['AddedID'];
	$trans_type = ST_MATERIAL_TRANSFER_RECEIPT;

	display_notification_centered(_("Material Transfer Receipt ".$trans_no." has been saved"));
        
        display_note(get_trans_view_str($trans_type, $trans_no, _("&View this Material Transfer Receipt #$trans_no")));
        
//	display_note(print_document_link($trans_no, _("&Print This Material Transfer Receipt"), true, $trans_type), 0, 0);

	hyperlink_no_params("$path_to_root/inventory/inquiry/material_requisition_transfers_inquiry.php?type=".ST_REQTRANSFER, _("Process &Another Material Transfer Receipt"));

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

	display_footer_exit();
}

if (isset($_POST['Process'])) {
    create_material_transfer_receipt(false);
}

$id = find_submit('Delete');
    if ($id != -1) {
        handle_delete_item($id);
    }

if (isset($_POST['AddItem'])) {
    handle_new_item();
}

if (isset($_POST['UpdateItem'])) {
    handle_update_item();
}

if (isset($_POST['CancelItemChanges'])) {
    line_start_focus();
}

if (isset($_GET['mrt_no']) && $_GET['mrt_no'] > 0) {
    if (! isset($_SESSION['mt_recp_items'])) {
        handle_new_order();
    }
    
    if ($_GET['mrt_no'] != $_SESSION['mt_recp_items']->order_id) {
        handle_new_order();
    }
}

start_form();

    global $systypes_array, $Ajax;

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

    display_material_transfer_receipt_header($_SESSION['mt_recp_items']);

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

            $Ajax->activate('mat_req_trn');
            div_start('mat_req_trn');
                display_material_transfer_receipt_items(_("Material Transfer Receipt Items"), $_SESSION['mt_recp_items']);
            div_end();
            
            mt_receipt_options_controls();

        end_outer_table(2, false);

    submit_center_first('Process', _("Create Material Transfer Receipt"), 'Create '.$systypes_array[ST_MATERIAL_TRANSFER_RECEIPT], 'default');    br(2);

end_form(3);

end_page();

?>