<?php
date_default_timezone_set('Asia/Kolkata'); 
include ('../config.php');
@session_start();
@$user_id1=$_SESSION['user_id1'];
@$idvfied1=$_SESSION['idverified1'];
@$namevfied1=$_SESSION['namevfied1'];
if(!isset($_SESSION['user_id1'])){
	header("Location: index.php");
}

$timeout = 60 * 60 * 24 * 365;
$s_name = session_name();
if(isset($_COOKIE[$s_name])) {
  setcookie($s_name, $_COOKIE[$s_name], time() + $timeout, '/');
}

$sel1=mysqli_query($conn,"select * from hr_dump where empid='".@$user_id1."'");
$fetch1=mysqli_fetch_array($sel1);

$queryFR=mysqli_query($conn,"select * from tracker where Functional_Reporting='".$fetch1['Employee_Number']."'");
$dataFR=mysqli_fetch_array($queryFR);

$queryFR=mysqli_query($conn,"select * from emp_leave where Functional_Reporting='".$fetch1['Employee_Number']."'");
$dataFR=mysqli_fetch_array($queryFR);
?>

<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Dashboard IC AMS</title>
	
	<?php include ('header.php'); ?>
	
	<div id="appCapsule">
        <div class="section wallet-card-section pt-1">
            <div class="wallet-card">
				<?php include ('include/wallet-balance.php'); ?>
				<div class="wallet-footer">
                    <div class="row text-center">
						<div class="col-6">
							<a href="viewcurrent.php"><div class="icon-wrapper bg-success text-white"><i class="fas fa-calendar-alt"></i></div>
								<strong class="pstrong">Current Month</strong>
							</a>
						</div>
						<div class="col-6">
							<a href="viewlast.php"><div class="icon-wrapper"><i class="fas fa-calendar-check"></i></div>
								<strong class="pstrong">Last Month</strong>
							</a>
						</div>
					</div>
                </div>
            </div>
        </div>
		
		<div class="col-md-12 col-sm-12 py-4">
			
			<h6 class="text-center">Attendance : <?php echo date("Y-F"); ?></h6>
			<p class="text-center">Update Time - 10:50 to 20:50 (Every 60 Min.)</p>
			
			<div class="table">
				<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
					<thead>
					<tr class="small text-center">
						<th>Date</th>
						<th>Status</th>
						<th>Office In - Out</th> 
					</tr>
					</thead>
					<tbody>
<?php
    $sn = date('Y-m-01');  // Start of the current month
    $tn = date('Y-m-d');   // Today's date

    while ($sn <= $tn) {
        $cmsql = mysqli_query($conn, "SELECT * FROM ams_final WHERE empid='" . @$user_id1 . "' AND OfficeDate='$sn'");
        $cmdata = mysqli_fetch_array($cmsql);
?>
    <tr class="small">
        <td><?php echo $sn; ?></td>

        <td class='text-center'>
            <?php
                if (!$cmdata) {
                    echo "<b class='text-danger'>A</b>";
                } elseif ($cmdata['FinalStatus'] == 'A') {
                    echo "<b class='text-danger'>A</b>";
                } elseif ($cmdata['FinalStatus'] == 'WOFF') {
                    echo "<b class='text-success'>WOFF</b>";
                } elseif ($cmdata['FinalStatus'] == 'HOLIDAY') {
                    echo "<span class='text-success'>HOLIDAY</span>";
                } elseif ($cmdata['FinalStatus'] == 'HALF') {
                    echo "<div class='bg-warning'>HALF</div>";
                } elseif ($cmdata['FinalStatus'] == 'SRT') {
                    echo "<div class='bg-warning'>SRT</div>";
                } elseif ($cmdata['FinalStatus'] == 'LATE') {
                    echo "<div class='bg-warning'>LATE</div>";
                } elseif ($cmdata['FinalStatus'] == 'EARLY') {
                    echo "<div class='bg-warning'>EARLY</div>";
                } elseif ($cmdata['FinalStatus'] == 'MIS') {
                    echo "<div class='bg-warning'>MIS</div>";
                } else {
                    echo $cmdata['FinalStatus'];
                }
            ?>
        </td>

        <td class='text-center'>
            <?php
                if (!$cmdata || $cmdata['InTime'] == '') {
                    echo "-";
                } else {
                    echo $cmdata['InTime'] . " - " . $cmdata['OutTime'];
                }

                if ($cmdata && $cmdata['Approval_Status'] == 'Pending') {
                    echo " <span class='bg-warning px-1'>Pending</span>";
                } elseif ($cmdata) {
                    echo " " . $cmdata['Approval_Status'];
                }
            ?>
        </td>
    </tr>
<?php
        $sn = date('Y-m-d', strtotime($sn . ' +1 day'));  // Increment date
    }
?>
</tbody>
				</table>
			</div>
		</div>

	<?php include ('include/copyright.php'); ?>
	</div>
	
	<?php include ('footer.php'); ?>
