<?php session_start(); ob_start(); ?>

<?php  include 'header.php'; ?>

<?php
ini_set('display_errors', 0);

if(empty($_SESSION['LOGINID']) && empty($_SESSION['LOGINNM']) ){

	header("Location:index.php");
}


include("user.php");

$year = $_GET["year"];

?>



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Report</title>
    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">
    <!-- Styles -->
     <link href="assets/css/lib/data-table/buttons.bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/owl.carousel.min.css" rel="stylesheet" />
    <link href="assets/css/lib/owl.theme.default.min.css" rel="stylesheet" />
    <link href="assets/css/lib/weather-icons.css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/unix.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
</head>

<body>

   
   
   
     <?php include("sidebar.php"); ?>
	
	
    <!-- /# sidebar -->
     <?php include("top.php"); ?>
	<!-- /# topebar --> 
	
	
	
    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-8 p-r-0 title-margin-right">
                        <div class="page-header">
                            <div class="page-title">
                                <h1>Hello, <span>Welcome Here</span></h1>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                    <div class="col-lg-4 p-l-0 title-margin-left">
                        <div class="page-header">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Dashboard</a></li>
                                    <li class="active">Home</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                </div>
                <!-- /# row -->
                <section id="main-content">
				
				
			
				
				
				
				
				
				<div class="row">
				
				        <div class="col-lg-12">
						
						<div class="panel panel-info m-t-15">
                                            <div class="panel-heading">Report</div>
                                            <div class="panel-body">
						
								  

								  
								  
								  
								 
								  
								  
								  
								  
								  
								  
								  
								  
								  
                                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card alert">
							
							
								
								
								 <div class="bootstrap-data-table-panel">
                                    <div class="table-responsive">
                                        <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                            <thead>
                                                <tr> <th>SL</th>
                                                    <th>Month</th>
													<th>Total Booking Value</th>
														<th>Paid</th>
													<th>Due</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											
								<?php 
											
														$sl=0;
                                $sqlSelectedLG = " select * from (select ( CASE w1.month  WHEN 'January' THEN 1
            WHEN 'February' THEN 2
            WHEN 'March' THEN 3
            WHEN 'April' THEN 4
            WHEN 'May' THEN 5
            WHEN 'June' THEN 6
            WHEN 'July' THEN 7
            WHEN 'August' THEN 8
            WHEN 'September' THEN 9
            WHEN 'October' THEN 10
            WHEN 'November' THEN 11
            WHEN 'December' THEN 12
          END ) as m , w1.*,IFNULL(w2.a_ev_value,0) a_ev_value,IFNULL(w3.in_total,0) in_total,IFNULL(w1.ev_value,0)+IFNULL(w2.a_ev_value,0)+IFNULL(w3.in_total,0) as total_booking_value,w4.event_value,w5.total_received,w6.total_no_bk from(SELECT MONTHNAME(approved_at) month, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='no') AND YEAR(approved_at) = '$year' group by MONTHNAME(approved_at) order by DATE_FORMAT('approved_at', '%m')) as w1 left join (SELECT MONTHNAME(approved_at) month, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) a_ev_value FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='yes') AND YEAR(approved_at) = '$year' group by MONTHNAME(approved_at) order by DATE_FORMAT('approved_at', '%m')) as w2 on w1.month=w2.month left join (SELECT MONTHNAME(date) month,sum(t1.inv_amount)-sum(t2.discount) as in_total from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items` group by invoice_id order by invoice_id desc) as t1 left join invoices as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id where YEAR(date) = '$year' group by MONTHNAME(date) order by DATE_FORMAT('date', '%m')) as w3 on w1.month=w3.month left join (SELECT MONTHNAME(t1.date) month,sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) event_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where t2.status=1 AND YEAR(t1.date) = '$year' group by MONTHNAME(t1.date) order by DATE_FORMAT('t1.date', '%m') ) as w4 on w1.month=w4.month left join (SELECT MONTHNAME(dd2.approved_at) month, sum(dd1.amount) total_received FROM `transactions` as dd1 left join bookings as dd2 on dd1.temp_booking_id=dd2.id where YEAR(dd2.approved_at) = '$year' group by MONTHNAME(dd2.approved_at) order by DATE_FORMAT('dd2.approved_at', '%m') ) as w5 on w1.month=w5.month left join (SELECT MONTHNAME(approved_at) month, count(id) total_no_bk FROM `bookings` where (booking_id!=0 AND status!=2) AND YEAR(approved_at) = '$year' group by MONTHNAME(approved_at) order by DATE_FORMAT('approved_at', '%m')) as w6 on w1.month=w6.month) as y order by y.m";

                               $sqlSelectedLG = mysqli_query($connection, $sqlSelectedLG);


                               while ($row1 = mysqli_fetch_object($sqlSelectedLG)) {

                                 $sl=$sl+1;
                                  $month=$row1->month;
	                             $ev_value=$row1->ev_value;
	                              $a_ev_value=$row1->a_ev_value;
								   $in_total=$row1->in_total;
								    $total_booking_value=$row1->total_booking_value;
									 $event_value=$row1->event_value;
									  $total_received=$row1->total_received;
									  
									  $total_no_bk=$row1->total_no_bk;
									  
			                     $total=$total_asset+$balance;						
					
				                $balancen=IND_money_format($balance);
								
									
									?>
											
											
											
											
                                                <tr>
                                                      <td>   <?php echo $sl; ?> </td>
                                                    <td> <?php echo $month; ?></td>
                                                    <td> <?php echo round($total_booking_value,0); ?></td>
                                                   
													
													 <td>	 <?php echo $total_received; ?> </td>
													  <td>	 <?php echo round($total_booking_value,0)-$total_received;; ?></td>
												
													
													
                                                </tr>
                                                
												
<?php } ?>			
												
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
								
								
								
								
								
								
								
                            </div>
                            <!-- /# card -->
                        </div>
                        <!-- /# column -->
                    </div>

                                   


							 </div> </div>
							
                        </div>
				
				
                        <!-- /# column -->
                        
                    </div>
				
				
				
				
				
                    <!-- /# row -->
                     <?php include("footer.php"); ?>
                </section>
            </div>
        </div>
    </div>

    <div id="search">
        <button type="button" class="close">×</button>
        <form>
            <input type="search" value="" placeholder="type keyword(s) here" />
            <button type="submit" class="btn btn-primary">Search</button>
        </form>
    </div>


    </div>
    <script src="assets/js/lib/jquery.min.js"></script>
    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
    <script src="assets/js/lib/bootstrap.min.js"></script>
    <!-- bootstrap -->
   
    <script src="assets/js/scripts.js"></script>
	
	 <script src="assets/js/lib/data-table/datatables.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.dataTables.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.flash.min.js"></script>
    <script src="assets/js/lib/data-table/jszip.min.js"></script>
    <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
    <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/datatables-init.js"></script>



</body>

</html>