<?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"];
	
	
?>


						  
	<?php
												  

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='address' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$address = $settingsSQL->value;

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='mobile' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$our_mobile = $settingsSQL->value;

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='email' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$our_email = $settingsSQL->value;
								   
?>	

<html>

<style>
body {
  background: rgb(204,204,204); 
}
page {
  background: white;
  display: block;
  padding-top: 2cm;
  padding-left: 2cm;
  padding-right: 2cm;
  margin: auto;
  margin-bottom: 2.0cm;
}
page[size="A4"] {  
  width: 21cm;
  height: 29.7cm; 
}
page[size="A4"][layout="landscape"] {
  width: 29.7cm;
  height: 21cm;  
}

@media print {
  body, page {
    margin: 0;
    box-shadow: 0;
  }
}



</style>

  <head>
    <title>Monthly Delivery Report</title>
	<meta http-equiv='content-type' content='text/html;charset=utf-8' />
  </head>
  
  <page size="A4">
  
  <body>
<center>
<table style="width:100%;border: 0px solid black;" cellpadding='0' height='' cellspacing='0'  >
 
  <tr align="center" >
    <td  style="width:100%; "  > <img src="assets/images/logo_wd.png" width="150" /> </br>
<?php echo "$address"; ?> </br>
<?php echo "$our_email"; ?> </br>
<?php echo "$our_mobile"; ?>  </br>
<b>Monthly Delivery Report</b> </br>
<b>Reporting Year: <?php echo "$year"; ?>  </b>

	</td>
  
  </tr>
</table>

</br></br>

<table style="width:100%" cellpadding='' height='' cellspacing='0' border='0' align='center' valign= 'top' >
	<tr align="left" >
	  <td style="width:40%;border-bottom: 1px solid black;" > 
	   &nbsp;&nbsp; <b>Month </b>
      </td> 
	 
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	   <b>Total Event</b>
      </td> 
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	  <b> Delivered</b>
      </td> 
	   <td style="width:20%;border-bottom: 1px solid black;" > 
	  &nbsp;&nbsp; <b> Due</b>
      </td>
	</tr> 
	
	
	
	 <?php 
											
											$sl=0;
                                $sqlSelectedLG = "select h1.*,IFNULL(h2.delivered_event,0) delivered_event , h1.total_event-IFNULL(h2.delivered_event,0) due from (SELECT month(t1.date) sl,monthname(t1.date) month, count(t1.id) total_event FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status!=0 AND t2.status!=2) AND year(t1.date)='$year' group by monthname(t1.date)) as h1 left join (SELECT month(t1.date) sl2,count(t1.id) delivered_event FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status!=0 AND t2.status!=2) AND year(t1.date)='$year' and t1.photo_dvd_st=2 AND CASE WHEN t1.videoincluded='checked' THEN t1.video_dvd_st=2 ELSE 1=1 END AND t1.photo_print_st=2 group by monthname(t1.date)) as h2 on h1.sl=h2.sl2 order by h1.sl";

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


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

                                 
                                  $month=$row1->month;
	                             $total_event=$row1->total_event;
	                              $delivered_event=$row1->delivered_event;
								   $due=$row1->due;
								   
								
									
									?>
	
	
	
	
	
	
	
	<tr align="left" >
	  <td style="width:40%;border-bottom: 1px solid black;" > 
	   &nbsp;&nbsp; <?php echo $month; ?>
      </td> 
	  
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	<?php echo $total_event; ?>
      </td> 
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	  <?php echo $delivered_event; ?> 
      </td> 
	   <td style="width:25%;border-bottom: 1px solid black;" > 
	  &nbsp;&nbsp;  <?php echo $due; ?>
      </td>
	</tr> 
	
	
							   <?php } ?>
</table>
</br></br>




 
 
 
 
 
 
 
 
 </center> 
 
 
  </body>
  
  </page>
  
</html>