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

$page_security = 'SA_I_OWE_YOU_ADVANCES_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/i_owe_you_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/approve_i_owe_you_enties_db.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");
include_once($path_to_root . "/includes/common_functions.inc");
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_advances_inquiry_db.inc");

include_once($path_to_root . "/includes/db/group_companies_db.inc");
include_once($path_to_root . "/includes/common_functions.inc");
include_once($path_to_root . "/includes/ui/ui_lists_group_companies.inc");

//C:\xampp\htdocs\saw\petty_cash\includes\db\i_owe_you_advances_inquiry_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 = "I Owe You Advances Inquiry"), false, false, "", $js);

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



if (isset($_GET['project_id']))
{
	$_POST['project_id'] = $_GET['project_id'];
}
if (isset($_GET['from_date']))
{
	$_POST['from_date'] = $_GET['from_date'];
}
if (isset($_GET['to_date']))
{
	$_POST['to_date'] = $_GET['to_date'];
}



function _iou_id($row)
{
   return get_petty_cash_trans_view_str(ST_I_OWE_YOU, $row['iou_id']);
}

function _batch_no($row)
{
   return get_petty_cash_trans_view_str(ST_I_OWE_YOU_ADVANCES_BATCH, $row['batch_no']);
}


function _format_iou_amount($row)
{
   return $row['iou_amount'];
}


function _show_employee_name($row)
{
    if(strlen($row['company_code']) > 1 && strlen($row['employee_code']) > 1){
        return get_group_company_employee_formatted_long_name($row['company_code'], $row['employee_code']);
    }
    else{
        return null;
    }
}


function _show_company_name($row)
{
    if(strlen($row['company_code']) > 1){
        return $row['company_name'];
    }
    else{
        return null;
    }
}

function _iou_date($row)
{
   return sql2date($row['iou_date']);
}

function _batch_date($row)
{
   return sql2date($row['advance_batch_date']);
}

function _reference($row)
{
        return $row['reference'];

}
function _show_project_name($row)
{
    return $row['project_description'];
}

function _show_float_name($row)
{
    return $row['float_name'];
}

function _format_advance_amount($row)
{
    return number_format($row['advance_amount'],2);
}

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


start_form();

start_table(TABLESTYLE_NOBORDER);
    start_row();
        ref_cells(text_bold("IOU No:"), 'iou_id', '',null, '', true);
        ref_cells(text_bold("Advances Batch No:"), 'batch_no', '',null, '', true);
        date_cells(_("Batch date From:"), 'from_date', '', null, -14);
        date_cells(_("Batch Date To:"), 'to_date');
    end_row();

end_row();

start_table(TABLESTYLE_NOBORDER);
    start_row();
        project_list_cells(_("Project:"), 'project_id', null, _('All projects'));
        petty_cash_floats_list_cells(_("Float:"), 'float_id', null, _('All floats'));
    end_row();
end_table();

start_table(TABLESTYLE_NOBORDER);
    start_row();    
    group_companies_list_cells("Company:", 'company_code', null, 'Please select a company', true);
    group_company_employees_simple_list_cells("Employee:", 'employee_code', $_POST['company_code'], null, 'Please select an employee', false);
    
        
        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
    end_row();

end_table();

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'];
}

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

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


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

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

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

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

    $sql = get_sql_for_i_owe_you_advances_inquiry($from_date, $to_date, $batch_no, $project_id, $float_id, $company_code, $employee_code, $iou_id);    
    
    $cols = array(
                _("IOU")=> array('fun'=>'_iou_id','align'=>'center'),
                _("Reference")=> array('fun'=>'_reference'),
                _("IOU Date")=> array('fun'=>'_iou_date','align'=>'center'), 
                _("IOU Amount")=> array('fun'=>'_format_iou_amount','align'=>'right'),
                _("Project")=> array('fun'=>'_show_project_name'),
                _("Company")=> array('fun'=>'_show_company_name','align'=>'left'), 
                _("Employee")=> array('fun'=>'_show_employee_name','align'=>'left'), 
                _("Adv. Amount")=> array('fun'=>'_format_advance_amount','align'=>'right'),
                _("Adv. Batch")=> array('fun'=>'_batch_no','align'=>'center'), 
                _("Batch Date")=> array('fun'=>'_batch_date','align'=>'center'), 
                _("Float")=> array('fun'=>'_show_float_name')
        
                
                
                
                
                
                
                
);
//-----------------------------------------------------------------------------------------
       
    
//if (get_post('StockLocation') != $all_items) {
//	$cols[_("Location")] = 'skip';
//}
//---------------------------------------------------------------------------------------------------

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

$table->width = "95%";

display_db_pager($table);

br();

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



?>
