<?php 
if($_REQUEST['Submit'])
{	
	$siteCode = $_REQUEST['sitecode'];
	$site_Code=substr($siteCode,0,3);
	$CurrentFinancialYear = date("y")."-".$Prefix_date;
	$year=$_SESSION['financialYearStart'];
	$Afteryear=$_SESSION['financialYearEnd'];
	$prefixcode="RGPR";
	$AutoSQL=DB_query("select * from rgp_return where branch='".$_REQUEST['sitecode']."'",$db);
	if(DB_num_rows($AutoSQL)>0)
	{
	$SQL1=DB_query("select max(return_no) as RENO from rgp_return where branch='".$_REQUEST['sitecode']."'",$db);
	$GetMax=DB_fetch_array($SQL1);
	$MaxId=substr($GetMax['RENO'],-2);
	$MaxId1=$MaxId+1;
	$FinalCode=$site_Code."/".$prefixcode."/".$year.$Afteryear."/".str_pad($MaxId1,6,"0",STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$site_Code."/".$prefixcode."/".$year.$Afteryear."/".'000001';
	}
	$data['branch']=$_REQUEST['sitecode'];
	$data['store']=$_REQUEST['store'];
	$data['return_no']=$FinalCode;
	$data['suplier']=$_REQUEST['suplier'];
	$data['return_date']=FormatDateForSQL($_REQUEST['return_date']);
	$data['return_time']=$_REQUEST['return_time'];
	$data['rgp_no']=$_REQUEST['rgpno'];
	$data['vehchile_no']=$_REQUEST['vehchile_no'];
	$data['remove_date']=FormatDateForSQL($_REQUEST['remove_date']);
	$data['remove_time']=$_REQUEST['remove_time'];
	$data['form_no']=$_REQUEST['form_no'];
	$data['removal_remarks']=$_REQUEST['removal_remarks'];
	$data['exp_time']=$_REQUEST['exp_time'];
	$data['exp_value']=$_REQUEST['exp_value'];
	$data['return_remark']=$_REQUEST['return_remark'];
	$data['rgp_return_time']=$_REQUEST['rgp_return_time'];
	$s->RecordInsert('rgp_return', $data);
	$Lastreq_id=DB_Last_Insert_ID($db,'rgp_return',$ErrMsg);
	$arr='';
	for($i=0;$i<count($_REQUEST['itemcode']);$i++)
	{
	if($_REQUEST['itemcode'][$i]!='')
	{
	$data1['parent_id']=$Lastreq_id;
	$data1['item_id']=$_REQUEST['itemcode'][$i];
	$data1['batch_no']=$_REQUEST['batch_no'][$i];
	$data1['qty']=$_REQUEST['qty'][$i];
	$data1['issueqty']=$_REQUEST['qty1'][$i];
	$data1['stock_qty']=$_REQUEST['stock_qty'][$i];
	$data1['job_process']=$_REQUEST['job_process'][$i];
	$data1['job_rate']=$_REQUEST['rate'][$i];
	$data1['job_value']=$_REQUEST['rvalue'][$i];
	$s->RecordInsert('rgp_return_details', $data1);
	}
	//$arr[]=$_REQUEST['qty'][$i]+$_REQUEST['pendingQty'][$i];
	$TotalPending=$_REQUEST['pendingQty'][$i];
	if($_REQUEST['pendingQty'][$i]!='0.00')
	{
	$Update=DB_query("update rgp_tab_details set pending_qty='".$TotalPending."',status='P'
	where id='".$_REQUEST['rgptab_detailId'][$i]."' ",$db);
	}
	else
	{
	$Update=DB_query("update rgp_tab_details set pending_qty='0.00' , status='Y' 
	where id='".$_REQUEST['rgptab_detailId'][$i]."'",$db);
	}	
	}
	$count1=0;
	$sql23=DB_query("select * from rgp_tab_details where parent_id='".$_REQUEST['rgpno']."'",$db);	
	$numcount=DB_num_rows($sql23);
	while($rw1=DB_fetch_array($sql23))
	{
	if($rw1['status']=='Y'){ $count1=$count1+1;}
	}
    if($count1==$numcount)
	{ $updatestatus='Y';  } else { $updatestatus='N';  }	
	
	
	$Update=DB_query("update rgp_tab set status='".$updatestatus."' where id='".$_REQUEST['rgpno']."'",$db);
	
	
$s->pageLocation("index.php?route=Inventory/transation/rgp_return_index".$rurl);//PAGE REDIRCTION
}

?>

<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<script type="text/javascript" language="javascript">
function getrgpdata(str)
{
	
	if (str.length==0)
	{
	document.getElementById("sitecode").innerHTML="";
	return;
	}
	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.split("__");
	document.getElementById("SUPLIER").innerHTML=data[0];	//alert(data);
	document.getElementById("STORECODE").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","GetRgpDetails.php?branch="+str,true);
	xmlhttp.send();
}



function getRGPNo(str)
{
	
	if (str.length==0)
	{
	document.getElementById("SUPLIER").innerHTML="";
	return;
	}
	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)
	{
	document.getElementById("RGPNO").innerHTML=xmlhttp.responseText;	//alert(data);
	}
	}
	
	xmlhttp.open("GET","GetRgpNO.php?suplierId="+str,true);
	xmlhttp.send();
}



function getRGPDetails(str)
{
	if(document.getElementById("return_date").value=='')
	{
	alert("must Select Date");
	return false;
	}
	if (str.length==0)
	{
	document.getElementById("RGPNO").innerHTML="";
	return;
	}
	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.split("__");
	document.getElementById("VehicleNo").innerHTML=data[0];
	document.getElementById("RemoveDate").innerHTML=data[1];
	document.getElementById("FormNo").innerHTML=data[2];
	document.getElementById("itemdata").innerHTML=data[3];
	document.getElementById("REMARK").innerHTML=data[4];
	document.getElementById("EXPTEDTIME").innerHTML=data[5];
	document.getElementById("EXPECTEDVALUE").innerHTML=data[6];
	//alert(data);
	}
	}
	var date=document.getElementById("return_date").value;
	xmlhttp.open("GET","GetRgpAllDetails.php?RGPID="+str+"&date="+date,true);
	xmlhttp.send();
}


