<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 4;
$PageName = 'Site to Site Transfer Issue';
include('includes/DefinePOClass.php');
include('includes/stockcalculation.php');
date_default_timezone_set('Asia/Calcutta');

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

									        $sql = "update transfer_issue set  
													remarks='".$_REQUEST['remarks']."',
													transporter_name='".$_REQUEST['transport']."',
													vehicle_no='".$_REQUEST['vehicle_no']."',
													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 transfer_issue_details where transfer_issue_id='".$_REQUEST['id']."'",$db);
                            

                $result = DB_query("select pending_qty,against_tra_id from stock_valuation_tbl 
                  where against_voucher_main_id = '".$_REQUEST['id']."' and type='STI'",$db);
                $data = DB_fetch_array($result);
                $pendingqty =  $s->getField('stock_valuation_tbl','id',$data['against_tra_id'],'pending_qty');
                $totalqty=$pendingqty+$data['pending_qty'];
                Db_query("Update stock_valuation_tbl set pending_qty='".$totalqty."',flag=0 where id='".$data['against_tra_id']."'",$db);
              
                DB_query("delete from stock_valuation_tbl where against_voucher_main_id='".$_REQUEST['id']."' and type='STI'",$db);

              	for($i=0; $i < count($_REQUEST['issueqty']) ;$i++)
							 {						 
					             if($_REQUEST['issueqty'][$i]!='')
					             {
            					     $sql2="INSERT INTO transfer_issue_details set
                                    transfer_issue_id='".$Lastreq_id."', 
                                    itemid='".$_REQUEST['itemdataid'][$i]."', 
                                    current_balance='".$_REQUEST['stock'][$i]."', 
                                    issueqty='".$_REQUEST['issueqty'][$i]."', 
                                    conv_fac='".$_REQUEST['confac'][$i]."', 
                                    uom='".$_REQUEST['uomid'][$i]."',
                                    uom1='".$_REQUEST['uomid1'][$i]."',
                                    item_description='".$_REQUEST['desc'][$i]."',
                                    issueqty1='".$_REQUEST['secondaryqty'][$i]."', 
                                    mfg='".ConvertSQLDate($_REQUEST['dateofmfg'][$i])."', 
                                    expiry='".ConvertSQLDate($_REQUEST['dateofexpiry'][$i])."', 
                                    batch_no='".$_REQUEST['batch_no'][$i]."'";
                      $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');

                        $insertResult2 = DB_query($sql2,$db,$ErrMsg);

                        $dtls_Lastreq_id=DB_Last_Insert_ID($db,'transfer_issue_details',$ErrMsg);
                               
                   $check_current_opening="Select * from stock_valuation_tbl where  site='".$_REQUEST['site']."'
                   and  store='".$_REQUEST['store']."' and mst_itemid='".$_POST['itemdataid'][$i]."' 
                    and batch_no='".$_REQUEST['batch_no'][$i]."'    and flag=0 order by id ASC ";
                   $check_current_op_result=DB_query($check_current_opening,$db);
                  if(DB_num_rows($check_current_op_result)=='0')
                  {
                  }
                  else
                  {                    
                      $pendingqty=$_REQUEST['issueqty'][$i];
                      $t=0;
                      while($check_current_op_row=DB_fetch_array($check_current_op_result))
                      {
                        if($pendingqty!='0.00')
                        {
                          $id=$check_current_op_row['id'];
                          if($check_current_op_row['pending_qty']!='0.00')
                          {
                              if($check_current_op_row['pending_qty']>$pendingqty)
                              {
                                  $inwardpenqty=$check_current_op_row['pending_qty']-$pendingqty;
                                  $outwards_qty=$pendingqty;
                                  $outward_rate=$check_current_op_row['inward_rate'];
                                  $outwardamount=$check_current_op_row['inward_rate']*$outwards_qty;
                              }
                              else
                              {
                                  $inwardpenqty=0;
                                  $outwards_qty=$check_current_op_row['pending_qty'];
                                  $outward_rate=$check_current_op_row['inward_rate'];
                                  $outwardamount=$check_current_op_row['inward_rate']*$outwards_qty;
                              }
                 
                             $primary_unit=$s->getField('item_master','id',$_POST['itemdataid'][$i],'mst_unitid');
                             $secondary_unit=$s->getField('item_master','id',$_POST['itemdataid'][$i],'conv_unit');
                             $confac=$s->getField('item_master','id',$_POST['itemdataid'][$i],'conv_factor');
                             $data_stock['site']                     =$_REQUEST['site'];
                             $data_stock['store']                    =$_REQUEST['store'];
                             $data_stock['mst_itemid']               =$_POST['itemdataid'][$i];
                             $data_stock['primary_unit']             =$primary_unit;
                             $data_stock['secondary_unit']           =$secondary_unit;
                             $data_stock['against_voucher_main_id']  =$Lastreq_id;
                             $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
                             $data_stock['against_tra_id']           =$check_current_op_row['id'];
                             $data_stock['type']                     ='STI';    
                             if($check_current_op_row['status']=='1')
                              $data_stock['status']=1;
                             else
                              $data_stock['status']=0;               
                             $data_stock['outwardqty_primary']       = $outwards_qty;
                             $data_stock['pending_qty']              =$outwards_qty;
                             $data_stock['outwardqty_secondary']     = $outwards_qty*$confac;  
                             $data_stock['inward_rate']             =$outward_rate;
                             $data_stock['outward_value']            =$outwardamount;
                             $data_stock['batch_no']                 =$_REQUEST['batch_no'][$i];
                             $data_stock['date_of_mfg']              =FormatDateForSQL($_REQUEST['dateofmfg'][$i]);
                             $data_stock['date_of_expiry']           =FormatDateForSQL($_REQUEST['dateofexpiry'][$i]);
                             $data_stock['trasaction']               =FormatDateForSQL($_REQUEST['issuedate'])." ".date('H:i:s', time());
                            $insertResult2 =$s->RecordInsert('stock_valuation_tbl', $data_stock);
                             $pendingqty=$pendingqty-$outwards_qty;
                             if($inwardpenqty!=0)
                                $status=0;
                            else
                              $status=1;
                            $update_summary="Update  stock_valuation_tbl set pending_qty='".$inwardpenqty."',
                                       flag='".$status."' where id=$id ";
                            $result2=DB_query($update_summary,$db);
                      }
                }   
                 $t++;  
                     
              }
           }                              
				               }
				         }

			}
		if($insertResult2 == true)
        {
	$_SESSION['success_msg']="Saved Successfully";
	 echo "<script>location.href='index.php?route=Inventory/transation/site_transfer_issue_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
       }	  
	}
 ?>
 <?php
   // $duprecord=$s->getField('transfer_receipt','issue_slipno',$_REQUEST['id'],'issue_slipno');
   // if($duprecord!='')
   // {

   // }

     $resultEdit=DB_query("select * from transfer_issue where id='".$_REQUEST['id']."'",$db);
     $rowEdit=DB_fetch_array($resultEdit);
     $function_filter[0]=$rowEdit['sitecode'];
     $function_filter[1]=$rowEdit['tostore'];
     $function_filter[2]=date('Y-m-d');   
  ?>

