<?php 
ob_start();

include('includes/stockcalculation.php');
if($_REQUEST['action']=='Edit')
{
		$recEdit=DB_fetch_array($s->GetRecordById('physical_stock','id='.$_REQUEST['id']));

		extract($recEdit);
}

if($_REQUEST['update'])
{	
	 date_default_timezone_set('Asia/Calcutta');
		$datap['date1']=FormatDateForSQL($_REQUEST['date']);
		$datap['store']=$_REQUEST['store'];
		$datap['remarks']=$_REQUEST['remarksP'];
		$datap['modifiedBy']=$_SESSION['UserID'];
		$datap['modifiedDate']=date('Y-m-d');
		$datap['transaction_time']=FormatDateForSQL($_REQUEST['date'])." ".date('H:i:s', time());
		$s->RecordEdit('physical_stock', $datap,"id=".$_REQUEST['phyStockid']);
		
			
	$last_id=$_REQUEST['phyStockid'];
	//$delete=DB_query("delete from physical_stock_details where physical_stock_id='".$_REQUEST['phyStockid']."'",$db);
	//$delete=DB_query("delete from stock_valuation_tbl where against_voucher_main_id='".$_REQUEST['phyStockid']."'	and type='PHY'",$db);		
			
	for($i=0;$i<count($_REQUEST['itemdataid']);$i++)
	{
		 if($_REQUEST['adjustment_type'][$i]!='plus')
         {
           $data= DB_query("SELECT pending_qty,against_tra_id FROM `stock_valuation_tbl` WHERE against_voucher_main_id='".$_REQUEST['phyStockid']."' AND mst_itemid='".$_POST['itemdataid'][$i]."' and type='PHY' ",$db);
           $pendigresult=  DB_fetch_array($data);
           $lastpendingqty=$pendigresult['pending_qty'];
           $againsttraid=$pendigresult['against_tra_id'];
           $pendingqty1 = $s->getField('stock_valuation_tbl','id', $againsttraid,'pending_qty');
           $newpendingqty = $pendingqty1+$lastpendingqty;
           
           DB_query("UPDATE stock_valuation_tbl SET pending_qty='".$newpendingqty."' WHERE id='".$againsttraid."'",$db);	
         }
         $delete=DB_query("delete from physical_stock_details where physical_stock_id='".$_REQUEST['phyStockid']."'",$db);
		 $delete=DB_query("delete from stock_valuation_tbl where against_voucher_main_id='".$_REQUEST['phyStockid']."'
		  and type='PHY'",$db);		

		$datac['physical_stock_id']=$last_id;
		$datac['mstitemid']=$_REQUEST['itemdataid'][$i];
		$datac['stock']=$_REQUEST['stock'][$i];
		$datac['adjustment_qty']=$_REQUEST['adjustment_qty'][$i];
		$datac['adjustment_type']=$_REQUEST['adjustment_type'][$i];
		$datac['remarks']=$_REQUEST['remarks'][$i];
		$datac['size_id']=$_REQUEST['sizesp'][$i];
		$datac['grade_id']=$_REQUEST['gradesp'][$i];
		$datac['uom']=$_REQUEST['uom'][$i];
		$datac['uom1']=$_REQUEST['uom1'][$i];
		$datac['conv_fac']=$_REQUEST['confac'][$i];
		$datac['stock_qty2']=$_REQUEST['secondaryqty'][$i];
		$datac['batch_no']=$_REQUEST['batchno'][$i];
		//echo "<pre>";
		//print_r($datac);
		$s->RecordInsert('physical_stock_details',$datac);
        
                    $dtls_Lastreq_id=DB_Last_Insert_ID($db,'physical_stock_details',$ErrMsg);
                    $primary_unit=$s->getField('item_master','id',$_POST['itemdataid'][$i],'mst_unitid');
                    $secondary_unit=$s->getField('item_master','id',$_POST['itemdataid'][$i],'conv_unit');
                    $data_stock['site']                     =$_REQUEST['site'];
                    $data_stock['store']                    =$_REQUEST['store'];
                    $data_stock['mst_itemid']               =$_POST['itemdataid'][$i];
                    $data_stock['size_id']                  =$_REQUEST['sizesp'][$i];
                    $data_stock['grade_id']                 =$_REQUEST['gradesp'][$i];
                    $data_stock['primary_unit']             =$primary_unit;
                    $data_stock['secondary_unit']           =$secondary_unit;
                    $data_stock['against_voucher_main_id']  =$last_id;
                    $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
                    $data_stock['date_of_mfg'] 				=FormatDateForSQL($_REQUEST['dateofmfg'][$i]);
                     $data_stock['date_of_expiry'] 			=FormatDateForSQL($_REQUEST['dateofexpiry'][$i]);
                    $data_stock['type']                     ='PHY';  
                     $data_stock['pending_qty']                 =$_REQUEST['adjustment_qty'][$i];   
                    if($_REQUEST['adjustment_type'][$i]=='plus')
                    {                  
                    $data_stock['inwardqty_primary']        =$_REQUEST['adjustment_qty'][$i];
                    $data_stock['inwardqty_secondary']      =$_REQUEST['secondaryqty'][$i];              
                    }
                    else
                    {
                    $data_stock['outwardqty_primary']        =$_REQUEST['adjustment_qty'][$i];
                    $data_stock['outwardqty_secondary']      =$_REQUEST['secondaryqty'][$i]; 	
                    }
                    $data_stock['trasaction']               =FormatDateForSQL($_REQUEST['date'])." ".date('H:i:s', time());
                    $data_stock['batch_no']                 =$_REQUEST['batchno'][$i];

                  $s->RecordInsert('stock_valuation_tbl', $data_stock);
	    }					
	
	$s->pageLocation("index.php?route=physical_adjustment_index".$rurl);	
}
?>

<script type="text/javascript" language="javascript">
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 GetStore(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("store").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","ajax_getstore.php?site="+str,true);
	xmlhttp.send();
}

function chkitemsstock(str)
{


	var site=document.getElementById("site").value;
	var date1=document.getElementById("textfield2").value;
	var hidcnt=document.getElementById("edit_cnt").value;
	var arritems=new Array();
	for(var i=0;i<hidcnt;i++)
	{
		if(document.getElementById("itemdataid1_"+i).value!='')
		{
			arritems[i]=document.getElementById("itemdataid1_"+i).value;
		}
		
	}
			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("__");
					var sp=data[0].split(",");
					var arrlength=sp.length;
					for(var t=0;t<arrlength;t++)
					{
						document.getElementById("Stockbalance_"+t).value=sp[t];
					}
				}
			}
			xmlhttp.open("GET","ajax_getstock_Edit.php?site="+site+"&storeid="+str+"&date2="+date1+"&itemsids="+arritems,true);
			xmlhttp.send();
}

