<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>
<link rel="stylesheet" href="css/new_mxerp.css">
<?php


if(isset($_POST['Submit']))
{

 

					      $prefixcode="ISS";
					      $year=$_SESSION['financialYearStart'];
					      $year_after=$_SESSION['financialYearEnd'];
					      $site_code=substr($_REQUEST['sitecode'],0,3);
						  $sql="select MAX(issue_slipno) from addissue where site = '".$_REQUEST['sitecode']."'";
						  $result =DB_query($sql,$db);
						  $myrow=DB_fetch_array($result);
						  $numrows = DB_num_rows($result);
						  $sqldata=DB_query("select locationname from locations where loccode='".$_REQUEST['sitecode']."'",$db);
						  $sqltext=DB_fetch_array($sqldata);
						  $sitename=$sqltext['locationname'];
						  $siteCode = $sitename;
						  $strdata=substr($myrow['MAX(issue_slipno)'],13,6);
						 
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
					 if($siteCode!='')
							if($numrows>0)
							{ 							   
							    
								$maxval = $strdata;
							}
						else
							{
								$maxval=0;
							}
			{
				$strChar = $site_code."/".$prefixcode."/".$year.$year_after."/";
			}
	  }
	  else
	  {
	  	$strChar = $site_code."/".$prefixcode."/".$year.$year_after."/";
	  }
	  
	 $strFinal = $maxval+1;
	   $strBothFinal = $strChar.str_pad($strFinal,6,"0",STR_PAD_LEFT);
	 
	                     $sql = "INSERT INTO addissue set
								id='',  
								site='".$_REQUEST['sitecode']."',  
								issue_slipno='".$strBothFinal."',  
								issuedate='".FormatDateForSQL($_REQUEST['issuedate'])."',  					  
								mst_storeid='".$_REQUEST['store']."',  
								store='".$s->GetFieldValue('storetype',"id='".$_REQUEST['store']."'",'StoreCode')."',  
								issueto='".$_REQUEST['issueto']."',  
								received_by='".$_REQUEST['received_by']."',
								department='".$_REQUEST['dept1']."',
								issue_reg_no='".$_REQUEST['issue_req_no']."',
								work_order_no='".$_REQUEST['work_order_no']."',
								job_card_no='".$_REQUEST['job_card_no']."',
								job_card_date='".FormatDateForSQL($_REQUEST['job_card_date'])."',
								finished_item='".$_REQUEST['finished_item']."',
								cost_center='".$_REQUEST['cost_center']."',
								material_received_by='".$_REQUEST['material_received_by']."',
								material_issue_by='".$_REQUEST['material_issue_by']."',
								remarks='".$_REQUEST['remarks']."',
								createdby='".$_SESSION['UserID']."', 
								companyID='".$_SESSION['ACGCompanyId']."', 
								createddate='".date('d/m/Y')."' ";	
													
				$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
				$insertResult = DB_query($sql,$db,$ErrMsg);
			    $Lastreq_id=DB_Last_Insert_ID($db,'addissue',$ErrMsg);
							 
				if($Lastreq_id!='')
				{				
					$totalqty=0;
					 for($i=0;$i<count($_REQUEST['itemdataid']);$i++)
					 {	
					       	
							if($_REQUEST['issueqty'][$i]!='')
							{	
								   $sql2 ="INSERT INTO issueqty set issue_id='".$Lastreq_id."',
										 mst_itemid='".$_REQUEST['itemdataid'][$i]."',
										 current_stock='".$_REQUEST['current_stock'][$i]."', 							 
										 issuerate='".$_REQUEST['issuerate'][$i]."',    
										 issueqty='".$_REQUEST['issueqty'][$i]."', 
										 primary_issueqty='".$_REQUEST['secondaryqty'][$i]."', 
										 req_qty='".$_REQUEST['req_qty'][$i]."'
										,totalamt='".$_REQUEST['totalamt'][$i]."'";	
																					
								 $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
								 
								 $insertResult2 = DB_query($sql2,$db,$ErrMsg);
												
						
						
						
						
					           
								    }
								  
								
								
				    }
				 
				
					
					
				
			
				 
			}
				
//$updateQty=DB_query("Update addissue set totalqty='".$totalqty."' where id='".$Lastreq_id."'",$db);
					
if($insertResult2 == true)
       {
                prnMsg( _('Record Inserted Successfully'),'success');
                echo "<script>location.href='index.php?route=Inventory/transation/Issue_slip_index&modid=".$_REQUEST['modid'].                      "&frmid=".$_REQUEST['frmid']."'</script>";
       }
 } 
?>

	
<h2 align="center"><strong>Material Issue</strong></h2>
<form name="form1" action="" method="post" >


