<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$fin_year=$_SESSION['fin_year'];
$type=$_REQUEST['type'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
$sq="CREATE TABLE IF NOT EXISTS stockverification (
  id int(11) NOT NULL AUTO_INCREMENT,
  itemcode varchar(100) DEFAULT NULL,
  itemname varchar(100) DEFAULT NULL,
  sellprice double(10,2) DEFAULT NULL,
  ledqty double(10,2) DEFAULT NULL,
  curstk double(10,2) DEFAULT NULL,
  brcode varchar(50) DEFAULT NULL,
  gname varchar(100) DEFAULT NULL,
  item_subgrp varchar(100) DEFAULT NULL,
  stock_short double(10,2) DEFAULT NULL,
  stock_excess double(10,2) DEFAULT NULL,
  stockverifydt date DEFAULT NULL,
  ref_no varchar(20) DEFAULT NULL,
  remrks text NOT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1";

mysqli_query($db,$sq);
$col = mysqli_query($db,"SELECT remrks FROM stockverification");
if (!$col){
    mysqli_query($db,"ALTER TABLE stockverification ADD remrks TEXT NOT NULL");

}
include_once('testtot.php');
      $y1=$_REQUEST['y1'];
      $m1=$_REQUEST['m1'];
      $d1=$_REQUEST['d1'];
      $y2=$_REQUEST['y2'];
      $m2=$_REQUEST['m2'];
      $d2=$_REQUEST['d2'];

$yeardat=explode('-',$fin_year);
$startingyr=$yeardat[0];
$strtdt='-04-01';
//$dfrom=$startingyr.$strtdt;
$dfrom=$startingyr.$strtdt;
//echo $ref_date;
 $dto=date('Y-m-d');
  $dto1=date('d-m-Y');
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
?>
<link type="text/css" href="jquery/jquery-ui.min.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery/jquery.jqEasyCharCounter.min.js"></script>
<script type="text/javascript" src="number_to_word.js"></script>
<script type="text/javascript">

$(function() {

  $("#ref_date").datepicker({
  dateFormat: "yy-mm-dd"
   });

 });
  </script>
<script type="text/javascript">
 function handleEnter (field, event)
    {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

        if (keyCode == 13)
            {
    var row=field.parentNode.parentNode.rowIndex;
                var col  =field.parentNode.cellIndex;
                var i;
                for (i = 0; i < field.form.elements.length; i++)
                if (field == field.form.elements[i])
          break;
                i = (i + 1) % field.form.elements.length;
    //alert(col);
                field.form.elements[i].focus();
    document.getElementById('myTable').rows[row+1].cells[6].getElementsByTagName("input")[0].focus();
                return false;

            }
        if (keyCode == 38){

                var row=field.parentNode.parentNode.rowIndex;
                var col  =field.parentNode.cellIndex;
                document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
            }
        if (keyCode == 40){
                var row=field.parentNode.parentNode.rowIndex;
                var col  =field.parentNode.cellIndex;
                document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
            }
        if (keyCode == 37){
                var i;
                for (i = 0; i < field.form.elements.length; i++)
                    if (field == field.form.elements[i])
          break;
      i = (i - 1) % field.form.elements.length;
      field.form.elements[i].focus();
      return false;


              }


    }
    function handleEnter2 (field, event)
    {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

        if (keyCode == 13)
            {
                var row=field.parentNode.parentNode.rowIndex;
                var col  =field.parentNode.cellIndex;

                //alert(col);
    //alert(row);
                //alert(document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[4].name);
    //document.getElementById('verfyqty'+col).focus;
    //alert(document.getElementById('verfyqty'+col).value);
                document.getElementById('myTable').rows[row+1].cells[col-1].getElementsByTagName("input")[0].focus();
            }
        if (keyCode == 38){

                var row=field.parentNode.parentNode.rowIndex;
                var col  =field.parentNode.cellIndex;
                document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
            }
        if (keyCode == 40){
                var row=field.parentNode.parentNode.rowIndex;
                var col  =field.parentNode.cellIndex;
                document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
            }
        if (keyCode == 37){
                var i;
                for (i = 0; i < field.form.elements.length; i++)
                    if (field == field.form.elements[i])
          break;
      i = (i - 1) % field.form.elements.length;
      field.form.elements[i].focus();
      return false;


              }


    }
</script>
<body bgcolor="#0033FF">
<?php //include('includes/top.php'); ?>
<center>
    <br>
 <form id="form1" name="form1" method="POST" action="updstockentry.php" onsubmit="return validateForm()">



<font   > <? print "<B>STOCK VERIFICATION ON ".$dto1."</B>";?></font>
<link rel="stylesheet" href="style.css" type="text/css" />
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />

<style type="text/css">

.paginate {
  //font-family:Arial, Helvetica, sans-serif;
  padding: 3px;
  margin: 3px;
}

.paginate a {
  padding:2px 5px 2px 5px;
  margin:2px;
  border:1px solid #999;
  text-decoration:none;
  color: #666;
}
.paginate a:hover, .paginate a:active {
  border: 1px solid #999;
  color: #000;
}
.paginate span.current {
    margin: 2px;
  padding: 2px 5px 2px 5px;
    border: 1px solid #999;

    font-weight: bold;
    background-color: #999;
    color: #FFF;
  }
  .paginate span.disabled {
    padding:2px 5px 2px 5px;
    margin:2px;
    border:1px solid #eee;
    color:#DDD;
  }




tr.top td { border-top: thin solid black; }
tr.bottom td { border-bottom: thin solid black; }
tr.row td:first-child { border-left: thin solid black; }
tr.row td:last-child { border-right: thin solid black; }
</style>
<center>
<?
$tbl="sparetmpdw".$brcode.$user;
$query="select stockverifydt,ref_no from stockverification order by ref_no desc limit 1";
$rs=mysqli_query($db,$query);
$varrow=mysqli_fetch_array($rs);
$endvrfydt=$varrow[0];
$endrefno=$varrow[1];
if($type!='')
{
mysqli_query($db,"drop table $tbl");
mysqli_query($db,"CREATE TABLE $tbl (partcode varchar(200),partname varchar(200),op_inqty double(10,2) default 0,op_outqty double(10,2) default 0, stkadj_in double(10,2) default 0, stkadj_out double(12,2) default 0,purch_in double(12,2) default 0,salertn_in double(12,2) default 0,trans_in double(12,2) default 0,trans_out double(12,2) default 0,sale_out double(12,2) default 0,purchrtn_out double(12,2) default 0,sto_verify double(12,2) )");
mysqli_query($db,"delete from $tbl");

if($type=='All')
{
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,op_outqty) select partcode,partname,sum(qty),sum(outqty) from adjstock where brcode='$brcode' and entrydate<'$dfrom' group by partcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select item_code,item,sum(qty) from itempurchase where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select itemcode,itemname,sum(opstk) from sparestock where brcode='$brcode' group by itemcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,sto_verify) select itemcode,itemname,sum(curstk) from stockverification where brcode='$brcode' and ref_no='$endrefno' group by itemcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select item_code,item,sum(rtnqty) from salesretn where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty) select item_code,item,sum(qty) from brtransferout where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select item_code,item,sum(qty) from brtransferin where brcode='$brcode' and invdate<'$dfrom'   group by item_code") or die('err12'.mysqli_error($db));

  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty) select item_code,item,sum(qty) from prod_invoice where brcode='$brcode' and invdate<'$dfrom'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty) select item_code,item,sum(qty) from purchretn where brcode='$brcode' and invdate<'$dfrom'  group by item_code") or die('err12'.mysqli_error($db));
