Advertisement
Guest User

Morgan2

a guest
Jan 20th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.49 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4.   <title>Housekeeping Room Assignment</title>
  5.   <!-- CSS for formatting control -->
  6.   <?php
  7.     include('dt.css');
  8.   ?>
  9.   <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
  10.   <meta http-equiv="Pragma" content="no-cache" />
  11.   <meta http-equiv="Expires" content="0" />
  12. </head>
  13.  
  14. <body>
  15.  
  16. <font size = +2>.: Housekeeping Stats :.</font>
  17. <!-- menu -->
  18.  
  19. <!-- End menu -->
  20.  
  21. <hr>
  22.  
  23. <?php
  24. include('header.php');
  25. ?>
  26. Select a date to show stats for that specific date:<br><br>
  27. <form method="post">
  28.   <label>Date To Show:</label>
  29.  
  30.  
  31.  
  32.  
  33. <?php
  34. $DaysToSubtract = 0;
  35. // Check if form is submitted successfully
  36. if(isset($_POST["TheDate"]))  
  37. {
  38.     //echo 'I have a date!';  
  39.     $now = time(); // or your date as well
  40.     $your_date = strtotime($_POST["TheDate"]);
  41.     $datediff =  $now - $your_date ;
  42.  
  43.     //echo round($datediff / (60 * 60 * 24));
  44.     $DaysToSubtract = round($datediff / (60 * 60 * 24)) - 1 ;
  45.     //echo $DaysToSubtract;
  46.     ?>
  47.     <input type="date" id="TheDate" name="TheDate" value="<?php echo date($_POST["TheDate"]); ?>" />
  48.     <?php
  49. }  
  50. else
  51. {
  52.     //Default to today!
  53.     ?>
  54.     <input type="date" id="TheDate" name="TheDate" value="<?php echo date('Y-m-d'); ?>" />
  55.     <?php
  56.    
  57. }
  58. ?>
  59.     <input type="submit">
  60.     </form>
  61. <?php
  62.  
  63.     //Get the HKs with boards today
  64.     $strSQLA = 'SELECT DISTINCT RoomNumber FROM Boards WHERE TheDate = CURRENT_DATE() - ' . $DaysToSubtract . ' Order By RoomNumber';
  65.     //echo $strSQLA ."<br>";
  66.     $resultA = @mysqli_query ($dbc,$strSQLA);
  67.     while ($rowA = mysqli_fetch_array ($resultA, MYSQLI_ASSOC))
  68.     {
  69.         $arrStarts = array();
  70.         $arrStops = array();
  71.         $arrCompletes = array();
  72.         $arrEmployees = array();
  73.         $RoomTotals = 0;
  74.         $arrTotals = array();
  75.         echo '<h2>Room ' . $rowA['RoomNumber'] . "</h2>";
  76.         //For each room, get the punches
  77.         $strSQLC= 'SELECT * FROM Punches WHERE date(Timestamp) = CURRENT_DATE() - ' . $DaysToSubtract . '  AND RoomNumber = ' .  $rowA['RoomNumber'] . ' Order By EmpID asc, TimeStamp asc';
  78.         //echo $strSQLC . '<br>';
  79.         $resultC = @mysqli_query ($dbc,$strSQLC);
  80.         while ($rowC = mysqli_fetch_array ($resultC, MYSQLI_ASSOC))
  81.         {
  82.             //Display the results
  83.             //echo $rowB['RoomNumber'] . ' - ' . $rowC['TimeStamp'] . ' - ' . $rowC['Status'] . '<br>';
  84.             //if a StartResume, add to the start array
  85.             //if a Pause or Clean_***, add to the finish array
  86.             //Ignore all others
  87.             switch  ($rowC['Status'])
  88.             {
  89.                 case 'StartResume':
  90.                     array_push($arrEmployees,$rowC['EmpID']);
  91.                     array_push($arrStarts,$rowC['TimeStamp']);
  92.                     break;
  93.                 case 'Pause':
  94.                 case 'Clean_Vac':
  95.                 case 'Clean_Occ':
  96.                     //array_push($arrEmployees,$rowC['EmpID']);
  97.                     array_push($arrStops,$rowC['TimeStamp']);
  98.                     array_push($arrCompletes,$rowC['Status']);
  99.                     break;  
  100.             }
  101.             //array_push($arrRooms,$strTemp);
  102.             //arrStarts = array();
  103.             //arrStops = array();
  104.             //arrCompletes = array();
  105.         }//End of punches
  106.         echo '<table border = 1><tr><th>Employee</th><th>Entered</th><th>Exited</th><th>Time In<br>Room</th><th>Status</th></tr>';
  107.         //Display what is in the arrays
  108.         for ($y = 0; $y < count((array) $arrStarts);$y++)
  109.         {
  110.             //Same name, do the calculation
  111.             $TempStart = new DateTime($arrStarts[$y]);//start time
  112.             $TempStop = new DateTime($arrStops[$y]);//start time
  113.             $interval = $TempStop->diff($TempStart);
  114.             //Get the employee name
  115.             $strSQLName = "SELECT EmpName From Employee WHERE EmpID = " . $arrEmployees[$y];
  116.             //echo $strSQLName . '<br>';
  117.             $resultName = @mysqli_query ($dbc,$strSQLName);
  118.             while ($rowName = mysqli_fetch_array ($resultName, MYSQLI_ASSOC))
  119.             {
  120.                 $strOutput = $rowName['EmpName'];
  121.             }
  122.  
  123.             echo '<tr><td>' . $strOutput . '</td><td>' . $arrStarts[$y] . '</td><td>' . $arrStops[$y] . '</td><td align="center">' . $interval->format('%i') . '</td><td>' . $arrCompletes[$y] . '</td></tr>';
  124.             //echo '- ' . $arrStarts[$y] . ' - ' . $arrStops[$y] . ' - ' . $interval->format('%i') . '<br>';
  125.             //$arrTotals = array();
  126.             //try
  127.             //{
  128.                 array_push($arrTotals,$interval->format('%i'));
  129.             //} catch (Exception $e)
  130.             //{
  131.             //  echo 'Morgan caught an error!';
  132.             //}
  133.            
  134.             $RoomTotals += $interval->format('%i');
  135.         }  
  136.         echo '<tr><td></td><td></td><td align="right"><b>Total</b></td><td align="center"><b>' . $RoomTotals . '</b></td></tr>';
  137.         echo '</table>';
  138.        
  139.         //echo $row['EmpID'] . '<br>';
  140.         echo '<hr>';
  141.     }//End of employee
  142. ?>
  143. <!-- footer -->
  144. <?php
  145. include('footer.php');
  146. ?>
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement