<?php 

function openingBalance($function_filter,$item)
							{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];								
								if($site!='')
								$filter[]="site = '".$site."'";
								if($store!='')
								$filter[]="store = '".$store."'";
								if($from!='--' && $to!='--')
								$filter[]="reveive_date <= '".$from."'";
								if($item!='')
								$filter[]="itemcode = '".$item."'";
								
								$filter=implode(' and ',$filter);
								 $sql1="Select stock, rate from opening_stockitemwise where $filter";
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								return $myrow1['stock'];
							}
                      
					   

						
                    function receivedMRN($function_filter,$item)
						{
							global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							if($site!='')
							$filter[]="addmrn.site = '".$site."'";
							if($store!='')
							$filter[]="addmrn.StoreCode = '".$store."'";
							if($item!='')
							$filter[]="addmrnqty.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							 $sql1="Select SUM(addmrnqty.reciveqty) from addmrn left join addmrnqty 
							       on(addmrn.id=addmrnqty.issue_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(addmrnqty.reciveqty)'];
						}
						

							
			               function issueSlip($function_filter,$item)
							{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];
								if($site!='')
								$filter[]="addissue.site = '".$site."'";
								if($store!='')
								$filter[]="addissue.mst_storeid = '".$store."'";
								if($item!='')
								$filter[]="issueqty.mst_itemid = '".$item."'";
								
								
								$filter=implode(' and ',$filter);
							
							 	$sql1="Select SUM(issueqty.issueqty) from addissue left join 
								 issueqty on(addissue.id=issueqty.issue_id) where $filter";
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								
								return $myrow1['SUM(issueqty.issueqty)'];
							}




				function receivedReturn($function_filter,$item)
				{
					global $db;
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="material_return.site = '".$site."'";
					if($store!='')
					$filter[]="material_return.store = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="material_return.returndate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="material_return_details.itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
					  $sql1="Select SUM(material_return_details.receiveqty) 
					  from material_return left join material_return_details    
					  on(material_return.id=material_return_details.parentId) where $filter";
				 
					
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					return $myrow1['SUM(material_return_details.receiveqty)'];
				}



				function receivedSiteToSite($function_filter,$item)
				{
					global $db;
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="transfer_receipt.Received_to = '".$site."'";
					if($store!='')
					$filter[]="transfer_receipt.Received_store = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="transfer_receipt.MRNDate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="transfer_receipt_details.itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
					
					 $sql1="Select SUM(transfer_receipt_details.reciveqty)
					  from transfer_receipt left join transfer_receipt_details 
					  on(transfer_receipt.id=transfer_receipt_details.transfer_receipt_id) where $filter";
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					return $myrow1['SUM(transfer_receipt_details.reciveqty)'];
				}

				function issueSiteToSite($function_filter,$item)
				{
					global $db;
				 
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="transfer_issue.sitecode = '".$site."'";
					if($store!='')
					$filter[]="transfer_issue.fromstore = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="transfer_issue.issuedate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="transfer_issue_details.itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
						 $sql1="Select SUM(transfer_issue_details.issueqty)  from
						  transfer_issue left join transfer_issue_details  
						  on(transfer_issue.id=transfer_issue_details.transfer_issue_id) where $filter";
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					$return_array=$myrow1['SUM(transfer_issue_details.issueqty)'];
					//$avg_rate=$myrow1['SUM(transfer_issue_details.rate)'];
					//$return_array[]=$avg_rate;
					return $return_array;
					
				}
					function issueMatarialReturn($function_filter,$item)
					{
						global $db;
						$site=$function_filter[0];
						$store=$function_filter[1];
						$from=$function_filter[2];
						$to=$function_filter[3];						
						if($site!='')
						$filter[]="inv_material_return.sitecode = '".$site."'";
						if($store!='')
						$filter[]="inv_material_return.storecode = '".$store."'";
						if($from!='--' && $to!='--')
						$filter[]="inv_material_return.MRNDate between '".$from."' and '".$to."'";
						if($item!='')
						$filter[]="inv_material_return_details.itemid = '".$item."'";
						
						$filter=implode(' and ',$filter);
						
					  $sql1="Select SUM(inv_material_return_details.ReturnQty) 
					  from inv_material_return left join inv_material_return_details   
					   on(inv_material_return.id=inv_material_return_details.parentId) where $filter";
						$result1=DB_query($sql1,$db);
						$myrow1=DB_fetch_array($result1);
						return $myrow1['SUM(inv_material_return_details.ReturnQty)'];
					}


                     function Rgpchallan($function_filter,$item)
					  {
					  
					      global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
							
							if($site!='')
							$filter[]="rgp_tab.branch = '".$site."'";
							if($store!='')
							$filter[]="rgp_tab.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="rgp_tab.date between '".$from."' and '".$to."'";
							if($item!='')
							$filter[]="rgp_tab_details.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							  $sql1="Select SUM(rgp_tab_details.qty) 
							  from rgp_tab left join rgp_tab_details 
							  on(rgp_tab.id=rgp_tab_details.parent_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(rgp_tab_details.qty)'];
					  
					  
					  		
					  }	
					  function Rgpreturn($function_filter,$item)
					    {
					  
					      global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
							
							if($site!='')
							$filter[]="rgp_return.branch = '".$site."'";
							if($store!='')
							$filter[]="rgp_return.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="rgp_return.return_date between '".$from."' and '".$to."'";
							if($item!='')
							$filter[]="rgp_return_details.item_id = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							  $sql1="Select SUM(rgp_return_details.qty) 
							  from rgp_return left join rgp_return_details 
							  on(rgp_return.id=rgp_return_details.parent_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(rgp_return_details.qty)'];
					  
					  
					  		
					  }	
					  
					   


					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($_REQUEST['Submit'])
{	

	$data['return_date']=FormatDateForSQL($_REQUEST['return_date']);
	$data['return_time']=$_REQUEST['return_time'];
	$data['removal_remarks']=$_REQUEST['removal_remarks'];
	$data['exp_time']=$_REQUEST['exp_time'];
	$data['exp_value']=$_REQUEST['exp_value'];
	$data['return_remark']=$_REQUEST['return_remark'];
	$data['rgp_return_time']=$_REQUEST['rgp_return_time'];

	$cond="id='".$_REQUEST['ID']."'";
	$s->RecordEdit('rgp_return', $data, $cond);
	for($i=0;$i<count($_REQUEST['itemdataid']);$i++)
	{
	$data1['batch_no']=$_REQUEST['batch_no'][$i];
	$data1['qty']=$_REQUEST['qty'][$i];
	$data1['job_process']=$_REQUEST['job_process'][$i];
	$data1['job_rate']=$_REQUEST['rate'][$i];
	$data1['job_value']=$_REQUEST['rvalue'][$i];
	$cond="id='".$_REQUEST['itemdataid'][$i]."'";
	$s->RecordEdit('rgp_return_details', $data1, $cond);
	
	 //*****************************************	Stock Summary ************************************//		 
					 $qty=$_REQUEST['qty'][$i]-$_REQUEST['oldqty'][$i];
					 
					  $data_date=explode('/',$_REQUEST['return_date']);
                              $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['itemid'][$i]."'";					
					$check_current_op_result=DB_query($check_current_opening,$db);
					
					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['itemid'][$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['itemid'][$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'];						
						}
							$inwards_qty=$qty; 
							$inwards_value=($_REQUEST['rate'][$i]*$qty);
							$inwards_rate=$inwards_value/$inwards_qty;
							
							$closing_qty=$opening_qty+$inwards_qty;
							$closing_value=$opening_value+$inwards_value;
							$closing_rate=round($closing_value/$closing_qty);
							
							$insert_first_summary="Insert into stock_summary set 
													site='".$_REQUEST['site']."',     
													store='".$_REQUEST['store']."',    
													item='".$_REQUEST['itemid'][$i]."',
													opening_qty='".$opening_qty."',  
													opening_rate='".$opening_rate."',    
													opening_value='".$opening_value."',    
													inwards_qty='".$inwards_qty."',    
													inwards_rate='".round($inwards_rate,2)."',    
													inwards_value='".$inwards_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'];
					$inwards_qty=$check_current_op_row['inwards_qty']+$qty; 
					$inwards_value=$check_current_op_row['inwards_value']+($_REQUEST['rate'][$i]*$qty); 
					$inwards_rate=$inwards_value/ $inwards_qty;
					
										
					$closing_qty=$check_current_op_row['opening_qty']+$inwards_qty
					            -$check_current_op_row['outwards_qty'];
					$closing_value=$check_current_op_row['opening_value']+$inwards_value-$check_current_op_row['outwards_value'];
					$closing_rate= round($closing_value/$closing_qty);
						
						$update_summary="Update  stock_summary set 
													inwards_qty='".$inwards_qty."',    
													inwards_rate='".round($inwards_rate,2)."',    
													inwards_value='".$inwards_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['return_date']);
                              $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['itemid'][$i],$closing_qty,$closing_rate,$closing_value);
					}	
	
	
	
	
	
	}
	
$s->pageLocation("index.php?route=Inventory/transation/rgp_return_index".$rurl);//PAGE REDIRCTION
}



