<?php
/**********************************************************************
Copyright (C) Evolve Techniologies
Author : Danushka Widanage
Email : dwidanage@gmail.com
Company : Evolve Technologies(pvt)Ltd
***********************************************************************/

$path_to_root = "../..";

include($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
//include($path_to_root . "/sales/includes/sales_ui.inc");
include_once($path_to_root . "/includes/ui.inc");

include_once($path_to_root . "/reporting/includes/reporting.inc");

$page_security = 'SA_ITEMSTRANSVIEW';

/*set_page_security( @$_POST['order_view_mode'],
	array(	'OutstandingOnly' => 'SA_SALESDELIVERY',
			'InvoiceTemplates' => 'SA_SALESINVOICE'),
	array(	'OutstandingOnly' => 'SA_SALESDELIVERY',
			'InvoiceTemplates' => 'SA_SALESINVOICE')
);*/

$js = "";
if ($use_popup_windows)
	$js .= get_js_open_window(900, 600);
if ($use_date_picker)
	$js .= get_js_date_picker();


	$_SESSION['page_title'] = _($help_context = "Search All Location Transfer");


$trans_type = ST_LOCTRANSFER;

page($_SESSION['page_title'], false, false, "", $js);


///------------------new function dwidanage   23.04.2014------------------------------
function print_loc_trans($dummy, $trans_no)
{
	global $trans_type;
	return print_location_transfer($trans_no, $trans_type);


}
//------------------------------------------

function location_trasfer_details($trans_no, $ref_no, $from , $to){
	
	$sql = "SELECT trans_no, reference, tran_date, loc_code AS from_location, trans_no 
				FROM ".TB_PREF."stock_moves AS SM WHERE type = ".ST_LOCTRANSFER;
	
	if ($ref_no != '')
		$sql .= " AND SM.reference = ".db_escape($ref_no);

	if ($trans_no != '')
		$sql .= " AND SM.trans_no = ".db_escape($trans_no);

	//------@widanage add new code for date range selection  filter option ---22.04.2013-------
	$date_after = date2sql($from);
	$date_before = date2sql($to);
	
	$sql .=  " AND SM.tran_date >= '$date_after'"." AND SM.tran_date <= '$date_before'";
	
	$sql .= " GROUP BY trans_no";
		
	return $sql;
}

start_form();

start_table(TABLESTYLE_NOBORDER);
start_row();
ref_cells(_("Transfer Number :"), 'TransNumber', '',null, '', true);
ref_cells(_("Ref Number :"), 'RefNumber', '',null, '', true);

/*if($show_dates) {
	end_row();
	end_table();

	start_table(TABLESTYLE_NOBORDER);
	start_row();
}*/

date_cells(_("from:"), 'from_date', '', null, -30);
date_cells(_("to:"), 'to_date', '', null, 1);

if (list_updated('RefNumber'))
	$Ajax->activate('_loc_trans_tbl_span');

if (list_updated('TransNumber'))
	$Ajax->activate('_loc_trans_tbl_span');

submit_cells('LocationTransfer', _("Search"),'',_('Select documents'), 'default');
hidden('type', $trans_type);

end_row();
end_table(1);
//---------------------------------------------------------------------------------------------
//	Location Transfer inquiry table
//
$sql = location_trasfer_details($_POST['TransNumber'], $_POST['RefNumber'], $_POST['from_date'], $_POST['to_date']);

	$cols = array(
		_("Transfer #") => array('align'=>'center'),
		_("Ref") => array('type'=>'reference', 'ord'=>''),
		_("Order Date") => 'tran_date',
		_("From Location") => 'from_location',
		//_("To Location") => 'to_location',
		_("Print") => array('align'=>'center', 'fun' =>'print_loc_trans')
	);

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

$table->width = "90%";

display_db_pager($table);

end_form();
end_page();
?>