<?php
 session_start();
 error_reporting(E_ERROR | E_PARSE);
 error_reporting(0);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Emp_Prod_Benchmark</title>
    <link rel="shortcut icon" href="images/Files_Download.png" type="image/x-icon"/>
</head>
<style>
    .split.bor{
            margin-left:5%;
            transition: 1s; 
         
        }
    #nav-toggle:checked ~ .split.bor
    {
        margin-left:20%;
        transition: 1s;
        /* margin-right:15%; */
        
    }

  th,td {
  text-align:center;
}
 h5{
     text-align: center;
 }

</style>
<script>
function myFunction() {
  var x = document.getElementById("search").value;
  document.getElementById("process").innerHTML = x;
}
</script>
<body>
    <?php
    include "Nav.php";
    include "Connection.php"; 
    ?>

    <?php 
        date_default_timezone_set('Asia/Kolkata');
        $date =  date('Y-m-d h:i:s');
    ?>


<br><br><br>
<div class="container split bor">
<h5>TAT Report By Process</h5>
    <div class="container">
        <div class="row">
            <div class="col-md-12"><br>
                <form action="" method = "POST" enctype="multipart/form-data">
                   
                        <div class="form-control" style="background-color:#ffefea">
                            <label for="Project" class=""><b>Select Project :</b></label>
                            <select id="Project" name="Project" class="" placeholder="Select-Project" value="">
                            <option value="" ></option>
                            <?php
                            $_SESSION['pro'] = $proj;
                            $q = mysqli_query($con,"SELECT * FROM epb_tbl WHERE PROJECT in ('PL','OPL','CC');");
                            while($q_row= mysqli_fetch_array($q)) {
                            ?>
                            <option>
                            <?php echo $project = $q_row['PROJECT'];?></option>
                            <?php
                            }
                            ?>
                            </select>
                                <label class=" control-label"><b>From:</b></label>
                                <input type="date" name="dateFrom" value="<?php echo date('Y-m-d');?>" required >
                                <label class="control-label"><b>To:</b></label>
                                <input type="date" name="dateTo" value="<?php echo date('Y-m-d');?>" required>
                                <label class=" control-label"><b>Process:</b></label>
                                <input type="text" name="PROCESS" value="" id="process" autocomplete="off" >                           
                                <button class="btn btn-success btn-sm" type="submit" name="search" value="Search" id="search" onclick="myFunction()" style="border-radius:15px;">Search</button>
                        </div>
                </form>
            </div>
        </div>
    </div>
     
    <?php
  $proj = $_SESSION['proj']; 
  if(isset($_POST['search'])){
  
    $Process             = $_POST['PROCESS'];
    $From_date           = $_POST['dateFrom'];
    $To_date             = $_POST['dateTo'];
    $_SESSION['pro']     = $Process;
    $Project             = $_POST['Project'];
    $up                  = "select * from epb_tbl where Project='$Project'" ;
    $Query               = mysqli_query($con, $up);
        if(!$Query){
        
        // echo("Failed");
        ?>
            <script>

               swal("Operation Failed",
                     "Something went wrong",
                        "error",
                        {
                           dangerMode: true,
                           buttons: false,
                           closeOnClickOutside: true,
                           timer:5000,
                        });
            </script> 
        <?php
  
    }else{

        while($r = mysqli_fetch_array($Query)){ 
            $D_B = $r['Database'];
            $S_I = $r['Server_ip'];
            $U_N = $r['Username'];
            $P_W = $r['Password'];
        } 
    }
  }
?> <br>
<br>
<div class="container">
<B>Showing Results For : <?php echo $Project;?>  </B>
<table class="table table-bordered table-striped ">
    <thead >
        <tr>
            <th style=" text-align:center">TOTAL</th>  
            <th style=" text-align:center">TAT</th>
            <th style=" text-align:center">OUT OF TAT</th>
            <th style=" text-align:center">TAT in %</th>
            <th style=" text-align:center">Out of TAT in %</th>
        </tr>
    </thead>
    <tbody>   
        <?php
            $server= $S_I;
            $user= $U_N;
            $password= $P_W;
            $db= $D_B ;
            $connect=mysqli_connect($server,$user,$password,$db);
            if($connect->connect_error){ 
            die();
        ?>
            <script>             
               swal("Connection Failed",
                     "....",
                        "error",
                        {
                           dangerMode: true,
                           buttons: false,
                           closeOnClickOutside: true,
                           timer:5000,
                        });
            </script> 
<?php
}
else{
}
?>
   <?php
        $up = "SELECT COUNT(*) as TOTAL, BatchNo as BN,CreatedDateTime as CDT, OutputDateTime as ODT,OutputFlag as OF,soleTextFlag as S,LEFT(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,CreatedDateTime,OutputDateTime )),8) as TDif,if((timestampdiff(SECOND,CreatedDateTime,OutputDateTime) > '7200'),'NO','YES') AS `FinalStatus` from batches where CreatedDate between '$From_date' and '$To_date' and soletextflag='Y';";
        $Query = mysqli_query($connect, $up);
        while ($r = mysqli_fetch_array($Query)){
        $Tot_IPro = $r['TOTAL']; 
        $Tot_Yes = $r['YES'];
        $Tot_No = $r['NO'];
        $Y =  ($Tot_Yes /$Tot_IPro ) * 100 ;
        $N = ($Tot_No /$Tot_IPro ) * 100 ;   
    ?>
        <tr>
        <td> <?php echo $r['TOTAL'] ;?> </td> 
        <td> <?php echo $r['YES'] ;?> </td> 
        <td> <?php echo $r['NO'] ;?> </td> 
        <td> <?php echo (round($Y));?><span>%</span> </td>
        <td> <?php echo (round($N));?><span>%</span> </td>
        </tr>
 <?php
    }
 ?>
</div>
</tbody>
</table> 
</div>
</body>
</html>
        