$GetSQL=DB_query("SELECT * FROM rgp_return where id='".$_REQUEST['ID']."'",$db);
$FetchRec=DB_fetch_array($GetSQL);
extract($FetchRec);
$function_filter[]=$FetchRec['branch'];
$function_filter[]=$FetchRec['store'];
$function_filter[]=$FetchRec['return_date'];

?>

<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<script type="text/javascript" language="javascript">
function getrgpdata(str)
{
	
	if (str.length==0)
	{
	document.getElementById("sitecode").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("SUPLIER").innerHTML=xmlhttp.responseText;	//alert(data);
	}
	}
	xmlhttp.open("GET","GetRgpDetails.php?branch="+str,true);
	xmlhttp.send();
}



function getRGPNo(str)
{
	
	if (str.length==0)
	{
	document.getElementById("SUPLIER").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("RGPNO").innerHTML=xmlhttp.responseText;	//alert(data);
	}
	}
	xmlhttp.open("GET","GetRgpNO.php?suplierId="+str,true);
	xmlhttp.send();
}



function getRGPDetails(str)
{
	
	if (str.length==0)
	{
	document.getElementById("RGPNO").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("VehicleNo").innerHTML=data[0];
	document.getElementById("RemoveDate").innerHTML=data[1];
	document.getElementById("FormNo").innerHTML=data[2];
	document.getElementById("itemdata").innerHTML=data[3];
	document.getElementById("REMARK").innerHTML=data[4];
	document.getElementById("EXPTEDTIME").innerHTML=data[5];
	document.getElementById("EXPECTEDVALUE").innerHTML=data[6];
	//alert(data);
	}
	}
	xmlhttp.open("GET","GetRgpAllDetails.php?RGPID="+str,true);
	xmlhttp.send();
}


