<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php 

$date;
if($_REQUEST['date']!=NULL){
 
 $date=date('Y-m-d', strtotime($_REQUEST['date']));
  
}else{

  $date=date('Y-m-d');
}


  $m->where("branch_id", $_SESSION['branch']);
  $branch=$m->get("edu_branch_config");


	$brnch=$_SESSION['branch'];


   $qr="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='P'  and branch_Id='$brnch' and date='$date'";

 
   $result=$m->query($qr);
   $p=$result[0]['total'];

   $qr_lev="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='L' and branch_Id='$brnch' and date='$date'";
   $result_lev=$m->query($qr_lev);
   $lev=$result_lev[0]['total'];

   $qr_ab="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='A' and branch_Id='$brnch' and date='$date'";
   $result_ab=$m->query($qr_ab);
   $abs=$result_ab[0]['total'];




?>
 <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<title>Daily Attendance Report</title>

<script type="text/javascript">
 window.print();
</script>
<style type="text/css">
.border{
  border-right: 1px solid black;
  border-top: 1px solid black;
}
tr td{padding:1%;font-size:12px;}
tr th{padding:1.5%;font-size:14px;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}



@media print {
    #Header, #Footer { display: none !important; }
}
@media screen
   {
      p.bodyText {font-family:verdana, arial, sans-serif;}
   }

   @media print
   {
      p.bodyText {font-family:georgia, times, serif;}
   }
   @media screen, print
   {
      p.bodyText {font-size:10pt}
   }
   @media print {
  a[href]:after {
    content: none !important;
  }
}
</style>
</head>
<body style="padding:2%;">


<div style="text-align:center;font-size:25px;font-weight:bold;margin:0 auto;color:#042954;"><?php echo $branch[0]['Branch_Name'];?>  </div> <br>


<div style="text-align:center;font-size:14px;"><b> Daily Attendance Report</b></div>

<hr style="width:100%;">

<div style="width:15%;float:left;">  <b> Date:</b> <?php echo date("d-M-Y", strtotime($date)); ?> </div>

<div style="width:15%; float:left; "> <b> Total Presents:</b> <?php echo $p;?> </div>

<div style="width:15%; float:left; "> <b> Total Late:</b> <?php echo $LA;?> </div>

<div style="width:15%; float:left; "> <b> Total Absents:</b> <?php echo $abs;?> </div>

<div style="width:15%; float:left; "> <b> Total Leaves:</b> <?php echo $lev;?> </div>

<div style="width:15%; float:left; "> <b> Total Short Leaves:</b> <?php echo $SL;?> </div>

<br>


  <table width="100%" class="table" style="font-size:11px;" cellspacing="0" >
  
  
  
  
    <tr style="background-color:#042954;color:white;">
      <th width="5%" class="border" style="border-left: 1px solid black;"><strong>S.No</strong></th>
      <th width="30%" class="border alignment"><strong>Class Name </strong></th>
      <th width="8%" class="border"><strong>Total </strong></th>
      <th width="8%" class="border"><strong>Present </strong></th>
      <th width="8%" class="border"><strong>Late </strong></th>
      <th width="8%" class="border"><strong>Absent </strong></th>
      <th width="8%" class="border"><strong>Leave </strong></th>
      <th width="8%" class="border" style="font-size:13px;"><strong>Short Leave </strong></th>
      <th width="8%" class="border"><strong>Present % </strong></th>
      <th width="8%" class="border "><strong> Date</strong></th>
      
      
    </tr>
   
        