function calculaterate(i)
{

	var qty=document.getElementById("qty_"+i).value;
	var rate=document.getElementById("rate_"+i).value;
	var tot=qty*rate;
	document.getElementById("rvalue_"+i).value=tot;
}

function checkQty(i)
{

	var qty=parseFloat(document.getElementById("qty_"+i).value);
	var qty1=parseFloat(document.getElementById("qty1_"+i).value);
	var PendingQty=parseFloat(document.getElementById("chkqty_"+i).value);
	if(qty>qty1 || qty>PendingQty)
	{
		alert("You Can't Take Greater Than Qty");
		document.getElementById("qty_"+i).value=PendingQty;
		document.getElementById("pendingQty_"+i).value=PendingQty;
		document.getElementById("qty_"+i).focus();
	}
	else
	{
	var issueqty=PendingQty-qty;
	document.getElementById("pendingQty_"+i).value=issueqty.toFixed(2);
	}
}

function GrabdTotal()
{
	var Total=0;
	count1=document.getElementById("count").value;
	for(var i=0;i<count1;i++)
	{
		var q=parseFloat(document.getElementById("rvalue_"+i).value);
		//alert(q);
		var Total=Total+q;
		//alert(Total);
	}
	document.getElementById("exp_value").value=Total;
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
	
<h1><strong>RGP Return</strong></h1>
<form name="form1" action="" method="post" >

<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td width="13%" align="right">Branch</td>
    <td width="35%">
<?php
		if($_SESSION['AssignedBranch']!='')
	  {	  	
  $ss1="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql1=DB_query($ss1,$db);
	  }
	  else
	  {
		$ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql1=DB_query($ss1,$db);
	  }
	  ?>
	 <select name="sitecode"  id="sitecode"  onchange="getrgpdata(this.value)">
      <option value="000">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql1))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($sitecode==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
      <?php } ?>
    </select>	</td>
    <td width="13%" align="right">Return No.</td>
    <td><div id='hid-Godown-div'><input name="text" type="text" size="20" value="Auto Generated" readonly="readonly"/>	</div>	</td>
