<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_FLOAT_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/project_advance_batches_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 = "Project Advance Batches Inquiry", false, false, "", $js);
//---------------------------------------------------------------------------------------------
simple_page_mode(true);

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


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

function id($row)
{
    return get_petty_cash_trans_view_str(ST_PROJECT_ADVANCE_BATCH, $row['id']);
    return $row['id'];
}

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

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

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

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

function processed($row)
{
    if($row['paid'] == 1){
        $paid = "Yes";
    }else{
        $paid = "No";
    }
    
    return $paid;
}


function edit_link($row) 
{
    if (@$_GET['popup'])
            return '';
    global $trans_type;
    $modify = "UBNo";
   
    if($row['paid'] == 1){
        return "";
    }else{
        return pager_link( _("Edit"), "/petty_cash/project_advance_batches.php?$modify=". $row['id'], ICON_EDIT); 
    }
     
}

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

//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();
    petty_cash_floats_list_cells("Float:", 'float_id', null, 'Please select a float', true);
        date_cells(_("From Date:"), 'from_date', '', null, -30);
        date_cells(_("To Date:"), 'to_date', '', null, +30);
        
        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');

    end_row();
end_table(1);

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

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


    $sql = get_sql_for_project_advance_batches_inquiry($float_id, $from_date, $to_date);    
    
    $cols = array(
                _("ID")=> array('fun'=>'id','align'=>'right'),
                _("Reference")=> array('fun'=>'reference'),
                _("Date")=>array('fun'=>'header_date','align'=>'center'),
                _("Float")=>array('fun'=>'float_name'),         
               
                _("Total")=> array('fun'=>'total','align'=>'right'),
                _("Comment")=>array('fun'=>'comment','align'=>'left'),     
                _("Processed")=>array('fun'=>'processed','align'=>'center'),
                            
            );
        array_append($cols, array(
            //array('insert'=>true, 'fun'=>'dispatch_link'),
            array('insert'=>true, 'fun'=>'edit_link')));

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

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

$table->width = "80%";

display_db_pager($table);

br();

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



?>
