<?php
    session_start();
    if(empty($_SESSION['id']) || $_SESSION['id'] == ''){
      header("Location: index.php");
      die();
    } 
    require_once "../system/conn.php";
?>
<!doctype html>
<html lang="en" class="semi-dark">
<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- loader-->
  <link href="assets/css/pace.min.css" rel="stylesheet" />
  <script src="assets/js/pace.min.js"></script>
  <!--plugins-->
  <link href="assets/plugins/vectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet"/>
  <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
  <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
  <link href="assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
  <link href="assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />
  <!-- CSS Files -->
  <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">
  <!--Theme Styles-->
  <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>UTCPL-Admin Panel</title>
</head>
<body>

  <!--start wrapper-->
  <div class="wrapper">
    <?php include'system/header.php'?>

    <!-- start page content wrapper-->
    <div class="page-content-wrapper">
      <!-- start page content-->
      <div class="page-content">

        <!--start breadcrumb-->
        <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
          <div class="breadcrumb-title pe-3">Dashboard</div>
          <div class="ps-3">
            <nav aria-label="breadcrumb">
              <ol class="breadcrumb mb-0 p-0 align-items-center">
                <li class="breadcrumb-item"><a href="javascript:;">
                    <ion-icon name="home-outline"></ion-icon>
                  </a>
                </li>
              </ol>
            </nav>
          </div>
        </div>
        <!--end breadcrumb-->

        <div class="row row-cols-1 row-cols-lg-2 row-cols-xl-4">
          <div class="col col-12 col-lg-12 col-xl-4">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $a=1;
                        $stmt = $conn->prepare("SELECT count(*) FROM `emp_details` where status=1 ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        echo $users;
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="all-employees.php">Total Employees</a></p>
                </div>
              </div>
            </div>
          </div>
          <div class="col col-12 col-lg-12 col-xl-4">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $a=1;
                        //$stmt = $conn->prepare("SELECT count(*) FROM `left_employee` where `status`= '1' ");
                        $stmt = $conn->prepare("SELECT COUNT(emp_details.`e_id`),emp_details.`branch`,left_employee.id FROM emp_details LEFT JOIN left_employee ON emp_details.`e_id`=left_employee.emp_id AND emp_details.branch=left_employee.branch WHERE emp_details.status='0' and left_employee.status='1' ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        echo $users;
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="left-employees.php">Left Employees</a></p>
                </div>
              </div>
            </div>
          </div>
          <?/*php ?><div class="col">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $a=1;
                        $stmt = $conn->prepare("SELECT count(*) FROM `rejoin_employee` ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        echo $users;
                    ?>
                   </h3>
                  <p class="text-muted mb-4"><a href="rejoin-employees.php">Rejoin Employees</a></p>
                </div>
              </div>
            </div>
          </div><?php */?>
          <div class="col col-12 col-lg-12 col-xl-4">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $date1=date('Y-m-d');
                        $date=date('Y-m', strtotime(date('Y-m')." -1 month"));
                        $date=explode('-',$date);
                        $month=$date[1];
                        $dateObj  = DateTime::createFromFormat('!m', $month);
                        $monthName = $dateObj->format('F');
                        $year=$date[0];
                        $year1 = $year.'-'.$month.'-'.'01';
							    
                        $stmt = $conn->prepare("SELECT count(*) FROM  emp_details WHERE e_doj BETWEEN '$year1' AND '$date1' AND status='1' ");
                        //print_r($stmt);exit;
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        echo $users;
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="new-employees.php">New Employees</a></p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!--end row-->
        
        <div class="row row-cols-1 row-cols-lg-2 row-cols-xl-4">
          <div class="col">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        $date1=date('Y-m-d');
                        $date=date('Y-m', strtotime(date('Y-m')." -1 month"));
                        $date=explode('-',$date);
                        $month=$date[1];
                        $monthNum  = $month;
                        $dateObj   = DateTime::createFromFormat('!m', $monthNum);
                        $monthName = $dateObj->format('F');
                        $year=$date[0];
                        
                        $stmt = $conn->prepare("SELECT SUM(net_pay) FROM `emp_salary` WHERE month='$month' AND year='$year'  ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        if($users>0){
                          echo round($users);  
                        }else{
                          echo '0';
                        }
                        
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="gross-sheet.php">Current Gross Salary</a></p>
                </div>
              </div>
            </div>
          </div>
          <div class="col">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $stmt = $conn->prepare(" SELECT SUM(net_pay) FROM `emp_salary` WHERE `month`='$month' and `year`='$year' and `block`='' and `cheque`='' and `ac_no`!='' ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        if($users>0){
                          echo $users;  
                        }else{
                          echo '0';
                        }
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="bank-sheet.php">Current Bank Sheet</a></p>
                </div>
              </div>
            </div>
          </div>
          <div class="col">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $stmt = $conn->prepare(" SELECT SUM(net_pay) FROM `emp_salary` WHERE `month`='$month' AND `year`='$year' AND (`cheque`='yes' OR `ac_no`='') ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        if($users>0){
                          echo $users;  
                        }else{
                          echo '0';
                        }
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="cheque-sheet.php">Current Cheque Sheet</a></p>
                </div>
              </div>
            </div>
          </div>
          <div class="col">
            <div class="card radius-10">
              <div class="card-body">
                <div class="mx-auto widget-icon bg-light-dark text-dark">
                  <i class="bi bi-people-fill"></i>
                </div>
                <div class="text-center mt-3">
                  <h3 class="text-dark mb-1">
                    <?php 
                        
                        $stmt = $conn->prepare(" SELECT SUM(net_pay) FROM `emp_salary` WHERE `month`='$month' AND `year`='$year' AND `block`='yes'  ");
                        $stmt->execute();
                        $users = $stmt->fetchColumn();
                        if($users>0){
                          echo $users;  
                        }else{
                          echo '0';
                        }
                    ?>
                  </h3>
                  <p class="text-muted mb-4"><a href="hold-sheet.php">Current Hold Sheet</a></p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!--end row-->


        <div class="row">
          <div class="col-12 col-lg-12 col-xl-6 d-flex">
            <div class="card radius-10 w-100">
              <div class="card-body">
                  
                <div id="chart5" class=""></div>
                <div class="d-flex align-items-center gap-5 justify-content-center mt-3 p-2 radius-10 border"> 
                 <a href="branch-list.php">
                  <div class="text-center">
                    <h3 class="text-dark mb-1">
                        <?php 
                            
                            $a=1;
                            $stmt = $conn->prepare("SELECT count(*) FROM `branch` ");
                            $stmt->execute();
                            $users = $stmt->fetchColumn();
                            if($users>0){
                          echo $users;  
                        }else{
                          echo '0';
                        }
                        ?>
                    </h3>
                    <p class="text-muted mb-4">Branch</p>
                  </div>
                 </a> 
                  <div class="border-end sepration"></div>
                  
               </div>
               
               <div class="d-flex align-items-center gap-5 justify-content-center mt-3 p-2 radius-10 border"> 
                 <a href="site-list.php">
                  <div class="text-center">
                    <h3 class="text-dark mb-1">
                        <?php 
                            
                            $a=1;
                            $stmt = $conn->prepare("SELECT count(*) FROM `site` ");
                            $stmt->execute();
                            $users = $stmt->fetchColumn();
                            if($users>0){
                              echo $users;  
                            }else{
                              echo '0';
                            }
                        ?>
                    </h3>
                    <p class="text-muted mb-4">Site</p>
                  </div>
                 </a> 
                  <div class="border-end sepration"></div>
                  
               </div>
               
               <div class="d-flex align-items-center gap-5 justify-content-center mt-3 p-2 radius-10 border"> 
                 <a href="designation.php">
                  <div class="text-center">
                    <h3 class="text-dark mb-1">
                        <?php 
                            
                            $a=1;
                            $stmt = $conn->prepare("SELECT count(*) FROM `designation` ");
                            $stmt->execute();
                            $users = $stmt->fetchColumn();
                            if($users>0){
                              echo $users;  
                            }else{
                              echo '0';
                            }
                        ?>
                    </h3>
                    <p class="text-muted mb-4">Designation</p>
                  </div>
                 </a> 
                  <div class="border-end sepration"></div>
                  
               </div>
               
              </div>
            </div>
          </div>
          <div class="col-12 col-lg-12 col-xl-6 d-flex">
            <div class="card radius-10 w-100">
              <div class="card-body">
                
                <div id="chart5" class=""></div>
                <div class="d-flex align-items-center gap-5 justify-content-center mt-3 p-2 radius-10 border"> 
                 <a href="all-employees.php">
                  <div class="text-center">
                    <h3 class="mb-2 text-dark">View all Emp</h3>
                  </div>
                 </a> 
                  <div class="border-end sepration"></div>
                  
               </div>
              </div>
            </div>
          </div>
          
        </div>
        <!--end row-->


      </div>
      <!-- end page content-->
    </div>
    <!--end page content wrapper-->


<?php include'system/footer.php'?>