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

$page_security = 'SA_UTILITY_BILL_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/ui.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc"); 
include_once($path_to_root . "/gl/includes/db/utility_bill_inquiry_db.inc");

$js = '';
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

page($help_context = "Utility Bill Stock Receipts Inquiry", false, false, "", $js);

simple_page_mode(true);

global $systypes_array;

function _trans_no($row) {
    return get_journal_trans_view_str($row['type'], $row['trans_no']);
}

function _type($row) {
    global $systypes_array;
    
    return $systypes_array[$row['type']];   
}

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

function _tran_date($row) {
   return sql2date($row['date']);
}

function _project_name($row) {
    return get_project_formatted_name($row['project_id']);
}

function _supp_name($row) {
    return get_supplier_formatted_name($row['supplier_id']); 
}

function _total($row) {
    return number_format($row['total'], 2);
}

function _source_trans_no($row) {
    if ($row['source_trans_no'] > 0) {
        return get_journal_trans_view_str($row['source_type'], $row['source_trans_no']);
    } else {
        return;
    }
}

function _source_type($row) {
    global $systypes_array;
    
    if ($row['source_type'] > 0) {
        return $systypes_array[$row['source_type']];   
    } else {
        return;
    }
}

$Ajax->activate('_page_body');

start_form();
    start_table();
        start_row();
            ref_cells(_("Trans #:"), 'trans_no', '',null, '', false);
            $types_array = array();
            $types_array[ST_UTILITY_BILL_STOCK_RECEIPT] = $systypes_array[ST_UTILITY_BILL_STOCK_RECEIPT];
            custom_values_list_cells('Trans Type:', 'type', $types_array, null, '', true);
            ref_cells(_("Reference:"), 'reference', '',null, '', false);
            date_cells("From Date:", 'from_date', '', null, -30);
            date_cells("To Date:", 'to_date', '', null);
        end_row();  
    end_table();

    start_table();
        start_row();
            project_list_cells(_("Project:"), 'project_id', null, _(''), true);        
            supplier_list_cells(_("Supplier:"), 'supplier_id', null, '', true);
            ref_cells(_("Source Trans #:"), 'source_trans_no', '',null, '', false);
            $source_types_array = array();
            $source_types_array[ST_UTILITY_BILLS] = $systypes_array[ST_UTILITY_BILLS];
            custom_values_list_cells('Source Trans Type:', 'source_type', $source_types_array, null, '', true);

            submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
        end_row();
    end_table(1);

    $sql = get_sql_for_utility_bill_stock_receipts_inquiry($_POST['trans_no'], $_POST['type'], $_POST['reference'], $_POST['from_date'], $_POST['to_date'], 
                                                           $_POST['project_id'], $_POST['supplier_id'], $_POST['source_trans_no'], $_POST['source_type']);    
    
    $cols = array(
                _("Trans #")=> array('fun'=>'_trans_no', 'align' => 'center'), 
                _("Type")=> array('fun'=>'_type'),                         
                _("Reference")=> array('fun'=>'_reference'),                         
                _("Tran Date")=> array('fun'=>'_tran_date', 'align' => 'center'), 
                _("Project Name")=>array('fun'=>'_project_name'),                
                _("Supplier")=>array('fun'=>'_supp_name'), 
                _("Total")=> array('fun'=>'_total', 'align' => 'right'), 
                _("Source Trans#")=> array('fun'=>'_source_trans_no', 'align' => 'center'), 
                _("Source Type")=> array('fun'=>'_source_type', 'align' => 'center'), 
            );
		
$table =& new_db_pager('orders_tbl', $sql, $cols, null, null);

$table->width = "98%";

display_db_pager($table);

end_form(2);
end_page();

?>