<div class="body_contain">
<div class="tab_div">
 <h1>Site to Site Transfer Issue</h1>
<form name="form1" onsubmit="return chkValidate();" method="post">
<div align="center">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
  <tr class="row1">
    <td width="13%" align="right">From Branch</td>
    <td width="20%"><select name="site"  id="site">
	   <option value="<?php echo $rowEdit['sitecode'] ?>"><?php echo $s->getField('locations','loccode',$rowEdit['sitecode'],'locationname'); ?></option>
    </select></td>     
    <td width="13%" align="right">Issue Slip No.</td>
    <td width="20%"><input name="issue_slipno" type="text" id="issue_slipno" readonly="readonly" value="<?php echo $rowEdit['issue_slipno']; ?>"></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($rowEdit['issuedate'])); ?>" size="15" class="datepicker" /></td>
  </tr>
  <tr class="row1">
  	<td align="right">To Branch</td>
    <td><select name="sitecode2" id="sitecode2">
	 <option value="<?php echo $rowEdit['sitecode_to']; ?>"><?php echo $s->getField('storetype','id',$rowEdit['sitecode_to'],'StoreName'); ?></option>
    </select></td>
  	<td align="right">Against</td>
    <td><input type="text" value="<?php echo $rowEdit['transfer_type']; ?>" /></td>
    <td align="right">MR Number</td>
    <td id="tdShowMRN"><input type="text" value="<?php
           if($rowEdit['transfer_type']=='MRN')
           {
             $dis="readonly";
             echo $s->getField('addmrn','id',$rowEdit['mrn_number'],'MRNNo'); 
            }
        else
        {
          $dis="";
       echo $rowEdit['mrn_number'];
        }
     ?>" /></tr>
    <tr class="row1">
      <td align="right">Transport Name</td>
      <td><input type="text" name="transport" value="<?php echo $rowEdit['transporter_name']; ?>" id="transport" /></td> 
      <td align="right">Vehicle No.</td>
      <td><input type="text" name="vehicle_no" value="<?php echo $rowEdit['vehicle_no']; ?>" id="vehicle_no" /></td>
      <td align="right">Store</td>
    	<td><select name="store">
              <option value="<?php echo $rowEdit['tostore']; ?>"> <?php echo $s->getField('storetype','id',$rowEdit['tostore'],'StoreName'); ?></option>
          </select></td>
    </tr>
