<?php
session_name('CAKEPHP'); session_start();
include('includes/stockcalculation.php');
 
?>
<style type="text/css">
.body_lightbox {
	width:100%;
	background-color:#e7e7e7;
	position:absolute;
	left:894px;
	top:394px;
	padding-left:5px;
	padding-right:5px;
	border:#666666 solid 3px;
	visibility: hidden;
}
</style>

<?php 
  $sql=DB_query("select * from addissue where id='".$_REQUEST['id']."'",$db);
  $row=DB_fetch_array($sql);
  extract($row);
    $function_filter[0]=$site;
	$function_filter[1]=$mst_storeid;
	$function_filter[2]=date('Y-m-d'); 
?>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form name="form1" action="" method="post" >
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td width="13%" align="right">Branch</td>
    <td width="20%">
	<?php	
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode='".$site."'";
		$site_sql=DB_query($ss,$db);
		?>
	<select name="sitecode" id="sitecode" >	
      <?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>
    <td width="13%" align="right">From Store</td>
    <td width="20%"><?php
		$sql_store12 ="select  id, StoreCode, StoreName from storetype where Store_Site='".$site."' and store_type='M' and id='".$mst_storeid."'  ";
		 $resultStkLocs12 = DB_query($sql_store12,$db);		?>
    	<select name="store" id="store"  >     
       <option value="0" >Select</option>
       <?php
         while($r=DB_fetch_array($resultStkLocs12))
         {
       	$t='';
       	if($r['id']==$mst_storeid)
       	$t="selected";
       ?>
       <option value="<?php echo $r['id']; ?>" <?php  echo $t; ?>><?php echo $r['StoreName']; ?></option>
       <?php } ?>
    </select>
	</td>
    <td width="13%" align="right">Issue No.</td>
    <td><input name="issue_slipno" type="text" id="issue_slipno" size="20" readonly="readonly" value="<?php echo $issue_slipno; ?>" /></td>
</tr>

<tr class="row1">	 
    <td align="right">Issue Date</td>
    <td><input name="issuedate" type="text" id="issuedate" value="<?php echo ConvertSQLDate($issuedate); ?>" class="datepicker" /></td>
   <!-- <td>Emp Name</strong></td>  -->
   <td align="right">To Store</td>
   <!-- <td>
	<div id="empdta">
	<select name="received_by" 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>  -->

	<td><?php
		$sql_store123 ="select  id, StoreCode, StoreName from storetype where Store_Site='".$site."' and id='".$to_store."'  ";
		 $resultStkLocs123 = DB_query($sql_store123,$db);		?>
    	<select name="store" id="store"  >     
       <!-- <option value="0" >Select</option> -->
       <?php
         while($r123=DB_fetch_array($resultStkLocs123))
         {
       	$t='';
       	if($r['id']==$mst_storeid)
       	$t="selected";
       ?>
       <option value="<?php echo $r123['id']; ?>" <?php  echo $t; ?>><?php echo $r123['StoreName']; ?></option>
       <?php } ?>
    </select></td>
    <td colspan="2">&nbsp;</td>
   <!--  <td><strong>Dept.</strong></td>
    <td>
    	<div id="dept">
<input id="dept12" type="text" readonly="" value="<?php echo $s->getField('deptmaster','id',$department,'deptname'); ?>" name="dept12">
<input id="dept1" type="hidden" readonly="" value="<?php echo $department; ?>" style="width:100%" name="dept1">
    	</div>
	</td>  -->
