<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

?>
<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="cal/jquery-ui1.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>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript">
$(function() {
$( "#ref_date" ).datepicker("destroy");
     var fyr=document.getElementById('f_yr').value;
     var splv=fyr.explode("-");
     var syr=splv[0];
     var eyr='20'.concat(splv[1]);
     var syr1='01-04-';
     var eyr1='31-03-';
     var stfnyr=syr1.concat(syr);
     var efnyr=eyr1.concat(eyr);
     $("#ref_date").datepicker({ dateFormat: 'dd-mm-yy', minDate: stfnyr, maxDate: efnyr});

$( "#ref_date1" ).datepicker("destroy");
     var fyr=document.getElementById('f_yr').value;
     var splv=fyr.explode("-");
     var syr=splv[0];
     var eyr='20'.concat(splv[1]);
     var syr1='01-04-';
     var eyr1='31-03-';
     var stfnyr=syr1.concat(syr);
     var efnyr=eyr1.concat(eyr);
     $("#ref_date1").datepicker({ dateFormat: 'dd-mm-yy', minDate: stfnyr, maxDate: efnyr});
});
</script>
<style>
  //tr1{background-color:white}
  th{background-color:steelblue;color:white}
</style>
<body bgcolor="#0033FF" onload=showitem(document.getElementById("sel").value)>
<?php //include('includes/top.php'); ?>
<script type="text/javascript">

