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

$page_security = 'SA_PROJECT_SALES_ORDER_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 . "/projects/includes/db/manual_project_invoice_inquiry_db.inc");
include_once($path_to_root . "/projects/includes/db/project_sales_orders_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 (Customer) Purchase Orders Inquiry", false, false, "", $js);
//---------------------------------------------------------------------------------------------

simple_page_mode(true);

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


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

function order_no($row)
{
   // return $row['order_no'];
    return get_project_trans_view_str(ST_PROJECT_SALES_ORDERS, $row['order_no']);
}

function project_name($row)
{
    return $row['project_description'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function branch_name($row)
{
    return $row['branch_name'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function reference($row)
{
    return $row['reference'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);      
}

function customer_name($row)
{
    return $row['customer_name'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function payment_terms($row)
{
    return $row['payment_terms'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);      
}

function salesman_name($row)
{
    return $row['salesman_name'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function payment_certificate_ref($row)
{
    return $row['payment_certificate_ref'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function payment_certificate_amount($row)
{
    return $row['payment_certificate_amount'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function tax_group_name($row)
{
    return $row['tax_group_name'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function po_reference($row)
{
    return $row['po_reference'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}

function rate_include_taxes($row)
{
    return $row['rate_include_taxes'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}


function edit_link($row) 
{
    if (@$_GET['popup'])
            return '';
    global $trans_type;
    $modify = "PSONo";   
        
        return pager_link( _("Edit"), "/projects/project_sales_orders.php?$modify=". $row['order_no'], ICON_EDIT);   
   
}


function dispatch_link($row)
{  
    return pager_link(_("Request Dispatch"),"/projects/project_dispatch_request.php?PSONo=".$row['order_no'], ICON_DOC);    		
}


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


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();
    start_row();
        date_cells("From Date:", 'from_date', '', null, -15);
        date_cells("To Date:", 'to_date', '', null, +15);
    end_row();  
end_table();

start_table();
    start_row();
        project_list_cells(_("Project:"), 'project_id', null, _('Select a project'), true);        
        customer_list_cells("Customer:", 'customer_id', null, "Select a Customer", true );

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



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

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

$customer_id = "";
if(isset($_POST['customer_id'])){
  $customer_id = $_POST['customer_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_sales_orders_inquiry($project_id, $customer_id, $from_date, $to_date);    
    
    $cols = array(
                _("ID")=> array('fun'=>'order_no'),
                _("Reference")=> array('fun'=>'reference'),
                _("Project")=> array('fun'=>'project_name'),
                _("PO Reference")=>array('fun'=>'po_reference'), 
                _("Customer")=> array('fun'=>'customer_name'),
                _("Branch")=>array('fun'=>'branch_name'),
                
                _("Order Date")=>array('fun'=>'ord_date'),           
                _("Payment Terms")=>array('fun'=>'payment_terms'),  
                _("Sales Person")=>array('fun'=>'salesman_name'),                    
                        
//                _("Rate Include Taxes")=>array('fun'=>'rate_include_taxes'),   
//                _("Tax Group") =>array('fun'=>'tax_group_name')                
               
);
    array_append($cols, array(
		array('insert'=>true, 'fun'=>'edit_link') //,
		//array('insert'=>true, 'fun'=>'dispatch_link')
            ));

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

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

$table->width = "90%";

display_db_pager($table);

br();

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


?>