</tr>
<tr class="row1">
<td align="right">Supplier</td>
    <td>
	<div id="SUPLIER">
	  <select name="select"  >
        <option value="0">Select</option>
      </select>
	</div>	</td>	
	<?php
$timezone = "Asia/Calcutta";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
$t=date("g:i a", time()); 
?>
    <td align="right">Return Date & Time</td>
    <td><input type="text"size="20" style="width:49%" id="return_date" name="return_date" readonly="readonly" class="datepicker"/>&nbsp;<input type="text"size="20" name="return_time" style="width:49%" value="<?php echo $t; ?>" readonly="readonly"/> 	</td>
</tr>

<tr class="row1">
 <td align="right">RGP No.</td>
    <td>
    	<div id="RGPNO"><select name="select"  >
        <option value="0">Select</option>
      </select>
    	</div>	</td>
  <td align="right">Vehicle No.</td>
    <td id="VehicleNo"><span><span style="margin-bottom:15px;">
      <input name="text" type="text" size="20" readonly="readonly"/>
    </span></span></td>
   
</tr>

<tr class="row1">
    <td align="right">Remove Date & Time</td>
    <td id="RemoveDate"><span style="margin-bottom:15px;">
      <input type="text"size="20" style="width:49%" readonly="readonly" class="datepicker"/>&nbsp;<input type="text"size="20" style="width:49%"  readonly="readonly"/>
    </span></td>
     <td align="right">Form No.</td>
    <td id="FormNo"><span style="margin-bottom:15px;">
      <input name="text" type="text" size="20" readonly="readonly"/>
    </span></td>
    </tr>
	<tr class="row1">
		<td align="right">Store</td>
		<td id="STORECODE"></td>
		<td></td><td></td>
	</tr>
</table> 
<br>
    <div id="itemdata">
      <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
        <tr>
			<th width="4%">S.No.</th>
          	<th width="10%">Part Code</th>
          	<th>Part Name</th>
          	<th width="7%">Unit</th>
		  	<th width="10%">Batch No.</th>
		  	<th width="9%">Stock Qty.</th>
      		<th width="9%">Qty.</th>
		  	<th width="14%">Reason</th>
		   	<th width="9%">Job Rate</th>
		    <th width="9%">Job Value</th>
        </tr>
        <tbody id="dataTable">
          <tr>
		  	<td>&nbsp;</td>
            <td><input type="text" value="" size="20"/>            </td>
            <td><input type="text" size="20"  value=""/></td>
            <td><input type="text" size="5"  value=""/></td>
			<td><input type="text" size="15"  value=""/></td>
            <td><input type="text" size="20"  value=""/></td>
            <td><input type="text" size="20"  value=""/></td>
           	<td><select><option>Select</option></select></td>
		   	<td><input type="text" size="20"  value=""/></td>
            <td><input type="text" size="20"  value=""/></td>
          </tr>
        </tbody>
      </table>
    </div>
  <br>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  

<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="13%" align="right">Removal Remarks</td>
	<td width="20%" id="REMARK"><textarea name="remarks"   id="remark"></textarea></td>
	<td width="13%" align="right">Expected Time</td>
	<td width="20%" id="EXPTEDTIME"><input type="text" id="material_issued"    value="" /></td>
	<td width="13%" align="right">Total Value</td>
	<td id="EXPECTEDVALUE"><input type="text" id="material_issued"    value="" /></td>
</tr>
<tr class="row1">
	<td align="right">Return Remarks</td>
	<td><textarea name="return_remark"   id="remark"></textarea></td>
	<td align="right">Return Time</td>
	<td><input type="text" id="rgp_return_time" name="rgp_return_time"     />  </td>
	<td colspan="2"></td>
</tr>
</table>


