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

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

include($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once ($path_to_root . "/trace.php");
include_once($path_to_root . "/includes/db/inventory_db.inc");
include_once($path_to_root . "/assets/includes/db/assets_db.inc");
include_once($path_to_root . "/purchasing/includes/db/grn_db.inc"); 
include_once($path_to_root . "/projects/includes/db/projects_db.inc"); 
include_once($path_to_root . "/assets/includes/ui/stock_asset_transfer_ui.inc");
include_once($path_to_root . "/assets/includes/db/stock_asset_transfer_db.inc");
include_once($path_to_root . "/includes/project_cost_functions.inc");
include_once($path_to_root . "/assets/includes/db/approve_asset_run_calculation_db.inc"); 
include_once($path_to_root . "/assets/includes/db/asset_valuations_db.inc"); 

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();
	
page(_($help_context = "Stock Asset Transfer"), @$_REQUEST['popup'], false, "", $js);

$type = ST_STOCK_ASSET_TRANSFER;

if (isset($_GET['GRN_No']) || isset($_POST['GRN_No'])) {
    $GRN_No = $_POST['GRN_No'] = isset($_GET['GRN_No']) ? $_GET['GRN_No'] : $_POST['GRN_No'];
    
    $header = get_grn_batch($GRN_No);
        if (! is_array($header)) {
            display_error(("Invalid GRN No."));
            display_footer_exit();
        } 
} elseif(isset($_GET['SavedID'])) { 
    $trans_no = $_GET['SavedID'];
} else {
    display_error(("Invalid GRN No."));
    display_footer_exit();
}

if (isset($_GET['SavedID'])) {
    $trans_type = ST_STOCK_ASSET_TRANSFER;

        display_notification("Stock Asset Transfer $trans_no has been created.");
        
        display_note(get_trans_view_str($trans_type, $trans_no, _("&View this Stock Asset Transfer #$trans_no.")), 0, 1);
	
        hyperlink_no_params($path_to_root."/purchasing/inquiry/grn_inquiry.php", _("Enter &another  Stock Asset Transfer"));
        
	display_footer_exit();
}

if (isset($_POST['StockAssetTransfer'])){
    $ssat_msg = save_stock_asset_transfer($GRN_No, $type);
        if ($ssat_msg['success'] !== true) {
            display_error($ssat_msg['message']);
        }
}


$Ajax->activate('_page_body');
    
    start_form(true);
    
        if (isset($_POST['GRN_No'])) {
            hidden('GRN_No', $_POST['GRN_No']);
        }
        
        display_stock_asset_transfer_header($GRN_No, $type);

        div_start('details');

            display_stock_asset_transfer_details($GRN_No);

        div_end();
        
        submit_center_first('StockAssetTransfer', 'Transfer Inventory Item to Asset', 'Create Stock Asset Transfer', false, ICON_SUBMIT);

    end_form(3);


end_page(@$_REQUEST['popup']);

?>