<?php

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


include("config.inc.php");
include("Functions_Purchase.php");

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

							
$querysetup="select base1, base2, grid_color1, grid_color2, serialNb_quantity_setup from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

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

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

function ClearForm()
{
  var x=document.itemserials;
  x.txtprefixserialnb.value='';
  x.txtfromserialnb.value='';
  x.txttoserialnb.value='';
  x.SRItemSerialNo.value = '';
  x.action='Form_AdjustmentSerialNo.php';
  x.submit();

}
function CloseForm(){
	var vAdjId      = x.SRAdjId.value;
	opener.document.adjustment.txtAdjId.value = vAdjId;
	opener.document.adjustment.action='Form_Adjustment.php';
	opener.document.adjustment.submit();
	self.close();
}

function HideShowSerialNo()
{
	x=document.itemserials;
	
	if (x.ChkQuery.checked)
		x.SRHideSerialNo.value = 1;
	else
		x.SRHideSerialNo.value = '';
		
	x.submit();
}

function ConfirmForm()
{
	x=document.itemserials;
	var vAdjDtId    = x.SRAdjDtId.value;
	var vAdjId      = x.SRAdjId.value;
	var vItemQty    = x.SRCount.value;
	var vAdjustType = x.AdjustType.value;
	
	if (confirm ( "Are you sure you want to Adjust Quantity from Serial No ?") )
	{
		x.action="Form_Adjustment_Actions.php?AdjustType='+vAdjustType+'&mode=editqty1&SAdjId="+vAdjId+"&SAdjDtId="+vAdjDtId+"&QItemQty="+vItemQty;
		x.submit();
			
		//opener.document.adjustment.txtAdjId.value = vAdjId;
		//opener.document.adjustment.action='Form_Adjustment.php';
		//opener.document.adjustment.submit();
		//self.close();
	}	
	
	document.getElementById('SRItemSerialNo').focus();
}

function LoadForm() 
{
	x=document.itemserials;
	//x.SRItemSerialNo.focus();
	x.SRItemSerialNo.disabled = false;
	document.getElementById('SRItemSerialNo').focus();
	
	ChangeLocation();
}


function ChangeLocation()
{
	x=document.itemserials;
	
    if (x.PMode.value == 1) {
		//opener.document.adjustment.action='Form_Adjustment.php';
		opener.document.adjustment.submit();
		
		if (x.message.value == '')
			self.close();
		
	}	
}

function SubmitForm(requiredQty, qty_setup) {
	x=document.itemserials;
	
	var vSrQty         = x.SRItemQty.value;
	var vSrItemCode    = x.SRItemCode.value;
	var vSrAdjDtId     = x.SRAdjDtId.value;
	var vSrAdjId       = x.SRAdjId.value;
	var vSrTotal       = x.SRCount.value;
	var vSrSerial      = x.SRItemSerialNo.value;
	var vSrWhCode      = x.SRWhCode.value;
	var vAdjustType    = x.AdjustType.value;
	
	var vSrPerPage = x.perpage.value;
	var vSrHide    = x.SRHideSerialNo.value;
	
	vSrQty   = parseInt(vSrQty);
	vSrTotal = parseInt(vSrTotal);
	
	vSrWhCode = vSrWhCode.replace('&','%26');
	
	
	if (vSrWhCode == '') {
		alert("Can't add Serial No "+vSrSerial+" warehouse is empty.");
	}	
	else if (vSrSerial == '') {
		alert('Please add a serial no.');
		x.SRItemSerialNo.focus();
	}
	else
	{
		x.SRItemSerialNo.disabled = true;
		if(qty_setup == 2){
		if( 1 > requiredQty) {
			alert('Total of serial numbers > Requested Quantity!');
			return 0;
		} else {
		x.action='Form_AdjustmentSerialNo_Actions.php?AdjustType='+vAdjustType+'&Mode=insert&ItemSerialNo='+vSrSerial+'&ItemCode='+vSrItemCode+'&ItemQty='+vSrQty+'&ItemWhCode='+vSrWhCode+'&AdjDtId='+vSrAdjDtId+'&AdjId='+vSrAdjId+'&PerPage='+vSrPerPage+'&HideSerialNo='+vSrHide;
		x.submit();
		}
		} else if(qty_setup == 1) {
			x.action='Form_AdjustmentSerialNo_Actions.php?AdjustType='+vAdjustType+'&Mode=insert&ItemSerialNo='+vSrSerial+'&ItemCode='+vSrItemCode+'&ItemQty='+vSrQty+'&ItemWhCode='+vSrWhCode+'&AdjDtId='+vSrAdjDtId+'&AdjId='+vSrAdjId+'&PerPage='+vSrPerPage+'&HideSerialNo='+vSrHide;
		x.submit();
		}
	}	
	
	//x.SRItemSerialNo.focus();
	document.getElementById('SRItemSerialNo').focus();
	
}