</tr>
</table>
<br>
  <div style="overflow:auto; width:100%; margin-left:auto; margin-right:auto; height:auto">
    <div id="itemdata">
      <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
        <tr>
          <th width="3%">S. No.</th>
          <th width="1"></th>
          <th width="10%">Item Code</th>
          <th>Item Name</th>
          <th width="6%">UOM</th>
          <th colspan="2" style="text-align:center;">Specification</th>		 
		  <th width="10%">Current Stock</th>
		  <th style='text-align:center;' colspan='3'>Qty. to be issued</th>		 
		  <th width="10%">Issue Rate</th>
		  <th width="8%">Total Amt.</th>
          <th width="1"></th>
        </tr>
        <tbody id="dataTable">
        	<?php
        	$i=1;
             $sql_details=DB_query("select * from issueqty where issue_id='".$_REQUEST['id']."'",$db);
             while($r_dtl=DB_fetch_array($sql_details))
             {
            $itemname=$s->getField('item_master','id',$r_dtl['mst_itemid'],'item_name');
            $itemcode=$s->getField('item_master','id',$r_dtl['mst_itemid'],'StockId');
            $confac=$s->getField('item_master','id',$r_dtl['mst_itemid'],'conv_factor');

            $op=openingBalance($function_filter,$r_dtl['mst_itemid']);
			$in_1=receivedMRN($function_filter,$r_dtl['mst_itemid']);
			$out_1=issueSlip($function_filter,$r_dtl['mst_itemid']);
			$out_2=issueSiteToSite($function_filter,$r_dtl['mst_itemid']);		
			$in_2=receivedSiteToSite($function_filter,$r_dtl['mst_itemid']);
			$out_3=issueMatarialReturn($function_filter,$r_dtl['mst_itemid']);
			$in_3=receivedReturn($function_filter,$r_dtl['mst_itemid']);	
			$out_4=Rgpchallan($function_filter,$r_dtl['mst_itemid']);
			$out_5=Nrgp($function_filter,$r_dtl['mst_itemid']);
			$in_4=Rgpreturn($function_filter,$r_dtl['mst_itemid']);	 
			$in_5=FinishedMR($function_filter,$r_dtl['mst_itemid']);
			$in_6=MaterialConReceived($function_filter,$r_dtl['mst_itemid']);
			$out_6=MaterialConIssue($function_filter,$r_dtl['mst_itemid']);
			$in_7=PhysicalStockPlus($function_filter,$r_dtl['mst_itemid']);
			$out_7=PhysicalStockMinus($function_filter,$r_dtl['mst_itemid']);
			$out_8=dispatchIssue($function_filter,$r_dtl['mst_itemid']);
			$out_9=jobWorkChallan57Issue($function_filter,$r_dtl['mst_itemid']);
			$in_8=jobWorkChallan57Received($function_filter,$r_dtl['mst_itemid']);
			 $invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8);
			$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9);
			$tot=$invalue-$outvalue;
		    $stockbalance=$tot;	
        	 ?>

          <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="<?php echo $r_dtl['id'];?>" id="delitem" /></td>
            <td><input type="hidden" readonly="" id="itemid_<?php echo $i; ?>"  name="itemdataid[]" value="<?php echo $r_dtl['mst_itemid'];?>" /></td>
            <td><input type="text" value="<?php echo $itemcode; ?>" tabindex="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" /></td>
            <td><input type="text" name="desc[]"  id="itemname_<?php echo $i; ?>" value="<?php echo $itemname; ?>"/></td>
            <td><select  name="uom[]" id="uom_<?php echo $i; ?>">  
            <option value="0">Select</option>      	
        	<?php $r_unit=DB_query("select * from unitsofmeasure where unitid='".$r_dtl['mst_unitid']."'",$db);
                   while($runit=DB_fetch_array($r_unit))
                   {
                   	$u='';
                   	if($runit['unitid']==$r_dtl['mst_unitid'])
                   		$u="selected";
        	 ?>
        	 <option value="<?php echo $runit['unitid']; ?>" <?php echo $u; ?>><?php echo $runit['unitname']; ?></option>
        	 <?php } ?>
            </select></td>
           <td width="8%"><select name="sizesp[]" id="sizesp_<?php echo $i; ?>" onchange="showconvac(this.value,this.id);">
   	<option value="0">select</option>
   	<?php
     $resultSize=DB_query("select * from size_master",$db);
     while($rowSize=DB_fetch_array($resultSize))
     {
     $size1='';
     if($rowSize['id']==$r_dtl['size_id'])
     $size1="selected"; 
     ?>
    <option value="<?php echo $rowSize['id']; ?>" <?php echo $size1; ?>><?php echo $rowSize['size']; ?></option>
     <?php }
   	 ?>
   </select></td>
   <td width="8%"><select name="gradesp[]" id="gradesp_<?php echo $i; ?>">
   	<option value="0">select</option>
   	<?php
      $resultGrade=DB_query("select * from product_grade",$db);
      while($rowGrade=DB_fetch_array($resultGrade))
      { 
	     $grade1='';
	     if($rowGrade['id']==$r_dtl['grade_id'])
	     $grade1="selected"; 
      	?>
     <option value="<?php echo $rowGrade['id']; ?>"<?php echo $grade1; ?>><?php echo $rowGrade['grade']; ?></option>
       <?php }
   	 ?>   
   </select></td>			
	<td><input type="text" name="current_stock[]" id="Stockbalance_<?php echo $i; ?>" value="<?php  echo $stockbalance+$r_dtl['issueqty'];	?>" readonly/></td>
	<td width="8%"><input type="text" name="issueqty[]" id="issueqty_<?php echo $i; ?>" value="<?php echo $r_dtl['issueqty']; ?>" onkeyup="calamtNew(this.id,this.value)" onkeypress="return isNumberKey(event)" /></td>
	<td width="1"><input type="hidden" name="confac[]" id="confac_<?php echo $i; ?>" value="<?php echo $r_dtl['confac']; ?>" /></td>
	<td width="8%"><input type="text" name="secondaryqty[]" id="secondary_<?php echo $i; ?>" value="<?php echo $r_dtl['stock_qty2']; ?>"/></td>
    <td><input type="text" name="issuerate[]"  id="issuerate_<?php echo $i; ?>" value="<?php echo $r_dtl['issuerate']; ?>" readonly /></td>
    <td><input  type="text" name="totalamt[]"  id="totalamt_<?php echo $i; ?>" value="<?php echo $r_dtl['issueqty']; ?>" readonly /></td>
    <td><input type='hidden' id="confactor_<?php echo $i; ?>" value='<?php echo $confac; ?>' /></td>
  </tr>
          <?php $i++; } ?>
        </tbody>
      </table>
    </div>
  </div>  