function calculaterate(i)
{

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


function GrabdTotal()
{
	var Total=0;
	count1=document.getElementById("count").value;
	for(var i=0;i<count1;i++)
	{
		var q=parseFloat(document.getElementById("rvalue_"+i).value);
		//alert(q);
		var Total=Total+q;
		//alert(Total);
	}
	document.getElementById("exp_value").value=Total;
}
</script>

	
<h2 align="center"><strong>RGP Return</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 echo $s->GetFieldValue('locations',"loccode='".$branch."'",'locationname');?>
	<input type="hidden" name="sitecode" id="sitecode" value="<?php echo $branch;?>" />
	</td>
    <th>Return No.</th>
    <td style="width: 250px;"><?php echo $return_no;?>
	<input type="hidden" name="store" id="store" value="<?php echo $store;?>" />
	</td>
</tr>

<tr> 


	
<th><strong>Supplier</strong></th>
    <td style="width:250px;"><?php echo $s->GetFieldValue('suppliers',"id='".$suplier."'",'vendor_name'); ?></td>	
    <th>Return Date & Time</th>
    <td><input type="text"size="20" style="width:49%" name="return_date" value="<?php echo ConvertSQLDate($return_date); ?>" readonly="readonly" class="datepicker"/>&nbsp;<input type="text"size="20" name="return_time" style="width:49%" value="<?php echo $return_time; ?>" readonly="readonly"/> 	</td>
</tr>

<tr>
 <th>RGP No.</th>
    <td style="width:250px;"><?php echo $s->GetFieldValue('rgp_tab',"id='".$rgp_no."'",'rgp_no'); ?></td>
  <th><strong>Vehicle No.</strong></th>
    <td id="VehicleNo"><?php echo $vehchile_no; ?></td>
   
</tr>

<tr>
    <th><strong>Remove Date & Time</strong></th>
    <td style="width:250px;" id="RemoveDate"><?php echo ConvertSQLDate($remove_date); ?>&nbsp;<?php echo $remove_time; ?></td>
     <th><strong>Form No.</strong></th>
    <td style="width:250px;" id="FormNo"><?php echo $form_no; ?></td>
    </tr>
</table> 
	
<p style="margin-bottom:15px;"></p>
  <div style=" width:973px;  overflow:auto; margin-left:auto; margin-right:auto; height:auto">
    <div id="itemdata">
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
		<th><strong>Sr.No</strong></th>
		<th></th>
          <th><strong>Part Code</strong></th>
          <th><strong>Part Name</strong></th>
          <th><strong>Unit</strong></th>
		  <th><strong>Batch No</strong></th>
		   <th><strong>Current Stock</strong></th>
		  <th><strong>Pending qty</strong></th>
          <th><strong>Qty</strong></th>
		   <th><strong>Reason</strong></th>
		   <th><strong>Job Rate</strong></th>
		    <th><strong>Job Value</strong></th>
        </tr>
        <tbody id="dataTable">
	<?php $i=0; $Get1sql=DB_query("SELECT * FROM rgp_return_details where parent_id='".$_REQUEST['ID']."'",$db); 
while($GetRowRec=DB_fetch_array($Get1sql)){
$Item_code=$s->GetFieldValue('item_master',"id='".$GetRowRec['item_id']."'",'StockID');
$ItemName=$s->GetFieldValue('item_master',"id='".$GetRowRec['item_id']."'",'item_name');
$unit=$s->GetFieldValue('item_master',"id='".$GetRowRec['item_id']."'",'unit');
$unit_name=$s->GetFieldValue('unitsofmeasure',"unitid='".$unit."'",'unitname');

    $check_last_mrn="Select issueqty,sum(qty) from rgp_return_details 
	  where parent_id='".$_REQUEST['ID']."' and item_id='".$GetRowRec['item_id']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	if($last_mrn_row['issueqty']!='' && $last_mrn_row['sum(qty)']!='' )
	{
		$pending_qty=$last_mrn_row['issueqty']-($last_mrn_row['sum(qty)']+$closeqty1);
	}
	else{$pending_qty=$purchdetails_row['quatity']-$closeqty1;}	
	
	
	      $op=openingBalance($function_filter,$GetRowRec['item_id']);
            //  echo "openingBalance"."<br>";
 		      $in_1=receivedMRN($function_filter,$GetRowRec['item_id']);
          //echo "receivedMRN"."<br>";
 		    $out_1=issueSlip($function_filter,$GetRowRec['item_id']);
           // echo "issueSlip"."<br>";
		   $out_2=issueSiteToSite($function_filter,$GetRowRec['item_id']);		
          // echo "issuesitetosite"."<br>";
		   $in_2=receivedSiteToSite($function_filter,$GetRowRec['item_id']);
		// echo " receivesitetosite"."<br>";
		  $out_3=issueMatarialReturn($function_filter,$GetRowRec['item_id']);
		 
		    $in_4=Rgpreturn($function_filter,$GetRowRec['item_id']);
		
		   $out_4=Rgpchallan($function_filter,$GetRecord['item_id']);
		 
		 	 
		  //$in_4=return_rejection($function_filter,$myrow['id']);
		   $invalue=($op+$in_1+$in_2+$in_3+$in_4);
		   $outvalue=($out_1+$out_2+$out_3+$out_4); 
		  //$in_4=return_rejection($function_filter,$myrow['mst_itemid']);
		 // $invalue=($op+$in_1+$in_2+$in_3);
		  //$outvalue=($out_1+$out_2+$out_3);
		  $tot=$invalue-$outvalue;
		  $total_current=$tot;



?>
          <tr bgcolor="#FFFFFF">
		  <td><?php echo $i+1; ?></td>
            <td><input  type="hidden" id="itemdataid"  name="itemdataid[]" value="<?php echo $GetRowRec['id'];?>" /></td>
			<td><?php echo $Item_code; ?>
			<input type="hidden" name="itemid[]" value="<?php echo $GetRowRec['item_id']; ?>" />
			</td>
            <td><?php echo $ItemName; ?></td>
            <td><?php echo $unit_name; ?></td>
         <td><input type="text" name="batch_no[]" value="<?php echo $GetRowRec['batch_no']; ?>"  id="batchno"  size="10"  /></td>
         <td><?php echo $total_current; ?><input type="hidden" name="stockqty[]" id="stock_<?php echo $i; ?>" value="<?php echo  $total_current; ?>" /></td>
		  <td><input type="hidden" name="pendingqty[]" id="pendingqty_<?php echo $i; ?>" value="<?php echo $pending_qty; ?>" />
		  <?php echo $pending_qty; ?></td>
		  <td>
		  <input type="hidden" name="oldqty[]" id="oldqty_<?php echo $i; ?>" value="<?php echo $GetRowRec['qty']; ?>"  />
		  <input type="text" name="qty[]" size="20" id="qty_<?php echo $i; ?>"  value="<?php echo $GetRowRec['qty']; ?>"
		   onkeyup="calamt(<?php echo $i; ?>)" /></td>
           <td><select name="job_process[]" id="jobprocess" >
			<option value="0">Select</option>
			<?php $sql_process=DB_query("select * from job_work_master",$db);
			while($row1=DB_fetch_array($sql_process)){
			$sel='';
			if($GetRowRec['job_process']==$row1['id'])
			$sel='selected';
			?>
			<option value="<?php echo $row1['id']; ?>"<?php echo $sel; ?>><?php echo $row1['jobwork_name']; ?></option>
			<?php } ?>
			</select></td>
		   <td><input type="text" name="rate[]" id="rate_<?php echo $i; ?>" onkeyup="calculaterate(<?php echo $i; ?>)"  value="<?php echo $GetRowRec['job_rate'] ?>"/></td>
            <td><input type="text" size="25" name="rvalue[]" id="rvalue_<?php echo $i; ?>"  value="<?php echo $GetRowRec['job_value'] ?>"/></td>
          </tr>
<?php $i++;} ?>
<input type="hidden" name="count" id="count" value="<?php echo $i; ?>" />
        </tbody>
      </table>
    </div>
  </div>
  <p style="margin-bottom:15px;"></p>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  

<div style="width:910px; ">
<table width="100%" border="1" cellpadding="3" cellspacing="0">


<tr>
<th><strong>Removal Remarks:</strong></th>
<td style="width:300px;" id="REMARK"><textarea name="removal_remarks"  style="width:100%" id="remark"><?php echo $removal_remarks; ?></textarea></td>
<th><strong>Expected Time:</strong></th>
<td id="EXPTEDTIME"><input type="text" id="exp_time"  name="exp_time" style="width:100%"  value="<?php echo $exp_time; ?>" /></td>
<th><strong>Total Value: </strong></th>
<td id="EXPECTEDVALUE"><input type="text" id="exp_value" name="exp_value"  style="width:100%" onfocus="GrabdTotal()"  value="<?php echo $exp_value; ?>" /></td>
</tr>
<tr>
<th><strong>Return Remarks:</strong></th>
<td style="width:300px;"><textarea name="return_remark"  style="width:100%" id="remark"><?php echo $return_remark; ?></textarea></td>

<th><strong>Return Time:</strong></th>
<td style="width:300px;" colspan="3"><input type="text" id="rgp_return_time" name="rgp_return_time"  style="width:100%" value="<?php echo $rgp_return_time; ?>"   />  </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!=0)
	{
		var element=document.getElementById("issueto");
		element.style.display = "none";
	}
	else
	{
		var element=document.getElementById("issueto");
		element.style.display = "";
	}
	if (str=="")
  {
  document.getElementById("dept").innerHTML="";
  return;
  }
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    	
	document.getElementById("dept").innerHTML=xmlhttp.responseText;
	
    }
  }
  
