<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 4;
$PageName = 'Material Return To Vendor';
include('includes/DefinePOClass.php');
include('includes/stockcalculation.php');

                    if(isset($_POST['Save']))
						{				
						  
               date_default_timezone_set('Asia/Calcutta');
									$sql = "update inv_material_return set
													remarks='".$_REQUEST['remarks']."',
													modify_by='".$_SESSION['UserID']."',  
													modify_date='".FormatDateForSQL(date('d/m/Y'))."' where id='".$_REQUEST['id']."' ";
								
								$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
								$insertResult = DB_query($sql,$db,$ErrMsg);
								$Lastreq_id=$_REQUEST['id'];
							 
				if($Lastreq_id!='')
				{
				DB_query("delete from inv_material_return_details where parentId='".$_REQUEST['id']."'",$db);
			        	for($i=0; $i < count($_REQUEST['returnqty']) ;$i++)
							{						 
					             if($_REQUEST['returnqty'][$i]!='')
					             {
					     $sql2="INSERT INTO inv_material_return_details set
								parentId='".$Lastreq_id."', 
								itemid='".$_REQUEST['itemdataid'][$i]."', 
								ReturnQty='".$_REQUEST['returnqty'][$i]."',
								size_id='".$_REQUEST['sizesp'][$i]."',
								grade_id='".$_REQUEST['gradesp'][$i]."',
								mrn_id='".$_REQUEST['mrnno']."',
								batch_no='".$_REQUEST['batch_no'][$i]."'
								";
					  $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
				      $insertResult2 = DB_query($sql2,$db,$ErrMsg);
				               }
				         }

			}
		if($insertResult2 == true)
        {
	$_SESSION['success_msg']="Saved Successfully";
	 echo "<script>location.href='index.php?route=Inventory/transation/Material_Return_To_Vendor_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
       }			  
					  
	}
   
     $resultReturn=DB_query("select * from inv_material_return where id='".$_REQUEST['id']."'",$db);
     $row=DB_fetch_array($resultReturn);
    

 ?>
<div class="body_contain">
<div class="tab_div">
 <h1>Material Return To Vendor</h1>
<form name="form1" onsubmit="return chkValidate();" method="post">
<div align="center">
<table width="100%" cellpadding="3" cellspacing="0" border="0" style="border-collapse:collapse;">
<tr class="row1">
    <td width="13%" align="right">Branch</td>
    <td width="20%"><div id="companybranch1"><select name="site"  id="site">
     <option value="<?php echo $row['sitecode']; ?>" ><?php echo $s->getField('locations','loccode',$row['sitecode'],'locationname'); ?></option>
    </select></div></td>     
    <td width="10%" align="right">MRV No.</td>
    <td width="20%"><input name="issue_slipno"  type="text" id="issue_slipno"  readonly="readonly" value="<?php echo $row['MRNno']; ?>"></td>
    <td width="13%" align="right">Date</td>
    <td><input name="issuedate" type="text" id="recieved_date" value="<?php echo date('d/m/Y',strtotime($row['return_date'])); ?>" size="15"  /></td>
</tr>
  <tr class="row1">
  	<td align="right">Against</td>
    <td><select name="trnsferType" id="trnsferType"   >
     <option value="<?php echo $row['return_type']; ?>"><?php echo $row['return_type']; ?></option>
    </select></td>
  	<td align="right">Vendor</td>
    <td><select name="vendor" id="vendor"  >
	       <option value="<?php echo $row['vendor_code']; ?>"><?php echo $s->getField('suppliers','id',$row['vendor_code'],'vendor_name'); ?></option>     
    </select></td>  	
    
    <td align="right">Store</td>
    <td><select name="storeTo"  id="storeTo"><option value="0">---Select---</option>
    <?php 
    $resultStore=DB_query("select * from storetype where Store_Site='".$row['sitecode']."'",$db);
    while($rowStore=DB_fetch_array($resultStore))
    { ?>
    <option value="<?php echo $rowStore['id']; ?>"  <?php echo ($rowStore['id']==$row['store'])?'selected="selected"':''; ?> ><?php echo $rowStore['StoreName']; ?></option>
    <?php } ?>
  </select></td>
  </tr>
  <?php 

   if($row['return_type']=='MRN')
    {?>
  <tr class="row1">
  	 <td align="right">MR Number</td>
    <td id="tdShowMRN"> <input type="text" readonly value="<?php echo $s->getField('addmrn','id',$row['mrn_id'],'MRNNo'); ?>" ></td> 
   <td align="right">MRN Date</td>
  	<td><input type="text"  value="<?php echo date('d/m/Y',strtotime($s->getField('addmrn','id',$row['mrn_id'],'MRNDate'))); ?>" name="mrn_date" id="mrn_date" /></td>
    <td colspan="2">&nbsp;</td> 
  </tr> 
  <?php }?>