<p align="center">
  <input type="submit" name="Submit" value="Save" class="search"  onclick="return validate()"/>
  <input type="reset" name="reset" value="View" class="search" />
  <input type="button" value="Cancel" name="Back" class="search" />
</p>
</form>

</div>
</div>

<script language="javascript" type="text/javascript">


 
 var xmlHttp

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

function getsitename(str)
{
if (str.length==0)
  {
  document.getElementById("txtsite").innerHTML="";
  return;
  }
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)
    {
    document.getElementById("txtsite").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_sitename.php?site="+str,true);
xmlhttp.send();
}
function getsitename22(str)
{
if (str.length==0)
  {
  document.getElementById("txtsite22").innerHTML="";
  return;
  }
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)
    {
    document.getElementById("txtsite22").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_sitename.php?q2="+str,true);
xmlhttp.send();
}
function Get_issuedetails(str)
{
  if (str.length==0)
  {
  document.getElementById("issueid").innerHTML="";
  return;
  }
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)
    {
    document.getElementById("issueid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssueDetails.php?q="+str,true);
xmlhttp.send();
}

function getpartyname(str)
{
	//alert(str);
	var hidparty=document.getElementById("hidden_party").value;
	//alert(hidparty);
	if (str.length==0)
  {
  document.getElementById("pname").innerHTML="";
  return;
  }
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)
    {
    document.getElementById("pname").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssuePartyName.php?name="+str+"&partytype="+hidparty,true);
xmlhttp.send();
}
	

function get_referredby(str)
{
	if (str.length==0)
  {
  document.getElementById("rname").innerHTML="";
  return;
  }
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)
    {
    document.getElementById("rname").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssueEmployeeName.php?q="+str,true);
xmlhttp.send();
}

 var xmlHttp
function requisition_detail(str)
{ 
   //alert(str);
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="reqdetail.php";
	url=url+"?req_number="+str;
	
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=changedetail;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function changedetail() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   var responsestr = xmlHttp.responseText;
	   resstr = responsestr.split("@@##@");
	   document.getElementById("reqdate").value=resstr[0];
	   document.getElementById("txtdetail").innerHTML=resstr[1];
	  
	}
}
function calculateTotalAmount(str)
{
	var str_BRK=str.split('_');
	if(str_BRK[1]==undefined)
	{
		var issue=document.getElementById("issueqty").value;
		var average=document.getElementById("averageamt").value;
		var TOTAL=issue*average;
		document.getElementById("totalamount").value=TOTAL.toFixed(2);
	}
	else
	{
		var issue=document.getElementById("issueqty_"+str_BRK[1]).value;
		var average=document.getElementById("averageamt_"+str_BRK[1]).value;
		var TOTAL=issue*average;
		document.getElementById("totalamount_"+str_BRK[1]).value=TOTAL.toFixed(2);
	}
}
function Get_departmentdetails(str)
{

if (str=="")
  {
  document.getElementById("department").innerHTML="";
  return;
  }
var xmlhttp;
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)
    {
	document.getElementById("department").value=xmlhttp.responseText;
	
    }
  }
  //alert(str);
xmlhttp.open("GET","get_department.php?department="+str,true);
xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

}

function showdept(str)
{
if (str=="")
  {
  document.getElementById("dept").innerHTML="";
  return;
  }
var xmlhttp;
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)
    {
    	
	document.getElementById("dept").innerHTML=xmlhttp.responseText;
	
    }
  }
  
