<?php 
    session_start();
    if(!$_SESSION['id']){
        header('location:index.php');
    }
    require_once '../system/conn.php';
?>
<!doctype html>
<html lang="en" class="semi-dark">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="assets/css/pace.min.css" rel="stylesheet" />
	<script src="assets/js/pace.min.js"></script>
    <link href="assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
    <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
    <link href="assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />
    <link href="assets/plugins/datatable/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/bootstrap-extended.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/icons.css" rel="stylesheet">
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
    <link href="assets/css/dark-theme.css" rel="stylesheet" />
    <link href="assets/css/semi-dark.css" rel="stylesheet" />
    <link href="assets/css/header-colors.css" rel="stylesheet" />
    <title>Previous Attendance (<?php echo $_POST['year'].' - '.$_POST['month'] ?>)</title>
  </head>
  <body>
    <div class="wrapper">
    <?php include'system/header.php'?>
	  <div class="page-content-wrapper">
        <div class="page-content">
          <!--start breadcrumb-->
          <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
            <?php $dateObj   = DateTime::createFromFormat('!m', $_POST['month'] );
            $monthName = $dateObj->format('F'); ?>
            <div class="breadcrumb-title pe-3">Previous Attendance (<?php echo $_POST['year'].' - '.$monthName ?>)</div>
            <div class="ms-auto">
              <a href="excel-prv-attendance.php?m=<?php echo $_POST['month']?>&y=<?php echo $_POST['year']?>"><button type="button" class="btn btn-primary px-5">Excel Download</button></a>
            </div>
          </div>
		  <hr/>
		  <div class="card">
			<div class="card-body">
			  <div class="table-responsive">
				<table id="example2" class="table table-striped table-bordered">
				  <thead>
					<tr>
						<th>SR No</th>
            			<th>Id No</th>
            			<th>Employee Id</th>
                        <th>Employee Name</th>
                        <th>Designation</th>
                        <th>Branch</th>
                        <th>Site</th>
                        <th>Attendance</th>
                        <th>Only OT</th>
                        <th>Check</th>
                        <th>Hold</th>
                        <th>Adv Deduction</th>
                        <th>Special Allowance</th>
					</tr>
				  </thead>
				  <tbody>
				    <?php
                      $month=$_POST['month'];
                      $year=$_POST['year'];
                      $cnt = 1;
                      $stmt = $conn->prepare(" SELECT emp_details.e_name , emp_details.designation, prv_attendance.emp_id, prv_attendance.branch, prv_attendance.site, prv_attendance.attendance, prv_attendance.only_ot , prv_attendance.check, prv_attendance.block, prv_attendance.advance_deduction, prv_attendance.spc_allow FROM `prv_attendance` LEFT JOIN `emp_details` ON prv_attendance.emp_id=emp_details.e_id AND prv_attendance.branch=emp_details.branch where prv_attendance.month='$month' and prv_attendance.year='$year' ORDER BY emp_details.e_name ASC; ");
                      //print_r($stmt);exit;
                      $stmt->execute();
                      $sql = $stmt->fetchAll();
                      foreach($sql as $row) 
                    { ?>
                    <tr>
                        <td><?php echo $cnt;?></td>
                        <td>
                            <a href="view-details-all-emp.php?id=<?php echo $row1['sn'];?>"><?php echo $row['emp_id'];?></a>
                        </td>
                        <td><?php echo $row['emp_id']; ?></td>
                        <td><?php echo $row['e_name']; ?></td>
                        <td><?php echo $row['designation']; ?></td>
                        <td>
                            <?php   
                                $stmt1 = $conn->prepare(" SELECT `name` FROM `branch` WHERE `id`='".$row['branch']."' ");
                                $stmt1->execute();
                                $sql1 = $stmt1->fetchAll();
                                foreach($sql1 as $row1) 
                                {  
                                  echo $row1['name'];    
                            } ?>
                        </td>
                        <td>
                            <?php   
                                $stmt2 = $conn->prepare(" SELECT `name` FROM `site` WHERE `id`='".$row['site']."' ");
                                $stmt2->execute();
                                $sql2 = $stmt2->fetchAll();
                                foreach($sql2 as $row2) 
                                {  
                                  echo $row2['name'];    
                            } ?>
                        </td>
                        <td><?php echo $row['attendance'];?></td>
                        <td><?php echo $row['only_ot'];?></td>
                        <td><?php echo $row['check'];?></td>
                        <td><?php echo $row['block'];?></td>
                        <td><?php echo $row['advance_deduction'];?></td>
                        <td><?php echo $row['spc_allow'];?></td>
                    </tr>
                    <?php  $cnt=$cnt+1; }?>
				  </tbody>
				  <tfoot>
					<tr>
						<th>SR No</th>
            			<th>Id No</th>
            			<th>Employee Id</th>
                        <th>Employee Name</th>
                        <th>Designation</th>
                        <th>Branch</th>
                        <th>Site</th>
                        <th>Attendance</th>
                        <th>Only OT</th>
                        <th>Check</th>
                        <th>Hold</th>
                        <th>Adv Deduction</th>
                        <th>Special Allowance</th>
					</tr>
				  </tfoot>
				</table>
			  </div>
			</div>
		  </div>
             
        </div>
        <!-- end page content-->
    </div>
<?php include'system/footer.php'?>