//****************************************************************************** in out*******
  mysqli_query($db,"insert into $tbl (partcode,partname,stkadj_in,stkadj_out) select partcode,partname,sum(qty),sum(outqty) from adjstock where brcode='$brcode' and entrydate>='$dfrom' and entrydate <='$dto' group by partcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,purch_in) select item_code,item,sum(qty) from itempurchase where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,salertn_in) select item_code,item,sum(rtnqty) from salesretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,trans_out) select item_code,item,sum(qty) from brtransferout where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,trans_in) select item_code,item,sum(qty) from brtransferin where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,sale_out) select item_code,item,sum(qty) from prod_invoice where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,purchrtn_out) select item_code,item,sum(qty) from purchretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
}
else
{
mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,op_outqty) select partcode,partname,sum(qty),sum(outqty) from adjstock where brcode='$brcode' and entrydate<'$dfrom' and gname = '$type' group by partcode") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select item_code,item,sum(qty) from itempurchase where brcode='$brcode' and invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));

mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select itemcode,itemname,sum(opstk) from sparestock where brcode='$brcode' and item_grp = '$type' group by itemcode") or die('err12'.mysqli_error($db));
//mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,sto_verify) select itemcode,itemname,sum(opstk),sum(curstk_nor) from sparestock where brcode='$brcode' and item_grp = '$type' group by itemcode") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select item_code,item,sum(rtnqty) from salesretn where brcode='$brcode' and invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty) select item_code,item,sum(qty) from brtransferout where brcode='$brcode' and invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty) select item_code,item,sum(qty) from brtransferin where brcode='$brcode' and invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));
//mysqli_query($db,"insert into $tbl (partcode,partname,sto_verify) select itemcode,itemname,sum(curstk) from stockverification where brcode='$brcode' and ref_no='$endrefno' and gname = '$type' group by itemcode") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty) select item_code,item,sum(qty) from prod_invoice where brcode='$brcode' and invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty) select item_code,item,sum(qty) from purchretn where brcode='$brcode' and invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));
//****************************************************************************** in out*******
mysqli_query($db,"insert into $tbl (partcode,partname,stkadj_in,stkadj_out) select partcode,partname,sum(qty),sum(outqty) from adjstock where brcode='$brcode' and entrydate>='$dfrom' and entrydate <='$dto' and gname = '$type'  group by partcode") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,purch_in) select item_code,item,sum(qty) from itempurchase where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,salertn_in) select item_code,item,sum(rtnqty) from salesretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,trans_out) select item_code,item,sum(qty) from brtransferout where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,trans_in) select item_code,item,sum(qty) from brtransferin where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,sale_out) select item_code,item,sum(qty) from prod_invoice where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,purchrtn_out) select item_code,item,sum(qty) from purchretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
}
//**************************************

