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

$page_security = 'SA_GL_BATCHES_INQ';
$path_to_root="../..";

include($path_to_root . "/includes/db_pager.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 . "/gl/includes/db/financial_integration_inquiry_db.inc");
include_once($path_to_root . "/gl/includes/fi/db/generate_fi_accounting_entries_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 = "GL Batches Inquiry"), false, false, "", $js);

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

if (get_post('Search'))
{
    $Ajax->activate('financial_integration_tbl');
}

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

if (!isset($_POST['filterType']))
	$_POST['filterType'] = -1;

start_form();

global $systypes_array;

$values_array[ST_GL_BATCH] = $systypes_array[ST_GL_BATCH];  
foreach ($systypes_array as $key => $value) {
    if($key >= 1000){
        $values_array[$key] = $value;   
    }    
}

start_table(TABLESTYLE_NOBORDER);
start_row();
ref_cells(_("Batch No:"), 'batch_no', '',null, _('Enter memo fragment or leave empty'));
system_users_list_cells("User", 'user_id', null, '', true); 
end_row();

start_row();
date_cells(_("Date From:"), 'FromDate', '', null, 0, -1, 0);
date_cells(_("Date To:"), 'ToDate');
end_row();
//systypes_list($name);
asort($values_array);

start_row();
custom_values_list_cells(_("Type:"), "filterType", $values_array, null, '', true);
//journal_types_list_cells(_("Type:"), "filterType");
submit_cells('Search', _("Search"), '', '', 'default');

//gl_all_accounts_list_cells(_("Account:"), 'account_no', null, false, false, 'Select an Account');
end_row();

end_table();

function _batch_no($row)
{
    return get_gl_batch_trans_view_str(ST_GL_BATCH, $row['batch_no']);
}

function _created_by($row)
{
    return $row['created_user']; 
}

function  _created_on($row)
{
    return $row['created_on']; 
}


function _trans_type($row)
{
    global $systypes_array;
    
    return $systypes_array[$row['gl_batch_type']];
}

function _tran_date($row)
{
    return sql2date($row['tran_date']);
}

//
//function gl_link($row) 
//{
//    if($row['deleted_by'] > 0){
//        return null;
//    }
//    else{
////	return get_gl_view_str(ST_GL_BATCH, $row["batch_no"]);
//	return get_gl_view_str($row["gl_batch_type"], $row["batch_no"]);
//    }
//}

function _delete_link($row) 
{
    if($row['deleted_by'] > 0){
        return "Deleted";
    }
    else{
        $modify = "batch_no";   
        return pager_link(_("Delete"), "/gl/delete_gl_batch.php?$modify=". $row['batch_no'], ICON_DELETE);  
    }

}


$sql = get_sql_for_gl_batches_inquiry(get_post('user_id', -1), get_post('batch_no'), get_post('filterType', -1),
                                                get_post('FromDate'), get_post('ToDate'));

$cols = array(
 
        _("Batch No") => array('fun'=>'_batch_no', 'align'=>'center'), 
        _("Type") =>array('fun'=>'_trans_type'),
        _("Transaction Date") =>array('fun'=>'_tran_date', 'align'=>'center'),
    	_("Created By") => array('fun'=>'_created_by', 'align'=>'center'),  
    	_("Created On") => array('fun'=>'_created_on', 'align'=>'center'), 
//        _("View") => array('insert'=>true, 'fun'=>'gl_link', 'align'=>'center'), 
		        	
//        _("Account") => array('fun'=>'account'), 
//	_("Accounts Total") => array('fun'=>'amount','align'=>'right'),    
        _("Delete") => array('insert'=>true, 'fun'=>'_delete_link', 'align'=>'center'),



);

br(1);

$table =& new_db_pager('financial_integration_tbl', $sql, $cols);

$table->width = "70%";

display_db_pager($table);

end_form();
end_page();



?>
