<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_BANKTRANSFER';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$path_to_root = "..";

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 . "/gl/includes/ui/batch_bank_transfer_ui.inc");
include_once($path_to_root . "/gl/includes/db/batch_bank_transfer_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 . "/includes/references.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(900, 500);
}

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

page(_($help_context = "Batch Bank Transfer Requests"), false, false, "", $js);

//----------------------------------------------------------------------------------------
simple_page_mode(true);


if (isset($_GET['AddedID'])) 
{
	//return;
        
    $trans_no = $_GET['AddedID']; 
    $message = $systypes_array[ST_BANKTRANSFER]."#".$trans_no." created.";
    clear_session_variable('ST_BATCH_BANK_TRANSFER_REQ_no');
    
	display_notification_centered($message);
        
//	display_note(print_document_link($trans_no, _("&Print this I Owe You"), true, $trans_type), 0, 0);

	hyperlink_no_params("$path_to_root/gl/inquiry/batch_bank_transfer_req_inquiry.php", _("Approve another ".$systypes_array[ST_BATCH_BANK_TRANSFER_REQ]));
        br();

	hyperlink_params("$path_to_root/gl/batch_bank_transfer.php",  _("Create another ".$systypes_array[ST_BATCH_BANK_TRANSFER_REQ]), "?NewBBT=Yes");

	display_footer_exit();
}


$BBTR_no = -1;
$type_id = ST_BATCH_BANK_TRANSFER_REQ;

if (isset($_GET['NewBBT'])){
    $_POST['trans_no'] = -1;    
}

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

if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0){
    $BBTR_no = $_POST['trans_no'];    
}
else{
    $n = get_session_variable("ST_BATCH_BANK_TRANSFER_REQ_no");
    if($n > 0){
        $BBTR_no = $n;
    }
} 
set_session_variable("ST_BATCH_BANK_TRANSFER_REQ_no", $_POST['trans_no']);

if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0){
    $BBTR_no = $_POST['trans_no'];
}
else{
    $BBTR_no = get_session_variable("ST_BATCH_BANK_TRANSFER_REQ_no");
    
}
//if(isset($_POST['ModifyMRNumber'])){
//    $iou_id = $_POST['ModifyMRNumber'];
//}




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

 
if(isset($_POST['Update_BBT_Header'])){
    handle_save_batch_bank_transfer_header($type_id, $BBTR_no);
}



if(isset($_POST['Approve_BBT'])){
    handle_release_batch_bank_transfer_header($type_id, $BBTR_no);
}



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


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

if (isset($_POST['_selected_id_update']) )
{
	$selected_id = $_POST['selected_id'];
	//$Ajax->activate('_page_body');
}
if (isset($_POST['SearchTrans']) )
{
	if(!($_POST['to_bank_act'] > 0)){
            display_error("Please select To (Debiting) bank account)");
            set_focus('to_bank_act');
        }
        
	if(!($_POST['filtering_type_id'] > 0)){
            display_error("Please select filtering transaction type");
            set_focus('filtering_type_id');
        }
	//$Ajax->activate('_page_body');
}


$new_trans_no = find_submit('AddTran');
if ($new_trans_no > 0)
{
    handle_save_batch_bank_transfer_item($type_id, $BBTR_no, $_POST['filtering_type_id'], $new_trans_no);
}

$del_trans_no = find_submit('DelTran');
if ($del_trans_no > 0)
{
    handle_delete_batch_bank_transfer_item($type_id, $BBTR_no, $del_trans_no);
}
   
//if (list_updated('employee_code')) 
	$Ajax->activate('_page_body');
//--------------------------------------------------------------------------------------------------

if (!@$_GET['popup']){
	start_form();
}
      

display_batch_bank_transfer_header($type_id, $BBTR_no);
if($BBTR_no > 0)
{
    submit_center_first('Update_BBT_Header', _("Update"), '', 'default');
//    submit('Approve_BBT', 'Approve', true, '', 'default');
    submit_center_last('Approve_BBT', _("Approve"), '', 'default');
    
}
else
{
//    submit_center_first('Add_BBT', _("Create"), '', 'default');
//    submit('Add_IOU_Release', 'Add and Release for Approval', true, '', 'default');
//    submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
}

br(1);

hidden('selected_id', $selected_id);

//if(isset($_POST['status_code']) && $_POST['status_code'] == "A"){
//    submit("pay_salary_advance", "Pay",true, _('Pay Salary Advance'), 'default');
//    submit('RESET', _("Cancel"), true, _('Cancel edition'), 'cancel');
//}
//else{
//    submit_add_or_update_center(!isset($_POST['ModifyMRNumber']), '', 'both');
//}

display_batch_bank_transfer_details($type_id, $BBTR_no);

display_batch_bank_transfer_filtering_controls();

display_batch_bank_transfer_edit_controls($BBTR_no, $_POST['to_bank_act'], $_POST['filtering_type_id'], $_POST['filtering_from_date'], $_POST['filtering_to_date']);



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

?>