//$re=mysqli_query($db,"select partcode,partname,sum(op_inqty),sum(op_outqty),sum(purch_in),sum(trans_in),sum(salertn_in),sum(stkadj_in),sum(sale_out),sum(trans_out),sum(purchrtn_out),sum(stkadj_out),sum(sto_verify) from $tbl group by partcode");
}
mysqli_query($db,"delete from $tbl where sto_verify > 0") or die('err12'.mysqli_error($db));
mysqli_query($db,"insert into $tbl (partcode,partname,sto_verify) select itemcode,itemname,sum(curstk) from stockverification where brcode='$brcode' and ref_no='$endrefno' and gname = '$type' group by itemcode") or die('err12'.mysqli_error($db));

$targetpage = "stockentry_intermediate.php";
$limit = 25;
$query = "SELECT COUNT(distinct(partcode)) as num FROM $tbl ";
  $total_pages = mysqli_fetch_array(mysqli_query($db,$query));
  $total_pages = $total_pages[num];
$stages = 3;
  $page = mysqli_escape_string($_GET['page']);
  if($page){
    $start = ($page - 1) * $limit;
  }else{
    $start = 0;
    }

$query1 = "select partcode,partname,sum(op_inqty),sum(op_outqty),sum(purch_in),sum(trans_in),sum(salertn_in),sum(stkadj_in),sum(sale_out),sum(trans_out),sum(purchrtn_out),sum(stkadj_out),sum(sto_verify) from $tbl group by partcode LIMIT $start, $limit";
//echo $query1;
// Initial page num setup
  if ($page == 0){$page = 1;}
  $prev = $page - 1;
  $next = $page + 1;
  $lastpage = ceil($total_pages/$limit);
  $LastPagem1 = $lastpage - 1;


  $paginate = '';
  if($lastpage > 1)
  {
$paginate .= "<div class='paginate'>";
    // Previous
    if ($page > 1){
      $paginate.= "<a href='$targetpage?page=$prev&type=$type'>previous</a>";
    }else{
      $paginate.= "<span class='disabled'>previous</span>";  }



    // Pages
    if ($lastpage < 7 + ($stages * 2))  // Not enough pages to breaking it up
    {
      for ($counter = 1; $counter <= $lastpage; $counter++)
      {
        if ($counter == $page){
          $paginate.= "<span class='current'>$counter</span>";
        }else{
          $paginate.= "<a href='$targetpage?page=$counter&type=$type'>$counter</a>";}
      }
    }
    elseif($lastpage > 5 + ($stages * 2))  // Enough pages to hide a few?
    {
      // Beginning only hide later pages
      if($page < 1 + ($stages * 2))
      {
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
        {
          if ($counter == $page){
            $paginate.= "<span class='current'>$counter</span>";
          }else{
            $paginate.= "<a href='$targetpage?page=$counter&type=$type'>$counter</a>";}
        }
        $paginate.= "...";
        $paginate.= "<a href='$targetpage?page=$LastPagem1&type=$type'>$LastPagem1</a>";
        $paginate.= "<a href='$targetpage?page=$lastpage&type=$type'>$lastpage</a>";
      }
      // Middle hide some front and some back
      elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
      {
        $paginate.= "<a href='$targetpage?page=1&type=$type'>1</a>";
        $paginate.= "<a href='$targetpage?page=2&type=$type'>2</a>";
        $paginate.= "...";
        for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
        {
          if ($counter == $page){
            $paginate.= "<span class='current'>$counter</span>";
          }else{
            $paginate.= "<a href='$targetpage?page=$counter&type=$type'>$counter</a>";}
        }
        $paginate.= "...";
        $paginate.= "<a href='$targetpage?page=$LastPagem1&type=$type'>$LastPagem1</a>";
        $paginate.= "<a href='$targetpage?page=$lastpage&type=$type'>$lastpage</a>";
      }
      // End only hide early pages
      else
      {
        $paginate.= "<a href='$targetpage?page=1&type=$type'>1</a>";
        $paginate.= "<a href='$targetpage?page=2&type=$type'>2</a>";
        $paginate.= "...";
        for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
        {
          if ($counter == $page){
            $paginate.= "<span class='current'>$counter</span>";
          }else{
            $paginate.= "<a href='$targetpage?page=$counter&type=$type'>$counter</a>";}
        }
      }
    }

        // Next
    if ($page < $counter - 1){
      $paginate.= "<a href='$targetpage?page=$next&type=$type'>next</a>";
    }else{
      $paginate.= "<span class='disabled'>next</span>";
      }

    $paginate.= "</div>";
}
//$mdate = '20'.substr($fin_year,-2).'-03-31';
$mdate=date('Y-m-d');
print "<table border=0 cellspacing=1 cellpadding=3 bgcolor='lightsteelblue' style='border-collapse: collapse;' id='myTable'>";
print "<tr style='border:1px solid black;'><td>Item Group : </td><td>$type</td><td colspan='11' align='right'>Select Date<input value='$mdate' id='ref_date' name='ref_date' style='width:141px;outline:none;border:1px solid grey; border-style:dotted; cursor:pointer; 120px 2px no-repeat; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;' readonly  type=text  value='' onKeydown='return handleEnter(this, event)'></td></tr>";
print "<tr><td>No.</td><td>Item Code </td><td>Item Name</td><td>Rate</td><td colspan='2'>Stock as per Ledger</td><td colspan='2'>Stock actually verified</td><td colspan='2' align='center'>Excess</td><td colspan='2' align='center'>Short</td><td>Remarks</td></TR>";
print "<TR><td></td><td></td><td></td><td></td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td></tr>";
$i=1;
$j=1;
$tprice=0;
$re=mysqli_query($db,$query1);
while($row=mysqli_fetch_array($re))
{

       $op_qty = $row[2]-$row[3];
       //echo $op_qty;
       //echo "<br>";
       //if(abs($op_qty)>0 || abs($row[4])>0 ||abs($row[5])>0 ||abs($row[6])>0 ||abs($row[7])>0 ||abs($row[8])>0 ||abs($row[9])>0 ||abs($row[10])>0 ||abs($row[11])>0)
       //{
          print "\n<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white' style='border:1px solid black;'><td>".$i++."</td>";
          print "<td><input type='text' value='".$row[0]."' name='partcode[]' id='partcode$j' size='8' readonly> </td><td>$row[1]</td>";
          $close = $op_qty+($row[4]+$row[5]+$row[6]+$row[7])-($row[8]+$row[9]+$row[10]+$row[11]);
          $prres=mysqli_query($db,"select ndpcost from spareprmast where partcode='$row[0]' order by effectfrom desc");
          $prrow=mysqli_fetch_row($prres);
          $pr=($prrow[0]*($close));
          $tprice+=$pr;
          $verfvl=$row[12]*$prrow[0];
              //$excsqty=$row[12]-$close;
		$rw12vl=number_format((float)$row[12], 2, '.', '');
		$close=number_format((float)$close, 2, '.', '');
		$excsqty=$rw12vl-$close;

          if($excsqty>0)
            {
                $excsqty1=$excsqty;
               $excsvl= $excsqty1*$prrow[0];
               $shrtqty='';
               $shrtvl='';
            }
          else
            {
               if($row[12]>0)
               {
                $shrtqty=abs($excsqty);
                $shrtvl= $excsqty*$prrow[0];
                $shrtvl=abs($shrtvl);
                $excsqty1='';
                $excsvl='';
                }
                else
                {
      //$row[12]=0;
                     $shrtqty='';
                    $shrtvl= '';

                        $excsqty1='';
                        $excsvl='';
                }

            }

          print "<td align=right><input type='text' value='".$prrow[0]."' name='itmrt[]' id='itmrt$j' size='6' readonly style='text-align: right'></td><td align=right >

              <input type='text' value='".$close."' name='ledqty[]' id='ledqty$j' size='4' readonly style='text-align: right'>
              </td><td align=right>".number_format($pr,2)."</td><td align='right'><input type='text' name='verfyqty[]' id='verfyqty$j' value='".$row[12]."' size='3' onKeydown='return handleEnter(this, event)' onchange='uplddta(this.value,this,this.id)' style='text-align: right' > </td><td><input type='text' name='verfvl[]' id='verfvl$j' onkeyup='uplddta(this.value,this,this.id)' onKeydown='return handleEnter2(this, event)' value='".$verfvl."' size='7' readonly style='text-align: right' ></td><td><input type='text' name='excsqty[]' id='excsqty$j' value='".$excsqty1."' size='5' readonly style='text-align: right' ></td><td><input type='text' name='excsvl[]' id='excsvl$j' value='".$excsvl."'  size='7' readonly style='text-align: right' ></td><td><input type='text' name='shrtqty[]' id='shrtqty$j' value='".$shrtqty."' size='5' readonly style='text-align: right'></td><td><input type='text' name='shrtvl[]' id='shrtvl$j' value='".$shrtvl."' size='7' readonly style='text-align: right' ></td><td><input type='text' name='rmrks[]' id='rmrks$j' value='' size='7' onkeyup='uplddta(this.value,this,this.id)' ></td></tr>";
          $j++;
       //}
}
?>

