<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../css/mm_training.css">
<script src="css/scrolltop/jquery-1.4.2.min.js" type='text/javascript'></SCRIPT>
<script type="text/javascript" src="css/scrolltop/scrolltopcontrol.js"></script>
<?php
include("../amssplus_connect.php");
require_once("../include/time_inc.php");
echo "<br><br><br><br>";
//ส่วนหัว
//if($month=='0'){ $month=date("m"); }
if($year==''){ $year=date("Y"); }
$mm=array("","01","02","03","04","05","06","07","08","09","10","11","12");
$mthai=array("-ไม่เลือก-","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
echo "<table width='60%' align=center ><tr><td align=right>";
//เลือกเดือน
echo "<select name='year' size=1
onChange=location.href='?on=report_meeting_statistic&month='+this.options[this.selectedIndex].value+'&year=$year';>";
for ($i=0; $i<=12; $i++){
if($mm[$i]==$month){
echo "<option value='$mm[$i]' selected>เดือน ".$mthai[$i]."</option>";
}else{
echo "<option value='$mm[$i]'>เดือน ".$mthai[$i]."</option>";
}
}
echo "</select>";
//เลือกปี
$sql="select book_date from meeting_main order by book_date DESC";
$dbquery=mysqli_query($connect,$sql);
echo "<select name='year' size=1
onChange=location.href='?on=report_meeting_statistic&month=$month&year='+this.options[this.selectedIndex].value;>";
//$this_year=date("Y");
//echo "<option value='$this_year'>".($this_year+543)."</option>";
while($result=mysqli_fetch_array($dbquery)){
$book_date=explode("-", $result['book_date']);
if($book_date[0]!=$book_year){
if($book_date[0]==$year){
echo "<option value='$book_date[0]' selected>ปี ".($book_date['0']+543)."</option>";
}else{
echo "<option value='$book_date[0]'>ปี ".($book_date['0']+543)."</option>";
}
}
$book_year=$book_date[0];
}
echo "</select>";
echo "</td></tr></table>";
//พิมพ์จากจุดนี้เป็นต้นไป
echo "<center>";
//ถ้าไม่เลือกเดือน แสดงประจำปี xx
//ถ้อเลือกเดือน แสดงประจำเดือน xxx ปี xx
if($month==''){
echo "<font color='#006666' size='3'><strong>สรุปข้อมูลสถิติการใช้ห้องประชุม ประจำปี ".($year+543)."</strong></font>";
}else{
$m=(int)$month;
echo "<font color='#006666' size='3'><strong>สรุปข้อมูลสถิติการใช้ห้องประชุม ประจำเดือน ".$mthai[$m]." พ.ศ.".($year+543)."</strong></font>";
}
echo "<br>";
echo $_SESSION['office_name'];
echo "</center>";
echo "<table class='myTable' width='50%' align='center'>";
echo "<tr style='background: blue; color: #fff; '>
<th width='10%'>ที่</th>
<th colspan=2>ประเภทการใช้งาน/ห้องประชุม</th>
<th width='15%'>จำนวนครั้ง</th>
<th width='15%'>จำนวนคน</th>
<th width='10%'>%</th></tr>";
//ข้อมูลสถิติ - แยกตามประเภทการใช้ห้องประชุม
if($month==''){
$sql = "select count(type_obj) as count_obj, sum(person_num) as sum_personnum, type_obj from meeting_main where book_date between '$year-01-01' and '$year-12-31' group by type_obj";
}else{
$sql = "select count(type_obj) as count_obj, sum(person_num) as sum_personnum, type_obj from meeting_main where book_date between '$year-$month-01' and '$year-$month-31' group by type_obj";
}
$dbquery = mysqli_query($connect,$sql);
while ($result=mysqli_fetch_array($dbquery)){
$sql2="select * from meeting_type_obj where code='$result[type_obj]' ";
$dbquery2=mysqli_query($connect,$sql2);
$result2=mysqli_fetch_array($dbquery2);
echo "<tr style='background: #aad5ff; '>";
echo "<td align='center'>".$result2[code]."</td>";
echo "<td colspan=2>".$result2['name']."</td>";
echo "<td align=center>".number_format($result['count_obj'])."</td>";
echo "<td align=center>".number_format($result['sum_personnum'])."</td>";
echo "<td align=center>100%</td>";
echo "</tr>";
//ข้อมูลสถิติ - แยกตามรายห้องประชุม
if($month==''){
$sql3 = "select count(room) as count_room, sum(person_num) as sum_personnum, room from meeting_main where room!='0' and type_obj='$result2[code]' and (book_date between '$year-01-01' and '$year-12-31') group by room";
}else{
$sql3 = "select count(room) as count_room, sum(person_num) as sum_personnum, room from meeting_main where room!='0' and type_obj='$result2[code]' and (book_date between '$year-$month-01' and '$year-$month-31') group by room";
}
$dbquery3 = mysqli_query($connect,$sql3);
while ($result3=mysqli_fetch_array($dbquery3)){
$sql4="select * from meeting_room where room_code='$result3[room]' ";
$dbquery4=mysqli_query($connect,$sql4);
$result4=mysqli_fetch_array($dbquery4);
if($result['sum_personnum']!='0'){
$percen_room=number_format(($result3['sum_personnum']/$result['sum_personnum'])*100,0);
}else{
$percen_room='0';
}
echo "<tr>";
echo "<td></td>";
echo "<td width='10%' align='center'>".$result4[id]."</td>";
echo "<td>".$result4['room_name']."</td>";
echo "<td align=center>".number_format($result3['count_room'])."</td>";
echo "<td align=center>".number_format($result3['sum_personnum'])."</td>";
echo "<td align=center>".$percen_room."%</td>";
echo "</tr>";
}
}
//รวมทั้งสิ้น
if($month==''){
$sql_all = "select count(room) as count_room, sum(person_num) as sum_personnum from meeting_main where room!='0' and (book_date between '$year-01-01' and '$year-12-31') ";
}else{
$sql_all = "select count(room) as count_room, sum(person_num) as sum_personnum from meeting_main where room!='0' and (book_date between '$year-$month-01' and '$year-$month-31') ";
}
$dbquery_all = mysqli_query($connect,$sql_all);
$result_all=mysqli_fetch_array($dbquery_all);
echo "<tr style='background: #aaffaa; '>";
echo "<td colspan=3><strong>รวมทั้งสิ้น</strong></td>";
echo "<td align=center><strong>".number_format($result_all['count_room'])."</strong></td>";
echo "<td align=center><strong>".number_format($result_all['sum_personnum'])."</strong></td>";
echo "<td align=center><strong>100%</strong></td>";
echo "</tr>";
//รวมทั้งหมด - แยกตามรายห้องประชุม
if($month==''){
$sql = "select count(room) as count_room, sum(person_num) as sum_personnum, room from meeting_main where room!='0' and (book_date between '$year-01-01' and '$year-12-31') group by room";
}else{
$sql = "select count(room) as count_room, sum(person_num) as sum_personnum, room from meeting_main where room!='0' and (book_date between '$year-$month-01' and '$year-$month-31') group by room";
}
$dbquery = mysqli_query($connect,$sql);
while ($result=mysqli_fetch_array($dbquery)){
$sql2="select * from meeting_room where room_code='$result[room]' ";
$dbquery2=mysqli_query($connect,$sql2);
while($result2=mysqli_fetch_array($dbquery2)){
if($result_all['sum_personnum']!='0'){
$percen_room=number_format(($result['sum_personnum']/$result_all['sum_personnum'])*100,0);
}else{
$percen_room='0';
}
echo "<tr style='background: #eaffea; '>";
echo "<td></td>";
echo "<td width='10%' align='center'>".$result2[id]."</td>";
echo "<td>".$result2['room_name']."</td>";
echo "<td align=center>".number_format($result['count_room'])."</td>";
echo "<td align=center>".number_format($result['sum_personnum'])."</td>";
echo "<td align=center>".$percen_room."%</td>";
echo "</tr>";
}
}
echo "</table>";
?>