</table>
</div>
<?php
  if($_REQUEST['action']=='Edit' || $_REQUEST['action']=='view'  )
  {
 ?>
<!--<p align="left">
<input type="button" onclick="opendata()" value="Pick Item" />&nbsp;
<input type="button" class="crmbutton small delete"  onclick="deleteRow_return('dataTable')" value="Delete" />
</p> -->
<?php } ?>
<br/>
<div id="divShowSiteTransfer" style="overflow:auto; width:100%; height:auto">
<input type="hidden" name="issue_slip_no" value="<?php echo $row['issue_slipno']; ?>">
<table width="100%"  border="0" cellspacing="0" cellpadding="3" class="thborder">
      <tr>
        <th width="10%">Item Code</th>
        <th width="1"></th>
        <th>Item Name</th>
        <th width="8%">Unit</th>
        <th width="10%">Item Stock Balance</th>
        <th width="10%">Batch Stock</th>
        <th width="10%">Batch No.</th>
        <!--<th>Issue Qty </th> -->
        <!-- <th>Rem. Qty </th> -->
        <th width="10%">Return Qty.</th>        
      </tr>
      <tbody id="dataTable">
      <?php
            // $issueQty=array();
            // $resultIssue=DB_query("select mst_itemid, reciveqty  from addmrnqty where issue_id='".$row['mrn_id']."' ",$db);
            // while($rowrIssue=DB_fetch_array($resultIssue))
            // {
            //  $issueQty[$rowrIssue['mst_itemid']]=$rowrIssue['reciveqty'];
            // }
       
            // $receivedQty=array();

            // $resultRecevied=DB_query($str="select itemid, SUM(ReturnQty) as returnQty from inv_material_return_details where mrn_id='".$row['mrn_id']."' and parentId!='".$_REQUEST['id']."'  group by itemid",$db);
            // echo $str;

            // while($rowRecevied=DB_fetch_array($resultRecevied))
            // {
            // $receivedQty[$rowRecevied['itemid']]=$rowRecevied['returnQty'];	
            // }   
           
 
	  // $i=0;
	 // echo "select * from addmrnqty where id='".$_GET['site']."'";
	  // $sql=DB_query($str="select * from inv_material_return_details where parentId='".$_REQUEST['id']."'",$db);
   //  echo $str;
	  // while($rowre=DB_fetch_array($sql))
	  // {
	  //  $itemcode=$s->getField('item_master','id',$rowre['itemid'],'StockID');
	  //   $itemname=$s->getField('item_master','id',$rowre['itemid'],'item_name');
	  //  $unitid=$s->getField('item_master','id',$rowre['itemid'],'mst_unitid');
	  // $unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');
	  
	  
      /* $op=openingBalance($function_filter,$rowre['itemid']);
$in_1=receivedMRN($function_filter,$rowre['itemid']);
$out_1=issueSlip($function_filter,$rowre['itemid']);
$out_2=issueSiteToSite($function_filter,$rowre['itemid']);    
$in_2=receivedSiteToSite($function_filter,$rowre['itemid']);
$out_3=issueMatarialReturn($function_filter,$rowre['itemid']);
$in_3=receivedReturn($function_filter,$rowre['itemid']);  
$out_4=Rgpchallan($function_filter,$rowre['itemid']);
$out_5=Nrgp($function_filter,$rowre['itemid']);
$in_4=Rgpreturn($function_filter,$rowre['itemid']);  
$in_5=FinishedMR($function_filter,$rowre['itemid']);
$in_6=MaterialConReceived($function_filter,$rowre['itemid']);
$out_6=MaterialConIssue($function_filter,$rowre['itemid']);
$in_7=PhysicalStockPlus($function_filter,$rowre['itemid']);
$out_7=PhysicalStockMinus($function_filter,$rowre['itemid']);
$out_8=dispatchIssue($function_filter,$rowre['itemid']);
$out_9=jobWorkChallan57Issue($function_filter,$rowre['itemid']);
$in_8=jobWorkChallan57Received($function_filter,$rowre['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; */


   //  echo $sql_batch_stock="select sum(inwardqty_primary)-sum(outwardqty_primary) as current_stock from stock_valuation_tbl where site='".$row['sitecode']."' and store='".$row['store']."' and mst_itemid='".$rowre['itemid']."' and batch_no='".$rowre['batch_no']."'  ";
   // $result_batch_stock=DB_query($sql_batch_stock,$db);
   // $rs_batch_stock=DB_fetch_array($result_batch_stock);
   // $tot=$rs_batch_stock['current_stock'];

		 // echo $total_current=$tot;
		 $function_filter[0]=$row['sitecode'];
    $function_filter[1]=$row['store'];
    $function_filter[2]=date('Y-m-d');