xmlhttp.open("GET","get_empdata.php?department="+str,true);
xmlhttp.send();	
	
}
function chkbalance(str)
{
	//alert(str);
	var k=parseFloat(document.getElementById('Stockbalance_'+str).value);
	
	var j=parseFloat(document.getElementById('issueqty_'+str).value);	
	//alert(document.getElementById('Stockbalance_0').value);
	if(isNaN(document.getElementById('issueqty_'+str).value))
	{
	alert("String Not Allowed");
	document.getElementById('issueqty_'+str).value='';
	return false;	
	}
	
	if(j > k)
	{
	alert("Issue Qty Not Grater then Stock Balance");
	document.getElementById('issueqty_'+str).value='';
	document.getElementById('issueqty_'+str).focus();
	}
	
	
}

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

function showsitename158(str)
{

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	var data=xmlhttp.responseText.split("__");	
	
	document.getElementById("hid-Godown-div").innerHTML=data[0];
    document.getElementById("empdta").innerHTML=data[1];
	
    }
  }
  xmlhttp.open("GET","GoDownIssueSlip.php?site="+str,true);
	xmlhttp.send();

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

	
}

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


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


</script>

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

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

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


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

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

}

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

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

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  var store=document.getElementById("store").value;
  var sitecode=document.getElementById("sitecode").value;
  var date=document.getElementById("issuedate").value;

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


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

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

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


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

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


function addRow(tableID) 
{

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

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

				case "hidden":

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

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

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

				break;

				case "button":

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

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

				break;

				case "checkbox":

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

				break;

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


function calamt(i)
{

var oldqty=parseFloat(document.getElementById("oldqty_"+i).value);
var pending=parseFloat(document.getElementById("pendingqty_"+i).value);
var qty=parseFloat(document.getElementById("qty_"+i).value);
var stock=parseFloat(document.getElementById("stock_"+i).value);
var total=oldqty+pending;
if(qty>total || qty>stock)
{
alert("return Qty Should be less then pending qty");
return false;
}
return true;

}

</script>