function GenerateSerialNbr(requiredQty, qty_setup) {
	x=document.itemserials;
	
	var vSrQty         = x.SRItemQty.value;
	var vSrItemCode    = x.SRItemCode.value;
	var vSrAdjDtId     = x.SRAdjDtId.value;
	var vSrAdjId       = x.SRAdjId.value;
	var vSrTotal       = x.SRCount.value;
	var vSrWhCode      = x.SRWhCode.value;
	var vAdjustType    = x.AdjustType.value;
	
	var prefixserialnb = x.txtprefixserialnb.value;
	var SrFromSerial = x.txtfromserialnb.value;
	var SrToSerial = x.txttoserialnb.value;
	
	var vSrPerPage = x.perpage.value;
	var vSrHide    = x.SRHideSerialNo.value;
	
	vSrQty   = parseInt(vSrQty);
	vSrTotal = parseInt(vSrTotal);
	
	vSrWhCode = vSrWhCode.replace('&','%26');
	
	
	if (vSrWhCode == '') {
		alert("Can't add Serial No warehouse is empty.");
	}	
	else if (SrFromSerial == '') {
		alert('Please add a serial no.');
		x.txtfromserialnb.focus();
	}else if (SrToSerial == '') {
		alert('Please add a serial no.');
		x.txttoserialnb.focus();
	}
		
	else
	{
		x.SRItemSerialNo.disabled = true;
		if(qty_setup == 2){
		if((SrToSerial - SrFromSerial +1) > requiredQty) {
			alert('Total of serial numbers > Requested Quantity!');
			return 0;
		} else {
		x.action='Form_AdjustmentSerialNo_Actions.php?Mode=insertgenerate&txtprefixserialnb='+prefixserialnb+'&txtfromserialnb='+SrFromSerial+'&txttoserialnb='+SrToSerial+'AdjustType='+vAdjustType+'&ItemCode='+vSrItemCode+'&ItemQty='+vSrQty+'&ItemWhCode='+vSrWhCode+'&AdjDtId='+vSrAdjDtId+'&AdjId='+vSrAdjId+'&PerPage='+vSrPerPage+'&HideSerialNo='+vSrHide;
		x.submit();
		}
		} else if(qty_setup == 1) {
			x.action='Form_AdjustmentSerialNo_Actions.php?Mode=insertgenerate&txtprefixserialnb='+prefixserialnb+'&txtfromserialnb='+SrFromSerial+'&txttoserialnb='+SrToSerial+'AdjustType='+vAdjustType+'&ItemCode='+vSrItemCode+'&ItemQty='+vSrQty+'&ItemWhCode='+vSrWhCode+'&AdjDtId='+vSrAdjDtId+'&AdjId='+vSrAdjId+'&PerPage='+vSrPerPage+'&HideSerialNo='+vSrHide;
		x.submit();
		}
	}	
	
	//x.SRItemSerialNo.focus();
	document.getElementById('SRItemSerialNo').focus();
	
}


function LoadSerials() {
	x=document.itemserials;
	
	var vAdjustType = x.AdjustType.value;
	var vAdjDtId 	= x.SRAdjDtId.value;
	var vAdjId 	 	= x.SRAdjId.value;
	var vString  	= x.SRString.value;
	var vSeqFrom 	= x.SRSeqFrom.value;
	var vSeqTo 	 	= x.SRSeqTo.value;
	
	
	var vPerPage = x.perpage.value;
	var vHide 	 = x.SRHideSerialNo.value;
	
	if (vString == '' || vSeqFrom == '' || vSeqTo == '') {
		alert('Please fill missing fields.');
		x.SRString.focus();
	}
	else if ((vSeqFrom*1 != vSeqFrom/1) || (vSeqTo*1 != vSeqTo/1) ) {
		alert('Sequence From/To should be a NUMERIC value.');
		x.SRSeqFrom.focus();
	}
	else if ((vString.length +  vSeqFrom.length) > 40) {
		alert('Length of Serial No should be less than 40 characters.');
		x.SRString.focus();
	}	
	else
	{
		x.btnLoad.disabled = true;
		x.action='Form_AdjustmentSerialNo_Actions.php?AdjustType='+vAdjustType+'&Mode=load&AdjDtId='+vAdjDtId+'&AdjId='+vAdjId+'&PerPage='+vPerPage+'&HideSerialNo='+vHide;
		x.submit();
	}	
}