/* $sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,conv_unit,mrp_rate,net_rate,item_mst_form_rate,conv_factor from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); */ 

$sql=DB_query("select * from inv_material_return_details where parentId='".$_REQUEST['id']."'",$db);
   
$i=0;

if(DB_num_rows($sql)>0)
{
  while($myrow=DB_fetch_array($sql))
  { 

     $itemcode=$s->getField('item_master','id',$myrow['itemid'],'StockID');
      $itemname=$s->getField('item_master','id',$myrow['itemid'],'item_name');
     $unitid=$s->getField('item_master','id',$myrow['itemid'],'mst_unitid');
    $unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');  
    $parameter=$myrow['id'];
    
   /* $op=openingBalance($function_filter,$myrow['itemid']);
        $in_1=receivedMRN($function_filter,$myrow['itemid']);
        $out_1=issueSlip($function_filter,$myrow['itemid']);
        $out_2=issueSiteToSite($function_filter,$myrow['itemid']);    
        $in_2=receivedSiteToSite($function_filter,$myrow['itemid']);
        $out_3=issueMatarialReturn($function_filter,$myrow['itemid']);
        $in_3=receivedReturn($function_filter,$myrow['itemid']);  
        $out_4=Rgpchallan($function_filter,$myrow['itemid']);
        $out_5=Nrgp($function_filter,$myrow['itemid']);
        $in_4=Rgpreturn($function_filter,$myrow['itemid']);  
        $in_5=FinishedMR($function_filter,$myrow['itemid']);
        $in_6=MaterialConReceived($function_filter,$myrow['itemid']);
        $out_6=MaterialConIssue($function_filter,$myrow['itemid']);
        $in_7=PhysicalStockPlus($function_filter,$myrow['itemid']);
        $out_7=PhysicalStockMinus($function_filter,$myrow['itemid']);
        $out_8=dispatchIssue($function_filter,$myrow['itemid']);
        $out_9=jobWorkChallan57Issue($function_filter,$myrow['itemid']);
        $in_8=jobWorkChallan57Received($function_filter,$myrow['itemid']);
        $in_9=directPurchase($function_filter,$myrow['itemid']);
        $in_10=saleReturn($function_filter,$myrow['itemid']);
        $out_10=invoice($function_filter,$myrow['itemid']);
        $in_11=storereceipt($function_filter,$myrow['id']);

        $invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8+$in_9+$in_10+$in_11);
        $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9+$out_10);
        $tot=$invalue-$outvalue;
        $stockallitems=$tot;

          $total_current=$tot;*/


           $sql_batch_stock="select sum(inwardqty_primary)-sum(outwardqty_primary) as current_stock from stock_valuation_tbl where site='".$row['sitecode']."' and store='".$row['store']."' and mst_itemid='".$myrow['itemid']."' and batch_no='".$myrow['batch_no']."' ";
        $result_batch_stock=DB_query($sql_batch_stock,$db);
        $rs_batch_stock=DB_fetch_array($result_batch_stock);
          $total_current=$rs_batch_stock[0];
     
	
	  
	  
	   ?>
	  	  
        <tr id="dataTable">
          <td><input type="text" value="<?php echo $itemcode; ?>" readonly tabindex="" id="itemcode_<?php echo $i; ?>" name="delitem[]" size="20" /></td>
          <td><input  type="hidden"   readonly  value="<?php echo $rowre['itemid']; ?>" id="itemdataid_<?php echo $i; ?>"  name="itemdataid[]"  /></td>
          <td><input type="text" name="desc[]" readonly id="descriptions_<?php echo $i; ?>" size="25"  value="<?php echo $itemname; ?>"/></td>
          <td><input type="text" name="uom[]" readonly id="uom_<?php echo $i; ?>" value="<?php echo $unit; ?>" readonly  size="30" /></td>
           <!-- <td nowrap><input type="hidden"  name="sizesp[<?php echo $rowre['itemid']; ?>]" value="<?php echo $rowre['size_id']; ?>" /><?php echo $s->GetFieldValue('size_master',"id='".$rowre['size_id']."'",'size'); ?></td>
   <td nowrap><input type="hidden"  name="gradesp[<?php echo $rowre['itemid']; ?>]" value="<?php echo $rowre['grade_id']; ?>" /><?php echo $s->GetFieldValue('product_grade',"id='".$rowre['grade_id']."'",'grade'); ?></td> -->
    <td><input type="text" name="stock[]"  id="Stockbalance_<?php echo $i; ?>"  size="20" value="<?php echo $total_current; ?>"   readonly/></td>

          <td><input type="text" value="<?php echo $rs_batch_stock[0]; ?>" readonly name="batch_no[<?php echo $rowre['itemid']; ?>]"></td>
         
        <!--   <td><input  type="text" name="issueqty[]" readonly value="<?php echo $issueQty[$rowre['itemid']]; ?>"  id="issueqty_<?php echo $i; ?>" size="30"   <?php echo ($row['return_type']=='Direct')?' disabled':''; ?>/></td>
           <td><input  type="text" readonly value="<?php echo (($issueQty[$rowre['itemid']] - $receivedQty[$rowre['itemid']] ) ); ?>"  size="20"   <?php echo ($row['return_type']=='Direct')?' disabled':''; ?>/></td> -->
            <td><input  type="text"  readonly name="batchno[]" value="<?php echo $myrow['batch_no']; ?>"  id="batchno_<?php echo $i; ?>" size="20" /></td>

            <td><input  type="text" readonly onkeypress="return isNumberKey(event)" name="returnqty[]" value="<?php echo $myrow['ReturnQty']; ?>"  id="receivedQty_<?php echo $i; ?>" size="20" /></td>         
        </tr>
		<?php $i++; } } ?>
     
    </table>
    <br/>
    <table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td width="13%" align="right">Remarks</td>
    <td><textarea name="remarks" id="remarks" readonly style="width:98%; height:60px; background:#FFF;"><?php echo $row['remarks']; ?></textarea></td>
  </tr>
