<? 
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");
include("calstock.php");

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
$qry=mysqli_query($db,"select * from invoice where invno='$inno'");
if(mysqli_num_rows($qry)<=0)
{
 print"<script>alert('invalid invoice number');document.location='excelinv1.php';</script>";
} 
else
{
 print "<script>window.print();</script>";
}
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>World Wide Automotive Center</title>
<style>



.tble1 input {
background-color:transparent;
border: 0px solid;
height:20px;
//width:160px;
color:black;
}
.tble1
{
border-collapse:collapse;
//font-style:normal;
}	



</style>

            
       <br>

<?
$qry=mysqli_query($db,"select * from invoice where invno='$inno'");
$row=mysqli_fetch_array($qry);       
$date = $row[1];
$newDate = date("d-m-Y", strtotime($date));
?>                                    


<center ><h2>INVOICE</h2></center >
<table width=100%>

<tr><td ><b>Customer Name:</b><? echo $row[2]; ?></td></tr><tr><td ><b>Invoice No:</b><? echo $row[0]; ?></td></tr>
<tr><td ><b>Register No:</b><? echo $row[3]; ?></td></tr><tr><td ><b>Invoice Date:</b><? echo $newDate; ?></td></tr>
<tr><td align='left'><b>Sales Person</b></td><td ><b>:</b></td><td align='left'><? echo $row[12]; ?></td></tr>


</table>

<table width=100% class='tble1' border=1>

<tr ><th>Sl No<th>Item<th>Unit<th>Quantity<th>Total<br>Amount<th>Disc<th>Net<br>Amount</tr>

<?
$i=1;
$s_ntot=0;
$l_ntot=0;
$res=mysqli_query($db,"select sum(qty),group1,sum(dis),sum(total) from invoice where invno='$inno' and flag='spares' group by group1");
if(mysqli_num_rows($res)>0)
{
?>
<tr><td colspan='7'align='left'><b>Spare</font></b></td></tr>
<?
}

//print "select sum(qty),group1,sum(dis),sum(total) from invoice where invno='$inno' group by group1";
while($res1=mysqli_fetch_array($res))
  {
   $tots=$res1[2]+$res1[3];
   print "<tr><td>".$i."</td><td>".$res1[1]."</td><td align='right'> litre</td><td align='right'>".$res1[0]."</td><td align='right'>".$tots."</td><td align='right'>".$res1[2]."</td><td align='right'>".$res1[3]."</td></tr>";
   $i++;
   $s_ntot+= $res1[3]; 
  }
?>


<?
$i=1;
$res2=mysqli_query($db,"select * from invoice where invno='$inno' and flag='labour' ");
if(mysqli_num_rows($res2)>0)
{
?>
<tr><td colspan='7'align='left' ><b><font >Labour</font></b></td></tr>
<?
}
//print "select sum(qty),group1,sum(dis),sum(total) from invoice where invno='$inno' group by group1";
while($res3=mysqli_fetch_array($res2))
  {
   $totl=$res3[8]+$res3[9];
   print "<tr><td>".$i."</td><td>".$res3[4]."</td><td align='right'> --</td><td align='right'>".$res3[6]."</td><td align='right'>".$totl."</td><td align='right'>".$res3[8]."</td><td align='right'>".$res3[9]."</td></tr>";
   $i++;
   $l_ntot+= $res3[9]; 
  }
  $gtot=$s_ntot+$l_ntot;
?>
</table>

<br><br>


       
    <br><br><br><br>
<script type="text/javascript" src="tabjs/jquery_004.js"></script>
    <script type="text/javascript">

        $('#default_notes_textarea, #to_address, #from_address').jqEasyCounter({
            'maxChars': 1000,
            'maxCharsWarning': 980,
            'msgFontSize': '10px',
            'msgFontColor': 'silver',
            'msgFontFamily': 'Arial',
            'msgTextAlign': 'right',
            'msgWarningColor': 'red',
            'msgAppendMethod': 'insertAfter',
            'allocateSpace': true
        });
        
        reCalculate(document.getElementById('sum_discount'),'dataTable','0.00');

        function loadReceiptLayer(obj){
            var to_id = $('#to_name').val();

            if (obj.checked){
                $('#receipts_layer').show(100, function(){
                    if (!$(this).attr('rloaded')){
                        $(this).attr('rloaded','true');
                        $('#receipts_layer').html('<img src="images/loadingsmall.gif">');

                        $.ajax({

                            url: "showExpenses.php?action=displayReceiptList&customer_id="+to_id+"&list=",
                            type: 'GET',
                            cache: false,
                            async: true,
                            dataType : 'json',
                            success:function(response){
                                if (response && response.success)
                                    $('#receipts_layer').html(response.html);
                                else
                                    $('#receipts_layer').html('Fail to load. Try Again');
                            },
                            error:function(){
                                $('#receipts_layer').html('There was an error. Try Again');
                            }
                        });




                    }
                }) ;
            }
            else{
                $('#receipts_layer').hide();
            }
        }

        $(function(){
            /*
            $('#to_name').change(function(){
                $('#receipts_layer').attr('rloaded','');
                document.getElementById('receipts_include').checked = false;
                $('#receipts_layer').hide();

            });
            */



        });
        $('#receipts_include').click(function(){


            var obj = $('#receipts_layer');
            if (document.getElementById('receipts_include').checked){


                if (obj.attr('rloaded') == 'true'){
                    obj.show();
            <b><b elssssssshbuhuuhbuhb);
     }else{
                obj.hide();
            }



        })

    </script>


    
						
		
		
		<!-- end main table wrapper -->
		</td></tr></tbody></table>
		
</body></html>


