<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_SUPPLIER_TRANSPORT_INVOICES_INQ';
$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 . "/sales/includes/sales_ui.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/transport/includes/db/supplier_transport_invoices_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 = "Supplier Trasport Invoices Inquiry"), false, false, "", $js);


function view_allocation($row)
{
//	global $trans_type;
    if($row['vehicle_allocation_id'] == 0){
        return null;
    }
    
	return get_transport_trans_view_str(ST_VEHICLE_ALLOCATION, $row['vehicle_allocation_id']);
}

function view_sti($row)
{
	return get_transport_trans_view_str(ST_SUPPLIER_TRANSPORT_INVOICES, $row['id']);
}

function view_vrc_batch($row)
{
    if($row['batch_no'] == 0){
        return null;
    }
	return get_transport_trans_view_str(ST_VEHICLE_RUNNING_CHART_BATCH, $row['batch_no']);
}


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


function format_amount($row)
{
  return number_format($row['sti_total'],2);
}

function format_batch_no($row)
{
    if($row['batch_no'] > 0){
        return $row['batch_no'];
    }
    else{
        return null;
    }
}



function edit_link($row) 
{
    if($row['approval_status'] == AS_NEW || $row['approval_status'] == AS_WITH_THE_APPROVER || $row['approval_status'] == AS_AWAITING_APPROVAL){
        return pager_link( _("Edit"), "/transport/supplier_transport_invoices.php?STINo=" . $row['id'], ICON_EDIT);
    }
    else{
        return null;
    }
}



if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders_tbl');
}


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

//start_table(TABLESTYLE_NOBORDER);
//start_row();
//
//ref_cells(_("Transport Invoice #:"), 'sti_id', '',null, '', false);
//date_cells(_("From:"), 'from_date', '', null, -15);
//date_cells(_("To:"), 'to_date', '', null, +15);
//supplier_list_cells(_("Supplier:"), 'supplier_id', null, '');
////ref_cells(_("MR Ref"), 'mr_reference', '',null, '', false);
//
//submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
////hidden('order_view_mode', $_POST['order_view_mode']);
////hidden('type', $trans_type);
//
//end_row();
//
//end_table(1);
//---------------------------------------------------------------------------------------------
//	Orders inquiry table
//
$sql = get_sql_for_approve_supplier_transport_invoices_inquiry($_SESSION['wa_current_user']->user);

	$cols = array(
                _("#") => array('fun' => 'view_sti', 'align' => 'center'), 
                _("Reference"), 
                _("Project"), 
                _("Sup. Inv. Ref."), 
                _("Supplier"),
                _("Date")=> array('fun' => 'convert_date', 'align' => 'center'), 
                _("Value")=> array('fun' => 'format_amount', 'align' => 'right'), 
                _("Originator") 
		);

	array_append($cols, array(
        array('insert'=>true, 'fun'=>'edit_link'),
//        array('insert'=>true, 'fun'=>'order_link', 'align' => 'center'), 
//		array('insert'=>true, 'fun'=>'dispatch_link', 'align' => 'center'), 
//        array('insert'=>true, 'fun'=>'return_link', 'align' => 'center'), 
		));


$table =& new_db_pager('orders_tbl', $sql, $cols);
//$table->set_marker('check_overdue', _("Marked items are overdue."));

$table->width = "80%";

display_db_pager($table);
submit_center('Update', _("Update"), true, '', null);

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