<?php
namespace PHPMaker2020\hostelmgr20;

// Session
if (session_status() !== PHP_SESSION_ACTIVE)
	session_start(); // Init session data

// Output buffering
ob_start();
?>
<?php include_once "autoload.php"; ?>
<?php

// Write header
WriteHeader(FALSE);

// Create page object
$_dashboard = new _dashboard();

// Run the page
$_dashboard->run();

// Setup login status
SetupLoginStatus();
SetClientVar("login", LoginStatus());

// Global Page Rendering event (in userfn*.php)
Page_Rendering();
?>
<?php include_once "header.php"; ?>
<?php
	 $DB =& DbHelper(); // Create instance of the database helper class by DbHelper() (for main database) or DbHelper("<dbname>") (for linked databases) where <dbname> is database variable name
 ?>
<div class="panel panel-defeault">
	 <div class="panel-heading">Floor-wise Strength</div>
	 <div class="panel-body">
 <?php
 $sql = "SELECT abscount.Date,  hostel.Hostel_Name, floor.Floor, Count(DISTINCT admission.id) AS Strength, Sum(DISTINCT abscount.Absent) AS Absent, Count(DISTINCT admission.id) - Sum(DISTINCT abscount.Absent) AS Present  FROM admission INNER JOIN hostel ON hostel.id = admission.Hostel  INNER JOIN floor ON floor.id = admission.Floor  INNER JOIN abscount ON hostel.id = abscount.Hostel AND floor.id = abscount.Floor  WHERE (abscount.Date = CurDate()) OR (abscount.Date = CurDate() - 1) GROUP BY abscount.Date, hostel.Hostel_Name, floor.Floor ORDER BY abscount.Floor";
 echo $DB->ExecuteHtml($sql, ["fieldcaption" => TRUE, "tablename" => ["hostel", "floor", "abscount"]]); // Execute a SQL and show as HTML table
 ?>
	 </div>
 </div>

 <div class="card">
	 <div class="card-heading">Hostel-wise Strength</div>
	 <div class="card-body">
 <?php
 $sql = "SELECT abscount.Date, hostel.Hostel_Name,  Sum(DISTINCT abscount.Absent) AS Sum_Absent FROM hostel  INNER JOIN abscount ON hostel.id = abscount.Hostel  INNER JOIN floor ON floor.id = abscount.Floor GROUP BY abscount.Date,  hostel.Hostel_Name ORDER BY abscount.Date DESC";
 echo $DB->ExecuteHtml($sql, ["fieldcaption" => TRUE, "tablename" => ["hostel", "floor", "abscount"]]); // Execute a SQL and show as HTML table
 ?>
	 </div>
 </div>
 
 <div class="card">
	 <div class="card-heading">Count</div>
	 <div class="card-body">
 <?php
 $sql = "SELECT abscount.Date,  hostel.Hostel_Name,  floor.Floor,  Sum(DISTINCT abscount.Absent) AS `Total Absent`FROM hostel  INNER JOIN abscount ON hostel.id = abscount.Hostel  INNER JOIN floor ON floor.id = abscount.Floor WHERE (abscount.Date = CurDate()) OR  (abscount.Date = CurDate() - 1) GROUP BY abscount.Date,  hostel.Hostel_Name,  floor.Floor";
 echo $DB->ExecuteHtml($sql, ["fieldcaption" => TRUE, "tablename" => ["hostel", "floor", "abscount"]]); // Execute a SQL and show as HTML table
 ?>
	 </div>
 </div>



<?php if (Config("DEBUG")) echo GetDebugMessage(); ?>
<?php include_once "footer.php"; ?>
<?php
$_dashboard->terminate();
?>