<?php

session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

$querylog=" select ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(FI_FrmRestrictWarehouse,0) As FI_FrmRestrictWarehouse ".
          " from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_ProjectParent,0) As Module_ProjectParent, ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ".
			 " ifNull(Module_BelongsToGroup,0) As Module_BelongsToGroup From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From SalesSetup Table
$querySalesSetup="Select SalesTTC From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

$MainCompanyName=explode('_',$HTTP_SESSION_VARS['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays ".
              " From ".$HTTP_SESSION_VARS['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$HTTP_SESSION_VARS['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	
			  
//echo $queryperiod;	

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on (($Module_ProjectParent=1 and project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%')) or ($Module_ProjectParent=0 and project.project_code = loginstk.project_code )) ".
			  " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);		  

$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on (($Module_CostCenterParent=1 and costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%')) or ($Module_CostCenterParent=0 and costcent.costcent_code = loginstk.costcent_code )) ".
			   " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  


$querywh=" select distinct warehouse.warehouse_code, warehouse_name ".
         " from warehouse inner join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on warehouse.warehouse_code = loginstk.warehouse_code ".
		 " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
		 " and (loginstk.warehouse_code is not null and loginstk.warehouse_code != '')  ".
		 " order by warehouse.warehouse_code";
$whresult = mysql_query($querywh,$connection) or die(mysql_error());
$whexist  = mysql_num_rows($whresult);	 

$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$HTTP_SESSION_VARS['dbLabel'].".ledgerstk  ".
			  " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];


//Get Default Project
$querydflproject="select project_code as defaultproject from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

if ((!isset($PProjectCode)) && $Module_Project == 1)
	$PProjectCode = $defaultproject;
if ((!isset($PCostCentCode)) && $Module_CostCenter == 1)	
	$PCostCentCode = $defaultcostcent;	

if (empty($orderby))  $orderby = 1;
if (empty($searchby)) $searchby = 2;

if ($startrange=='')  $startrange = 0;
if ($perpage=='')	  $perpage = 20;

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<title>Search Payment Requests</title>
<script type="text/javascript" language="javascript">

function ClearForm()
{
	var vTransType = document.search.TransType.value;	
	
	document.search.PRef.value='';
	document.search.PProjectCode.value='';
	document.search.PCostCentCode.value='';
	document.search.SelectedID.value = '';
	document.search.startrange.value = '';
	document.search.action='Form_TransSearchSorder.php?TransType='+vTransType;
	document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.PRef.focus();

	ChangeLocation();
}

function SetNextPage(startrange,perpage){ 
	var vTransType = document.search.TransType.value;	
    document.search.startrange.value = startrange;
	document.search.action='Form_TransSearchSorder.php?TransType='+vTransType+'&PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
	var vTransType = document.search.TransType.value;	
	document.search.startrange.value = startrange;
	document.search.action='Form_TransSearchSorder.php?TransType='+vTransType+'&PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}



function LoadRecord(SorderId,SorderRef){
	var vMsg = 'Are you sure you want to Load Sales Order with reference = '+SorderRef+' ?';
	var vTransType = document.search.TransType.value;	
	
	if (confirm (vMsg) )
	{
		document.search.action="Form_Trans_Actions.php?TransType='+vTransType+'&mainmode=loadsorder&SSorderId="+SorderId;
		document.search.submit();
		
	}

}

function ChangeLocation()
{
	var vTransType = document.search.TransType.value;
	var vTransId   = document.search.TransId.value;
	
    if (document.search.PMode.value == 1) {
		opener.document.trans.txtTransId.value = vTransId;
		opener.document.trans.mainaction.value = 'edit';
		opener.document.trans.actionmode.value = '';
		//opener.document.trans.action='Form_Trans.php?TransType='+vTransType+'&txtTransId='+vTransId;
		opener.document.trans.submit();
		self.close();
	} else {
		opener.document.trans.txtTransId.value='';
		opener.document.trans.mainaction.value='';
		opener.document.trans.actionmode.value='';
	}
	
}



function showlistProject(str){

  window.open('List_SorProject.php?frm=6&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=6&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function SelectOrderBy()
{
  document.search.startrange.value = '';
  //document.search.PRef.value='';
  //document.search.action='Form_TransSearchSorder.php';
  document.search.submit();

}

function SelectSearchBy()
{	
  document.search.startrange.value = '';
  //document.search.PRef.value='';
  //document.search.action='Form_TransSearchSorder.php';
  document.search.submit();

}

function SubmitForm()
{	
  document.search.startrange.value = '';
  //document.search.PRef.value='';
  //document.search.action='Form_TransSearchSorder.php';
  document.search.submit();

}

function kd(e)
{
	x=document.search;
    var intKey = (window.Event) ? e.which : e.keyCode;
	
    if (intKey == 13) { //enter key
        x.btnSubmit.click();
		return false;
    }
    return true;
}


</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body onLoad='LoadForm();'>
<form name='search' method='post' action="">
<input type='hidden' name='TransType' value='$TransType' >
<input type='hidden' name='TransId' value='$TransId'>
<input type='hidden' name='SelectedID' id='SelectedID' value='$SelectedID'>

HERE;

//echo "<input type='hidden' name='message' value='".htmlspecialchars($message, ENT_QUOTES)."'>";

echo"<table border='0' cellspacing='1'  style='table-layout:fixed'>
	  <col width=20>
	  <col width=80>
	  <col width=80>
	  <col width=100>
	  <col width=200>
	  <col width=120>
	  <col width=120>
	  <col width=50>
	  <col width=120>
	 	     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='9'><span class='style16'>List of Sales Orders</span></td></tr>
	  <tr bgcolor='#DDDDDD'>";
	  
if ($Module_Project == 1) {
	echo" <td align='left' colspan='2'><span class='style11'>Project</span></td>
	      <td align='left' colspan='2'><span class='style11'>
		    <input type='text' name='PProjectCode' id='PProjectCode' value='$PProjectCode' size='15' maxlength='15' /></span>
		    <label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo" <td align='left' colspan='4'><input type='hidden' name='PProjectCode' id='PProjectCode' value='$PProjectCode' /></td>";

}			

if ($Module_CostCenter == 1) {		  
	echo" <td align='right' ><span class='style11'>Costcenter</span></td>		
		  <td align='left' ><span class='style11'>
		    <input type='text' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' size='10' maxlength='15' /></span>
		    <label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
} else {
	echo" <td align='left' colspan='2'><input type='hidden' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' /></td>";

}	  


echo" 	<td align='right' ><span class='style11'>Order By</span></td>		
		<td align='left' colspan='2'><span class='style11'><select name='orderby' id='orderby' value='$orderby' onchange='SelectOrderBy();'>";
		
		if ($orderby==1)
			$s11 = 'selected';
		else if ($orderby==2)
			$s12 = 'selected';
			
		echo"<option ".$s11." value='1'>Date</option>
			 <option ".$s12." value='2'>Reference</option>
			 </select></span></td>";
		  
echo" </tr>";
echo" <tr bgcolor='#DDDDDD'>	  
	    <td align='left' colspan='2'><span class='style11'>Search By</span></td>
		<td align='left' colspan='4'><span class='style11'><input type='text' name='PRef' id='PRef' value='$PRef' style='width:200px;' /><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
			<input type='hidden' name='startrange' value='$startrange'>
			<select name='searchby' id='searchby' value='$searchby' onchange='SelectSearchBy();'>";
		
			if ($searchby==1)
				$s21 = 'selected';
			else if ($searchby==2)
				$s22 = 'selected';
			else if ($searchby==3)
				$s23 = 'selected';
			else if ($searchby==4)
				$s24 = 'selected';		
				
			echo"<option ".$s21." value='1'>Date (yyyy-mm-dd)</option>
				 <option ".$s22." value='2'>Reference</option>
				 <option ".$s23." value='3'>Client</option>
				 </select>";	
				 
echo"       <input type='submit' name='btnSubmit' value='Find' onclick='SubmitForm();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
			<input type='button' name='btnCancel' value='Cancel' onclick='ClearForm();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
		<td align='left' valign='center' ><span class='style11'>Result per page</span></td>
		<td colspan='2'><span class='style11'><select name='perpage' id='perpage' value='$perpage' onchange='SelectOrderBy();'>";
              


        if ($perpage==20)
			$s20 = 'selected';
		else if ($perpage==30)
			$s30 = 'selected';
		else if ($perpage==40)
			$s40 = 'selected';
		else if ($perpage==50)
			$s50 = 'selected';

			
				
        echo'<option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span></td>';	
echo" </tr>
	  <tr bgcolor='#DDDDDD'>
		<td align='center' colspan='9'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6'>
		<td  height='25' align='center'><span class='style25'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style25'>Reference </span></td>
		<td  height='25' align='center'><span class='style25'>Date </span></td>
		<td  height='25' align='center'><span class='style25'>Client</span></td>
		<td  height='25' align='center'><span class='style25'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style25'>Project</span></td>
		<td  height='25' align='center'><span class='style25'>CostCenter</span></td>
		<td  height='25' align='center'><span class='style25'>Curr</span></td>
		<td  height='25' align='center'><span class='style25'>Amount</span></td>
	  </tr>";
		

	

	
if (empty($PRef))   
   $PRef = 'Null';
else
   $PRef = "'".$PRef."'"; 

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;
			 
		 
$querysearch=" Select Sorder.Sorder_ID, Sorder.Sorder_Reference, Date_Format(Sorder.Sorder_Date,'%d-%m-%Y') As Sorder_Date, ".
             " Sorder.Client_Code As ClientCode, Clients.Ledger_name As ClientName, Sorder.Currency_code, ".
			 " Sorder.Project_Code As ProjectCode, Sorder.costcent_code As CostCentCode, ".
			 " Round((if($SalesTTC=1,ifNull(Sorder.Sorder_Taxable,0)*(1+$Setup_VatPercentage/100),ifNull(Sorder.Sorder_Taxable,0)) + ifNull(Sorder.Sorder_NoneTaxable,0) + if($SalesTTC=1,0,IfNull(Sorder.Sorder_VAT,0)) - ifNull(Sorder.Sorder_DiscountAmount,0) + ".
			 " (ifNull(Sorder.Sorder_Tax1,0) + ifNull(Sorder.Sorder_Tax2,0) + ifNull(Sorder.Sorder_Tax3,0) + ifNull(Sorder.Sorder_Tax4,0) + ifNull(Sorder.Sorder_Tax5,0))), ".$DecimalBase.") As NetTotal,  ".
			 " if(ifNull(Sorder.Sorder_disapproved,0)=1, 'Cancelled', if(ifNull(Sorder.Sorder_confirmed,0)=1, 'Confirmed', 'Unconfirmed')) As Sorder_Status, ".
			 " ifNull(Temp_Sorder.Sorder_Id, -1) As TempSorderId ".
			 " From Sorder ".
			 " Inner Join Clients on Sorder.Client_Code = Clients.Ledger_Number ".
			 " Left Join Temp_Sorder on Temp_Sorder.Sorder_Id = Sorder.Sorder_Id ";

			 
if ($projectexist >	0)
  $querysearch= $querysearch." Inner join ( select distinct project_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q1 on (($Module_ProjectParent=1 and Sorder.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and Sorder.project_code = Q1.project_code )) ";
							 
if ($costcentexist > 0)
  $querysearch= $querysearch." Inner join ( select distinct costcent_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
							 "             and (costcent_code is not null and costcent_code != '') ".
							 "			 ) Q2 on (($Module_CostCenterParent=1 and Sorder.costcent_code like concat(Q2.costcent_code,'%')) or ($Module_CostCenterParent=0 and Sorder.costcent_code = Q2.costcent_code )) ";

if ($ledgerexist > 0)
  $querysearch= $querysearch." Inner join ( select distinct ledger_number from ".$HTTP_SESSION_VARS['dbLabel'].".ledgerstk ".
							 "			    where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
							 "              and (ledger_number is not null and ledger_number != '') ".
							 "			 )  Q3 on (($ledgerinclude = 1 and Sorder.Client_Code like concat(Q3.ledger_number,'%') ) or ($ledgerinclude = 0 and Sorder.Client_Code Not like concat(Q3.ledger_number,'%') ) or Sorder.Client_Code is null) ";							 	

if ($whexist > 0 && $FI_FrmRestrictWarehouse == 1)
  $querysearch= $querysearch." Inner join ( select distinct sorderdt.Sorder_Id ".
							 " 				from sorderdt inner join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on sorderdt.warehouse_code = loginstk.warehouse_code ".
							 " 				where loginstk.user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
							 " 				and (loginstk.warehouse_code is not null and loginstk.warehouse_code != '')  ".
							 "			 ) Q4 on Sorder.Sorder_Id = Q4.Sorder_Id ";

							 
$querysearch= $querysearch.											 
			 " Where (($searchby = 2 and ifNull(Sorder.Sorder_Reference,-1) Like Concat(ifNull($PRef, ifNull(Sorder.Sorder_Reference,-1)),'%')) Or ".
			 "        ($searchby = 1 and Date_Format(Sorder.Sorder_Date,'%Y-%m-%d') = ifNull(Date_Format($PRef,'%Y-%m-%d'), Date_Format(Sorder.Sorder_Date,'%Y-%m-%d'))) Or  ".
			 "        ($searchby = 3 and Sorder.Client_Code Like Concat('%', ifNull($PRef, Sorder.Client_Code),'%'))  ) ".
			 " And Sorder.Sorder_Type = 'SO' ".
			 " And ifNull(Sorder.Sorder_confirmed,0) = 1 and ifNull(Sorder.Sorder_disapproved,0) = 0 And ifNull(Sorder.Sorder_Hide,0) = 0 ".
			 " And ifNull(Sorder_Invoiced,0) = 0 ".
			 " And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(Sorder.Sorder_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',Sorder.Sorder_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
             "                                                      and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(Sorder.Sorder_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ";
			 
if ($Module_BelongsToGroup == 1)
	$querysearch= $querysearch." And ifNull(Sorder.Sorder_BelongsToGrp,0) >= ifNull($FI_BelongsToGrp,0) ";
	
			 
if ($PProjectCode != '')
	$querysearch= $querysearch." And Sorder.project_code like concat('".$PProjectCode."','%') ";
if ($PCostCentCode != '')
	$querysearch= $querysearch." And Sorder.costcent_code like concat('".$PCostCentCode."','%') ";			 

if ($orderby == 1)
	$querysearch= $querysearch." Order By Sorder.Sorder_Date Desc, Sorder.Sorder_Reference Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By Sorder.Sorder_Reference Desc ";	
	
			 
			 
//echo $querysearch;			 

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
	
$querysearch = $querysearch." limit ".$startrange.",".$perpage;

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		

$i = 0;
while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
		
		

	$EditHint   = 'Load Sales Order';
	if ($TempSorderId != -1) $EditHint = 'Exists in Pending';
	
	$EditMode = 1;
	if ($TempSorderId != -1) $EditMode = 0;
		
		   
	echo'<tr '.$Color.'>';
	
	if ($EditMode == 1)
	    echo'<td align="center"><span class="style15"><img src="img/button_edit.png" onMouseOver="style.cursor=\'hand\'" onclick="LoadRecord('.$Sorder_ID.','.$Sorder_Reference.');" title="'.$EditHint.'"  ></span></td>';
	else
		echo'<td align="center"><span class="style15">&nbsp;</span></td>';
		 
	
	echo'	<td align="left"><span class="style15">'.$Sorder_Reference.'</span></td>
			<td align="center"><span class="style15">'.$Sorder_Date.'</span></td>
			<td align="left"><span class="style15">'.$ClientCode.'</span></td>
			<td align="left"><span class="style15">'.$ClientName.'</span></td>
			<td align="left"><span class="style15">'.$ProjectCode.'</span></td>
			<td align="left"><span class="style15">'.$CostCentCode.'</span></td>
			<td align="center"><span class="style15">'.$Currency_code.'</span></td>
			<td align="right"><span class="style15">'.number_format($NetTotal, $DecimalBase1).'</span></td>
		</tr>';
		
}
							

			
		
echo"   <tr><td colspan='9'>&nbsp;</td></tr>
		<tr><td colspan='9'><table width='100%' border=0><tr><td width='300'>&nbsp;</td><td width='145' align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='145' align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td width='300'>&nbsp;</td></tr>";
		echo"</table>";

echo"</td></tr></table>";
	


          

		  

print <<<HERE

</form>
</body>

HERE;

?>