<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
    <th><strong>Branch</strong></th>
    <td style="width:250px;">
	<?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
  $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }
	?>
	<select name="sitecode" style="width:100%" id="sitecode"  onchange="showsitename158(this.value)">
	 <option value="0">Select</option>
      <?php 
			while ($myrow=DB_fetch_array($site_sql))
				{
				  $p='';
				 if($myrow['loccode']==$site)
				 $p='selected';
				
				?>
      <option value="<?php echo $myrow['loccode']; ?>"  <?php  echo $p;?>><?php echo $myrow['locationname'];?></option>
      <?  }	?>
    </select></td>
    <th>Godown</th>
    <td style="width: 250px;"><div id='hid-Godown-div'>
    	<?php
		      $sql_store12 ="select  id, StoreCode, StoreName from storetype  ";
		 $resultStkLocs12 = DB_query($sql_store12,$db);
		?>
    	<select name="store" style="width:100%" id="store"  >
	<option value="0">Select</option>
      
      <option value="0" >Select</option>
    </select></div>
	</td>
</tr>

<tr> <th><strong>Issue No.</strong></th>
    <td>
      <input name="issue_slipno" type="text" id="issue_slipno" size="20" style="width:100%" readonly="readonly" value="Auto Generate" />
       	 
	</td>
    <th>Issue Date</th>
    <td><input name="issuedate" type="text" id="issuedate"  style="width:100%"  class="datepicker" />
	</td>
</tr>

<tr>
    <th><strong> Emp Name</strong></th>
    <td style="width:250px;">
	<div id="empdta">
	<select name="received_by" style="width:100%" id="received_by" onchange="Get_Employee(this.value)" >
	<option value="0">Select</option>
	<?php 
	$floor_sql=DB_query("Select * from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by emp_name ASC   ",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{
			     $p='';
				 if($floor_row['id']==$received_by)
				 $p='selected';	
	
	?>
	<option value="<?php echo $floor_row['id'];?>"<?php echo $received_by==$floor_row['id']?'selected':''; ?>><?php echo $floor_row['emp_name'];?></option>
	<?php 	
	}
	?>
    </select>
	</div>	
	</td>
    <th>Dept.</th>
    <td style="width:250px;">
    	<div id="dept"><input type="text" name="dept1" style="width:100%" id="dept1" readonly>
		
    	</div>
	</td>
</tr>

<tr>
       <th><strong>Work Order No</strong></th>
        <td style="width:250px;"><div id="workod">
		<select name="work_order_no" id="work_order_no" onchange="Get_oderdata(this.value)" style="width:100%">
		<option value="0">Select</option>
		<?php
		$floor_sql1=DB_query("Select * from salesorder order by orderNo ASC",$db);
			while($floor_row1=DB_fetch_array($floor_sql1))
			{?>
	
     <option value="<?php echo $floor_row1['id'];?>"<?php echo $work_order_no==$floor_row1['id']?'selected':''; ?>><?php echo $floor_row1['orderNo'];?></option>
	<?php 	
	}
	?>
		
		</select>	</div>
	   </td>


    
    <th>Issue Req No.</th>
    <td> <input name="issue_req_no" type="text" id="issue_req_no"  style="width:100%"  value="" />
	</td>
</tr>

<tr>
    <th><strong>Finished Item Details</strong></th>
    <td style="width:250px;">
	<div id="oderitem">
	</div>
	
    <th>Cost Centre</th>
    <td> <input name="cost_center" type="text" id="cost_center"  style="width:100%"  value="" />
	</td>
</tr>
 
 <tr>
    <th><strong>Job Card No</strong></th>
    <td style="width:250px;">
	<div id="jobcarddata">
	</div>
	
    <th><strong>Job Card Date</strong></th>
    <td><div id="jobcarddate1"></div> 
	</td>
</tr>
 
 
</table> 
	
<p align="left" style="padding-left:10px;">
 <!-- <input type="button" name="Add" value="Add"  onclick="addRow('dataTable')"/>
  <input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="checkdata()" class="search" />-->
    <input type="button" name="Add" value="Add" class="search" />                  
  </p>
  <div style="overflow:auto; width:950px; margin-left:auto; margin-right:auto; height:auto">
    <div id="itemdata">
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
          <th><strong>S. No.</strong></th>
          <th></th>
          <th><strong>Item Code</strong></th>
          <th><strong>Item Name</strong></th>
          <th><strong>Primary UOM</strong></th>
		   <th><strong>Secondary UOM</strong></th>
		  <th><strong>Current Stock</strong></th>
		   <th><strong>Conv Factor</strong></th>
          <th><strong>Req Qty</strong></th>
           <th><strong>Primary Issued Qty</strong></th>
		   <th><strong>Secondary Issued Qty</strong></th>
		   <th><strong>Issue Rate</strong></th>
		    <th><strong>Total Amt</strong></th>
          
        </tr>
        <tbody id="dataTable">
          <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" id="delitem" /></td>
            <td><input  type="hidden"   readonly=""  id="itemdataid"  name="itemdataid[]" /></td>
            <td><input type="text" value="" tabindex=""   id="itemcode" name="itemcode[]"size="20"
			 onkeyup="opendata(this.value,this.id)"/>
            </td>
            <td><input type="text" name="desc[]"  id="descriptions" size="25"  value=""/></td>
            <td><input type="text" name="uom[]" id="uom" value="" readonly /> </td>
			 <td><input type="text" name="secondary[]" id="secondary" value="" readonly /> </td
><td><input type="text" name="current_stock[]" id="Stockbalance" size="10" value="<?php  echo $stockbalance;	?>" readonly/></td>
		 <td><input  type="text" name="confac[]"  id="confac" size="30"  value="" readonly="readonly"/></td>	
       
	    <td><input  type="text" name="req_qty[]"  id="receive" size="30"  value=""/></td>     
	 <td><input  type="text" name="secondaryqty[]"  id="secondaryqty" size="30"   value=""  onkeyup="calamt1(this.id,this.value)"   /></td>	
	 <td><input  type="text" name="issueqty[]"  id="issueqty" size="30"   value=""   /></td>
		

		  <td><input  type="text" name="issuerate[]"  id="issuerate" size="30"  value="" readonly /></td>
            <td><input  type="text" name="totalamt[]"  id="totalamt" size="30"   value="" readonly  /></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" />

<div style="width:810px; overflow:auto;">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Remarks </strong></th>
<td colspan="3"><textarea name="remarks"  style="width:100%" id="remark"></textarea></td>
</tr>

<tr>
<th><strong>Material Recd by</strong></th>
<td style="width:150px;"><input name="material_received_by" type="text" id="material_rec"  style="width:100%"  value="" /></td>
<th><strong>Material Issued by</strong></th>
<td style="width:150px;"><input name="material_issue_by" type="text" id="material_issued"  style="width:100%"  value="" /></td>
</tr>
</table>
</div>


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

<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=="")
  {
  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 Get_oderdata(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)
    {
    var data=xmlhttp.responseText.split("__");	
	document.getElementById("oderitem").innerHTML=data[0];
	document.getElementById("jobcarddata").innerHTML=data[1];
    }
  }
  
