<?php
  session_start();
  if(empty($_SESSION['branch']) || $_SESSION['branch'] == ''){
    header("Location: index.php");
    die();
  }
    require_once 'system/conn.php';
?>
<?php
    $empp_id = $_POST["empp_id"];
    
    $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];
    
    if ($empp_id == "General Bank Sheet"){
      $i = 1;
      $stmt = $conn->prepare(" SELECT `emp_id`,`name` FROM `emp_salary` WHERE `month`='$month' and `year`='$year' and `branch`='".$_SESSION['branch']."' and `block`='' and `cheque`='' and `ac_no`!='' ");
      $stmt->execute();
      $sql1 = $stmt->fetchAll(); ?>
      <option value="">Select Employee (GBS)</option>
    <?php foreach($sql1 as $row1) { ?>
      <option value="<?php echo $row1["emp_id"];?>"><?php echo $row1["name"];?> (<?php echo $row1["emp_id"];?>)</option>
   <?php  $i=$i+1; }
     
    } else if($empp_id == "General Cheque Sheet") {
      $a = 1;
      $stmt2 = $conn->prepare(" SELECT `emp_id`,`name` FROM `emp_salary` WHERE `branch`='".$_SESSION['branch']."' AND `month`='$month' AND `year`='$year' AND (`cheque`='yes' OR `ac_no`='') ");
      $stmt2->execute();
      $sql12 = $stmt2->fetchAll(); 
    ?>
      <option value="">Select Employee (GCS)</option>
    <?php foreach($sql2 as $row2) { ?>
      <option value="<?php echo $row2["emp_id"];?>"><?php echo $row2["name"];?> (<?php echo $row2["emp_id"];?>)</option>
   <?php  $a=$a+1; }
   
    } else if($empp_id == "OT Bank Sheet") {
      $b = 1;
      $stmt3 = $conn->prepare(" SELECT `emp_name`, `emp_id` FROM `ot_details` where `branch`='".$_SESSION['branch']."' and `month`='$month' and `year`='$year' and `Hold`='' and `cheque`='' and `ac_no`!='' ");
      $stmt3->execute();
      $sql13 = $stmt3->fetchAll(); 
    ?>
      <option value="">Select Employee (OBS)</option>
    <?php foreach($sql3 as $row3) { ?>
      <option value="<?php echo $row3["emp_id"];?>"><?php echo $row3["emp_name"];?> (<?php echo $row3["emp_id"];?>)</option>
   <?php  $b=$b+1; }
   
    } else {
      $c = 1;
      $stmt4 = $conn->prepare(" SELECT `emp_name`, `emp_id` FROM `ot_details` where `branch`='".$_SESSION['branch']."' AND `month`='$month' AND `year`='$year' AND (`cheque`='yes' OR `ac_no`='') ");
      $stmt4->execute();
      $sql14 = $stmt4->fetchAll(); 
    ?>
      <option value="">Select Employee (OCS)</option>
    <?php foreach($sql4 as $row4) { ?>
      <option value="<?php echo $row4["emp_id"];?>"><?php echo $row4["emp_name"];?> (<?php echo $row4["emp_id"];?>)</option>
   <?php  $c=$c+1; }
    }
?>