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

?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Dispatch Report</title>
<link rel="stylesheet" href="../css/form.css" type="text/css" />  
<link rel="stylesheet" href="../style.css" type="text/css" />
<link type="text/css" href="../css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript">
  $(function() {
    $( "#datefrom" ).datepicker({ dateFormat: 'yy-mm-dd' });

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

  });
  </script>
<script type="text/javascript">
$(document).ready(function(){
    $("select.grp").change(function(){
        var selectedGrp = $(".grp option:selected").val();
        $.ajax({
            type: "POST",
            url: "selectsubgrp.php",
            data: { grp : selectedGrp } 

        }).done(function(data){

            $("#response").html(data);

        });

    });

});
</script>
<!-- js code below for active enter with textfield-->
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			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;
		} 
		else
		return true;
	}      








</script>

<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;
}
table.form{
font-weight: normal;border:1px;
} 
</style>
<style>
.cont{
      background-color:#fff;
      //background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
      width: 100%;position: absolute ;
      height:99%;
      /* Optional - just for DIV)*/
      //border: solid 1px #000000;
      -moz-box-shadow: 0px 5px 5px #888;
      -webkit-box-shadow: 0px 5px 5px #888;
      box-shadow: 0px 5px 10px #888;
    
      }


#pg{
       text-decoration:none;
}
#pg button{
       background-color:#3b5998;
}

</style>



<body bgcolor="#A9F5A9">
<div class='cont' style="background-color:#E0F8E0" >



<?
include('top.php');

?>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px; color:white;">  &nbsp;&nbsp;Master >> Item Master</font>

<style>
th{background-color:steelblue;color:white}
</style>
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			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;
		} 
		else
		return true;
	}      


</script>
<?
$xx=$_GET['id']+1;
?>
<body>
<center>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='white'>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<table cellspacing=1 cellpadding=3 class='form'>
<th colspan=4><font size=3>DISPATCH PENDING REPORT</th>
<tr><td>From Dispatch Date</td><td><input type=text id='datefrom' name='datefrom' ></td><tr><td>To Dispatch Date</td><td><input type=text id='dateto' name='dateto' ></td></tr>

<th colspan=4><input type=submit value='Show' name='show'><input type=button value="Excel" onclick=billexc()>
</table>

</form>
</td></tr>
</table>
<br><br>
<table cellspacing=1 cellpadding=3 class='form'>
<?
if(isset($_POST['show']))
{
    $mdf = $_REQUEST['datefrom'];
    $mdt = $_REQUEST['dateto'];
    //print "select invno,entrydate,customer,'engineer',sum(item_total) tot,brcode,proddesc from sap_einvoice where brcode = '$brcode' and entrydate >='$mdf' and entrydate <='$mdt' group by invno order by invno";
    $g=mysqli_query($db,"select invno,entrydate,customer,'',sum(item_total) tot,brcode,proddesc from sap_einvoice where brcode = '$brcode' and entrydate >='$mdf' and entrydate <='$mdt' group by invno order by invno");
    //$g=mysqli_query($db,"select invno,entrydate,customer,engineer,sum(tot) tot,brcode,partcode from spareinvoice where brcode = '$brcode' and entrydate >='$mdf' and entrydate <='$mdt' group by invno order by invno");
   // print "select invno,entrydate,sum(tot) from spareinvoice where brcode = '$brcode' and entrydate >='$mdf' and entrydate <='$mdt' order by entrydate group by invno";
    print "<tr><th>Branch<th>Manufacturer<th>Invoice No.</th><th>Invoice Date</th><th>Customer</th><th>Location</th><th>Engineer</th><th>Inv Amount";
    while($grow=mysqli_fetch_array($g))
    {
        $invdt=implode('-', array_reverse(explode('-', $grow['entrydate'])));
        $g1=mysqli_query($db,"select invno from dispatchinvoice where brcode = '$brcode' and invno= '$grow[0]'");
        $sprrow=mysqli_fetch_array($g1);
        if(strlen($sprrow[0])>0)
        {
            $a=1;   
        }
        else
        {
            //$sq222="select manufacturer from partmaster where partcode='$grow[partcode]' limit 1;";
	        //$re222=mysqli_query($db,$sq222)or die('Err3:'.mysqli_error($db));
	        //$row222=mysqli_fetch_array($re222);
	        //$sq223="select corp from customer where acname='$grow[customer]' limit 1;";
	        //$re223=mysqli_query($db,$sq223)or die('Err3:'.mysqli_error($db));
	        //$row223=mysqli_fetch_array($re223);
            print "<tr><td>$grow[brcode]<td>$row222[0]<td>$grow[invno]</td><td>$invdt</td><td>$grow[customer]</td><td>$row223[0]</td><td>$grow[engineer]</td><td align='right'>$grow[tot]</td></tr>";
        }
    } 
    print "</table>";
}?>

<script type="text/javascript">
function getinvno(str)
{
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;
      
    }
  }
xmlhttp.open("GET","showinvdtls.php?invno="+str,true);
xmlhttp.send();

}

function billexc()
    {
   var dfrom=document.f1.datefrom.value;
   var dto=document.f1.dateto.value;
   document.location="dispatchpndexcel.php?datefrom="+dfrom+"&&dateto="+dto,true;
    }
</script>
