<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_DAILY_ITEM_ISSUE';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$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/ui.inc");
include_once($path_to_root . "/includes/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");
include_once($path_to_root . "/transport/includes/db/vehicles_db.inc");
include_once($path_to_root . "/assets/includes/db/assets_db.inc");

include_once($path_to_root . "/includes/approval_functions.inc");
include_once($path_to_root . "/includes/project_cost_functions.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");

include_once($path_to_root . "/inventory/includes/ui/batch_item_issue_ui.inc");
include_once($path_to_root . "/inventory/includes/ui/batch_item_issue_select_ui.inc");
include_once($path_to_root . "/inventory/includes/ui/batch_item_issue_create_pr_issues_ui.inc");
include_once($path_to_root . "/inventory/includes/db/batch_item_issue_create_pr_issues_db.inc");
include_once($path_to_root . "/inventory/includes/db/batch_item_issue_db.inc");

include_once($path_to_root . "/inventory/includes/ui/batch_item_issue_transactions_ui.inc");
include_once($path_to_root . "/inventory/includes/db/batch_item_issue_transactions_db.inc");

include_once($path_to_root . "/purchasing/includes/ui/pr_issues_ui.inc");
include_once($path_to_root . "/purchasing/includes/pr_validations.inc");
include_once($path_to_root . "/purchasing/includes/db/purchase_requisitions_db.inc");
include_once($path_to_root . "/purchasing/includes/db/pr_issues_db.inc");

include_once($path_to_root . "/inventory/includes/ui/batch_item_issue_create_mr_issues_ui.inc");
include_once($path_to_root . "/inventory/includes/issue_materials_ui.inc");
include_once($path_to_root . "/inventory/includes/db/batch_item_issue_create_mr_issues_db.inc");
include_once($path_to_root . "/inventory/includes/db/material_requisitions_db.inc");
include_once($path_to_root . "/inventory/includes/db/issue_materials_db.inc");

include_once($path_to_root . "/inventory/includes/ui/batch_item_issue_create_di_issues_ui.inc"); 
include_once($path_to_root . "/inventory/includes/db/batch_item_issue_create_di_issues_db.inc");
include_once($path_to_root . "/inventory/includes/db/daily_item_issue_db.inc");

include_once($path_to_root . "/includes/project_cost_functions.inc");
include_once($path_to_root . "/includes/db/approval_functions_db.inc");
include_once($path_to_root . "/includes/db/project_cost_functions_db.inc");
 

$js = '';

if ($SysPrefs->use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}

page(_($help_context = "Batch Item Issue - Select Transactions"), false, false, "", $js);
//----------------------------------------------------------------------------------------
simple_page_mode(true);

$trans_type = ST_BATCH_ITEM_ISSUE;

$batch_no = 0;

if (isset($_GET['bii']))
{
    $_POST['bii'] = $_GET['bii'];
}
if(isset($_POST['bii']))
{
    $batch_no=$_POST['bii'] ;
} 



if (isset($_GET['processed_ID'])) 
{
	//return;
        
    $trans_no = $_GET['processed_ID'];
	
    $message = get_session_variable('batch_item_issue_messages');
    clear_session_variable('batch_item_issue_messages');
    
	display_notification_centered($message);
        
        display_note(get_trans_view_str(ST_BATCH_ITEM_ISSUE, $trans_no, _("View this ".$systypes_array[ST_BATCH_ITEM_ISSUE])), 0, 0);
//        hyperlink_no_params("$path_to_root/inventory/batch_item_issue.php", _("Create another ".$systypes_array[ST_BATCH_ITEM_ISSUE]));
        hyperlink_params("$path_to_root/inventory/batch_item_issue.php", _("Create another ".$systypes_array[ST_BATCH_ITEM_ISSUE]), "NewIssue=0");
        
        hyperlink_no_params("$path_to_root/inventory/inquiry/batch_item_issue_inquiry.php", _("Select another ".$systypes_array[ST_BATCH_ITEM_ISSUE]));
	
	display_footer_exit();
}


$batch = get_batch_item_issue_header_record($batch_no);
$project_id = $batch['project_id'];    
$user_id = $_SESSION['wa_current_user']->user;
$cap = can_access_project($project_id, $user_id);
if($cap['success'] !== true) 
{
    display_error($cap["message"]);
    display_footer_exit();
    return false;
}
    

function clear_data()
{
    $_POST['id'] = 0;
    $_POST['expence_date'] = "";
    $_POST['bill_no'] = "";
    $_POST['expence_description'] = "";   
    $_POST['amount'] = 0;  
}

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


if(isset($_POST['Process_BII'])){
    
    $pbii_msg = handle_process_batch_item_issue_transactions($batch_no);
    if($pbii_msg["success"] !== true){
        display_error($pbii_msg["message"]);
    }
    else{
        set_session_variable('batch_item_issue_messages', $pbii_msg["message"]);
        meta_forward($_SERVER['PHP_SELF'], "processed_ID=".$pbii_msg["trans_no"]);
    } 
    
}


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



if ($Mode == 'RESET')
{
    clear_data();
	$selected_id = -1;
}

if (isset($_POST['_selected_id_update']) )
{
	$selected_id = $_POST['selected_id'];
	//$Ajax->activate('_page_body');
}

//if(isset($_POST['Approve_Petty_Cash_Expense'])){
//    approve_petty_cash_payment(get_post('iou_id'));
//    approve_i_owe_you_expense($row_id, $approved_amount, $status_code);
//}

    

//if (list_updated('employee_code')) 
	$Ajax->activate('_page_body');
//--------------------------------------------------------------------------------------------------
        

start_form();
 
global $expense_categories, $Ajax;
//-------------------------------------------------------------------------------------

$batch_h = get_batch_item_issue_header($batch_no);

$_POST['biih_row_state'] = $batch_h['row_state'];
hidden('biih_row_state', $_POST['biih_row_state']);

view_batch_item_issue_header($trans_type, $batch_h['trans_no']);

hidden('bii', $_POST['bii']);

display_batch_item_issue_select_details($batch_no); 

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

div_start('expences_table');


//br();

div_end();

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


//submit_center_first('Process_BII', _("Process"), '', 'default');
submit_center_first('Process_BII', _("Process"), '', 'process');
//submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');

br(1);

hyperlink_params("$path_to_root/inventory/batch_item_issue.php", _("Edit this Batch Item Issue"), "ModifyIssue=".$batch_no); 

br(2);

    
    
    


if (!@$_GET['popup'])
{
	end_form();
	end_page(@$_GET['popup'], false, false);
}
?>
