<?php

session_start();
if($_SESSION['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($_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);
} 

$querylog="select ifNull(FI_PurchasesDel,0) As FI_PurchasesDel, ifNull(FI_PurchasesMod,0) As FI_PurchasesMod, ifNull(FI_PurchasesApp,0) As FI_PurchasesApp from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['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_LoadSerials,0) As Module_LoadSerials ".
			 " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}			 

//Access Mode On Insert/Edit/Delete
$PurDelMode = '';
$PurInsertMode = '';
if ($FI_PurchasesDel == 0)
	$PurDelMode = ' disabled ';
if ($FI_PurchasesApp == 0)
	$PurInsertMode = ' disabled ';	
	

	
$SRPurId    	= $_POST['SRPurId']; if ($SRPurId == ""){$SRPurId = $_GET["SRPurId"];}
$SRPurDtId    	= $_POST['SRPurDtId']; if ($SRPurDtId == ""){$SRPurDtId = $_GET["SRPurDtId"];}
$SRCount  		= $_POST['SRCount']; if ($SRCount == ""){$SRCount = $_GET["SRCount"];}
$SRItemQty    	= $_POST['SRItemQty']; if ($SRItemQty == ""){$SRItemQty = $_GET["SRItemQty"];}
$SRItemCode    	= $_POST['SRItemCode']; if ($SRItemCode == ""){$SRItemCode = $_GET["SRItemCode"];}
$SRWhCode 		= $_POST['SRWhCode']; if ($SRWhCode == ""){$SRWhCode = $_GET["SRWhCode"];}
$SRRemainQty  	= $_POST['SRRemainQty']; if ($SRRemainQty == ""){$SRRemainQty = $_GET["SRRemainQty"];}
$SRItemSerialNo = $_POST['SRItemSerialNo']; if ($SRItemSerialNo == ""){$SRItemSerialNo = $_GET["SRItemSerialNo"];}
$SRHideSerialNo	= $_POST['SRHideSerialNo']; if ($SRHideSerialNo == ""){$SRHideSerialNo = $_GET["SRHideSerialNo"];}
$SRString	= $_POST['SRString']; if ($SRString == ""){$SRString = $_GET["SRString"];}
$SRSeqFrom 	= $_POST['SRSeqFrom']; if ($SRSeqFrom == ""){$SRSeqFrom = $_GET["SRSeqFrom"];}
$SRSeqTo	= $_POST['SRSeqTo']; if ($SRSeqTo == ""){$SRSeqTo = $_GET["SRSeqTo"];}
$perpage	= $_POST['perpage']; if ($perpage == ""){$perpage = $_GET["perpage"];}
$startrange	= $_POST['startrange']; if ($startrange == ""){$startrange = $_GET["startrange"];}



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

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

}
function CloseForm(){
	var PurId = document.itemserials.SRPurId.value;
	opener.document.purchase.txtPurId.value = PurId;
	opener.document.purchase.action='Form_Purchase.php';
	opener.document.purchase.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 PurDtId = x.SRPurDtId.value;
	var PurId   = x.SRPurId.value;
	var ItemQty = x.SRCount.value;
	
	if (confirm ( "Are you sure you want to Adjust Quantity from Serial No ?") )
	{
			if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	var data = xmlhttp.responseText;
					if(data==1){ 
						opener.document.purchase.txtPurId.value = PurId;
						opener.document.purchase.action='Form_Purchase.php';
						opener.document.purchase.submit();
						self.close();
					}
					
				}
		}
  }

	    
		xmlhttp.open("GET","Form_Purchase_Actions.php?mode=editqty1&SPurId="+PurId+"&SPurDtId="+PurDtId+"&ajxused=1&QItemQty="+ItemQty);
		xmlhttp.send();
		
		//x.action="Form_Purchase_Actions.php?mode=editqty1&SPurId="+PurId+"&SPurDtId="+PurDtId+"&QItemQty="+ItemQty;
		//x.submit();
			
		
					 
					
	}	
	
	document.getElementById('SRItemSerialNo').focus();
}

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

function ChangeLocation()
{
	opener.document.purchase.action='Form_Purchase.php';
	opener.document.purchase.submit();
}

function SubmitForm(requiredQty, qty_setup) {
	x=document.itemserials;
	
	var SrQty = x.SRItemQty.value;
	var Sritemcode = x.SRItemCode.value;
	var SrPurDtId = x.SRPurDtId.value;
	var SrPurId = x.SRPurId.value;
	var Srtotal = x.SRCount.value;
	var SrSerial = x.SRItemSerialNo.value;
	var SrWhCode = x.SRWhCode.value;
	var SrPurDtRemQty = x.SRRemainQty.value;
	
	var SrPerPage = x.perpage.value;
	var SrHide = x.SRHideSerialNo.value;
	
	SrQty = parseInt(SrQty);
	Srtotal = parseInt(Srtotal);
	SrPurDtRemQty = parseInt(SrPurDtRemQty);
	/*if (SrSerial != '' && Srtotal >= SrQty) {
		alert("Can't add Serial No "+SrSerial+" Exceeds Max="+SrQty);
		
	}
	else */
	
	SrWhCode = SrWhCode.replace('&','%26');
	
	if (SrWhCode == '') {
		alert("Can't add Serial No "+SrSerial+" warehouse is empty.");
	}	
	else if (SrSerial == '') {
		alert('Please add a serial no.');
		x.SRItemSerialNo.focus();
	}
	else if (SrPurDtRemQty != '' && (Srtotal + 1) > SrPurDtRemQty ) {
		alert('Quantity entered not allowed. Qty must be <= Remaining Ordered Qty ['+SrPurDtRemQty+'].');
		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_PurchaseSerialNo_Actions.php?Mode=insert&ItemSerialNo='+SrSerial+'&ItemCode='+Sritemcode+'&ItemQty='+SrQty+'&ItemWhCode='+SrWhCode+'&PurDtId='+SrPurDtId+'&PurId='+SrPurId+'&PerPage='+SrPerPage+'&HideSerialNo='+SrHide;
		x.submit();
		}
		} else if(qty_setup == 1) {
			x.action='Form_PurchaseSerialNo_Actions.php?Mode=insert&ItemSerialNo='+SrSerial+'&ItemCode='+Sritemcode+'&ItemQty='+SrQty+'&ItemWhCode='+SrWhCode+'&PurDtId='+SrPurDtId+'&PurId='+SrPurId+'&PerPage='+SrPerPage+'&HideSerialNo='+SrHide;
		x.submit();
		}
	}	
	
	//x.SRItemSerialNo.focus();
	//document.getElementById('SRItemSerialNo').focus();
	
}
function GenerateSerialNbr(requiredQty, qty_setup) {
	x=document.itemserials;
	
	var SrQty = x.SRItemQty.value;
	var Sritemcode = x.SRItemCode.value;
	var SrPurDtId = x.SRPurDtId.value;
	var SrPurId = x.SRPurId.value;
	var Srtotal = x.SRCount.value;
	var prefixserialnb = x.txtprefixserialnb.value;
	var SrFromSerial = x.txtfromserialnb.value;
	var SrToSerial = x.txttoserialnb.value;
	var SrFromNbr = x.txtfromnb.value;
	var SrToNbr = x.txttonb.value;
	var SrWhCode = x.SRWhCode.value;
	var SrPurDtRemQty = x.SRRemainQty.value;
	
	var SrPerPage = x.perpage.value;
	var SrHide = x.SRHideSerialNo.value;
	
	if(SrToNbr == '') SrToNbr = 1;
	
	SrQty = parseInt(SrQty);
	Srtotal = parseInt(Srtotal);
	SrPurDtRemQty = parseInt(SrPurDtRemQty);	
	SrWhCode = SrWhCode.replace('&','%26');
	
	if (SrWhCode == '') {
		alert("Can't add Serial No "+SrSerial+" 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 if (SrPurDtRemQty != '' && (Srtotal + 1) > SrPurDtRemQty ) {
		alert('Quantity entered not allowed. Qty must be <= Remaining Ordered Qty ['+SrPurDtRemQty+'].');
		x.txtfromserialnb.focus();
	}	
	else
	{
		 x.SRItemSerialNo.disabled = true;
		if(qty_setup == 2){
		if(((SrToSerial - SrFromSerial +1)*SrToNbr) > requiredQty) {
			alert('Total of serial numbers > Requested Quantity!');
			return 0;
		} else {
			x.action='Form_PurchaseSerialNo_Actions.php?Mode=insertgenerate&txtprefixserialnb='+prefixserialnb+'&SrFromNbr='+SrFromNbr+'&SrToNbr='+SrToNbr+'&txtfromserialnb='+SrFromSerial+'&txttoserialnb='+SrToSerial+'&ItemCode='+Sritemcode+'&ItemQty='+SrQty+'&ItemWhCode='+SrWhCode+'&PurDtId='+SrPurDtId+'&PurId='+SrPurId+'&PerPage='+SrPerPage+'&HideSerialNo='+SrHide;
			x.submit();
		}
		} else if(qty_setup == 1) {
			x.action='Form_PurchaseSerialNo_Actions.php?Mode=insertgenerate&txtprefixserialnb='+prefixserialnb+'&SrFromNbr='+SrFromNbr+'&SrToNbr='+SrToNbr+'&txtfromserialnb='+SrFromSerial+'&txttoserialnb='+SrToSerial+'&ItemCode='+Sritemcode+'&ItemQty='+SrQty+'&ItemWhCode='+SrWhCode+'&PurDtId='+SrPurDtId+'&PurId='+SrPurId+'&PerPage='+SrPerPage+'&HideSerialNo='+SrHide;
			x.submit();
		} 
	}	
	
	//x.SRItemSerialNo.focus();
	//document.getElementById('SRItemSerialNo').focus();
	
}


function GenerateSerials() {
	x=document.itemserials;
	
	var vPurDtId = x.SRPurDtId.value;
	var vPurId 	 = x.SRPurId.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.btnGenerate.disabled = true;
		
		x.action='Form_PurchaseSerialNo_Actions.php?Mode=generate&PurDtId='+vPurDtId+'&PurId='+vPurId+'&PerPage='+vPerPage+'&HideSerialNo='+vHide;
		x.submit();
	}	
}

function ImportSerials() {
	x=document.itemserials;
	
	var vPurDtId = x.SRPurDtId.value;
	var vPurId 	 = x.SRPurId.value;
	
	var vPerPage = x.perpage.value;
	var vHide 	 = x.SRHideSerialNo.value;
	
	x.btnImport.disabled = true;
		
	x.action='Form_PurchaseSerialNo_Actions.php?Mode=loadexcel&PurDtId='+vPurDtId+'&PurId='+vPurId+'&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 SrQty = x.SRItemQty.value;
	var Sritemcode = x.SRItemCode.value;
	var SrPurDtId = x.SRPurDtId.value;
	var SrPurId = x.SRPurId.value;
	var SrWhCode = x.SRWhCode.value;
	
	var SrPerPage = x.perpage.value;
	var SrHide = x.SRHideSerialNo.value;
	
	SrWhCode = SrWhCode.replace('&','%26');
	
	if (confirm ( "Are you sure you want to Delete this record ?") )
	{
		x.action='Form_PurchaseSerialNo_Actions.php?Mode=delete&ItemSerialNo='+SerialNo+'&SerialId='+SerialId+'&ItemCode='+Sritemcode+'&ItemQty='+SrQty+'&ItemWhCode='+SrWhCode+'&PurDtId='+SrPurDtId+'&PurId='+SrPurId+'&PerPage='+SrPerPage+'&HideSerialNo='+SrHide;
		x.submit();
	}
	
	//x.SRItemSerialNo.focus();
	document.getElementById('SRItemSerialNo').focus();
}