function getOther(int)
{
	if(int=="other")
	{
	document.getElementById("otherReason").style.display="block";
	}
	else
	{
	document.getElementById("otherReason").style.display="none";
	}
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Physical Stock Adjustment Add</h1>
<form action="" method="post" name="myform">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<?php $dates=$s->getField('physical_stock','id',$id,'date1');  ?>
<input type="hidden" name="phyStockid" id="phyStockid" value="<?php echo $id; ?>" />
	   <td width="13%" align="right"><strong>Branch</strong></td>
		<td width="35%">
		<?php $ss="Select loccode, locationname from locations  where loccode='".$site."'";
	  	 $site_sql=DB_query($ss,$db);
		$siteRow=DB_fetch_array($site_sql);
		 ?>
		 <input type="hidden" name="site" id="site" value="<?php echo $siteRow['loccode']; ?>" readonly="" style="width:98%;"><?php echo $siteRow['locationname']; ?>
		</td>
	<td width="13%" align="right"><strong>ADJ. Voucher No.</strong></td>
    <td><input type="text" name="ADJ_voucher_no" id="ADJ_voucher_no" value="<?php echo $ADJ_voucher_no; ?>" readonly="" style="width:98%;"></td>
</tr>

<tr class="row1">
  <td align="right"><strong>Godown/Location</strong></td>
    <td><select name="store" id="store" style="width:98%;" onChange="chkitemsstock(this.value)">
        	<option value="0">Select</option>
		<?php $SQLStore=DB_query("SELECT id,StoreName FROM storetype where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($StoreDe=DB_fetch_array($SQLStore)){ 
			$selstore='';
			if($store==$StoreDe['id'])
			$selstore='selected';
			?>
			<option value="<?php echo $StoreDe['id']; ?>"<?php echo $selstore; ?>><?php echo $StoreDe['StoreName']; ?></option>
			<?php }?>
      </select></td>
    <td align="right"><strong>Date</strong></td>
    <td><input type="text" name="date" id="textfield2" value="<?php echo ConvertSQLDate($dates); ?>" style="width:98%;" readonly></td>
  </tr>

 <tr class="row1">
	<td align="right"s><strong>Remarks</strong></td>
	<td colspan="3"><textarea name="remarksP" style="width:99%;" rows="5"><?php echo $remarks; ?></textarea></td>
 </tr> 
 </table> 
<!-- <tr class="row1">
 <td class="tabledata1"><strong>Reason</strong>		</td>
 <td colspan="3">
		<?php
			
		 $mosql=DB_query("SELECT id,reason FROM reason_master where moduleid='".$_REQUEST['modid']."' and frm_id='".$_REQUEST['frmid']."' and reason_type='2' and created_by='".$_SESSION['UserID']."' and CompanyId='".$_SESSION['ACGCompanyId']."' order by created_date DESC",$db);
		$selectreason=DB_query("SELECT reason_id FROM log_reason where doc_id='".$_REQUEST['id']."' order by id DESC",$db);
		$secarr=DB_fetch_array($selectreason); ?>
		<select name="reason" id="reason" style="width:200px;" onchange="getOther(this.value)">
      <option value="">--Select--</option>
	 <?php while($mo=DB_fetch_array($mosql)){
	 ?>
	  <option value="<?php echo $mo['id']; ?>" <?php echo ($secarr['reason_id']==$mo['id']?'selected':'')?>><?php echo $mo['reason']; ?></option>
	  <?php }?>
	  <option value="other" <?php echo ($secarr['reason_id']=='other'?'selected':'')?>>Other</option>
    </select>
	<textarea name="otherReason" id="otherReason" style="display:none;"></textarea></td>
	</tr>
	<tr class="row1"></tr>
<!--<tr class="row1">
	<td class="tabledata1" colspan="4">
		<input type="button" onClick="addRow('dataTable')" value="Add More" class="search" />&nbsp;
		<input type="button"  onclick="deleteRow('dataTable')" value="Delete" class="search" />
	</td>
</tr>-->
<br>
	<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border:1px solid #808080;">
  		<tr>
			<th width="3%">S. No.</th>
			<th width="10%">Part Code</th>
			<!--<th>&nbsp;</th>-->
			<th>Part Name</th>
			<!--<th>UOM</th>-->
			<!--<th colspan="2" style="text-align:center;">Specification</th>-->
			<th width="5%">Adj. Type</th>
			<th width="7%"><center>Batch No.</center></th>
			<th width="7%"><center>Date of Mfg.</center></th>
			<th width="7%"><center>Date of Expiry</center></th>
			<th width="7%">Stock Qty</th>
			<th colspan="5" style="text-align:center;">Adjustment Qty</th>			
			<th width="11%">Remarks</th>
			<th width="1"></th>
		</tr>
 <tbody id="dataTable">
<?php
     $resultPhy=DB_query($str="select * from physical_stock where id='".$_REQUEST['id']."'",$db);
     $rowPhy=DB_fetch_array($resultPhy);

 $function_filter[0]=$rowPhy['site'];
 $function_filter[1]=$rowPhy['store'];
 $function_filter[2]=date('Y-m-d');
         $sizeItem=array();
     $resultSize=DB_query("select * from size_master",$db);
     $p=0;
     while($rowSize=DB_fetch_array($resultSize))
     { 
    $sizeItem[$p]['size']=$rowSize['size'];
    $sizeItem[$p]['id']=$rowSize['id'];  
      $p++; }
     $gradeItem=array(); $p=0;
      $resultGrade=DB_query("select * from product_grade",$db);
      while($rowGrade=DB_fetch_array($resultGrade))
      { 
        $gradeItem[$p]['id']=$rowGrade['id'];
      $gradeItem[$p]['grade']=$rowGrade['grade'];
       $p++; }

 $s=new db_query(); 
$i=1;
$recEdit2=$s->GetRecordById('physical_stock_details','physical_stock_id='.$_REQUEST['id']); 
 while($PhyDetails=DB_fetch_array($recEdit2)){

				/*$op=openingBalance($function_filter,$myrow['id']);
				$in_1=receivedMRN($function_filter,$myrow['id']);
				$out_1=issueSlip($function_filter,$myrow['id']);
				$out_2=issueSiteToSite($function_filter,$myrow['id']);    
				$in_2=receivedSiteToSite($function_filter,$myrow['id']);
				$out_3=issueMatarialReturn($function_filter,$myrow['id']);
				$in_3=receivedReturn($function_filter,$myrow['id']);  
				$out_4=Rgpchallan($function_filter,$myrow['id']);
				$out_5=Nrgp($function_filter,$myrow['id']);
				$in_4=Rgpreturn($function_filter,$myrow['id']);  
				$in_5=FinishedMR($function_filter,$myrow['id']);
				$in_6=MaterialConReceived($function_filter,$myrow['id']);
				$out_6=MaterialConIssue($function_filter,$myrow['id']);
				$in_7=PhysicalStockPlus($function_filter,$myrow['id']);
				$out_7=PhysicalStockMinus($function_filter,$myrow['id']);
				$out_8=dispatchIssue($function_filter,$myrow['id']);
				$out_9=jobWorkChallan57Issue($function_filter,$myrow['id']);
				$in_8=jobWorkChallan57Received($function_filter,$myrow['id']);
				$in_9=directPurchase($function_filter,$myrow['id']);
				$out_10=invoice($function_filter,$myrow['id']);
				$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8+$in_9);
				$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;*/
 
				$PartCode=$s->GetFieldValue('item_master',"id='".$PhyDetails['mstitemid']."'",'stockID');
				$PartName=$s->GetFieldValue('item_master',"id='".$PhyDetails['mstitemid']."'",'item_name');
				$UnitId=$s->GetFieldValue('item_master',"id='".$PhyDetails['mstitemid']."'",'mst_unitid');
				$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$PhyDetails['uom']."'",'unitname');
				$UnitName1=$s->GetFieldValue('unitsofmeasure',"unitid='".$PhyDetails['uom1']."'",'unitname');
				$confac=$s->GetFieldValue('item_master',"id='".$PhyDetails['mstitemid']."'",'conv_factor');

				$bachno=$PhyDetails['batch_no'];
				$dateofmfg=$s->GetFieldValue('stock_valuation_tbl',"against_voucher_dtls_id='".$PhyDetails['id']."'",'date_of_mfg');
				$dateofexpiry=$s->GetFieldValue('stock_valuation_tbl',"against_voucher_dtls_id='".$PhyDetails['id']."'",'date_of_expiry');


 		   $query = "SELECT SUM(inwardqty_primary) AS inwardqty_primary,SUM(outwardqty_primary) AS outwardqty_primary,date_of_mfg,date_of_expiry,batch_no	 FROM `stock_valuation_tbl` 
			 WHERE mst_itemid = '".$PhyDetails['mstitemid']."' AND site='".$rowPhy['site']."' AND store='".$rowPhy['store']."' AND batch_no='".$bachno."' GROUP BY batch_no";
	//echo $query;
	$sql = DB_query($query,$db); 
	$a=0;
	// if(DB_num_rows($sql)>0)
	// {
		while($myrow=DB_fetch_array($sql))
		{
			//print_r($myrow);
			$qty=$myrow['inwardqty_primary'] - $myrow['outwardqty_primary'];
			//echo $qty;
		
	// }

//echo "***".$qty;


?>
 <tr bgcolor="#fff">
	<td><?php echo $i; ?></td>
	<td><?php echo $PartCode; ?><input type="hidden" id="itemdataid_<?php echo $i; ?>"  name="itemdataid[]" value="<?php echo $PhyDetails['mstitemid']; ?>" /></td>
	<td><?php echo $PartName; ?></td>
	<td><select name="adjustment_type[]" style="width:98%;" id="adj_<?php echo $i; ?>" onchange="selectFunction()">
	<option value="plus"<?php echo($PhyDetails['adjustment_type']=='plus'?'selected':''); ?>>Plus</option>
	<option value="minus"<?php echo($PhyDetails['adjustment_type']=='minus'?'selected':''); ?>>Minus</option>
	</select> </td>

	<!--<td><?php //echo $UnitName; ?><input type="hidden" name="uom[]" value="<?php //echo $PhyDetails['uom'] ?>"></td>
	 <td><select  name="sizesp[]" id="sizesp_<?php //echo $i; ?>"  style="width:80px;"  onchange="showconvac(this.value,this.id);"   >
    <option value="0">Select</option>
   <?php /* $k=0;
       while($k < count($sizeItem))
       { ?>
  <option value="<?php echo $sizeItem[$k]['id']; ?>" <?php echo ($sizeItem[$k]['id'] == $PhyDetails['size_id'])?'selected="selected"':''; ?>> <?php echo $sizeItem[$k]['size']; ?></option>
        <?php  $k++; }
    
    ?>
   
   </select> </td>
   <td><select  name="gradesp[]"  style="width:80px;"  >
   
   <option value="0">Select</option>
    <?php $k=0;
       while($k < count($gradeItem))
       { ?>
  <option value="<?php echo $gradeItem[$k]['id']; ?>" <?php echo ($gradeItem[$k]['id'] == $PhyDetails['grade_id'])?'selected="selected"':''; ?>> <?php echo $gradeItem[$k]['grade']; ?></option>
        <?php  $k++; }
    
   */ ?>
   
   </select></td>-->
   <td><input type="text" name="batchno[]"  id="batchno_1"  value="<?php echo $bachno ;?>" ondblclick="displayBatch(this.value,this.id);" readonly /></td>
<td><input id="dateofmfg_1" class="adatepicker" type="text" style="width:98%;" value="<?php echo $dateofmfg; ?>" name="dateofmfg[]"readonly></td>
<td><input id="dateofexpiry_1" class="adatepicker" type="text" style="width:98%;" value="<?php echo $dateofexpiry; ?>" name="dateofexpiry[]" readonly>
</td>
	<td id="stockbal"><input type="text" name="stock[]"  id="Stockbalance_<?php echo $i; ?>" value="<?php echo $qty; //echo $stockallitems; ?>" style="width:98%;" readonly/></td>
	<td width="7%"><input type="text" name="adjustment_qty[]" onkeypress="return isNumberKey(event)"  value="<?php echo $PhyDetails['adjustment_qty']; ?>"   style="width:98%;" onkeypress="return isNumberKey(event)" onkeyup="chk_recived_qty(this.value,this.id);"  id="adjustment_qty_<?php echo $i; ?>" /></td>
	<td width="1"><input  type="hidden" name="confac[]" style="width:98%;"  id="confac_<?php echo $i; ?>" value="<?php echo $PhyDetails['conv_fac']; ?>"   /></td>
    <td width="7%"><select name="uom[]" id="uom_1" style="width:98%;">   
	  <option value='<?php echo $PhyDetails['uom']; ?>'><?php echo $UnitName; ?></option></select></td>
    <td width="7%"><input  type="text" name="secondaryqty[]" style="width:98%;"  id="secondary_<?php echo $i; ?>" value="<?php echo $PhyDetails['stock_qty2']; ?>"  readonly /></td>  
	<td width="7%"><select name="uom1[]" id="uom1_1" style="width:98%;">
	  <option value='<?php echo $PhyDetails['uom1']; ?>'><?php echo $UnitName1; ?></option> </select>
	</td>
	<td><input type="text" name="remarks[]"  id="remarks_<?php echo $i; ?>" value="<?php echo $PhyDetails['remarks']; ?>" style="width:98%;" /></td>
	<td><input  type="hidden"  style="width:98%;"  id="confactor_<?php echo $i; ?>" value="<?php echo $confac; ?>"   /></td>
  </tr>
<?php $i++;}}?> 
  </tbody>