</table>
</div>
<p align="left">
 <?php
    if($_REQUEST['action']=='Edit')
    {
  ?>
<span style="display:<?php echo ($rowEdit['transfer_type']=='MRN')?'none':'block'; ?>; text-align:left;">
<input type="button" onclick="opendata()" value="Pick Item" class="search" />&nbsp;
<input type="button" class="search"  onclick="deleteRow_return('dataTable')" value="Delete" />
</span>
<?php } ?>
</p>
<div id="divShowSiteTransfer" >

<table width="100%" id="" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>
     <th width="2%"></th>
     <th width="10%">Item Code</th>
     <th width="1"></th>
     <th>Item Name</th>
     <th width="10%">Pkg description</th>
     <th width="8%">Batch No.</th>
     <th width="7%">Date of Mfg.</th>
     <th width="7%">Date of Expiry</th>           
     <!--<th class="tabledata1" colspan="2"><center>Specification</center></th>-->
	   <th width="7%">Batch Stock Qty.</th>
	   <!--<th class="tabledata1">Batch No.</strong></th>-->
     <th colspan="7" style="text-align:center">Issue Qty.</th>
    <th width="1"></th>
  </tr>
  <tbody id="dataTable">
    <?php 
/* 
*/
      $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++; 
      }

     $resultItem=DB_query("select * from transfer_issue_details where transfer_issue_id='".$_REQUEST['id']."'",$db);
     $i=0;
     while($rowIetm=DB_fetch_array($resultItem))
     { 
        $unitid=$rowIetm['uom'];
        $unitid1=$rowIetm['uom1'];
        $unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');
        $unit1=$s->getField('unitsofmeasure','unitid',$unitid1,'unitname');

         /*  $op=openingBalance($function_filter,$rowIetm['itemid']);
        $in_1=receivedMRN($function_filter,$rowIetm['itemid']);
        $out_1=issueSlip($function_filter,$rowIetm['itemid']);
        $out_2=issueSiteToSite($function_filter,$rowIetm['itemid']);    
        $in_2=receivedSiteToSite($function_filter,$rowIetm['itemid']);
        $out_3=issueMatarialReturn($function_filter,$rowIetm['itemid']);
        $in_3=receivedReturn($function_filter,$rowIetm['itemid']);  
        $out_4=Rgpchallan($function_filter,$rowIetm['itemid']);
        $out_5=Nrgp($function_filter,$rowIetm['itemid']);
        $in_4=Rgpreturn($function_filter,$rowIetm['itemid']);  
        $in_5=FinishedMR($function_filter,$rowIetm['itemid']);
        $in_6=MaterialConReceived($function_filter,$rowIetm['itemid']);
        $out_6=MaterialConIssue($function_filter,$rowIetm['itemid']);
        $in_7=PhysicalStockPlus($function_filter,$rowIetm['itemid']);
        $out_7=PhysicalStockMinus($function_filter,$rowIetm['itemid']);
        $out_8=dispatchIssue($function_filter,$rowIetm['itemid']);
        $out_9=jobWorkChallan57Issue($function_filter,$rowIetm['itemid']);
        $in_8=jobWorkChallan57Received($function_filter,$rowIetm['itemid']);
        $in_9=directPurchase($function_filter,$rowIetm['itemid']);
        $in_10=saleReturn($function_filter,$rowIetm['itemid']);
        $out_10=invoice($function_filter,$rowIetm['itemid']);
         $invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8+$in_9 + $in_10);
        $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) as inward,sum(outwardqty_primary) as outward from stock_valuation_tbl where site='".$rowEdit['sitecode']."' and store='".$rowEdit['tostore']."' and mst_itemid='".$rowIetm['itemid']."' and batch_no='".$rowIetm['batch_no']."' ";
        $result_batch_stock=DB_query($sql_batch_stock,$db);
        $rs_batch_stock=DB_fetch_array($result_batch_stock);
       $current_stock=$rs_batch_stock[0]-$rs_batch_stock[1];
        
        $confac=$s->getField('item_master','id',$rowIetm['itemid'],'conv_factor');
        
        if($rowEdit['transfer_type']=='MRN')
        {?>
          <tr>
             <td><input name="delitem[]" type="checkbox"  id="delitem" /></td>
             <td><input type="text" value="<?php echo $s->getField('item_master','id',$rowIetm['itemid'],'StockID');  ?>" tabindex="" readonly id="itemcode_<?php echo $i; ?>" name="itemcode[]"  /></td>
             <td><input  type="hidden"   readonly="" value="<?php echo $rowIetm['itemid']; ?>"  id="itemdataid_<?php echo $i; ?>"  name="itemdataid[]" /></td>
             <td><input type="text" name="item_name[]"  id="itemname_<?php echo $i;?>" value="<?php echo $s->getField('item_master','id',$rowIetm['itemid'],'item_name');  ?>"  readonly></td>
             <td><input type="text" name="desc[]"  id="desc<?php echo $i; ?>" size="25"  value="<?php echo $rowIetm['item_description']; ?>" /></td>
             <td><input  type="text" name="batch_no[]"  id="batchno_<?php echo $i; ?>" readonly value="<?php echo $rowIetm['batch_no']; ?>"   /></td>
             <td><input type="text"  name="dateofmfg[]" class="adatepicker" readonly value="<?php echo ConvertSQLDate($rowIetm['mfg']); ?>" id="dateofmfg_1"  /></td>
             <td><input type="text"  name="dateofexpiry[]" class="adatepicker" readonly value="<?php echo ConvertSQLDate($rowIetm['expiry']);?>" id="dateofexpiry_1"  /></td>
             <td><input type="text" name="stock[]" id="stock_<?php echo $i; ?>" value="<?php echo $current_stock; //echo $stockbalance + $rowIetm['issueqty']; ?>" readonly   /></td> 
             <td width="5%"><input  type="text" name="issueqty[]" readonly onkeyup="chk_recived_qty(this.value,this)" onkeypress="return isNumberKey(event)" id="reciveqty_<?php echo $i; ?>" <?php echo $dis; ?> value="<?php echo $rowIetm['issueqty']; ?>" /></td>
             <td width="1"><input  type="hidden" name="confac[]"  id="confac_<?php echo $i; ?>" value="<?php echo $rowIetm['conv_fac']; ?>" /></td>
             <td width="5%"><input  type="text" name="uom[]"  id="uom_<?php echo $i; ?>" value="<?php echo $unit; ?>"  readonly /></td>
             <td width="5%"><input  type="text" name="secondaryqty[]" readonly  id="secondary_<?php echo $i; ?>" value="<?php echo $rowIetm['issueqty1']; ?>"  <?php echo $dis; ?>  /></td>
             <td width="5%"><input  type="text" name="uom1[]"  id="uom1_<?php echo $i; ?>" value="<?php echo $unit1; ?>" readonly /></td>
             <td width="1"><input  type="hidden"   id="confactor_<?php echo $i; ?>" value="<?php echo $confac; ?>" /></td>
             <td width="1"><input  type="hidden"  name="uomid1[]"  id="uomid1_<?php echo $i; ?>" value="<?php echo $unitid1; ?>" /></td>
             <td><input  type="hidden"  name="uomid[]"  id="uomid_<?php echo $i; ?>" value="<?php echo $unitid; ?>"/></td>   
          </tr>
        <?php 
        }
        else
        {?>
            <tr>
 <td><input name="delitem[]" type="checkbox"  id="delitem" /></td>
 <td><input type="text" value="<?php echo $s->getField('item_master','id',$rowIetm['itemid'],'StockID');  ?>" tabindex="" readonly id="itemcode_<?php echo $i; ?>" name="itemcode[]"  /></td>
 <td><input  type="hidden"   readonly="" value="<?php echo $rowIetm['itemid']; ?>"  id="itemdataid_<?php echo $i; ?>"  name="itemdataid[]" /></td>
 <td><input type="text" name="item_name[]"  id="itemname_<?php echo $i;?>" value="<?php echo $s->getField('item_master','id',$rowIetm['itemid'],'item_name');  ?>"  readonly></td>
 <td><input type="text" name="desc[]"  id="desc<?php echo $i; ?>" size="25"  value="<?php echo $rowIetm['item_description']; ?>" readonly/></td>
 <td><input  type="text" name="batch_no[]" readonly id="batchno_<?php echo $i; ?>"  ondblclick="displayBatch(this.value,this.id);" value="<?php echo $rowIetm['batch_no']; ?>"   /></td>
 <td><input type="text"  name="dateofmfg[]" class="adatepicker" readonly value="<?php echo ConvertSQLDate($rowIetm['mfg']); ?>" id="dateofmfg_1"  /></td>
 <td><input type="text"  name="dateofexpiry[]" class="adatepicker" readonly value="<?php echo ConvertSQLDate($rowIetm['expiry']);?>" id="dateofexpiry_1"  /></td>
 <td><input type="text" name="stock[]" id="stock_<?php echo $i; ?>" value="<?php echo $current_stock; //echo $stockbalance + $rowIetm['issueqty']; ?>" readonly   /></td> 
 <td width="5%">
    <input  type="text" name="issueqty[]" onkeyup="chk_recived_qty(this.value,this)" onkeypress="return isNumberKey(event)" 
    id="reciveqty_<?php echo $i; ?>"  <?php echo $dis; ?>  value="<?php echo $rowIetm['issueqty']; ?>"/>
 </td>
 <td width="1"><input  type="hidden" name="confac[]"  id="confac_<?php echo $i; ?>" value="<?php echo $rowIetm['conv_fac']; ?>" /></td>
 <td width="5%"><input  type="text" name="uom[]"  id="uom_<?php echo $i; ?>" value="<?php echo $unit; ?>"  readonly /></td>
 <td width="5%"><input  type="text" name="secondaryqty[]"  id="secondary_<?php echo $i; ?>" value="<?php echo $rowIetm['issueqty1']; ?>"  <?php echo $dis; ?>  /></td>
 <td width="5%"><input  type="text" name="uom1[]"  id="uom1_<?php echo $i; ?>" value="<?php echo $unit1; ?>" readonly /></td>
 <td width="1"><input  type="hidden"   id="confactor_<?php echo $i; ?>" value="<?php echo $confac; ?>" /></td>
 <td width="1"><input  type="hidden" name="uomid1[]"  id="uomid1_<?php echo $i; ?>" value="<?php echo $unitid1; ?>" /></td>
 <td><input  type="hidden" name="uomid[]"  id="uomid_<?php echo $i; ?>" value="<?php echo $unitid; ?>"/></td>   
          </tr>
        <?php 
        }
       ?>
<?php $i++; } ?> 
   </tbody>
</table>
<div class="body_lightbox1" id="lightbox1" style="overflow:auto; width:600px; height:250px; display:none;"></div>
<input type="hidden" name="hiditemcount" value="<?php echo $i; ?>" id="hiditemcount"  />
  <input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
  <input type="hidden" name="" value="<?php echo $i; ?>" id="rowcount1" />
<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" cols="" rows="" style="height:60px;"><?php echo $rowEdit['remarks']; ?></textarea></td>
  </tr>
</table>
<?php if($_REQUEST['action']=='Edit')
{ ?>
   <p align="center"><input type="submit" name="Save" value="Save" class="search" /></p>
   <?php } ?>



</div><!--divShowSiteTransfer-->
</form>
</div>
</div>




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


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="reciveqty";
  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="reciveqty_"+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="reciveqty";
  var hrdvalue=document.getElementById(id1).value;
  chk_recived_qty(hrdvalue,id1);
    }
  else
  {
  document.getElementById("confac_"+brk[1]).value=xmlhttp.responseText;
  var id1="reciveqty_"+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,obj)
{
        
        var total_issue_amount;
      var itamdatid=new Array();
     jQuery('input[id^=itemdataid_]').each(function(){
      itamdatid.push(parseInt(jQuery(this).val()));
          //alert(partic_pack);
      }); 
     
      var batch_no=new Array();
     jQuery('input[id^=batchno_]').each(function(){
         batch_no.push(parseInt(jQuery(this).val()));
          //alert(partic_pack);
    });   


        var issue_amount = new Array();
        jQuery('input[id^=reciveqty_]').each(function(){
         issue_amount.push(parseInt(jQuery(this).val()));
          //alert(partic_pack);
    });

     var issue_amount = new Array();
        jQuery('input[id^=reciveqty_]').each(function(){
         issue_amount.push(parseInt(jQuery(this).val()));
          //alert(partic_pack);
    }); 

        var i;
for(i = 0; i < itamdatid.length; i++){
     
 for (var j = 0; j < itamdatid.length; j++) 
            {
                if (i != j) 
                {
                    if (itamdatid[i] == itamdatid[j] && batch_no[i]==batch_no[j]) 
                    {

                       total_issue_amount = issue_amount[i]+issue_amount[j];

                       var stock=parseInt($(obj).closest('tr').find('td:eq(8)').find('input').val());
                       if(stock<total_issue_amount)
                           {
                            alert("Quantity can not be greater then stock");
                            $(obj).closest('tr').find('td:eq(9)').find('input').val("");
                            $(obj).closest('tr').find('td:eq(12)').find('input').val("");
                            return false;
                           }
                           else{
                             var disamt = parseFloat(amount * val);         
                              $(obj).closest('tr').find('td:eq(12)').find('input').val(disamt);
                            }

                       //alert(total_issue_amount)
                      
                        //return true; // means there are duplicate values
                    }
                }
            }

      
}
    
 //alert(total_issue_amount);
     // alert(itamdatid);
      //alert(batch_no);
     // alert(issue_amount);





   var amount = $(obj).closest('tr').find('td:eq(10)').find('input').val();
  
    var stock=parseInt($(obj).closest('tr').find('td:eq(8)').find('input').val());
    //alert(stock);
       //var val=parseInt(value);

 if(stock<val)
       {
        alert("Quantity can not be greater then stock");
        $(obj).closest('tr').find('td:eq(9)').find('input').val("");
        $(obj).closest('tr').find('td:eq(12)').find('input').val("");
        return false;
       }
       else{
         var disamt = parseFloat(amount * val);         
          $(obj).closest('tr').find('td:eq(12)').find('input').val(disamt);
        }

        
}



/*function chk_recived_qty(obj)
{
    var stockQty=$(obj).closest('tr').find('td:eq(7)').find('input[type="text"]').val();
      if(parseFloat(stockQty) < parseFloat($(obj).val()) )
      {
      	alert(' Received quantity should be less stock quantity');
      	$(obj).val(stockQty);
      }
}*/


  function changeQty(value,obj)
   {


       var stock=parseInt($(obj).closest('tr').find('td:eq(8)').find('input').val());
       var val=parseInt(value);
      //alert(stock);
       if(stock<value)
       {
        alert("Quantity can not be greater then stock");
        $(obj).closest('tr').find('td:eq(9)').find('input').val("");
       }
       var unit=$(obj).closest('tr').find('td:eq(9)').find('input').attr('data');
      // alert(unit);
         var total =parseFloat(value * unit);
        // alert(total);
         $(obj).closest('tr').find('td:eq(12)').find('input').val(total);
          
         var rates = $(obj).closest('tr').find('td:eq(13)').find('input').val();
        
         var total='';
         if(rates!='')
         {
          //var qty = $(obj).closest('tr').find('td:eq(9)').find('input')
          // var total = rates * value;
         //  $(obj).closest('tr').find('td:eq(14)').find('input').val(total);
         }
        // $(obj).closest('tr').find('td:eq(17)').find('input').val(total)
        /* if(discount!='')
            {
              disamt = parseFloat(total *  discount/100);
              $(obj).closest('tr').find('td:eq(15)').find('input').val(disamt);
              var tot = total - disamt;
              $(obj).closest('tr').find('td:eq(16)').find('input').val(tot);
      }
      else
        $(obj).closest('tr').find('td:eq(17)').find('input').val(total);*/

     // calculateBasicAmount(); 


    /*if(id.indexOf("_")!='-1')
    {
      var brk=id.split('_');
      //var unit = document.getElementById('u1_'+brk[1]).value;
      var unit = $('#q1_'+brk[1]).attr('data');//document.getElementById('u1_'+brk[1]).value;

      //document.getElementById('u1_'+i).value =unit ;
      var total = parseFloat(str * unit);
      document.getElementById("q2_"+brk[1]).value=total;

      var rates = document.getElementById("rates_"+brk[1]).value;
      total_amt = parseFloat(rates*str);
      document.getElementById("amounts_"+brk[1]).value =total_amt.toFixed(2); 
      document.getElementById("basicamt_"+brk[1]).value =total_amt.toFixed(2); 
      calculateBasicAmount();
    }
    else
    {
      //var unit = document.getElementById('u1').value;
      var unit = $('#q1').attr('data');//document.getElementById('u1_'+brk[1]).value;

      var total = parseFloat(str * unit);
      document.getElementById("q2").value=total;
      var rates = document.getElementById("rates").value;
      total_amt = parseFloat(rates*str);
      document.getElementById("amounts").value= total_amt.toFixed(2);
      document.getElementById("basicamt").value =total_amt.toFixed(2); 
      calculateBasicAmount();
    }*/
  }








function get_MRN_number(obj)
{
	      if($('#site').val()=='0')
	      {
	      	alert('Please select from branch.');
	      	return false;
	      }
            
            if($(obj).val()=='MRN')
            {   $('#divShowSiteTransfer').html('');
	          $.ajax({
						url : "get_mrn_by_site.php",
						type : "POST",
						data : {
						action:'getMRN',	
						site:$('#site').val()
						},
						success : function(data) {//alert(data);
		                    $('#tdShowMRN').html(data);
												 }
					       });
	      }
	      else
	      {
	      	 $('#tdShowMRN').html('<input name="mrnno" type="text" />');
	      	 $.ajax({
						url : "get_struct_dirct_transfer.php",
						type : "POST",
						data : {
						},
						success : function(data) {//alert(data);
		                $('#divShowSiteTransfer').html(data);
												 }
					       });
	      }

}
function get_store_by_site()
{//getStore
     if($('#sitecode2').val()=='0')
     {
       alert('Please select site to.');
       return false;
     }
      $.ajax({
						url : "get_mrn_by_site.php",
						type : "POST",
						data : {
							action:'getStore',
							site:$('#sitecode2').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;
    }
  }
  xmlhttp.open("GET","get_mrnitemdata.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)
    {

$("#lightbox1").dialog({
        title:'Item List',
        modal: true,
        resizable: false,
        width:1000,
        height:350,
        closeText: 'fechar',
        draggable: true,
        position:'static',
        show: 'fade',
        hide: 'fade',
        dialogClass: 'main-dialog-class',
        buttons: {
          Exit: function()
          {
            $(this).dialog("close");
          }
        }
      });

    document.getElementById("lightbox1").style.display='block';	
	document.getElementById("lightbox1").innerHTML=xmlhttp.responseText;	
   // document.getElementById("textitem").innerHTML=data[1];	
    }
  }
  var store=document.getElementById("tostore").value;
 

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



function displayBatch(value,id)
 {
 // alert("The paragraph was double-clicked."); 
 // alert(value+"  "+id);
 //alert(id);
  var itemcode='';
  var itemname='';
  var unit='';
  var item_ids='';

  if(id.indexOf('_')!='-1')
  {
    var ids = id.split('_');
    itemcode = document.getElementById('itemcode_'+ids[1]).value;
    itemname = document.getElementById('itemname_'+ids[1]).value;
    //unit = document.getElementById('u1_'+ids[1]).value;
    item_ids = document.getElementById('itemdataid_'+ids[1]).value;
    //alert(item_ids);
    
  }
  else
  {
    itemcode = document.getElementById('itemcode').value;
    itemname = document.getElementById('itemname').value;
   // unit = document.getElementById('u1_').value;
    item_ids = document.getElementById('itemids').value;
    //alert("asdas"+item_ids);
    
  }

  if(itemcode=='')
  {
    alert("Please select items");
  }
  else if(itemname=='')
  {
    alert("Please enter itemname");
  }
  /*else if(unit=='')
  {
    alert("Please enter unit");
  }*/
  else
  {
    //var LeaveType=document.getElementById("LeaveType_"+tt2).value;
    $("#lightbox1").dialog({
        title:'Batch List',
        modal: true,
        resizable: false,
        width:900,
        height:400,
        closeText: 'fechar',
        draggable: true,
        show: 'fade',
        hide: 'fade',
        dialogClass: 'main-dialog-class',
        buttons: {
          Exit: function()
          {
            $(this).dialog("close");
          }
        }
      });
    
    var site=document.getElementById("site").value;
   var store=document.getElementById("tostore").value;
    //var invoiceTime=$('#invoiceTime').val();
    //alert('Getstock_items_store.php?site='+site+'&invoicedate='+invoicedate+'&invoiceTime='+invoiceTime);
    $.ajax({url:'getItemBatch.php?item_id='+item_ids+'&batch_id='+id+'&site='+site+'&store='+store,success:function(result)
      {
        $('#lightbox1').html(result);
        }
         });
  }
}



function addBatchData(id,value,unit,batch,mfg,expiry)
{
  if(id.indexOf("_")!="-1")
  {
    var ids = id.split('_');
    if($('#stock_'+ids[1]).val()!='')
    {

       var batch_no=new Array();
     jQuery('input[id^=batchno_]').each(function(){
         batch_no.push(parseInt(jQuery(this).val()));
          //alert(partic_pack);
    });  

      for (var i = 0; i < batch_no.length; i++) {
      if (batch_no[i] == batch) {
        alert('Batch  Is All Ready Selected.');
        return false;

          }
     }


      var thisRow = $('#batchno_'+ids[1]).closest( 'tr' )[0];
        $( thisRow ).clone().insertAfter( thisRow ).find( 'input:text' );
        $('#stock_'+ids[1]).val(value);
        $('#batchno_'+ids[1]).val(batch);
        var dArr = mfg.split("-");  // ex input "2010-01-18"
        var msgd= dArr[2]+ "-" +dArr[1]+ "-" +dArr[0].substring(0);
        $('#dateofmfg_'+ids[1]).val(msgd);
        var dArr1 = expiry.split("-");  // ex input "2010-01-18"
        var msgd1= dArr1[2]+ "-" +dArr1[1]+ "-" +dArr1[0].substring(0);
        $('#dateofexpiry_'+ids[1]).val(msgd1);
        
    }
     else
      {
          var dArr = mfg.split("-");  // ex input "2010-01-18"
          var msgd= dArr[2]+ "-" +dArr[1]+ "-" +dArr[0].substring(0);
          var dArr1 = expiry.split("-");  // ex input "2010-01-18"
        var msgd1= dArr1[2]+ "-" +dArr1[1]+ "-" +dArr1[0].substring(0);
        $('#stock_'+ids[1]).val(value); 
        $('#batchno_'+ids[1]).val(batch);
        $('#dateofmfg_'+ids[1]).val(msgd);
        $('#dateofexpiry_'+ids[1]).val(msgd1);

      }
    }
    else
    {
      if($('#stock').val()!='')
    {
      var thisRow = $("#batchno").closest( 'tr' )[0];
        $( thisRow ).clone().insertAfter( thisRow ).find( 'input:text' );
        $('#stock').val(value);
        $('#batchno').val(batch);
        $('#dateofmfg').val(mfg);
        $('#dateofexpiry').val(expiry);
      }
      else
      {
        $('#stock').val(value); 
        $('#batchno').val(batch);
        $('#dateofmfg').val(mfg);
        $('#dateofexpiry').val(expiry);
      }
    }
  
   $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
 }





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,unit,unit1,ctr,cotr1)
{ 
   
  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 ctr1=parseInt(document.getElementById("rowcount1").value);

  
	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('itemname_1').value = shade;
	document.getElementById('uom_1').value = netrate;
  document.getElementById('uom1_1').value = mrprate;
  //document.getElementById('stock_1').value = mrprate;
    document.getElementById('confac_1').value = cotr1;
    document.getElementById('confactor_1').value = cotr1;
	}
	}
	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('itemname_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
  document.getElementById('uom1_'+i).value = mrprate;
  // document.getElementById('stock_'+i).value = mrprate;
     document.getElementById('confac_'+i).value = cotr1;
     document.getElementById('confactor_'+i).value = cotr1;
	}	
	}	
	//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"   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()
 {
 	 var chkflag=false;
   if($('#site').val()==0)
   {
   	alert('Please select branch.');
   	return false;
   }
   if($('#recieved_date').val()=='')
   {
   	alert('Please Enter Receipt date.');
   	return false;
   }
    if($('#store').val()==0)
    {
    	alert('Please select stote.');
    	return false;
    }

     if($('#work_order_no').val()==0)
     {
     	alert('Please select work order number.');
     	return false;
     }

     if($('#work_order_date').val()=='')
     {
     	alert('Please Enter work order date.');
     	return false;
     }
      if($('#job_card_no').val()==0 || $('#job_card_no').val()==0)
      {
      	alert('Please Enter job card number.');
      	return false;
      }

    



      return true;
 }


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

}
</style>
