<?
session_start();
include("opendb.php");
include("test.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Xpress</title>
 <script src=" rightclick_deactive.js"></script> 
</head>
<style type="text/css"> 
table,tr,td{border-collapse:collapse;padding:0px;border: 1px solid red;}
body{text-transform:uppercase;font-family:Verdana;font-size:10px;color:black;}

tr:nth-child(odd)    { background-color:white; }
tr:nth-child(even)    { background-color:#fff; }
p{
	padding:0px;
	margin:0px;
	text-align: left;text-transform:capitalize;font-size:10px;
}
select,input[type=text], textarea{  
background: #eeeeee; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjIzJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, #eeeeee 0%, #ffffff 23%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(23%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* IE10+ */
background: linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#ffffff',GradientType=0 ); /* IE6-8 */
border:1px solid #999; padding:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;


}p{padding:0px;}
em{font-size:14px;}
h3{color:#000;font-size:12px;margin:0px;padding:5px 20px;}
</style>
 <script type="text/javascript" src="scripts/jquery-latest.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" src="js/jquery-1.6.1.min.js"></script>

    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>

<style>
.cont
	{


       background-color:#3b5998;

	//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;
    
	}
</style>

<script type="text/javascript">
    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            //$(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "110",
               width: "110",
              
            }, "fast");
        }, function() {
            // hover out
         //   $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "80",
                width: "80",
                
            }, "fast");
        });
        
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });









/////

(function($){
    $.fn.enterNext = function(){
       var _i =0;
       $('input[type=text], select',this)
            .each(function(index){
            _i = index;
            $(this)
                .addClass('tab'+index)
                .keydown(function(event){
                    if(event.keyCode==13){
                        $('.tab'+(index+1)).focus();
                        event.preventDefault();
                    }
                });

        })
     $( "input[type=submit]",this ).addClass('tab'+(_i+1));
}})(jQuery);
    </script>

<link rel="stylesheet" href="cal/jquery-ui.css" />
  <script src="cal/jquery-1.9.1.js"></script>
  <script src="cal/jquery-ui1.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
    
  });
 $(function() {
    
    $( "#datepicker1" ).datepicker();
  });
  </script>

<body >

<?php include('includes/top.php'); ?>
<div align='left'><font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Service >>  invoice report</font></div>
<br/><br/>
<form name='f1' action='<?print $PHP_SELF?>'
<table class="container" width="93%" align='center' ><tr><td>
<?
  $qry=mysqli_query($db,"select distinct(invno) from invoice where brcode='$brcode' order by invno");
 $qry1=mysqli_query($db,"select distinct(invno) from invoice where brcode='$brcode' order by invno");
?>
<table class="form" style="width:auto;" align='center' >
<tr><th style="background:grey;">INVOICE REPORT</th></tr>
<tr><td><tr><td>Show Report From <input type="text" id="datepicker" name="fromdt" readonly/> To <input type="text" id="datepicker1" name="todt" readonly/></td></tr>