function SetNextPage(ItemCode, PurDtQty, WhCode, PurDtId, PurId, startrange, perpage){
	x=document.itemserials;
	WhCode = WhCode.replace('&','%26');
	
	x.action='Form_PurchaseSerialNo.php?SRItemCode='+ItemCode+'&SRItemQty='+PurDtQty+'&SRWhCode='+WhCode+'&SRPurDtId='+PurDtId+'&SRPurId='+PurId+'&startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

function SetPrvPage(ItemCode, PurDtQty, WhCode, PurDtId, PurId, startrange, perpage){
	x=document.itemserials;
	WhCode = WhCode.replace('&','%26');
	
	x.action='Form_PurchaseSerialNo.php?SRItemCode='+ItemCode+'&SRItemQty='+PurDtQty+'&SRWhCode='+WhCode+'&SRPurDtId='+PurDtId+'&SRPurId='+PurId+'&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 x = document.itemserials;
	var SrQty = x.SRItemQty.value;
	var Sritemcode = x.SRItemCode.value;
	var SrPurDtId = x.SRPurDtId.value;
	var SrPurId = x.SRPurId.value;
	var SrWhCode = x.SRWhCode.value;
	
	var SrPerPage = x.perpage.value;
	var SrHide = x.SRHideSerialNo.value;
	
	SrWhCode = SrWhCode.replace('&','%26');

		if (confirm ( "Are you sure you want to Delete all these records?") )
	{
		x.action='Form_PurchaseSerialNo_Actions.php?Mode=deleteall&ItemCode='+Sritemcode+'&ItemQty='+SrQty+'&ItemWhCode='+SrWhCode+'&PurDtId='+SrPurDtId+'&PurId='+SrPurId+'&PerPage='+SrPerPage+'&HideSerialNo='+SrHide;
		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: 0px;
	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;
}

.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();'  class='bodybackground'>
<form enctype='multipart/form-data' name='itemserials' method='post' action='' >
		    
HERE;
//onunLoad='ChangeLocation();'

$query = " 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 PurchaseDt_id  = ".$SRPurDtId. 
		 " AND Items.Item_Code = '".$SRItemCode."'  ".
		 " AND Journal_Type = 'PI' ";
if($txtprefixserialnb != '' && $txttoserialnb != '')		 
$query = $query." and SerialNo_Code between concat('$txtprefixserialnb',$txtfromserialnb) and concat('$txtprefixserialnb',$txttoserialnb) 
				and CHAR_LENGTH(SerialNo_Code) <= CHAR_LENGTH(concat('$txtprefixserialnb',$txttoserialnb)) ";
		 //" AND Logged_Code = '".$_SESSION['useraccount']."' ".
$query =$query." ORDER BY Serial_ID Desc ";

			 
			 
//echo $query;

$result=mysql_query($query,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($result);
$SRCount = $totalrows;
	
if ($startrange=='')
	$startrange = 0;

	
if ($perpage=='' && $config['DftResultPerPage'] != '')
	$perpage = $config['DftResultPerPage'];	
if ($perpage=='')
	$perpage = 30;

if($perpage != 'a')
$query = $query." 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=90>
	  <col width=60>
	  <col width=220>
	  <col width=150>
	  <col width=50>
	  <tr class='Search-header-bg'>
	    <td align='left' valign='top' 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='SRPurDtId' id='SRPurDtId' value='$SRPurDtId' size='10' maxlength='40'/>
			<input type='hidden' name='SRPurId' id='SRPurId' value='$SRPurId' 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'/>
			<input type='hidden' name='SRRemainQty' value='$SRRemainQty' >
			<br>";
	if($serialNb_quantity_setup == 2){		
$requiredQty = $SRItemQty - $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 type='button' id='btnClear' name='btnClear' onclick='ClearForm(); return false;' title='Clear'><span><span>Clear</span></span></button>
	
			
			
			</td>
		<td align='left' valign='center'><span class='style4'>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';	
		else if ($perpage=='a')
			$sa = '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>
			 <option '.$sa.' value="a">All</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='btnGenerate' value='Generate' onclick='GenerateSerials();' 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>		";
}
		
		
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 type='button' id='btnImport' name='btnImport' onclick='ImportSerials(); return false;' title='Import'><span><span>Import</span></span></button>
		</td></tr>";
		
		  
/*<input type='text' name='txtFileName' id='txtFileName' readonly='true' >
	<input type='button' name='btnBrowse' value='Browse' onclick='OpenExcelFile();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' />		  
*/
echo "<tr bgcolor='#E6E6E6'><td><span class='style4'>Field # From</span></td><td><input type='text' name='txtfromnb' id='txtfromnb' value='$txtfromnb' style='width:100px;'>
			</td>";
echo "<td><span class='style4'>Field # To</span>&nbsp;<input type='text' name='txttonb' id='txttonb' value='$txttonb' style='width:100px;'></td><td></td></tr>";
echo "<tr bgcolor='#E6E6E6'><td><span class='style4'>Prefix</span></td><td><input type='text' name='txtprefixserialnb' id='txtprefixserialnb' value='$txtprefixserialnb' style='width:100px;'>
			</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' style='width:100px;'>
			</td>";
echo "<td><span class='style4'>To</span>&nbsp;<input type='text' name='txttoserialnb' id='txttoserialnb' value='$txttoserialnb' style='width:100px;'></td>";	
if($serialNb_quantity_setup == 2){		
$requiredQty = $SRItemQty - $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('0','$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>	";
if(strlen($message) <=200)	  
echo" <tr bgcolor='#DDDDDD'>
		<td align='center' colspan='4'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	";	  
else if(strlen($message) > 200)	{   
	$newmsg = explode(',',$message);
	$ctt=1;
	echo" <tr bgcolor='#DDDDDD'>
		<td align='center' colspan='4'><div style='overflow-y:scroll;height:100px;width:550px;'><font size='1' color='#FF0000' face='Verdana'><b>";
	foreach($newmsg	as $message){
		echo $message.", ";
		if(!($ctt%15)) echo "<br>";
		$ctt++;
	}
	echo "</b></font></div></td></tr>	";	
}
echo	 " <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($query,$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.'>';
		echo "<td height='20' align='center'><span class='style15'><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="style15">'.$CurrentRow.'</span></td>
				<td height="20" align="left"><span class="style15">'.$SerialNo_Code.'</span></td>
				<td height="20" align="center"><span class="style15">&nbsp;</span></td>';
			
		echo'</tr>';		
		
		$i++;
		
	}
}			
	echo"</table><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";		
if ($SRHideSerialNo == '') {		
echo"   
		<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:920px;' valign='top'><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.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=\"SetPrvPage('".htmlentities($SRItemCode)."','".$SRItemQty."','".htmlentities($SRWhCode)."','".$SRPurDtId."','".$SRPurId."','".$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.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=\"SetNextPage('".htmlentities($SRItemCode)."','".$SRItemQty."','".htmlentities($SRWhCode)."','".$SRPurDtId."','".$SRPurId."','".$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>
</html>
HERE;



?>