xmlhttp.open("GET","get_empdata.php?department="+str,true);
xmlhttp.send();	
	
	
}
function calTotal1(str)
{	
var k=parseFloat(document.getElementById('issueqty_'+str).value);
var j=parseFloat(document.getElementById('Stockbalance_'+str).value);
if(j<k)
{
alert("Issue Qty Not Grater then Stock Balance");
document.getElementById('issueqty_'+str).focus();
}	
}
function calTotal(obj)
{
	
	var k=parseFloat(document.getElementById('issueqty_'+obj).value);
var j=parseFloat(document.getElementById('Stockbalance_'+obj).value);
if(j<k)
{
alert("Issue Qty Not Grater then Stock Balance");
document.getElementById('issueqty_'+obj).focus();
}
	
}
function Get_contractor(str)
{	
	//alert(str);
	if(str!='')
	{
		var element=document.getElementById("received_by");
		element.style.display = "none";
	}
	else
	{
		var element=document.getElementById("received_by");
		element.style.display = "";
	}
	
}
function Get_Employee(str)
{
		
	if(str!=0)
	{
		var element=document.getElementById("issueto");
		element.style.display = "none";
	}
	else
	{
		var element=document.getElementById("issueto");
		element.style.display = "";
	}
	if (str=="")
  {
  document.getElementById("dept").innerHTML="";
  return;
  }
var xmlhttp;
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)
    {
    	
	document.getElementById("dept").innerHTML=xmlhttp.responseText;
	
    }
  }
  
xmlhttp.open("GET","get_empdata.php?department="+str,true);
xmlhttp.send();	
	
}
function chkbalance(str)
{
	//alert(str);
	var k=parseFloat(document.getElementById('Stockbalance_'+str).value);
	
	var j=parseFloat(document.getElementById('issueqty_'+str).value);	
	//alert(document.getElementById('Stockbalance_0').value);
	if(isNaN(document.getElementById('issueqty_'+str).value))
	{
	alert("String Not Allowed");
	document.getElementById('issueqty_'+str).value='';
	return false;	
	}
	
	if(j > k)
	{
	alert("Issue Qty Not Grater then Stock Balance");
	document.getElementById('issueqty_'+str).value='';
	document.getElementById('issueqty_'+str).focus();
	}
	
	
}

function validate()
{  
   
   var rowCount = 0;
  	if(document.getElementById("sitecode").value=='0')
	{
	alert("Must Select Branch Name");
	return false;	
	}
	if(document.getElementById("issueto").value=='0') 
	{ 
	var count=0; 
	}
	if(document.getElementById("received_by").value=='0')
	{
	var count=0;
	}
   if(document.getElementById("issueto").value!='0' || document.getElementById("received_by").value!='0')
   {
   var count=1;
   }
   if(count==0)
   {
   alert("Must Select Contractor Name /Employee Name");
    return false;
   }	
  if(rowCount=='0') 
  {
  
   var issueqty=document.getElementById("issueqty").value;
   if(issueqty=='')
   { 
  alert("Must Fill Issue Qty"); 	return false;
   	}  
  }   
	 return true; 
	 }

function showsitename158(str)
{

var xmlhttp;
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.split("__");	
	
	document.getElementById("hid-Godown-div").innerHTML=data[0];
    document.getElementById("empdta").innerHTML=data[1];
	
    }
  }
  xmlhttp.open("GET","GoDownIssueSlip.php?site="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

	
}

function checkdata()
{
if(document.getElementById("sitecode").value=='0')
{
alert("Must Select Branch Name");
return false;	
}
window.open("issu_searchpopupnew.php?1=1<?php echo $rurl;?>&site=<?php echo $_SESSION['site']?>&store=<?php echo $_SESSION['godwan'];?>","profiles_popup_window","height=425,width=600,toolbar=no,menubar=no,dependent=yes,resizable=yes");
			
return true;	
}


function calculateAmt(i)
{
var IssueQty=document.getElementById("issueqty_"+i).value;
var AverageRate=document.getElementById("averagerate_"+i).value;	
var Amount1 =parseFloat(IssueQty)*parseFloat(AverageRate);
document.getElementById("amount1_"+i).value =Amount1.toFixed(2);
}


</script>

<script language="javascript" type="text/javascript">
function Remaningqtn(str)
{

var StockBalance=document.getElementById("Stockblance_"+i).value;	
var Issuequantity=document.getElementById("issuebalanc_"+i).value;	
var RemaningBalance =parseFloat(StockBalance)-parseFloat(Issuequantity;)
document.getElementById("remaningbalance_"+i).value =RemaningBalance;
}

