<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_LEAVE_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 . "/payroll/includes/db/payroll_inquiry_db.inc");
include_once($path_to_root . "/payroll/includes/attendance_calculation.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 = "Leave Inquiry"), false, false, "", $js);
}
if (isset($_GET['order_number']))
{
	$order_number = $_GET['order_number'];
}

//-----------------------------------------------------------------------------------
// Ajax updates
//
if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders_tbl');
} elseif (get_post('_order_number_changed')) 
{
	$disable = get_post('order_number') !== '';

	$Ajax->addDisable(true, 'OrdersAfterDate', $disable);
	$Ajax->addDisable(true, 'OrdersToDate', $disable);
	$Ajax->addDisable(true, 'StockLocation', $disable);
	$Ajax->addDisable(true, '_SelectStockFromList_edit', $disable);
	$Ajax->addDisable(true, 'SelectStockFromList', $disable);

	if ($disable) {
		$Ajax->addFocus(true, 'order_number');
	} else
		$Ajax->addFocus(true, 'OrdersAfterDate');

	$Ajax->activate('orders_tbl');
}
//---------------------------------------------------------------------------------------------

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

start_table(TABLESTYLE_NOBORDER);
start_row();

date_cells(_("from:"), 'from_date', '', null, -30);
date_cells(_("to:"), 'to_date');

emoplyees_list_cells(_(" Employee:"), 'employee_code', null,
	  "", false, check_value('show_inactive'));

value_list_code_cells("Status Code:", "status_code", "ATTENDANCE_STATUS", false, "");

submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
end_row();
end_table(1);
//---------------------------------------------------------------------------------------------
if (isset($_POST['order_number']))
{
	$order_number = $_POST['order_number'];
}

if (isset($_POST['SelectStockFromList']) &&	($_POST['SelectStockFromList'] != "") &&
	($_POST['SelectStockFromList'] != ALL_TEXT))
{
 	$selected_stock_item = $_POST['SelectStockFromList'];
}
else
{
	unset($selected_stock_item);
}

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



function get_revoke_name($row)
{
    if($row['is_revoke'] == 0){
        return "No";
    }
    else{
        return "Yes";
    }
}


function get_np_days($row)
{
    if($row['nopay_days'] == 0.0){
        return "";
    }
    else{
        return $row['nopay_days'];
    }
}


function get_pr_id($row)
{
    if($row['payroll_run_id'] == 0){
        return "";
    }
    else{
        return $row['payroll_run_id'];
    }
}



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

$from_date = "";
if(isset($_POST['from_date'])){
    $from_date = $_POST['from_date'];
}
$to_date = "";
if(isset($_POST['to_date'])){
    $to_date = $_POST['to_date'];
}
$employee_code = "";
if(isset($_POST['employee_code'])){
    $employee_code = $_POST['employee_code'];
}
$ot_only = 0;
if(isset($_POST['status_code'])){
    $status_code = $_POST['status_code'];
}

$sql = get_sql_for_leave_inquiry($from_date, $to_date, $employee_code, $status_code);

$cols = array(
		_("Employee"), 
		_("Leave Type") => array('align'=>'center'),
                _("From Date") => array('align'=>'center'),
		_("From Session") => array('align'=>'center'), 
                _("To Date") => array('align'=>'center'),
                _("To Session") => array('align'=>'center'),
                _("Days") => array('align'=>'center'),
		_("Revoke") => array('fun' => 'get_revoke_name', 'align'=>'center'),  
                _("Comment") => array('align'=>'center'),
                _("Status") => array('align'=>'center'),
                _("No Pay Days") => array('fun' => 'get_np_days', 'align'=>'center'),
		_("Payroll Run") => array('fun' => 'get_pr_id', 'align'=>'center'),  

);

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

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

$table->width = "80%";

display_db_pager($table);

br();

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