<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>
<?php


					function get($site,$store,$date1,$item,$closqty,$closerate,$closevalue)
					{
					global $db;
					   $check_current_opening="Select * from stock_summary where date='".$date1."'
					 and site='".$site."' and store='".$store."'
					  and item='".$item."'";
					
					$check_current_op_result=DB_query($check_current_opening,$db);
					if(DB_num_rows($check_current_op_result)=='0')
					{
					$closing_qty=$closqty;		
					$closing_value=$closevalue;
					$closing_rate=$closerate;						
					}
					else
					{
						$check_current_op_row=DB_fetch_array($check_current_op_result);
						$id=$check_current_op_row['id'];
						$opening_qty=$closqty;
						$opening_value=$closevalue;  
						$opening_rate=round($opening_value/$opening_qty);
						
						$closing_qty=$opening_qty+$check_current_op_row['inwards_qty']-$check_current_op_row['outwards_qty'];
					$closing_value=$opening_value+$check_current_op_row['inwards_value']-$check_current_op_row['outwards_value'];
						$closing_rate= round($closing_value/$closing_qty);
					
						$update_summary="Update  stock_summary set 
													opening_qty='".$opening_qty."',    
													opening_rate='".round($opening_rate,2)."',    
													opening_value='".$opening_value."', 								   
													closing_qty='".$closing_qty."',    
													closing_rate='".$closing_rate."',    
													closing_value='".$closing_value."' where id=$id ";
						$result2=DB_query($update_summary,$db);
						
						
					}

                               $date2= strtotime(date("Y-m-d", strtotime($date1)) . " +1 day");
                                $date11= date("Y-m-d",$date2);
							 
							    if($date11<=date('Y-m-d'))
							   {
 										get($site,$store,$date11,$item,$closing_qty,$closing_rate,$closing_value);
								}		
								}		
			
									




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

 

					      $prefixcode="ISS";
					      $year=date('y');
					      $year_after=$year+1;
					      $site_code=substr($_REQUEST['sitecode'],0,3);
						  $sql="select * from addissue where site = '".$_REQUEST['sitecode']."'";
						  $result = DB_query($sql,$db);
						  $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;
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
					 if($siteCode!='')
							if($numrows>0)
							{ 
								$maxval = $numrows;
							}
						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']."',
								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']."',  
								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]."', 
										 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);
												
						
						
						
						
						
					//*****************************************	Stock Summary //		 
					
										
					  $data_date=explode('/',$_REQUEST['issuedate']);
                      $date51=$data_date[2].'-'.$data_date[1].'-'.$data_date[0];	
			          $date12= strtotime(date("Y-m-d", strtotime($date51)) . " +0 day");					
                        $date= date("Y-m-d",$date12);
					
					
					$check_current_opening="Select * from stock_summary where date='".$date."'
					 and site='".$_REQUEST['sitecode']."' and store='".$_REQUEST['store']."'
					  and item='".$_REQUEST['itemdataid'][$i]."'";
					
					$check_current_op_result=DB_query($check_current_opening,$db);
					//echo DB_num_rows($check_current_op_result);
					
					if(DB_num_rows($check_current_op_result)=='0')
					{
						$get_previous_closing="Select * from stock_summary where site='".$_REQUEST['sitecode']."'
						 and store='".$_REQUEST['store']."' and item='".$_REQUEST['itemdataid'][$i]."' 
						 and date<'".$date."' ORDER BY DATE DESC LIMIT 0,1";
						$previous_closing_result=DB_query($get_previous_closing,$db);
						$previous_closing_row=DB_fetch_array($previous_closing_result);
						if(DB_num_rows($previous_closing_result)=='0')
						{
							$check_opening_entry="Select * from opening_stockitemwise 
													where site='".$_REQUEST['sitecode']."' 
													and store='".$_REQUEST['store']."' 
													and itemcode='".$_REQUEST['itemdataid'][$i]."'
													and reveive_date<'".$date."'  ";
							$check_opening_entry_result=DB_query($check_opening_entry,$db);
							$check_opening_entry_row=DB_fetch_array($check_opening_entry_result);
							if(DB_num_rows($check_opening_entry_result)>0){
							$opening_qty=$check_opening_entry_row['stock'];
							$opening_rate=$check_opening_entry_row['rate'];
							$opening_value=$check_opening_entry_row['amount'];}else
							{$opening_qty='';
							$opening_rate='';
							$opening_value='';}
						}
						else
						{
							$opening_qty=$previous_closing_row['closing_qty'];
							$opening_rate=$previous_closing_row['closing_rate'];
							$opening_value=$previous_closing_row['closing_value'];
						}
							$outwards_qty=$_REQUEST['issueqty'][$i]; 
							$outwards_value=$_REQUEST['totalamt'][$i];
							$outwards_rate=$outwards_value/$outwards_qty;
							
							$closing_qty=$opening_qty-$outwards_qty;
							$closing_value=$opening_value-$outwards_value;
							$closing_rate=round($closing_value/$closing_qty);
							$insert_first_summary="Insert into stock_summary set 
													site='".$_REQUEST['sitecode']."',     
													store='".$_REQUEST['store']."',    
													item='".$_REQUEST['itemdataid'][$i]."',
													opening_qty='".$opening_qty."',  
													opening_rate='".$opening_rate."',    
													opening_value='".$opening_value."',    
													outwards_qty='".$outwards_qty."',    
													outwards_rate='".round($outwards_rate,2)."',    
													outwards_value='".$outwards_value."',    
													closing_qty='".$closing_qty."',    
													closing_rate='".$closing_rate."',    
													closing_value='".$closing_value."',    
													date='".$date."' 	";
							$result1=DB_query($insert_first_summary,$db);
						
					}
					else
					{
						$check_current_op_row=DB_fetch_array($check_current_op_result);
						$id=$check_current_op_row['id'];
						$outwards_qty=$check_current_op_row['outwards_qty']+$_REQUEST['issueqty'][$i]; 
						$outwards_value=$check_current_op_row['outwards_value']+$_REQUEST['totalamt'][$i]; 
						$outwards_rate=$outwards_value/ $outwards_qty;
						$closing_qty=$check_current_op_row['opening_qty']+$check_current_op_row['inwards_qty']-$outwards_qty;
					$closing_value=$check_current_op_row['opening_value']+$check_current_op_row['inwards_value']-$outwards_value;
						$closing_rate= round($closing_value/$closing_qty);
							$update_summary="Update  stock_summary set 
													outwards_qty='".$outwards_qty."',    
													outwards_rate='".round($outwards_rate,2)."',    
													outwards_value='".$outwards_value."',    
													closing_qty='".$closing_qty."',    
													closing_rate='".$closing_rate."',    
													closing_value='".$closing_value."' where id=$id ";
						$result2=DB_query($update_summary,$db);
						
						
					}
					
					          $data_date1=explode('/',$_REQUEST['issuedate']);
                             $date52=$data_date1[2].'-'.$data_date1[1].'-'.$data_date1[0];	 
					          $date2= strtotime(date("Y-m-d", strtotime($date52)) . " +1 day");
                              $date1= date("Y-m-d",$date2);
							   if($date1<=date('Y-m-d'))
							   {
 	get($_REQUEST['sitecode'],$_REQUEST['store'],$date1,$_REQUEST['itemdataid'][$i],$closing_qty,$closing_rate,$closing_value);
								}		
					              
								    }
								  
								
								
				    }
				 
				
					
					
				
			
				 
			}
				
