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

include($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc"); 
include_once($path_to_root . "/inventory/includes/ui/view_issue_lot_selection_edit_ui.inc"); 
include_once($path_to_root . "/inventory/includes/db/lot_allocations_db.inc"); 
include_once($path_to_root . "/includes/db/inventory_db.inc"); 
include_once($path_to_root . "/inventory/includes/ui/lot_ui.inc"); 
include_once($path_to_root . "/inventory/includes/db/lots_db.inc"); 

$js = "";
$js .= get_js_open_window(800, 500);

global $systypes_array;

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

page(_($help_context = "View ".$systypes_array[$_POST["type"]]." Lot Selection Edit"), true, false, "", $js);

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

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

if (isset($_POST['Save_LOT'])) {        
    $msg = save_issue_lot_selections($_POST["type"], $_POST["trans_no"], $_POST["line_id"]);
        if ($msg['success'] !== true) {
            if (isset($msg["focus_to"])) {
                set_focus($msg["focus_to"]);            
            }
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
            clear_issue_lot_selection_details($_POST["type"], $_POST["trans_no"], $_POST["line_id"]);
        }
}

start_form();

    if (isset($_POST["type"])) {
        hidden('type', $_POST["type"]);
    }
    if (isset($_POST["trans_no"])) {
        hidden('trans_no', $_POST["trans_no"]);
    }
    if (isset($_POST["line_id"])) {
        hidden('line_id', $_POST["line_id"]);
    }
    
    $Ajax->activate('issue_lot_selection');
    div_start('issue_lot_selection');
    
        display_line_details($_POST["type"], $_POST["trans_no"], $_POST["line_id"]);

        display_issue_lot_selections($_POST["type"], $_POST["trans_no"], $_POST["line_id"]);
        
        start_table();
            submit_center_last('Save_LOT', _("Save Issue Lots"), _("Save"), 'default');   
        end_table(2);
        
   div_end();

end_form();
    
end_page(true, false, false, ST_JOB_LOT_SELECTION, $_POST["trans_no"]);

?>