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

function get_sql_for_inventory_transactions_inquiry($location, $from_date, $to_date, $type)
{

    $sql = "SELECT vit.type, vit.id, vit.reference, vit.tran_date, vit.from_location, vit.to_location,
                    fl.location_name as from_location_name,
                    tl.location_name as to_location_name 
            FROM 0_vw_inventory_transactions vit 
                    LEFT JOIN ".TB_PREF."locations fl ON 
                            vit.from_location = fl.loc_code
                    LEFT JOIN ".TB_PREF."locations tl ON 
                            vit.to_location = tl.loc_code
            WHERE  vit.tran_date >= ".db_escape(date2sql($from_date))." AND 
                    vit.tran_date <= ".db_escape(date2sql($to_date))."   ";


   	if ($location != null) {
   		$sql .= " AND (vit.from_location = ".db_escape($location)." OR 
                                vit.to_location = ".db_escape($location).") ";
	}
	if ($type != null) 
	{
		$sql .= " AND vit.type = ".db_escape($type);
	} 
	
        $sql .= " ORDER BY vit.tran_date";
        
   	return $sql;
}
?>