<div align=center>
<?php
 echo $total_pages.' Results';
 // pagination
 echo $paginate;
?>
</div>
<div id="strtxt"></div>
</table>
 </form>
<script type="text/javascript">

function validateForm() {
    var x = document.form1.ref_date.value;
    if (x == null || x == "") {
        alert("Date must be filled out");
        return false;
    }
}
function uplddta(str,r,qid)
 {
    if(str.length==0)
        {
            str=0;
        }
     var i=r.parentNode.parentNode.rowIndex;
     var tbl = document.getElementById('myTable');
     var id1=tbl.rows[i].cells[0].innerHTML;
     var part = document.getElementById("verfyqty"+id1).value;
//alert(part);
     var refdat=document.getElementById("ref_date").value;
     if(part=='')
        {
            alert('Enter Quantity');
            document.getElementById("verfyqty"+id1).focus();
        }
        else if(refdat=='')
        {
            alert('Please Select date');
            document.getElementById("ref_date").focus();
        }

    else
        {
            var itemcd=document.getElementById("partcode"+id1).value;
            var ledstck=document.getElementById("ledqty"+id1).value;
             var verqty=document.getElementById("verfyqty"+id1).value;
             var remarks=document.getElementById("rmrks"+id1).value;
            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("strtxt").innerHTML=xmlhttp.responseText;
            document.getElementById("verfvl"+id1).value=document.getElementById("vrflvl").value;
            document.getElementById("excsqty"+id1).value=document.getElementById("mblqty").value;
            document.getElementById("excsvl"+id1).value=document.getElementById("mblrate").value;
            document.getElementById("shrtqty"+id1).value=document.getElementById("mshrtqty").value;
            document.getElementById("shrtvl"+id1).value=document.getElementById("shrtvl").value;
            document.getElementById("ref_date").value=document.getElementById("entrydt").value;
            //var excesqty=((document.getElementById("verfyqty"+id1).value)-(document.getElementById("ledqty"+id1).value)).toFixed(2);




  }
}
   }

//var url="svstkentry.php?ldqty="+ledstck+"&&verqt="+verqty+"&&itemcod="+itemcd+"&&entrdt="+refdat+"&&notes="+remarks;
//alert(url);
xmlhttp.open("GET","svstkentry.php?ldqty="+ledstck+"&&verqt="+verqty+"&&itemcod="+itemcd+"&&entrdt="+refdat+"&&notes="+remarks,true);
xmlhttp.send();
}
</script>
