location_list.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @var Customer $customer
  4. * @var Location[] $locations
  5. */
  6. [$date_start, $date_end] = $customer->getYearCycleDates();
  7. $counts = [];
  8. if($locations) {
  9. $location_ids_csv = implode(", ", array_column($locations, "id"));
  10. $sql = "SELECT `location_id`, COUNT(`id`) AS `test_count`, SUM(IF(`retest` = 1, 1, 0)) AS `retest_count` FROM `test` WHERE `location_id` IN ($location_ids_csv) AND `dts_start` BETWEEN '$date_start' AND '$date_end' GROUP BY `location_id`";
  11. $result = DB::query($sql);
  12. while($row = DB::fetchAssoc($result)) {
  13. $counts[$row["location_id"]] = $row;
  14. }
  15. }
  16. ?>
  17. <div class="table-responsive limit-height-2">
  18. <table class="table table-sm table-sm-text table-hover">
  19. <thead>
  20. <tr>
  21. <th class="text-right pr-3">ID</th>
  22. <th>Name / Address</th>
  23. <th>Legal Entity</th>
  24. <th>Internal ID</th>
  25. <th>Tests</th>
  26. <th>Retests</th>
  27. <th></th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <?php
  32. foreach($locations as $location) {
  33. $class = "";
  34. if($location->isArchived()) $class = "text-muted";
  35. $test_count = $counts[$location->id]["test_count"] ?? 0;
  36. $retest_count = $counts[$location->id]["retest_count"] ?? 0;
  37. ?>
  38. <tr class="<?=$class?>">
  39. <td class="text-right pr-3">
  40. <?=$location->id?>
  41. </td>
  42. <td>
  43. <a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a>
  44. <?php
  45. if($location->closed) {
  46. ?>
  47. <span class="badge badge-danger">Closed</span>
  48. <?php
  49. }
  50. if($location->isArchived()) {
  51. ?>
  52. <span class="badge badge-secondary"><?=htmlspecialchars(__("Archived"))?></span>
  53. <?php
  54. }
  55. ?>
  56. <br />
  57. <small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]))?></small>
  58. </td>
  59. <td>
  60. <?=htmlspecialchars($location->legal_entity_name)?>
  61. </td>
  62. <td>
  63. <?=htmlspecialchars($location->internal_id)?>
  64. </td>
  65. <td class="text-right">
  66. <?=htmlspecialchars(number_format($test_count))?>
  67. </td>
  68. <td class="text-right">
  69. <?=htmlspecialchars(number_format($retest_count))?>
  70. </td>
  71. <td class="text-right align-middle">
  72. <a class="btn btn-sm btn-outline-primary" href="/account/locations/<?=$location->id?>/edit">Edit</a>
  73. </td>
  74. </tr>
  75. <?php
  76. }
  77. ?>
  78. </tbody>
  79. </table>
  80. </div>
  81. <?php
  82. if(empty($locations)) {
  83. ?>
  84. <div class="alert alert-info">
  85. No locations to display.
  86. </div>
  87. <?php
  88. }
  89. ?>