<!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>Expense Details</title>

        <style>
            table
            {
                border-collapse:collapse;
            }
            table, td, th
            {
                
                font-family:Arial, Helvetica, sans-serif;
                padding:5px;
            }
            th
            {
                font-weight:bold;
                font-size:13px;

            }
            td
            {
                font-size:12px;

            }
        </style>
        <style type="text/css">
            <!--
            .style1 {
                color: #0000FF;
                font-weight: bold;
                font-size: 24px;
            }
            -->
        </style>
    </head>

    <body> 

        <?php
        require_once("config.inc.php");
        require_once("DBConnector1.php");
        $db = new DBConnector();









        $sql_head = "select * from invpara";
        $result_head = $db->RunQuery($sql_head);
        $row_head = mysqli_fetch_array($result_head);

        echo "<center><span class=\"style1\">" . $row_head["COMPANY"] . "</span></center><br>";

        $heading = "<center><strong>Expense Details From  " . $_GET["DT1"] . " To ".  $_GET["DT2"]  . " </strong><br><br>";
        echo $heading;


        $sql = "select * from ledger where l_code = '12502' and grp1 != ''";
        
        if($_GET["grp1"] != 'All'){
           $sql .= " and grp1 = '".$_GET["grp1"]."'"; 
        }
        if($_GET["grp2"] != 'All'){
           $sql .= " and grp2 = '".$_GET["grp2"]."'"; 
        }
        if($_GET["grp3"] != 'All'){
           $sql .= " and grp3 = '".$_GET["grp3"]."'"; 
        }
        
        $sql .=" and l_date between '" .$_GET["DT1"]. "' and '" . $_GET["DT2"]. "' order by grp1, grp2, grp3";

        echo "<center><table border=1><tr>
        <th>Ref No</th><th>Date</th><th>Description</th><th>Amount</th></tr>";
	
	$brand = "";
	$brand1 = "";
	$brand2 = "";
        $result =$db->RunQuery($sql);
	
        $grp3 = 0;
        $totGrp3 = 0;
        while ($rows = mysqli_fetch_array($result)){
		if ($brand != $rows["grp1"]){
                    if($grp3!=0){
                        echo "<th colspan=7 align=right><b>".number_format($grp3, 2, ".", ",")."</b></th></tr>";                    
                        $grp3 = 0;
                    }
		    $brand=$rows["grp1"];

			echo "
			<th colspan=7 align=left><b>".$rows["grp1"]."</b></th></tr>";
			
		}
		if ($brand1 != $rows["grp2"]){
                    
                    if($grp3!=0){
                        echo "<th colspan=7 align=right><b>".number_format($grp3, 2, ".", ",")."</b></th></tr>";                    
                        $grp3 = 0;
                    }
                    
		    $brand1=$rows["grp2"];
			echo "
			<th colspan=7 align=center><b>".$rows["grp2"]."</b></th></tr>";
			
		} 
		if ($brand2 != $rows["grp3"]){
                    
                    if($grp3!=0){
                        echo "<th colspan=7 align=right><b>".number_format($grp3, 2, ".", ",")."</b></th></tr>";                    
                        $grp3 = 0;
                    }
                    
		    $brand2=$rows["grp3"];


			echo "
			<th colspan=7 align=right><b>".$rows["grp3"]."</b></th></tr>";
			
		} 
		
		echo "<tr><td>".$rows["l_refno"]."</td><td>".$rows["l_date"]."</td><td>".$rows["l_lmem"]."</td><td align=\"right\">".number_format($rows["l_amount"], 2, ".", ",")."</td></tr>";
		$grp3 += $rows["l_amount"];
		$totGrp3 += $rows["l_amount"];
	}
	echo "<th colspan=7 align=right><b>".number_format($grp3, 2, ".", ",")."</b></th></tr>";
	echo "<th colspan=7 align=right><b>".number_format($totGrp3, 2, ".", ",")."</b></th></tr>";
	
	echo "</table>";
        
        ?>



    </body>
</html>