xmlhttp.open("GET","get_orderdata.php?salid="+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];
	document.getElementById("workod").innerHTML=data[2];
	
    }
  }
  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 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;	
			}
		}
	}
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,secondary,confac,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('secondary').value = secondary;
	document.getElementById('confac').value = confac;
	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('secondary_'+i).value = secondary;
	document.getElementById('confac_'+i).value = confac;
	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_old(id,str)
{


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

if(id1[1]==undefined)
{
if(document.getElementById("confac").value!='')
var confac=parseFloat(document.getElementById("confac").value);
else
var confac=0;
var total2=parseFloat(str)*confac;
document.getElementById("secondaryqty").value=total2.toFixed(2);
if(parseFloat(document.getElementById("Stockbalance").value)<parseFloat(document.getElementById("secondaryqty").value))
{
alert("Issue qty should not be greater than stock qty");
document.getElementById("issueqty").focus();
document.getElementById("issueqty").value='';
document.getElementById("totalamt").value='';
document.getElementById("secondaryqty").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(document.getElementById("confac_"+i).value!='')
var confac=parseFloat(document.getElementById("confac_"+i).value);
else
var confac=0;
var total2=parseFloat(str)*confac;
document.getElementById("secondaryqty_"+i).value=total2.toFixed(2);
if(parseFloat(document.getElementById("Stockbalance_"+i).value)<parseFloat(document.getElementById("secondaryqty_"+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 calamt1(id,str)
{
var id1=id.split("_");
var i=id1[1];
if(id1[1]==undefined)
{
if(document.getElementById("confac").value!='')
var confac=parseFloat(document.getElementById("confac").value);
else
var confac=0;
var total2=parseFloat(str)/confac;
document.getElementById("issueqty").value=total2.toFixed(2);
if(parseFloat(document.getElementById("Stockbalance").value)<parseFloat(document.getElementById("secondaryqty").value))
{
alert("Issue qty should not be greater than stock qty");
document.getElementById("secondaryqty").focus();
document.getElementById("secondaryqty").value='';
document.getElementById("totalamt").value='';
document.getElementById("issueqty").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(document.getElementById("confac_"+i).value!='')
var confac=parseFloat(document.getElementById("confac_"+i).value);
else
var confac=0;
var total2=parseFloat(str)/confac;
document.getElementById("issueqty_"+i).value=total2.toFixed(2);
if(parseFloat(document.getElementById("Stockbalance_"+i).value)<parseFloat(document.getElementById("secondaryqty_"+i).value))
{
alert("Issue qty should not be greater than stock qty");
document.getElementById("secondaryqty_"+i).focus();
document.getElementById("secondaryqty_"+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 Get_oderdata1(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("jobcarddate1").innerHTML=xmlhttp.responseText;
	
    }
  }
  
xmlhttp.open("GET","get_joborderdata.php?salid="+str,true);
xmlhttp.send();	
	
}

</script>