Advertisement
Guest User

Morgan

a guest
Jan 20th, 2024
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.45 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.         echo '<h2>Room ' . $rowA['RoomNumber'] . "</h2>";
  75.         //For each room, get the punches
  76.         $strSQLC= 'SELECT * FROM Punches WHERE date(Timestamp) = CURRENT_DATE() - ' . $DaysToSubtract . '  AND RoomNumber = ' .  $rowA['RoomNumber'] . ' Order By EmpID asc, TimeStamp asc';
  77.         //echo $strSQLC . '<br>';
  78.         $resultC = @mysqli_query ($dbc,$strSQLC);
  79.         while ($rowC = mysqli_fetch_array ($resultC, MYSQLI_ASSOC))
  80.         {
  81.             //Display the results
  82.             //echo $rowB['RoomNumber'] . ' - ' . $rowC['TimeStamp'] . ' - ' . $rowC['Status'] . '<br>';
  83.             //if a StartResume, add to the start array
  84.             //if a Pause or Clean_***, add to the finish array
  85.             //Ignore all others
  86.             switch  ($rowC['Status'])
  87.             {
  88.                 case 'StartResume':
  89.                     array_push($arrEmployees,$rowC['EmpID']);
  90.                     array_push($arrStarts,$rowC['TimeStamp']);
  91.                     break;
  92.                 case 'Pause':
  93.                 case 'Clean_Vac':
  94.                 case 'Clean_Occ':
  95.                     //array_push($arrEmployees,$rowC['EmpID']);
  96.                     array_push($arrStops,$rowC['TimeStamp']);
  97.                     array_push($arrCompletes,$rowC['Status']);
  98.                     break;  
  99.             }
  100.             //array_push($arrRooms,$strTemp);
  101.             //arrStarts = array();
  102.             //arrStops = array();
  103.             //arrCompletes = array();
  104.         }//End of punches
  105.         echo '<table border = 1><tr><th>Employee</th><th>Entered</th><th>Exited</th><th>Time In<br>Room</th><th>Status</th></tr>';
  106.         //Display what is in the arrays
  107.         for ($y = 0; $y < count((array) $arrStarts);$y++)
  108.         {
  109.             //Same name, do the calculation
  110.             $TempStart = new DateTime($arrStarts[$y]);//start time
  111.             $TempStop = new DateTime($arrStops[$y]);//start time
  112.             $interval = $TempStop->diff($TempStart);
  113.             //Get the employee name
  114.             $strSQLName = "SELECT EmpName From Employee WHERE EmpID = " . $arrEmployees[$y];
  115.             //echo $strSQLName . '<br>';
  116.             $resultName = @mysqli_query ($dbc,$strSQLName);
  117.             while ($rowName = mysqli_fetch_array ($resultName, MYSQLI_ASSOC))
  118.             {
  119.                 $strOutput = $rowName['EmpName'];
  120.             }
  121.  
  122.             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>';
  123.             //echo '- ' . $arrStarts[$y] . ' - ' . $arrStops[$y] . ' - ' . $interval->format('%i') . '<br>';
  124.             //$arrTotals = array();
  125.             try
  126.             {
  127.                 array_push($arrTotals,$interval->format('%i'));
  128.             } catch (Exception $e)
  129.             {
  130.                 echo 'Morgan caught an error!';
  131.             }
  132.            
  133.             $RoomTotals += $interval->format('%i');
  134.         }  
  135.         echo '<tr><td></td><td></td><td align="right"><b>Total</b></td><td align="center"><b>' . $RoomTotals . '</b></td></tr>';
  136.         echo '</table>';
  137.        
  138.         //echo $row['EmpID'] . '<br>';
  139.         echo '<hr>';
  140.     }//End of employee
  141. ?>
  142. <!-- footer -->
  143. <?php
  144. include('footer.php');
  145. ?>
  146. </body>
  147. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement