<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_ISSUE_PETTY_CASH_ITEMS';
$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 . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");

include_once($path_to_root . "/inventory/includes/issue_petty_cash_items_ui.inc");
include_once($path_to_root . "/inventory/includes/db/issue_petty_cash_items_db.inc");
include_once($path_to_root . "/inventory/includes/db/petty_cash_item_receive_db.inc");
include_once($path_to_root . "/inventory/includes/db/petty_cash_item_receive_inquiry_db.inc");

include_once($path_to_root . "/inventory/includes/lots_validation.inc");
include_once($path_to_root . "/inventory/includes/serial_no_validation.inc");
include_once($path_to_root . "/inventory/includes/db/serial_no_adjustments_db.inc");
include_once($path_to_root . "/inventory/includes/db/serial_no_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");


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

global $systypes_array;

page(_($help_context = $systypes_array[ST_PETTY_CASH_ITEM_ISSUE]), false, false, "", $js);

//-----------------------------------------------------------------------------------------------

check_db_has_costable_items(_("There are no inventory items defined in the system which can be adjusted (Purchased or Manufactured)."));

check_db_has_movement_types(_("There are no inventory movement types defined in the system. Please define at least one inventory adjustment type."));

//-----------------------------------------------------------------------------------------------

if (isset($_GET['Added_ID'])) 
{
    global  $systypes_array;


    $trans_no = $_GET['Added_ID'];
	$trans_type = $_GET['Type_ID'];
    
        $message = $systypes_array[$trans_type]." #".$trans_no." has been created.";
        
	display_notification_centered($message);
        
//	display_note(print_document_link($trans_no, _("&Print This Material Issue"), true, $trans_type), 0, 0);

	hyperlink_no_params("$path_to_root/inventory/inquiry/petty_cash_item_receipts_inquiry.php", _("Create &Another ".$systypes_array[$trans_type]));

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

	display_footer_exit();
}


//--------------------------------------------------------------------------------------------------

function line_start_focus() {
  global 	$Ajax;

  $Ajax->activate('items_table');
  set_focus('_stock_id_edit');
}
//-----------------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------------------------



//-----------------------------------------------------------------------------------------------


function add_lot_details()
{
    if(!isset($_SESSION['lot_info#'.ST_MATERIAL_ISSUE])){
        return;
    }
    
    $lot_info_array =  $_SESSION['lot_info#'.ST_MATERIAL_ISSUE];

    foreach ($_SESSION['im_items']->line_items as $line_item) {
       	if($line_item->stock_control_method != SKCM_NORMAL){
            $line_item->lot_details = $lot_info_array[$line_item->stock_id] ;
        } 
    }    
}    


//-------------------------------------------------------------------------------


if (isset($_POST['Create_IM']))
{
    create_petty_cash_item_issue();
} 

if (isset($_POST['Create_IM_Close_MR'])){
    create_petty_cash_item_issue(true);
}

if(isset($_POST['Close_MR'])){
    close_material_requisition($_SESSION['im_items']->order_id);
}


//
//$stype = $sdid = 0;

if (isset($_GET['stype']) && $_GET['stype'] > 0) 
{
    $_POST['stype'] = $_GET['stype'];
}
if (isset($_GET['sdid']) && $_GET['sdid'] > 0) 
{
    $_POST['sdid'] = $_GET['sdid'];
}

$stype = $_POST['stype'];
$sdid = $_POST['sdid'];

//$source_row = get_petty_cash_stock_item_record_by_id($id);
//$tran_type = $source_row['type'];
//$trans_no = $source_row['trans_no'];

//-----------------------------------------------------------------------------------------------
start_form();

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

br(2);

display_petty_cash_item_receive_source($stype, $sdid);

br(2);

display_petty_cash_item_issue_header($stype, $sdid);

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

display_petty_cash_item_issue_items($stype, $sdid);


mrt_options_controls();

//end_outer_table(1, false);

//submit_center_first('Update', _("Update"), '', null);
submit_center_first('Create_IM', _("Issue Items"), '', 'default');
br(2);
//submit_center_first('Create_IM_Close_MR', _("Create Issue & Close Petty Cash Item Receipt"), '', 'default');
//submit('Create_IM_Close_MR', 'Create MI & Close MR', true, '', 'default');
//submit_center_last('Close_MR', 'Close Close Petty Cash Item Receipt', '', 'default');

end_form();

br(1);
end_page();

?>