</tbody>
</table>
   <?php 
     if($_REQUEST['action']=='Edit')
     {
    ?>
    <!-- <p align="center"><input type="submit" name="Save" value="Save" class="search" /></p> -->
    <?php } ?>

</div><!--divShowSiteTransfer-->
<div class="body_lightbox1" id="lightbox1" style="overflow:auto; width:600px; height:250px; display:none;"></div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>" />
  <input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
  <input type="hidden" name="" value="<?php echo $i; ?>" id="rowcount1" />
</form>
</div>
</div>



<script type="text/javascript">
$(function() {
$("#recieved_date").datepicker({ dateFormat: 'dd/mm/yy', 
    minDate:'0'});
});
</script>
<script language="javascript" type="text/javascript">

function get_MRN_date()
{    
	 if($('#mrnno').val()==0)
	 {
	   return false;
	 }
	   $.ajax({
						url : "get_mrn_by_site.php",
						type : "POST",
						data : {
						action:'get_mrn_date',	
					    mrn_id:$('#mrnno').val()
						},
						success : function(data) {//alert(data);
		                    $('#mrn_date').val(data);
												 }
					       });
}


function chk_recived_qty(obj)
{
    var stockQty=$(obj).closest('tr').find('td:eq(5)').find('input[type="text"]').val();

      if(parseFloat(stockQty) < parseFloat($(obj).val()) )
      {
      	alert(' Return quantity should be less stock quantity');
      	$(obj).val(stockQty);
      }
}
function get_MRN_number(obj)
{
	      if($('#site').val()=='0')
	      {
	      	alert('Please select  branch.');
	      	return false;
	      }
	      if($('#trnsferType').val()=='')
	      {
	      	alert('Please select against.');
	      	return false;
	      }
            if($('#trnsferType').val()=='MRN')
            {   $('#divShowSiteTransfer').html('');
	          $.ajax({
						url : "get_mrn_by_site.php",
						type : "POST",
						data : {
						action:'getMRN',	
						site:$('#site').val(),
						vendor_id:$('#vendor').val()
						},
						success : function(data) {//alert(data);
		                    $('#tdShowMRN').html(data);
												 }
					       });
	      }
	      else
	      {
	      	 $('#tdShowMRN').html('<input name="mrnno" type="text" style="width:100%" />');
	      	 $.ajax({
						url : "get_vendor_return_direct_struct.php",
						type : "POST",
						data : {
						},
						success : function(data) {//alert(data);
		                $('#divShowSiteTransfer').html(data);
												 }
					       });
	      }

}
function get_vendor_by_site()
{//get_vendor_by_site
       if($('#site').val()=='0')
          {
        $('#vendor').html('<option value="0">----Select----</option>');
       return false;
         }
      $.ajax({
						url : "get_mrn_by_site.php",
						type : "POST",
						data : {
							action:'get_vendor_by_site',
							site:$('#site').val()
						},
						success : function(data) {//alert(data);
		                $('#vendor').html(data);
												 }
					       });
}