</table>
<p align="center">
	<input type="submit" class="search" name="update" value="Update" onclick="return validate();">
	<input type="submit" name="Cancel" class="search" value="Cancel">
	</p>
<div class="body_lightbox1" id="lightbox1" style="overflow:auto; width:600px; height:298%; display:none;"></div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
</form>


</div></div>
<script language="javascript" type="text/javascript">
function showconvac(str,id)
{
  
var brk=id.split('_');

if(str=='0')
{

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

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

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

 var xmlhttp;
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  if(brk[1]==undefined)
  { 
  document.getElementById("confac").value=xmlhttp.responseText;
  var id1="adjustment_qty";
  var hrdvalue=document.getElementById(id1).value;
  chk_recived_qty(hrdvalue,id1);
    }
  else
  {
  document.getElementById("confac_"+brk[1]).value=xmlhttp.responseText;
  var id1="adjustment_qty_"+brk[1];
  var hrdvalue=document.getElementById(id1).value;
  chk_recived_qty(hrdvalue,id1);
     }
  //document.getElementById("empdta").innerHTML=data[1];
  //var id1="stock_qty_"+brk[1];
  //var hrdvalue=document.getElementById(id1).value;
  //calcValue1(hrdvalue,id1);
  
  }
  }

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

}




}
function chk_recived_qty(val,id)
{
  var id1=id.split("_");
  var i=id1[2];
 //alert(i);
  if(id1[2]==undefined)
  {
    var stockBal = document.getElementById("Stockbalance").value;
    //var isuRate = document.getElementById("issuerate").value;
    var confac=document.getElementById("confac").value;
   if(confac=='') confac=0;
     //if(isuRate==''){isuRate=0}
     // var totamt = parseFloat(isuRate)*val;
     // document.getElementById("totalamt").value=totamt.toFixed(2);
      var secondaryqty=parseFloat(val)*parseFloat(confac);
      document.getElementById("secondary").value=secondaryqty.toFixed(2);
   
  }
  else
  {
    var stockBal = document.getElementById("Stockbalance_"+i).value; 
    //alert(stockBal);
    var confac=document.getElementById("confac_"+i).value; 
     if(confac=='') confac=0;  
    var secondaryqty=parseFloat(val)*parseFloat(confac);
    document.getElementById("secondary_"+i).value=secondaryqty.toFixed(2);
    }
  }