<?php 

    $count=1;
    $branch=$_SESSION['branch'];
    $WorkAssignListings = $m->query("SELECT sec.*, cls.* FROM edu_adm_section_detail as sec LEFT JOIN edu_class_config as cls ON sec.class_id = cls.class_id where cls.class_id!='' and cls.branch_id='$branch' ORDER BY cls.class_id asc");

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

     
     
	  $cls=$WorkAssignListVal['class_id'];
	  $section=$WorkAssignListVal['section_id'];
	  
      $qr_total_std="SELECT count(*) as total FROM edu_student_details WHERE status='0' and branch_id='$brnch' and class_id='$cls' and section_id='$section'";
      //echo $qr_total_std;
       $total_std=$m->query($qr_total_std);
       $TotalStd=$total_std[0]['total'];


       $attendanceReport = $m->query("SELECT COUNT(IF(att.attendance = 'P', 1, NULL)) 'Present', COUNT(IF(att.attendance = 'LA', 1, NULL)) 'Lait', COUNT(IF(att.attendance = 'L', 1, NULL)) 'Leave', COUNT(IF(att.attendance = 'SL', 1, NULL)) 'sLeave', COUNT(IF(att.attendance = 'A', 1, NULL)) 'Absent' FROM eduportal_attendance_detail as att  where att.class_id='$cls'and att.section_id='$section' and att.branch_Id='$brnch' and att.date='$date'");

      /* $qr_attendance="SELECT COUNT(IF(att.attendance = 'P', 1, NULL)) 'Present', COUNT(IF(att.attendance = 'LA', 1, NULL)) 'Lait', COUNT(IF(att.attendance = 'L', 1, NULL)) 'Leave', COUNT(IF(att.attendance = 'SL', 1, NULL)) 'sLeave', COUNT(IF(att.attendance = 'A', 1, NULL)) 'Absent' FROM eduportal_attendance_detail as att  where att.class_id='$cls'and att.section_id='$section' and att.branch_Id='$brnch' and att.date='$date'";
//print_r($qr_attendance);
        $attendanceReport=$m->query($qr_attendance);*/

       $p=$attendanceReport[0]['Present'];
       $LA=$attendanceReport[0]['Lait'];
       $lev=$attendanceReport[0]['Leave'];
       $SL=$attendanceReport[0]['sLeave'];
       $abs=$attendanceReport[0]['Absent'];

  
	/*   $qr="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='P' and branch_Id='$brnch' and class_id='$cls' and section_id='$section' and date='$date'";
	   $result=$m->query($qr);
	   $p=$result[0]['total'];*/

       /*$qr_la="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='LA' and branch_Id='$brnch' and class_id='$cls' and section_id='$section' and date='$date'";
       $result_la=$m->query($qr_la);
       $LA=$result_la[0]['total'];*/

	   /*$qr_lev="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='L' and branch_Id='$brnch' and class_id='$cls' and section_id='$section' and date='$date'";
	   $result_lev=$m->query($qr_lev);
	   $lev=$result_lev[0]['total'];*/

        /*$qr_SL="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='SL' and branch_Id='$brnch' and class_id='$cls' and section_id='$section' and date='$date'";
       $result_SL=$m->query($qr_SL);
       $SL=$result_SL[0]['total'];*/

	   /*$qr_ab="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='A' and branch_Id='$brnch' and class_id='$cls' and section_id='$section' and date='$date'";
	   $result_ab=$m->query($qr_ab);
	   $abs=$result_ab[0]['total'];*/

$total_students+= $TotalStd;
$total_present+= $p;
$total_late+= $LA;
$total_absent+= $abs;
$total_leave+= $lev;
$total_Shortleave+= $SL;

?>
    <tr>
      <td  class="border center" style="border-left: 1px solid black;"><?php echo  $count; ?> </td>
      <td  class="border alignment"><?php echo  $WorkAssignListVal['Class_Name']." - ".$WorkAssignListVal['section_name'] ; ?></td>
      <td  class="border center"><?php echo  $TotalStd; ?></td>
      <td  class="border center"><?php echo  $p; ?></td>
      <td  class="border center"><?php echo  $LA; ?></td>
      <td  class="border center"><?php echo  $abs; ?></td>
      <td  class="border center"><?php echo  $lev; ?></td>
      <td  class="border center"><?php echo  $SL; ?></td>
      <td  class="border center"><?php echo  number_format($p*100/$TotalStd,2); ?>%</td>
      <td  class="border center"> <?php echo date("d-M-Y");?> </td>
      
    </tr>
   
<?php $count++; 
    }
?>
      <tr style="background-color:#042954;color:white;">
       <th colspan="2" class="border center" style="border-left: 1px solid black; border-bottom: 1px solid black;">Total: </th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo $total_students;?></th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo $total_present;?></th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo $total_late;?></th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo $total_absent;?></th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo $total_leave;?></th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo $total_Shortleave;?></th>
       <th class="border center" style="border-bottom: 1px solid black;"><?php echo  number_format($total_present*100/$total_students,2); ?>%</th>
       <th class="border center" style="border-bottom: 1px solid black;"></th>
      </tr>
   
  </table>

</body>
</html>
