<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PURCH_INDENTS_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 . "/includes/ui/ui_input.inc");
include_once($path_to_root . "/includes/ui/ui_lists.inc");
include_once($path_to_root . "/includes/ui/ui_lists_custom.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/purchasing/includes/db/purchase_indents_db.inc");
include_once($path_to_root . "/includes/ui/ui_controls_custom.inc"); 

if (!@$_GET['popup'])
{
	$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 = "Search Purchase Indents"), false, false, "", $js);
}
if (isset($_GET['order_number']))
{
	$order_number = $_GET['order_number'];
}

//-----------------------------------------------------------------------------------
// Ajax updates
//
if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders');
} elseif (get_post('_order_number_changed')) 
{
	$disable = get_post('order_number') !== '';

//	$Ajax->addDisable(true, 'OrdersAfterDate', $disable);
//	$Ajax->addDisable(true, 'OrdersToDate', $disable);
//	$Ajax->addDisable(true, 'supplier', $disable);

	if ($disable) {
		$Ajax->addFocus(true, 'order_number');
	} else
		$Ajax->addFocus(true, 'OrdersAfterDate');

	$Ajax->activate('orders');
}
//---------------------------------------------------------------------------------------------

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

start_table(TABLESTYLE_NOBORDER);
start_row();

    ref_cells(_(text_bold("Indent No:")), 'indent_number', '',null, '', true);
    ref_cells(_(text_bold("PR No:")), 'pr_number', '',null, '', true);
    ref_cells(_(text_bold("PO No:")), 'po_number', '',null, '', true);

end_row();
end_table();

start_table(TABLESTYLE_NOBORDER);
start_row();
    date_cells(_("from:"), 'required_from', '', null, -30);
    date_cells(_("to:"), 'required_to');
    supplier_list_cells(_("Select a supplier: "), 'supplier', get_post('supplier'), true);
    submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
end_row();
end_table(1);

//start_table(TABLESTYLE_NOBORDER);
//start_row();
//
////stock_items_list_cells(_("for item:"), 'SelectStockFromList', null, true);
//
//
//end_row();
//end_table(1);
//---------------------------------------------------------------------------------------------
if (isset($_POST['required_from']))
{
    $required_from = $_POST['required_from'];
}
if (isset($_POST['required_to']))
{
    $required_to = $_POST['required_to'];
}

if (isset($_POST['indent_number']) )
{
    $indent_number = $_POST['indent_number'];
}
if (isset($_POST['pr_number'])  )
{
    $pr_number = $_POST['pr_number'];
}
if (isset($_POST['po_number']))
{
    $po_number = $_POST['po_number'];
}

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


//---------------------------------------------------------------------------------------------
function trans_view($trans)
{
	return get_supplier_trans_view_str(ST_PURCH_INDENTS, $trans["indent_id"]);
}

function ord_date($trans)
{
	return  sql2date($trans["required_date"]);
}


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

$sql = get_sql_for_indent_search_completed(date2sql($required_from),date2sql($required_to),$indent_number,$pr_number,$po_number,$supplier);


$cols = array(
		_("#") => array('fun'=>'trans_view', 'ord'=>''),
		_("Supplier"),
                _("New Supplier"),
		_("Location"),
                _("New Location"),
		_("Required Date")  => array('fun'=>'ord_date', 'ord'=>''),
);



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

$table->width = "80%";

display_db_pager($table);

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