$(function(){
  $(".inno").live("keydown.autocomplete",function(){
  $inno = $(this);
  $row = $inno.parent().parent();
  $(this).autocomplete({
    source: function( request, response ) {
    $.ajax({
      url: "search6.php",
      dataType: "json",
      data: "key="+$inno.val(),
      success: function( data ) {
        response( $.map( data, function( item ) {
          return {
            label: '<span class="la-code">'+item.inno+' </span><span class="la-name">'+  item.partname + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
            value: item.inno,
            name:item.partname,
            tax:item.tax,
            stock:item.stock,
            rate:item.rate,
            reduct:item.reduct,
            }
        }));
      }
    });
  }
  ,
  minLength: 2,
  select: function( event, ui ) {
  $row.find('.partname').val(ui.item.name);
  $row.find('.stok').val(ui.item.stock);
  $row.find('.unitprice').val(ui.item.rate);

  $row.find('.tax').val(ui.item.tax);
  $row.find('.itmvl').val(ui.item.reduct);
  $row.find('.qty').focus();
  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

  }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };
  });
});

$(function(){
  $(".partcode").live("keydown.autocomplete",function(){
  $partcode = $(this);
  $row = $partcode.parent().parent();
  $(this).autocomplete({
    source: function( request, response ) {

    $.ajax({
      url: "search5.php",
      dataType: "json",
      data: "key="+$partcode.val(),
      success: function( data ) {
        response( $.map( data, function( item ) {


          return {
            label: '<span class="la-code">'+item.partcode+' </span><span class="la-name">'+  item.partname + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
            value: item.partcode,
            name:item.partname,
            tax:item.tax,

            stock:item.stock,
            rate:item.rate,
            reduct:item.reduct,


          }
        }));
      }
    });
  }
  ,
  minLength: 2,
  select: function( event, ui ) {
  $row.find('.partname').val(ui.item.name);
  $row.find('.stok').val(ui.item.stock);
  $row.find('.unitprice').val(ui.item.rate);
  $row.find('.tax').val(ui.item.tax);
  $row.find('.itmvl').val(ui.item.reduct);
  $row.find('.qty').focus();
  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

  }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };
});

$(".partname").live("keydown.autocomplete",function(){

$partname = $(this);

$row = $partname.parent().parent();
$(this).autocomplete({
    source: function( request, response ) {

    $.ajax({
      url: "search5.php?type=name",
      dataType: "json",
      data: "key="+$partname.val(),
      success: function( data ) {
        response( $.map( data, function( item ) {
          return {
            label: '<span class="la-code">'+item.partcode+' </span><span class="la-name">'+  item.partname + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
            code: item.partcode,
            value:item.partname,
            tax:item.tax,

            stock:item.stock,
            rate:item.rate,
            rate2:item.rate2,
            reduct:item.reduct,


          }

        }));
      }
    });
  }

,
  minLength: 2,
  select: function( event, ui ) {

  $row.find('.partcode').val(ui.item.code);
  $row.find('.stok').val(ui.item.stock);
  $row.find('.unitprice').val(ui.item.rate);
  $row.find('.pur_rate').val(ui.item.rate2);
  $row.find('.tax').val(ui.item.tax);
  $row.find('.itmvl').val(ui.item.reduct);
  $row.find('.qty').focus();

  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

  }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };


});



});

</script>
<script type="text/javascript">
function showitem(str)
{
if(document.f1.type.value!='single')
{
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("itgr").innerHTML=xmlhttp.responseText;
  document.getElementById("itcd").style.visibility = "hidden";
  document.getElementById("itgr").style.visibility = "visible";
  document.getElementById("print").style.visibility = "visible";

    }
  }

xmlhttp.open("GET","grpitm.php?gname="+str,true);
xmlhttp.send();

}
else{
document.getElementById("itcd").style.visibility = "visible";
document.getElementById("itgr").style.visibility ="hidden";

}
}
function printfn()
 {
  
   var dfrom=document.f1.fromdt.value;

 
   var dto=document.f1.todt.value;

 var gname=document.f1.type.value;
 var prtcd=document.f1.itemcode.value;
 var prtcd1=document.f1.partcode1.value;
 ///var url="calcleddw_print.php?dfrom="+dfrom+"&&dto="+dto+"&&type="+gname+"&&partcode="+prtcd+"&&partcode1="+prtcd1;
 //alert(url);
 document.location="calcleddw_print.php?dfrom="+dfrom+"&&dto="+dto+"&&type="+gname+"&&itemcode="+prtcd+"&&partcode1="+prtcd1,true;
 }
</script>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px; color:white;">  &nbsp;&nbsp;REPORTS >> STOCK REPORT</font>
<center>
<h3><font color='white'>ITEM STOCK REPORT DATE WISE</font></H3>
<form action='calcleddw.php' method='post' name='f1'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>  <input type=hidden name='f_yr' id='f_yr' value='<? echo $fin_year ?>'>
<table class=noprint>
<tr>
<th style="background:grey;" colspan='2'>ITEM STOCK REPORT DATE WISE</th></td><td></td></tr>
<?
$yeardat=explode('-',$fin_year);
$startingyr=$yeardat[0];
?>
<tr><td>Date from </td><td><input type="text" id="ref_date" value="<?echo '01-04-'.$startingyr;?>" name="fromdt" readonly></td>
</tr>
<tr><td> To </td>
<td><input type="text" id="ref_date1" value="<?echo date('d-m-Y');?>" name="todt" readonly></td>
</tr>
<?
$mgrp=mysqli_query($db,"select gname from groupmaster order by gname");
//$mgr="select gname from groupmaster order by gname";
//echo $mgr;
?>

<tr><td align='center'>Item Group :  </td>
<td><select name='type' id='type' onchange='showitem(this.value)'>
<option value='single'>Single</option>
<?while($grrow=mysqli_fetch_array($mgrp))
{
?>
<option><?print $grrow[0]?></option>
<?
}?>
</td></tr>
<tr id='itcd'><td > <b>Item Code :</b></td>
<td><input type='text' name='partcode' id='partcode' class='partcode'><b>Name<input type='text' name='partname' id='partname' class='partname'></td></tr>
<tr id="itgr"  style="visibility:hidden;"></tr>
<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'>
<input type=button value='Print' id='print' onClick=printfn() style="visibility:hidden;"></td></tr>
</table>
</td></tr>
</table>
</form>
