<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_EMPLOYEE_VIEW';
$path_to_root="../..";
include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");
include_once($path_to_root . "/includes/ui/ui_lists.inc");
include_once($path_to_root . "/includes/ui/ui_lists_custom.inc");
include_once($path_to_root . "/includes/ui/ui_view_custom.inc"); 
include_once($path_to_root . "/payroll/includes/db/employees_db.inc");
include_once($path_to_root . "/payroll/includes/db/payroll_inquiry_db.inc");

include_once($path_to_root . "/reporting/includes/reporting.inc");
if (!@$_GET['popup'])
{
	$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 = "Employee Inquiry"), false, false, "", $js);
}
//-----------------------------------------------------------------------------------
// Ajax updates
//
if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders_tbl');
} 
//---------------------------------------------------------------------------------------------

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

//start_table(TABLESTYLE_NOBORDER);
//    start_row();
//    emoplyees_list_cells(_(" Employee:"), 'employee_code', null, "", false, check_value('show_inactive'));
//    end_row();
//end_table(1);

start_table(TABLESTYLE_NOBORDER);
    start_row();
    text_cells(_("Employee Code:"), 'employee_code');
    text_cells(_("Full Name:"), 'middle_name');
    text_cells(_("Calling Name:"), 'first_name');

    end_row();
end_table(1);

start_table(TABLESTYLE_NOBORDER);
    start_row();
    text_cells(_("NIC No:"), 'nic');
    text_cells(_("EPF No:"), 'epf_no');
    submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
    end_row();
end_table(1);

//---------------------------------------------------------------------------------------------
function emp_view($row)
{
    return get_trans_view_str(ST_EMPLOYEE, $row['employee_code']);
}


function format_dj($row)
{
    return sql2date($row['date_of_joining']);
}

function edit_link($row) 
{
    $modify = "employee_code";
    return pager_link( _("Edit"), "/payroll/manage/employees.php?$modify=" . $row['employee_code'], ICON_EDIT);

}
//---------------------------------------------------------------------------------------------


$employee_code = "";
if(isset($_POST['employee_code'])){
    $employee_code = $_POST['employee_code'];
}
$first_name = "";
if(isset($_POST['first_name'])){
    $first_name = $_POST['first_name'];
}
$middle_name = "";
if(isset($_POST['middle_name'])){
    $middle_name = $_POST['middle_name'];
}
$epf_no = "";
if(isset($_POST['epf_no'])){
    $epf_no = $_POST['epf_no'];
}
$nic = "";
if(isset($_POST['nic'])){
    $nic = $_POST['nic'];
}


$sql = get_sql_for_employee_inquiry($employee_code, $first_name, $middle_name, $epf_no, $nic);

$cols = array(
		_("Code") => array('fun'=>'emp_view', 'align'=>'center'),
		_("Full Name"), 
        _("Calling Name"), 
        _("NIC"), 
        _("Date Joined") => array('fun'=>'format_dj'), 
        _("Office Mobile"), 
        _("Work Phone"), 
        _("Mobile"),);

array_append($cols, array(
		array('insert'=>true, 'fun'=>'edit_link'))); 
        
                    



//if (get_post('StockLocation') != $all_items) {
//	$cols[_("Location")] = 'skip';
//}
////---------------------------------------------------------------------------------------------------

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

$table->width = "90%";

display_db_pager($table);

br();

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