function get_store_by_site()
{//getStore
     if($('#site').val()=='0')
     {
       return false;
     }
      $.ajax({
						url : "get_mrn_by_site.php",
						type : "POST",
						data : {
							action:'getStore',
							site:$('#site').val()
						},
						success : function(data) {//alert(data);
		                $('#storeTo').html(data);
												 }
					       });
}
function showsitename165(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)
    {
	document.getElementById("divShowSiteTransfer").innerHTML=xmlhttp.responseText;
	get_MRN_date();
    }
  }
  xmlhttp.open("GET","get_return_mrndata.php?site="+str,true);
	xmlhttp.send();
}
function issuedetails(str)
{
	var branch=document.getElementById("site").value;
	var godown=document.getElementById("store").value;
	
if (str.length==0)
  {
  document.getElementById("ISSUE").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("ISSUE").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","JobWorkItems.php?q="+str+"&site="+branch+"&store="+godown,true);
xmlhttp.send();

}
function openPopupProfile(i)
{ 
        window.open("issu_searchpopupfinish.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=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 opendata()
{

   var sitecode=document.getElementById("site").value;
   var date=document.getElementById("recieved_date").value;
   
	if(sitecode=='0')
	{
	alert("Must Select Site");
	document.getElementById("site").focus();
	return;
	}
	else if(date=='')
	{
	alert("Must Select Date");
	document.getElementById("recieved_date").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("lightbox1").style.display='block';	
	document.getElementById("lightbox1").innerHTML=xmlhttp.responseText;	
   // document.getElementById("textitem").innerHTML=data[1];	
    }
  }
  //var store=document.getElementById("store").value;
 var store='';

  xmlhttp.open("GET","issu_searchpopupfinish.php?store="+store+"&site1="+sitecode+"&date="+date,true);
	xmlhttp.send();	
	
}
function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       } 


function hidedata()
{
document.getElementById("lightbox1").style.display='none';
}

function getItemsList1(id,code,shade,netrate,mrprate,rate,ctr)
{ 
    
  var ctr=$('#dataTable').find('tr:last').find('td:eq(1)').find('input[type="text"]').attr('id');
  var rowCount=$('#dataTable').find('tr').length;
  var rowItem=$('#dataTable').find('tr').find('td:eq(2)').find('input[type="hidden"]').val();
    
   
    var ctr1=parseInt(document.getElementById("rowcount1").value)+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(rowCount==1 && rowItem=='')
	{
		    
	if(document.getElementById('itemdataid_1'))
	{
	
	document.getElementById('itemdataid_1').value = id;
	document.getElementById('itemcode_1').value = code;
	document.getElementById('descriptions_1').value = shade;
	document.getElementById('uom_1').value = netrate;
	document.getElementById('stock_1').value = mrprate;
	}
	}
	else
	{
		 var i=ctr1;


		//alert(i);
    addRow22('dataTable'); 
	if(document.getElementById('itemdataid_'+i))
	{		
	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('stock_'+i).value = mrprate;
	}	
	}	
	//document.getElementById("lightbox1").style.display='none';
	//var data= addRow('dataTable')
	
}
 function addRow22(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount").value=='')
	r =rowCount+1;
	else
	{
	var t=document.getElementById("edit_cnt").value;
	var t1=document.getElementById("hiditemcount").value;
	r=parseInt(t1);
	r1=parseInt(t1)+1;
	}
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1)+1;
	document.getElementById("rowcount1").value=rr;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rr;
	document.getElementById("edit_cnt").value=rr;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {		
	var newcell = row.insertCell(i);
			newcell.className='tabledata';
           			// newcell.style.background='#ffffff';
			
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
			 

				//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
	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]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
	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]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
	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]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
		//document.getElementById(countid).innerHTML=rowCount;

	}