function hiderow(i,id)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			data=xmlhttp.responseText;
			//document.getElementById("hide_"+i).style.innerHTML=data;
			document.getElementById("hide_"+i).style.display='none';
		}
	}
	xmlhttp.open("GET","ajax_Delete_phy_item.php?idItem="+id,true);
	xmlhttp.send();
}
function openPopupProfile(i)
{ 
		window.open("issu_searchpopup.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}

function opendata(str,id)
{

   var sitecode=document.getElementById("site").value;
   var date=document.getElementById("textfield2").value;
   
  if (str.length == 0)
    {    	
     document.getElementById("lightbox1").innerHTML="";
     document.getElementById("lightbox1").style.border="0px";
     return;
    }	
	if(sitecode=='0')
	{
	alert("Must Select Site");
	document.getElementById("site").focus();
	return;
	}
	else if(date=='')
	{
	alert("Must Select Date");
	document.getElementById("textfield2").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;
 

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


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

function getItemsList1(id,code,shade,netrate,stockbalance,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 = stockbalance;
	//}
	}
	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 = stockbalance;
	//}	
	}	
	document.getElementById("lightbox1").style.display='none';
	//var data= addRow('dataTable')
	
}

function validate()
{
	var item_count=0;
	var remarks_count=0;
	
	 jQuery('input[id^=itemdataid_]').each(function()
	 {
         
         var val_item=(jQuery(this).val());
         if(val_item=='')
         {
         	item_count+=1;
         }
            
           
	 });
           
	     if(item_count>0)
            {
            	alert("Please Select at least one item");
            	return false;
            }

            jQuery('input[id^=remarks_]').each(function()
	        {
         
			         var val_remarks=(jQuery(this).val());
			         if(val_remarks=='')
			         {
			         	remarks_count+=1;
			         }
            });

              if(remarks_count>0)
            {
            	alert("Please Write Remarks");
            	return false;
            }

}

</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>