<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>" />
<input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
  <br>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td align="right">Remarks</td>
<td colspan="5"><textarea name="remarks" id="remark"><?php echo $remarks; ?></textarea></td>
</tr>
<tr class="row1">
<td width="13%" align="right">Material Recd by</td>
<td width="20%"><input name="material_received_by" type="text" id="material_rec" value="<?php echo $material_received_by ?>" /></td>
<td width="13%" align="right">Material Issued by-</td>
<td><?php echo $s->GetFieldValue('www_users','id="'.$material_issue_by.'"','realname');?><input name="material_issue_by" type="hidden" id="material_issued" value="<?php echo $_SESSION['UserID'];?>" readonly="true" /></td>
<td colspan="2"></td>
</tr>
</table>
</form>
</div>
</div>
<script language="javascript" type="text/javascript">
function showconvac(str,id)
{
	
var brk=id.split('_');

if(str=='0')
{

	if(brk[1]==undefined)
	{
	var conf=document.getElementById('confactor').value;
	document.getElementById("confac").value=conf;
	 var id1="issueqty";
	var hrdvalue=document.getElementById(id1).value;
	calamtNew(id1,hrdvalue);
	}
	else
	{
	var conf=document.getElementById('confactor_'+brk[1]).value;

	document.getElementById("confac_"+brk[1]).value=conf;
	 var id1="issueqty_"+brk[1];
	var hrdvalue=document.getElementById(id1).value;
	calamtNew(id1,hrdvalue);
	}

   
}
else
{
var brk=id.split('_');

 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)
	{
	if(brk[1]==undefined)
	{	
	document.getElementById("confac").value=xmlhttp.responseText;
	var id1="issueqty";
	var hrdvalue=document.getElementById(id1).value;
	calamtNew(id1,hrdvalue);
    }
	else
	{
	document.getElementById("confac_"+brk[1]).value=xmlhttp.responseText;
	var id1="issueqty_"+brk[1];
	var hrdvalue=document.getElementById(id1).value;
	calamtNew(id1,hrdvalue);
     }
	//document.getElementById("empdta").innerHTML=data[1];
	//var id1="stock_qty_"+brk[1];
	//var hrdvalue=document.getElementById(id1).value;
	//calcValue1(hrdvalue,id1);
	
	}
	}

	if(brk[1]==undefined)
	{
	var str2=document.getElementById("itemid").value;
	}
	else
	{
	var str2=document.getElementById("itemid_"+brk[1]).value;
	}
	xmlhttp.open("GET","convactor.php?site="+str+"&itemid="+str2,true);
	xmlhttp.send();

}




}
function calamtNew(id,val)
{
	var id1=id.split("_");
	var i=id1[1];
	if(id1[1]==undefined)
	{
		var stockBal = document.getElementById("Stockbalance").value;
		var isuRate = document.getElementById("issuerate").value;
		var confac=document.getElementById("confac").value;
		if(parseInt(val)>parseInt(stockBal))
		{
			alert("Issued Quantity Cannot Be Greater Than Stock Balance");
			document.getElementById("issueqty").value='';
			document.getElementById("totalamt").value='';
			document.getElementById("issueqty").focus();
			return false;
		} 
		else 
		{		
			if(isuRate==''){isuRate=0}
			var totamt = parseFloat(isuRate)*val;
			document.getElementById("totalamt").value=totamt.toFixed(2);
			var secondaryqty=parseFloat(val)*parseFloat(confac);
			document.getElementById("secondary").value=secondaryqty.toFixed(2);
		}
	}
	else
	{
		var stockBal = document.getElementById("Stockbalance_"+i).value;
		var isuRate = document.getElementById("issuerate_"+i).value;
		var confac=document.getElementById("confac_"+i).value;
		if(parseInt(val)>parseInt(stockBal))
		{
			alert("Issued Quantity Cannot Be Greater Than Stock Balance");
			document.getElementById("issueqty_"+i).value='';
			document.getElementById("totalamt_"+i).value='';
			document.getElementById("issueqty_"+i).focus();
			return false;
		} 
		else 
		{	
		if(isuRate==''){isuRate=0}
		var totamt = parseFloat(isuRate)*val;
		document.getElementById("totalamt_"+i).value=totamt.toFixed(2);
		var secondaryqty=parseFloat(val)*parseFloat(confac);
			document.getElementById("secondary_"+i).value=secondaryqty.toFixed(2);
		}
	}
}
function open_items()
{
   if($('#sitecode').val()==0)
   {
   	alert('Please select branch.');
   	return false;
   }
    if($('#store').val()==0 || $('#store').val()=='')
    {
    	alert('Please select store.');
    	return false;
    }
    
    var site=$('#sitecode').val();
    var store=$('#store').val();

 window.open("crmquotes2_exotic_issue.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&site="+site+"&stote="+store,"item_popup_window","height=500,width=500,left=1111px,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
 /*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 Get_jobcard(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("jobcarddate1").innerHTML=data[0];
	document.getElementById("issue_req").innerHTML=data[1];
    }
  }
  
xmlhttp.open("GET","get_jobcard.php?jobid="+str,true);
xmlhttp.send();	
	
}

function Get_jobcard1(str)
{
var site=document.getElementById("sitecode").value;
var store=document.getElementById("store").value;
if (str=="0")
  {
  document.getElementById("para").style.display="block";
  }else{
  document.getElementById("para").style.display="hidden";
  }
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)
    {
	//alert(xmlhttp.responseText);
    var data=xmlhttp.responseText.split("__");	
	document.getElementById("issue_req1").innerHTML=data[0];
	document.getElementById("workod").innerHTML=data[1];
	document.getElementById("orderitem").innerHTML=data[2];
	document.getElementById("cost_center").value=data[3];
	document.getElementById("dataTable").innerHTML=data[4];
	document.getElementById("indentid").innerHTML=data[5];
    }
  }
  
xmlhttp.open("GET","get_jobcard1.php?jobid="+str+"&site="+site+"&store="+store,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");
	document.getElementById("sitecode").focus();
	return false;	
	}
	if(document.getElementById("received_by").value=='0')
	{
	alert("Must Select Employee Name");
	document.getElementById("received_by").focus();
	return false;	
	}
	if(document.getElementById("itemcode").value=='')
	{
	alert("Must Enter Item Deatils");
	document.getElementById("itemcode").focus();
	return false;	
	}
	if(document.getElementById("issueto").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("jobcard").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 rowCount1 = table.rows.length;
		var row = table.insertRow(rowCount1);
		if(document.getElementById("hiditemcount").value=='')
	    rowCount =rowCount1+1;
	    else
	    {
	    var t1=document.getElementById("hiditemcount").value;
		rowCount=parseInt(t1)+1;	
	    }
		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;
					var nod_id = newcell.childNodes[0].id.split("_");
					if(!isNaN(nod_id[1]))
					newcell.childNodes[0].id = nod_id[0]+'_'+rowCount;
					else
					newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rowCount;

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

				case "hidden":

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

					var nod_id = newcell.childNodes[0].id.split("_");
					if(!isNaN(nod_id[1]))
					newcell.childNodes[0].id = nod_id[0]+'_'+rowCount;
					else
					newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id.split("_");
					if(!isNaN(nod_id[1]))
					newcell.childNodes[0].id = nod_id[0]+'_'+rowCount;
					else
					newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id = newcell.childNodes[0].id.split("_");
					if(!isNaN(nod_id[1]))
					newcell.childNodes[0].id = nod_id[0]+'_'+rowCount;
					else
					newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id.split("_");
					if(!isNaN(nod_id[1]))
					newcell.childNodes[0].id = nod_id[0]+'_'+rowCount;
					else
					newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+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)
    {
	data=xmlhttp.responseText;
    document.getElementById("abc").style.display='block';	
	document.getElementById("abc").innerHTML=data;
	
   // 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();


	
	
}

</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("abc").style.display='none';
}



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();	
	
}

function check_qty(strid, strval)
{
	var strid1=strid.split("_");
	var i=strid1[1];
	
	if(strval>parseInt(document.getElementById("Stockbalance_"+i).value)){
		alert("Primary Issued Qty not more than Stock Qty.");
		document.getElementById(strid).value="";
		document.getElementById(strid).focus();
		return false;
	}
	
	if(strval>parseInt(document.getElementById("receive_"+i).value)){
		alert("Primary Issued Qty not more than Req Qty.");
		document.getElementById(strid).value="";
		document.getElementById(strid).focus();
		return false;
	}
	if(document.getElementById("confac_"+i).value==''){
		var secval = strval*1;
	}else{
		var secval = strval*document.getElementById("confac_"+i).value;
	}
	document.getElementById("secondaryqty_"+i).value=secval;
	
	var str = document.getElementById("primaryqty_"+i).value;
	if(document.getElementById("issuerate_"+i).value!='')
	var issuerate=document.getElementById("issuerate_"+i).value;
	else
	var issuerate=0;
	var total=parseFloat(str)*issuerate;
	document.getElementById("totalamt_"+i).value=total.toFixed(2);
	
	return true;
}

function calamt2(strid,strval)
{
	var strid1=strid.split("_");
	var i=strid1[1];
	var str = document.getElementById("primaryqty_"+i).value;
	
	if(document.getElementById(strid).value!='')
	var issuerate=strval;
	else
	var issuerate=0;
	var total=parseFloat(str)*issuerate;
	document.getElementById("totalamt_"+i).value=total.toFixed(2);
	return true;
}

function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       } 
</script>