function deleteRow_return(tableID) 
	{
		
	 if($('#dataTable').find('input[type="checkbox"][name="delitem[]"]:checked').length > 0)	
         {
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			
			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--;
					}
				}

		}
		catch(e) 
		{
			alert(e);
		}
   }
   else
   	alert('Please select at least one row for delete.');
	}

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("workorder").innerHTML=data[1];
	
    }
  }
  xmlhttp.open("GET","GoDownIssueSlip10.php?site="+str,true);
	xmlhttp.send();

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

	
}


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("__");	
	 if($('#against').val()=='Direct')
	{
		$('#jobcarddata').html('<input name="job_card_no" type="text" id="job_card_no"  style="width:100%;"  size="15" />');
			
	  	
	}
	else 
	document.getElementById("jobcarddata").innerHTML=data[0];
	document.getElementById("work_order_date").value=data[1];
	
    }
  }
  
xmlhttp.open("GET","get_orderdata9.php?salid="+str,true);
xmlhttp.send();	
	
}



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)
    {
	var data=xmlhttp.responseText.split("__");	
	//alert(data[0]);
   	//document.getElementById("oderitem").innerHTML=data[0];
	document.getElementById("jobcarddate1").innerHTML=data[1];
	
    }
  }
  
xmlhttp.open("GET","get_joborderdata.php?salid="+str,true);
xmlhttp.send();	
	
}

function calamt(str,str1)
{
var k=str.split("_");
if(k[1]==undefined)
{
if(parseFloat(document.getElementById("reciveqty").value)>parseFloat(document.getElementById("stock").value))
{
alert("Receive Qty Should Be less then Stock Qty");
document.getElementById("reciveqty").value='';
}

}
else
{
var i=k[1];
if(parseFloat(document.getElementById("reciveqty_"+i).value)>parseFloat(document.getElementById("stock_"+i).value))
{
alert("Receive Qty Should Be less then Stock Qty");
document.getElementById("reciveqty_"+i).value='';

}
}


}
 function chkValidate()
 {
 	
   if($('#site').val()==0)
   {
   	alert('Please select branch.');
   	return false;
   }
   if($('#recieved_date').val()=='')
   {
   	alert('Please Enter Return date.');
   	return false;
   }
    if($('#trnsferType').val()=='')
    {
    	alert('Please select return type.');
    	return false;
    }

     if($('#vendor').val()==0)
     {
     	alert('Please select vendor.');
     	return false;
     }

     if($('#storeTo').val()==0)
     {
     	alert('Please select store.');
     	return false;
     }
     


      return true;
 }


</script>
<style type="text/css">
.body_lightbox1 {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