var countries=new ddtabcontent("countrytabs")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init();
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}


 var xmlHttp
function changestorename(str)
{  
 // alert('hi');
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="storename.php";
	url=url+"?store_code="+str;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function NumberChanged1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   document.getElementById("txtid").innerHTML=xmlHttp.responseText;
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
</script>
<script language="javascript" type="text/javascript">

function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}

function opendata(str,id)
{
 var store=document.getElementById("store").value;
  var sitecode=document.getElementById("sitecode").value;
  var date=document.getElementById("issuedate").value;

 if (str.length == 0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	
	
	if(sitecode=='0')
	{
	alert("Must Select Site");
	document.getElementById("sitecode").focus();
	return;
	}
	else if(date=='')
	{
	alert("Must Select Date");
	document.getElementById("issuedate").focus();
	return;
	}

var xmlhttp;
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)
    {
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  var store=document.getElementById("store").value;
  var sitecode=document.getElementById("sitecode").value;
  var date=document.getElementById("issuedate").value;

  xmlhttp.open("GET","showpopup.php?site="+str+"&data="+id+"&store="+store+"&site1="+sitecode+"&date="+date,true);
	xmlhttp.send();


	
	
}
function getItemsList(id,code,shade,netrate,mrprate,ctr)
{

   
  
   
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	
	} else  {var counter=edit_cnt;}
	  
	
	if(document.getElementById('itemdataid').value=='')
	{
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	document.getElementById('Stockbalance').value = mrprate;
	}
	else
	{
	for(i=counter; i<itemcount; i++)
	{
	if(document.getElementById('itemcode_'+i).value=='')
	{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	document.getElementById('Stockbalance_'+i).value = mrprate;
	break;
	}
	else
	{
	continue;
	}
	}
	}
	
	document.getElementById("lightbox").style.display='none';
		
}

function getItemsList1(id,code,shade,netrate,mrprate,rate,ctr)
{ 
    var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	if(ctr1[1]==undefined)
	{
	//if(document.getElementById('itemdataid').value=='')
	//{
	
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	document.getElementById('Stockbalance').value = mrprate;
	document.getElementById("issuerate").value=rate;
	//}
	}
	else
	{
	//if(document.getElementById('itemdataid_'+i).value=='')
	//{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	document.getElementById('Stockbalance_'+i).value = mrprate;
	document.getElementById("issuerate_"+i).value=rate;
	//}	
	}	
	document.getElementById("lightbox").style.display='none';
	var data= addRow('dataTable')
	
}
</script>


    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.bpopup-0.7.0.min.js"></script>
	<script src="js/scripting.min.js"></script>
<script>
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}
function calamt(id,str)
{


var id1=id.split("_");
var i=id1[1];

if(id1[1]==undefined)
{
if(parseFloat(document.getElementById("Stockbalance").value)<parseFloat(document.getElementById("issueqty").value))
{
alert("Issue qty should not be greater than stock qty");
document.getElementById("issueqty").focus();
document.getElementById("issueqty").value='';
document.getElementById("totalamt").value='';
return; 
}
if(document.getElementById("issuerate").value!='')
var issuerate=parseFloat(document.getElementById("issuerate").value);
else
var issuerate=0;
var total=parseFloat(str)*issuerate;
document.getElementById("totalamt").value=total.toFixed(2);
}
else
{
if(parseFloat(document.getElementById("Stockbalance_"+i).value)<parseFloat(document.getElementById("issueqty_"+i).value))
{
alert("Issue qty should not be greater than stock qty");
document.getElementById("issueqty_"+i).focus();
document.getElementById("issueqty_"+i).value='';
document.getElementById("totalamt_"+i).value='';
return; 
}
if(document.getElementById("issuerate_"+i).value!='')
var issuerate=parseFloat(document.getElementById("issuerate_"+i).value);
else
var issuerate=0;
var total=parseFloat(str)*issuerate;
document.getElementById("totalamt_"+i).value=total.toFixed(2);
}
}


function addRow(tableID) 
{
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			  newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
					
					
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}

</script>