<tr><td align='center'><input type='submit' name='show' value='Show' ></td></tr></form>
</table>
<br><br>
<?
if($show)
 {
?>

  <table align='center' class='report'>        
<tr><td><h3>SNo. </h3></td><td><h3>Car No.</h3></td><td><h3>Bill No</h3></td><td><h3>Oil </h3></td><td><h3>Original</h3></td><td><h3>QR.</h3></td><td><h3>Purchase Cost.</h3></td><td><h3>Oil Filter  </h3></td><td><h3>QR </h3></td>
<td><h3>Purchase Cost.</h3></td><td><h3>Labour  </h3></td><td><h3>QR </h3></td><td><h3>Total QR </h3></td><td><h3>Grand Total</h3></td></tr>
<?

   if($inv1>$inv2)
   {
   print "<script>alert('Wrong Selection');document.location='invrepo.php';</script>";
   }
   else
   {
  $l=1;
  $ntot=0;
$ntot1=0;
$ntot2=0;
$nprtot=0;
$nprtot1=0;
$ngtot=0;
$ngdtot=0;
 $res1=mysqli_query($db,"select distinct(invno) from invoice where brcode='$brcode' and invdate between '$fromdt' and '$todt'  order by invno ");//order by invno 
 while($row1=mysqli_fetch_array($res1))
  {
$i=1;
$j=1;
$k=1;
$m=1;
$gdtot=0;

$res=mysqli_query($db,"select * from invoice where brcode='$brcode' and invno='$row1[0]' ");//order by invno 
//echo "select * from invoice where brcode='$brcode' and invno='$row1[0]' ";
 while($row=mysqli_fetch_array($res))
  {
     
	if($row['group2']=='Oil')
  	 {
	$re=mysqli_query($db,"select ndpcost from spareprmast where brcode='$brcode' and partcode='$row[21]' ");
	
	
	$re1=mysqli_fetch_row($re);
  	 $a[$i]=$row['item'];
	if($row['item']!=$row['org_item'])
  	  {
          $org[$i]=$row['org_item'];
         }
        else
    	  {
          $org[$i]='';
         }
	$prtot[$i]=$re1[0]*$row['qty'];
        $tot[$i]=$row[9];
         $gdtot+=$tot[$i];
         
  	 $i++;
  	 }
	elseif($row['group2']=='Filters')
   	{
	$re=mysqli_query($db,"select ndpcost from spareprmast where brcode='$brcode' and partcode='$row[21]' ");
	$re1=mysqli_fetch_row($re);
  	 $b[$j]=$row['item'];
	$prtot1[$j]=$re1[0]*$row['qty'];
         $tot1[$j]=$row[9];
	 $gdtot+=$tot1[$j];

	  	 $j++;
  	 }
     if($row['flag']=='labour')
   	{
  	 $c[$m]=$row['item'];
	 
         $tot2[$m]=$row[9];
	 $gdtot+=$tot2[$m];
	 $m++;
  	 }
   $veh=$row['vehno'];
   $invo=$row[0];
	

  }
  $max= max($i, $j,$m);
  $cnt=$max-1;
  for($k=1;$k<$max;$k++)
    {
      
      if($a[$k]==''){$a[$k]='--';} if($org[$k]==''){$org[$k]='--';} if($b[$k]==''){$b[$k]='--';} if($c[$k]==''){$c[$k]='--';}

     if($tot[$k]==''){$tot[$k]='0';} if($prtot[$k]==''){$prtot[$k]='0';} if($tot1[$k]==''){$tot1[$k]='0';} if($prtot1[$k]==''){$prtot1[$k]='0';}if($tot2[$k]==''){$tot2[$k]='0';}

     $gtot=$tot1[$k]+$tot[$k]+$tot2[$k];
    
    print "<tr><td>".$l."</td><td>".$veh."</td><td>".$invo."</td><td>".$a[$k]."</td><td>".$org[$k]."</td><td align='right'>".putcoma($tot[$k])."</td><td align='right'>".putcoma($prtot[$k])."</td><td>".$b[$k]."</td><td align='right'>".putcoma($tot1[$k])."</td><td align='right'>".putcoma($prtot1[$k])."</td><td>".$c[$k]."</td><td align='right'>".putcoma($tot2[$k])."</td><td align='right'>".putcoma($gtot)."</td>";
   
   if($k==1)
	{
    print "<td rowspan='".$cnt."' align='right'>".putcoma($gdtot)."</td>";
	}
    print "</tr>";
    $l++;
 //  $gdtot=0;
     $ntot+=$tot[$k];
	$ntot1+=$tot1[$k];
	$ntot2+=$tot2[$k];
	$nprtot+=$prtot[$k];
	$nprtot1+=$prtot1[$k];
       $ngtot+=$gtot;
       
 	 $tot1[$k]='';$tot[$k]='';$tot2[$k]=''; $a[$k]=''; $b[$k]=''; $c[$k]='';$org[$k]='';$prtot[$k]='';$prtot1[$k]='';
    }

    
   }
print "<tr><td colspan='5' align='left'><b>Total</b></td><td align='right'><b>".putcoma($ntot)."</b></td><td align='right'><b>".putcoma($nprtot)."</b></td><td></td><td align='right'><b>".putcoma($ntot1)."</b></td><td align='right'><b>".putcoma($nprtot1)."</b></td><td></td><td align='right'><b>".putcoma($ntot2)."</b></td><td align='center' colspan='2'><b>".putcoma($ngtot)."</b></td></tr>";

print "<tr><td rowspan='8' colspan='10' align='left'><b>Summary</b></td>";
print "<tr><td  colspan='4'><hr width='100%'></hr></td></tr>";
print "<tr><td  align='right' colspan='2'><b>Total Oil QR:</b></td><td align='right' colspan='2'><b>".putcoma($ntot)."</b></td></tr>";
print "<tr><td  align='right' colspan='2'><b>Total Oil Purchase Cost:</b></td><td align='right' colspan='2'><b>".putcoma($nprtot)."</b></td></tr>";
print "<tr><td  align='right' colspan='2'><b>Total Oil Filter QR:</b></td><td align='right' colspan='2'><b>".putcoma($ntot1)."</b></td></tr>";
print "<tr><td  align='right' colspan='2'><b>Total Filter Purchase Cost:</b></td><td align='right' colspan='2'><b>".putcoma($nprtot1)."</b></td></tr>";
print "<tr><td  align='right' colspan='2'><b>Total Labour QR:</b></td><td align='right' colspan='2'><b>".putcoma($ntot2)."</b></td></tr>";
print "<tr><td  align='right' colspan='2'><b>Grand Total QR:</b></td><td align='right' colspan='2'><b>".putcoma($ngtot)."</b></td></tr>";
print"</table>";
  }
 }
?>
</td></tr></table>