function ImportSerials() {
	x=document.itemserials;
	
	var vAdjustType = x.AdjustType.value;
	var vAdjDtId 	= x.SRAdjDtId.value;
	var vAdjId 	 	= x.SRAdjId.value;
	
	var vPerPage = x.perpage.value;
	var vHide 	 = x.SRHideSerialNo.value;
	
	x.btnImport.disabled = true;
		
	x.action='Form_AdjustmentSerialNo_Actions.php?AdjustType='+vAdjustType+'&Mode=loadexcel&AdjDtId='+vAdjDtId+'&AdjId='+vAdjId+'&PerPage='+vPerPage+'&HideSerialNo='+vHide;
	x.submit();
}

function OpenExcelFile() {
	x=document.itemserials;
	
	document.getElementById('excelfile').click();
	document.getElementById('txtFileName').value = document.getElementById('excelfile').value;
	//x.excelfile.click();
	//x.txtFileName.value = x.excelfile.value;
}

function DeleteSerialNo(SerialId, SerialNo) {
	x=document.itemserials;
	var vSrAdjDtId = x.SRAdjDtId.value;
	var vSrAdjId   = x.SRAdjId.value;
	var vSrPerPage = x.perpage.value;
	var vSrHide    = x.SRHideSerialNo.value;
	var vAdjustType = x.AdjustType.value;
	
	
	if (confirm ( "Are you sure you want to Delete this record ?") )
	{
		x.action='Form_AdjustmentSerialNo_Actions.php?AdjustType='+vAdjustType+'&Mode=delete&ItemSerialNo='+SerialNo+'&SerialId='+SerialId+'&AdjDtId='+vSrAdjDtId+'&AdjId='+vSrAdjId+'&PerPage='+vSrPerPage+'&HideSerialNo='+vSrHide;
		x.submit();
	}
	
	//x.SRItemSerialNo.focus();
	document.getElementById('SRItemSerialNo').focus();
}