//$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>Quality  Checking</strong></h2>
<form name="form1" action="" method="post" >


 <table width="50%">
  <tr>
    <td>Branch</td>
    <td><select name="site">
        <option value="">-------------Select-------------</option>
        
      </select>
    </td>
    
    <td>From</td>
    <td>
	
      <input name="fromDate" type="text" class="datepicker"/></td>
	<td>To</td>
	<td> <input name="toDate" type="text" class="datepicker"/></td>
	
	
	<td><input type="submit" name="View" value="Search MRN" /></td>

  </tr>
 
</table>
	
<p>&nbsp;</p>
 
    
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
          <th><strong>S. No.</strong></th>
          
          <th><strong>Date </strong></th>
          <th><strong>MRN No. </strong></th>
          <th><strong>Vendor</strong></th>
		  <th><strong>PR  No.</strong></th>
          <th><strong>PO No.</strong></th>
          <th><strong>Item Details</strong></th>
		   <th><strong>UOM</strong></th>
		    <th><strong>PO Qty</strong></th>
			<th><strong>MRN Qty</strong></th>
			<th><strong>QC passed Qty</strong></th>
			<th><strong>Reject Qty</strong></th>
			<th><strong>Reject Reason</strong></th>
          
        </tr>
        <tbody id="dataTable">
          <tr bgcolor="#FFFFFF">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
			<td></td>
			<td><input type="text" size="20"  value=""/></td>
			<td></td>
			<td><input size="20"  value=""/></td>
			
			
          </tr>
        </tbody>
      </table>
      




<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!=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 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,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);
}
}

</script>