<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_FLOAT_INQ';
if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$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/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 . "/petty_cash/includes/db/project_float_inquiry_db.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 = "Project Float Inquiry"), false, false, "", $js);


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

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

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

function show_type_name($row)
{
    global  $systypes_array;
    
    if (array_key_exists($row['tran_type'], $systypes_array)) {
        return $systypes_array[$row['tran_type']];
    } else {
        return;
    }
}


function view_link($row)
{
//    return $row['type_no'];
    return get_trans_view_str($row['tran_type'], $row['type_no']);
    
}

function show_employee_name($row)
{
    return get_group_company_employee_formatted_long_name($row['company_code'], $row['employee_code']);
}

function show_amount($row)
{
   return number_format($row['amount'], 2);
}

function show_balance($row)
{
   return number_format($row['balance'], 2);
}

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

if ($Mode == 'Delete')
{
        $recs = delete_i_owe_u($selected_id, $_POST['employee_code']);
        
        if($recs == 1){
                display_notification(_("Salary advance has been deleted."));
        }
        else{
                display_error(_("Salary advance could not be deleted."));
        }

	$Mode = 'RESET';
}

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

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

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

if (!@$_GET['popup'])
	start_form();
start_table(TABLESTYLE_INQUIRY_PARAMETERES);
    start_row();
        project_list_cells(_("Project:"), 'project_id', null, _('All Projects'), true);
//        tasks_list_cells(_("Task:"), 'task_id', $_POST['project_id'], null, _('Select a task'), true);
//        emoplyees_list_cells(_("Select an Employee:"), 'employee_code', null, true, true, check_value('show_inactive'));
        
        

    end_row();
    start_row();
//        value_list_cells("I Owe You Type:", "type_id", "PETTY_CASH_TYPES", null, '');
        date_cells(_("from:"), 'from_date', '', null, -7);
        date_cells(_("to:"), 'to_date', '', null, +7);
//        project_list_cells("Project", "project_id", null, "All Projects", true);
        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
    end_row();
   
end_table(1);

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

$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'];
}
$float_id = -1;
if(isset($_POST['float_id'])){
    $float_id = $_POST['float_id'];
}

$project_id= 0;
if(isset($_POST['project_id'])){
    $project_id = $_POST['project_id'];
}

$task_id= 0;
if(isset($_POST['task_id'])){
    $task_id = $_POST['task_id'];
}

    $sql = get_sql_for_project_float_inquiry($from_date,$to_date, $project_id);    
    
    $cols = array(
                _("Id"),
                _("Type")=> array('fun'=>'show_type_name','align'=>'left'),                 
                _("Tran No") => array('fun'=>'view_link', 'align'=>'center'),
                _("Project"), 
                _("Employee") => array('fun'=>'show_employee_name', 'align'=>'center'),
                _("Date") => array('fun' => 'convert_date', 'align'=>'center'), 
                _("Amount") => array('fun'=>'show_amount', 'align'=>'right'),                
                _("Balance") => array('fun'=>'show_balance', 'align'=>'right')     

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

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

$table->width = "80%";

display_db_pager($table);

br();

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

?>