function SetNextPage(AdjDtId, AdjId, startrange, perpage){
	x=document.itemserials;
	
	x.action='Form_AdjustmentSerialNo.php?SRAdjId='+AdjId+'&SRAdjDtId='+AdjDtId+'&startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

function SetPrvPage(AdjDtId, AdjId, startrange, perpage){
	x=document.itemserials;
	
	x.action='Form_AdjustmentSerialNo.php?SRAdjId='+AdjId+'&SRAdjDtId='+AdjDtId+'&startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

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

function selectAll(){
	
	var alldel = document.itemserials.SRCount.value;
	var indx = 0;
	if(document.getElementById("txtselectall").checked){
	for(indx =0; indx<alldel;indx++){
		document.getElementById('txttodelete'+indx).checked=true; 
	}
	} else {
		for(indx =0; indx<alldel;indx++){
		document.getElementById('txttodelete'+indx).checked=false; 
	}
	}
}
function deleteAll(){
	var vSrAdjDtId = x.SRAdjDtId.value;
	var vSrAdjId   = x.SRAdjId.value;
	var vSrPerPage = x.perpage.value;
	var vSrHide    = x.SRHideSerialNo.value;
	var vAdjustType = x.AdjustType.value;
	
	
		if (confirm ( "Are you sure you want to Delete all these records?") )
	{
		x.action='Form_AdjustmentSerialNo_Actions.php?Mode=deleteall&AdjDtId='+vSrAdjDtId+'&AdjId='+vSrAdjId+'&PerPage='+vSrPerPage+'&HideSerialNo='+vSrHide;
		x.submit();
	}
	
}
function FilterSerialnbr(){
	document.itemserials.submit();
}
</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 {
   font-size: 11px;
   color: #000000;
   font-family: Verdana, Arial, Helvetica, sans-serif;   }
   
.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 enctype='multipart/form-data' name='itemserials' method='post' action=''>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='PMode' id='PMode' value='$PMode'/>
<input type='hidden' name='AdjustType' value='$AdjustType'>		    
HERE;
//onunLoad='ChangeLocation();'

if ($AdjustType == 'O')      { $FormTitle = 'STOCK OUT';  $JourType = 'AR'; }
else if ($AdjustType == 'I') { $FormTitle = 'STOCK IN';   $JourType = 'AI'; }
else if ($AdjustType == 'A') { $FormTitle = 'ADJUSTMENT'; $JourType = 'AI'; } 

$sub_query = " Select Item_code, Warehouse_Code, Abs(AdjustmentDt_Quantity), AdjustmentDt.Journal_Type ".
			 " From Temp_AdjustmentDt As AdjustmentDt ".
			 " Where Adjustment_ID = '".$SRAdjId."' ".
			 " And AdjustmentDt_id = '".$SRAdjDtId."' ";
$sub_result = selectData($connection, $sub_query);	    

$SRItemCode = $sub_result[0];
$SRWhCode   = $sub_result[1];
$SRItemQty  = $sub_result[2];
$JourType   = $sub_result[3];


$sub_query1 = " SELECT Serial_ID, Items.Item_Code As ItemCode, Items.Item_Description As ItemDesc, SerialNo_Code, SerialNo_Used, RelatedSerial_Id, SerialNo_Quantity  ".
			  " FROM temp_purchasesserialno ".
			  " Inner Join Items on temp_purchasesserialno.Item_Code = Items.Item_Code ".
			  " WHERE AdjustmentDt_ID  = '".$SRAdjDtId."' ". 
			  " AND Items.Item_Code = '".$SRItemCode."'  ".
			  " AND Journal_Type = '".$JourType."' ";
if($txtprefixserialnb != '' && $txttoserialnb != '')		 
$sub_query1 = $sub_query1." and SerialNo_Code between concat('$txtprefixserialnb',$txtfromserialnb) and concat('$txtprefixserialnb',$txttoserialnb) 
				and CHAR_LENGTH(SerialNo_Code) <= CHAR_LENGTH(concat('$txtprefixserialnb',$txttoserialnb)) ";					  
$sub_query1 = $sub_query1." ORDER BY Serial_ID Desc ";
			 
//echo $sub_query1;

$sub_result1=mysql_query($sub_query1,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($sub_result1);

$SRCount = $totalrows;
	
if ($startrange=='')
	$startrange = 0;
	
	
if ($perpage=='' && $config['DftResultPerPage'] != '')
	$perpage = $config['DftResultPerPage'];	
if ($perpage=='')
	$perpage = 5;
		
$sub_query1 = $sub_query1." limit ".$startrange.",".$perpage;


echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' >";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:500px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Serial Numbers for Item $SRItemCode
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
		 
echo "<table border='0' style='table-layout:fixed' align='center' cellspacing='1'>
	  <col width=100>
	  <col width=80>
	  <col width=200>
	  <col width=150> 

	<tr class='Search-header-bg'>
	    <td align='left' valign='center' colspan='2'><span class='style4'>Enter Serial No</span></td>
		<td align='left' valign='top' ><span class='style4'>
			<input type='text' name='SRItemSerialNo' id='SRItemSerialNo' value='$SRItemSerialNo' size='29' maxlength='40' onkeydown='return kd(event)'/>
			<input type='hidden' name='SRItemCode' id='SRItemCode' value='$SRItemCode' size='20' maxlength='40'/>
			<input type='hidden' name='SRWhCode' id='SRWhCode' value='$SRWhCode' size='20' maxlength='40'/>
			<input type='hidden' name='SRItemQty' id='SRItemQty' value='$SRItemQty' size='10' maxlength='40'/>
			<input type='hidden' name='SRAdjDtId' id='SRAdjDtId' value='$SRAdjDtId' size='10' maxlength='40'/>
			<input type='hidden' name='SRAdjId' id='SRAdjId' value='$SRAdjId' size='10' maxlength='40'/>
			<input type='hidden' name='SRCount' id='SRCount' value='$SRCount' size='10' maxlength='40'/>
			<input type='hidden' name='SRHideSerialNo' id='SRHideSerialNo' value='$SRHideSerialNo' size='10' maxlength='40'/>
			
			<br>";
			
			if($serialNb_quantity_setup == 2){
	$queryqty = " select AdjustmentDt_Quantity from Temp_AdjustmentDt where AdjustmentDt_ID = $SRAdjDtId"; 
	$resltqty = mysql_query($queryqty, $connection);
	$rwsqty = mysql_fetch_row($resltqty);
					
	$requiredQty = $rwsqty[0] - $SRCount;		
	echo "<button type='button' id='btnSubmit' name='btnSubmit' onclick=\"SubmitForm('$requiredQty','$serialNb_quantity_setup'); return false;\" title='Submit'><span><span>Submit</span></span></button>";
	} else echo "<button type='button' id='btnSubmit' name='btnSubmit' onclick=\"SubmitForm('0','$serialNb_quantity_setup'); return false;\" title='Submit'><span><span>Submit</span></span></button>";
		echo "<button type='button' id='btnClose' name='btnClose' onclick='CloseForm(); return false;' title='close'><span><span>Close</span></span></button>
			<button name='btnClear' value='clear' onclick='ClearForm();'><span><span>Clear</span></span></button>
			</td>
		<td align='left' valign='center'><span class='style4'>Result per page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange='ClearForm();'>";
              
//<input type='text' name='SRMode' id='SRMode' value='$SRMode' size='10' maxlength='40'/>
//<input type='text' name='SRSerialId' id='SRSerialId' value='$SRSerialId' size='10' maxlength='40'/>
			
        if ($perpage==20)
			$s20 = 'selected';	
		else if ($perpage==30)
			$s30 = 'selected';	
		else if ($perpage==60)
			$s60 = 'selected';
		else if ($perpage==90)
			$s90 = 'selected';
		else if ($perpage==120)
			$s120 = 'selected';
		else if ($perpage==500)
			$s500 = 'selected';
		else if ($perpage==1000)
			$s1000 = 'selected';
		else if ($perpage==2000)
			$s2000 = 'selected';
			
				
        echo'<option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s60.' value="60">60</option>
			 <option '.$s90.' value="90">90</option>
			 <option '.$s120.' value="120">120</option>
			 <option '.$s500.' value="500">500</option>
			 <option '.$s1000.' value="1000">1000</option>
			 <option '.$s2000.' value="2000">2000</option>
			 </select></span></td>';	
echo" </tr>";

if ($Module_LoadSerials == 1) {
	echo" <tr bgcolor='#E6E6E6'>
			<td align='left' valign='center' colspan='2'><span class='style4'>String</span></td>
			<td align='left' valign='center' colspan='2'><span class='style4'>
				<input type='text' name='SRString' id='SRString' value='$SRString' style='width:210px;' maxlength='35'/></span>
				<input type='button' name='btnLoad' value='Load' onclick='LoadSerials();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' />
			</td>
		  </tr>	
		  <tr bgcolor='#E6E6E6'>
			<td align='left' valign='center' colspan='2'><span class='style4'>Sequence</span></td>
			<td align='left' valign='center' colspan='2'><span class='style4'> From: </span>
				<input type='text' name='SRSeqFrom' id='SRSeqFrom' value='$SRSeqFrom' style='width:70px;' maxlength='7'/>
				<span class='style4'> To: </span>
				<input type='text' name='SRSeqTo' id='SRSeqTo' value='$SRSeqTo' style='width:70px;' maxlength='7'/>
			</td>
		  </tr>		";
}

if (($AdjustType == 'I') || ($AdjustType == 'A' && $JourType == 'AI')) {
	echo" 	<tr bgcolor='#E6E6E6'>
				<td align='left' valign='center' colspan='2'><span class='style4'>Load Excel</span></td>
				<td align='left' valign='center' colspan='2'>
					<input type='file' name='excelfile' id='excelfile' accept='text/xls' style='width:200px; ' >
					<button name='btnImport' value='Import' onclick='ImportSerials();'><span><span>Import</span></span></button>
				</td>
			  </tr>	";	
}			  
echo "<tr bgcolor='#E6E6E6'><td><span class='style4'>Prefix</span></td><td><input type='text' name='txtprefixserialnb' id='txtprefixserialnb' value='$txtprefixserialnb' width='50px'>
			</td><td></td><td><button type='button' id='btnFilter' name='btnFilter' onclick='FilterSerialnbr(); return false;' title='Filter'><span><span>Filter</span></span></button></td></tr>";
echo "<tr bgcolor='#E6E6E6'><td><span class='style4'>From</span></td><td><input type='text' name='txtfromserialnb' id='txtfromserialnb' value='$txtfromserialnb' width='50px'>
			</td>";
echo "<td><span class='style4'>To</span>&nbsp;<input type='text' name='txttoserialnb' id='txttoserialnb' value='$txttoserialnb' width='50px'></td>";	
if($serialNb_quantity_setup == 2){
	$queryqty = " select AdjustmentDt_Quantity from Temp_AdjustmentDt where AdjustmentDt_ID = $SRAdjDtId"; 
	$resltqty = mysql_query($queryqty, $connection);
	$rwsqty = mysql_fetch_row($resltqty);
					
	$requiredQty = $rwsqty[0] - $SRCount;			
echo "<td><button type='button' id='btnGeneratesrl' name='btnGeneratesrl' onclick=\"GenerateSerialNbr('$requiredQty','$serialNb_quantity_setup'); return false;\" title='Generate'><span><span>Generate</span></span></button>
		</td></td>";
} else echo "<td><button type='button' id='btnGeneratesrl' name='btnGeneratesrl' onclick=\"GenerateSerialNbr('$requiredQty','$serialNb_quantity_setup'); return false;\" title='Generate'><span><span>Generate</span></span></button>
		</td></td>";		
echo "</tr>	";
echo" <tr bgcolor='#DDDDDD'>
		<td align='left' colspan='4'><span class='style4' style='margin:0px 5px 0px 5px;'><input type='checkbox' name='txtselectall' id='txtselectall' onclick='selectAll();'>Select All</span>
		<button type='button' id='btnDeleteall' name='btnDeleteall' onclick='deleteAll(); return false;' title='Delete All'><span><span>Delete All</span></span></button></td>
	  </tr>	";
echo" <tr class='Search-header-bg'>
		<td align='center' colspan='4'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr class='Search-Label-bg'>
	    <td  height='25' align='left'><span class='style4'>&nbsp; </span></td>
		<td  height='25' align='left'><span class='style4'>S/N </span></td>
		<td  height='25' align='center'><span class='style4'>Serial No </span></td>
		<td  height='25' align='left'><span class='style4'>
		<input name='ChkQuery' type='checkbox' id='ChkQuery' value='1' onClick='HideShowSerialNo();'   "; 
	          if($SRHideSerialNo==1) echo "checked />"; else echo " /> "; 
echo" 	Hide SerialNo</span></td>
	  </tr>";
		

	

	
if ($SRHideSerialNo == '') {
	$i=0;
	$result=mysql_query($sub_query1,$connection) or die(mysql_error());		
	while($rows=mysql_fetch_array($result)){
			
		extract($rows);
		$ct+=1;

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

			
		$CurrentRow = $totalrows - $startrange - $ct + 1;
			
				
		echo'<tr '.$Color.'><td height="20" align="center"><span class="style5">';
		echo "<input type='checkbox' name='txttodelete[]' id='txttodelete$i' value='$Serial_ID'>";
		echo '	<img src="img/delete.png" onclick="DeleteSerialNo('.$Serial_ID.',\''.$SerialNo_Code.'\');" onMouseOver="style.cursor=\'hand\'"  title="Delete Record"  ></span></td>
				<td height="20" align="left"><span class="style5">'.$CurrentRow.'</span></td>
				<td height="20" align="left"><span class="style5">'.$SerialNo_Code.'</span></td>
				<td height="20" align="center"><span class="style5">&nbsp;</span></td>';
			
		echo'</tr>';		
		
		$i++;
		
	}
			
echo"</table><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			
		
echo"   <tr height='30'>
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:920px;' valign='top'>";
		
echo "<table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' 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('".$SRAdjDtId."','".$SRAdjId."','".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' 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('".$SRAdjDtId."','".$SRAdjId."','".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"</table>";
echo"</td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td></tr>";


}
else{

	echo"<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:920px;' valign='top'></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td></tr>";

}

echo"</table>";
	


          

		  

print <<<HERE
</form>
</body>

HERE;



?>