show.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /** @var \App\Domain\Sprint $sprint */
  3. /** @var \App\Domain\User $currentUser */
  4. /** @var string $csrfToken */
  5. /** @var list<\App\Domain\SprintWeek> $weeks */
  6. /** @var list<\App\Domain\SprintWorker> $sprintWorkers */
  7. /** @var array<int, array<int, float>> $grid sw_id => week_id => days */
  8. /** @var array<int, array{ressourcen:float, after_reserves:float, committed_prio1:float, available:float}> $capacity */
  9. use function App\Http\e;
  10. if (!function_exists('fmt_days')) {
  11. function fmt_days(float $x): string
  12. {
  13. // Show 0 as "0", whole numbers as integer, halves as x.5
  14. if (abs($x - round($x)) < 1e-9) {
  15. return (string) (int) round($x);
  16. }
  17. return number_format($x, 1);
  18. }
  19. }
  20. ?>
  21. <section class="space-y-6"
  22. data-sprint-root
  23. data-sprint-id="<?= (int) $sprint->id ?>"
  24. data-csrf="<?= e($csrfToken) ?>"
  25. data-reserve-fraction="<?= e(number_format($sprint->reserveFraction, 4, '.', '')) ?>">
  26. <header class="flex items-end justify-between gap-4">
  27. <div>
  28. <nav class="text-xs text-slate-500">
  29. <a href="/" class="hover:underline">Sprints</a> /
  30. </nav>
  31. <h1 class="text-2xl font-semibold tracking-tight"><?= e($sprint->name) ?></h1>
  32. <p class="text-slate-600 mt-1 text-sm">
  33. <?= e($sprint->startDate) ?> – <?= e($sprint->endDate) ?>
  34. · Reserve <?= e(number_format($sprint->reserveFraction * 100, 0)) ?>%
  35. <?php if ($sprint->isArchived): ?>
  36. · <span class="inline-block px-2 py-0.5 text-xs bg-slate-100 text-slate-600 rounded">archived</span>
  37. <?php endif; ?>
  38. </p>
  39. </div>
  40. <div class="flex items-center gap-3">
  41. <div data-status
  42. class="text-sm border rounded px-3 py-1 opacity-0 transition-opacity duration-200 border-slate-200 bg-slate-50 text-slate-700">
  43. </div>
  44. <?php if ($currentUser->isAdmin): ?>
  45. <a href="/sprints/<?= (int) $sprint->id ?>/settings"
  46. class="inline-flex items-center gap-2 rounded-md border border-slate-300 bg-white text-slate-700 px-3 py-2 text-sm hover:bg-slate-100">
  47. Settings
  48. </a>
  49. <?php endif; ?>
  50. </div>
  51. </header>
  52. <?php if ($sprintWorkers === [] || $weeks === []): ?>
  53. <div class="rounded-md border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900">
  54. <?php if ($weeks === []): ?>
  55. No weeks yet. <a href="/sprints/<?= (int) $sprint->id ?>/settings" class="underline">Open settings</a> to add some.
  56. <?php elseif ($sprintWorkers === []): ?>
  57. No workers on this sprint yet. <a href="/sprints/<?= (int) $sprint->id ?>/settings" class="underline">Open settings</a> to add some.
  58. <?php endif; ?>
  59. </div>
  60. <?php else: ?>
  61. <!-- Arbeitstage grid -->
  62. <section class="rounded-lg border bg-white overflow-x-auto">
  63. <table class="min-w-full text-sm" data-arbeitstage>
  64. <thead class="bg-slate-50 text-slate-600 text-xs uppercase tracking-wider">
  65. <tr>
  66. <th class="text-left px-3 py-2 font-semibold sticky left-0 bg-slate-50 z-10">&nbsp;</th>
  67. <?php foreach ($weeks as $w): ?>
  68. <th class="text-center px-2 py-2 font-semibold whitespace-nowrap">
  69. <div class="font-mono">KW<?= (int) $w->isoWeek ?></div>
  70. <div class="text-[10px] text-slate-500 font-normal"><?= e($w->startDate) ?></div>
  71. </th>
  72. <?php endforeach; ?>
  73. <th class="text-center px-2 py-2 font-semibold">Σ</th>
  74. <th class="text-center px-2 py-2 font-semibold">RTB</th>
  75. </tr>
  76. </thead>
  77. <tbody class="divide-y divide-slate-100" data-tbody>
  78. <!-- Arbeitstage (max working days) row -->
  79. <tr class="bg-slate-50">
  80. <th class="text-left px-3 py-2 font-semibold text-slate-700 sticky left-0 bg-slate-50">
  81. Arbeitstage
  82. </th>
  83. <?php $sumMax = 0.0; foreach ($weeks as $w): $sumMax += $w->maxWorkingDays; ?>
  84. <td class="px-1 py-1 text-center">
  85. <?php if ($currentUser->isAdmin): ?>
  86. <input type="number" min="0" max="5" step="0.5"
  87. value="<?= e(fmt_days($w->maxWorkingDays)) ?>"
  88. data-week-max data-week-id="<?= (int) $w->id ?>"
  89. class="w-14 rounded border border-slate-300 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">
  90. <?php else: ?>
  91. <span class="font-mono"><?= e(fmt_days($w->maxWorkingDays)) ?></span>
  92. <?php endif; ?>
  93. </td>
  94. <?php endforeach; ?>
  95. <td class="px-2 py-1 text-center font-mono font-semibold" data-sum-max>
  96. <?= e(fmt_days($sumMax)) ?>
  97. </td>
  98. <td>&nbsp;</td>
  99. </tr>
  100. <!-- One row per sprint worker -->
  101. <?php foreach ($sprintWorkers as $sw): ?>
  102. <?php $rowDays = $grid[$sw->id] ?? []; $rowSum = array_sum($rowDays); ?>
  103. <tr data-sw-row data-sw-id="<?= (int) $sw->id ?>">
  104. <th class="text-left px-3 py-2 font-medium sticky left-0 bg-white z-10">
  105. <span class="flex items-center gap-2">
  106. <?php if ($currentUser->isAdmin): ?>
  107. <span class="handle cursor-grab text-slate-400 select-none">&#8801;</span>
  108. <?php endif; ?>
  109. <?= e($sw->workerName) ?>
  110. </span>
  111. </th>
  112. <?php foreach ($weeks as $w): $v = (float) ($rowDays[$w->id] ?? 0.0); ?>
  113. <td class="px-1 py-1 text-center">
  114. <?php if ($currentUser->isAdmin): ?>
  115. <input type="number" min="0" max="5" step="0.5"
  116. value="<?= e(fmt_days($v)) ?>"
  117. data-day data-sw-id="<?= (int) $sw->id ?>"
  118. data-week-id="<?= (int) $w->id ?>"
  119. class="w-14 rounded border border-slate-200 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">
  120. <?php else: ?>
  121. <span class="font-mono"><?= e(fmt_days($v)) ?></span>
  122. <?php endif; ?>
  123. </td>
  124. <?php endforeach; ?>
  125. <td class="px-2 py-1 text-center font-mono font-semibold"
  126. data-sum-days data-sw-id="<?= (int) $sw->id ?>">
  127. <?= e(fmt_days($rowSum)) ?>
  128. </td>
  129. <td class="px-1 py-1 text-center">
  130. <?php if ($currentUser->isAdmin): ?>
  131. <input type="number" min="0" max="1" step="0.05"
  132. value="<?= e(number_format($sw->rtb, 2, '.', '')) ?>"
  133. data-rtb data-sw-id="<?= (int) $sw->id ?>"
  134. class="w-16 rounded border border-slate-200 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">
  135. <?php else: ?>
  136. <span class="font-mono"><?= e(number_format($sw->rtb, 2, '.', '')) ?></span>
  137. <?php endif; ?>
  138. </td>
  139. </tr>
  140. <?php endforeach; ?>
  141. </tbody>
  142. </table>
  143. </section>
  144. <!-- Capacity summary — one column per worker, aligned with task columns in Phase 6 -->
  145. <section class="rounded-lg border bg-white overflow-x-auto">
  146. <div class="px-4 py-2 border-b bg-slate-50 text-xs uppercase tracking-wider text-slate-600 font-semibold">
  147. Capacity
  148. </div>
  149. <table class="min-w-full text-sm">
  150. <thead>
  151. <tr class="bg-slate-50 text-slate-600 text-xs">
  152. <th class="text-left px-3 py-2 font-semibold sticky left-0 bg-slate-50 z-10">&nbsp;</th>
  153. <?php foreach ($sprintWorkers as $sw): ?>
  154. <th class="text-center px-2 py-2 font-semibold whitespace-nowrap">
  155. <?= e($sw->workerName) ?>
  156. </th>
  157. <?php endforeach; ?>
  158. </tr>
  159. </thead>
  160. <tbody class="divide-y divide-slate-100">
  161. <tr>
  162. <th class="text-left px-3 py-2 text-slate-700 font-medium sticky left-0 bg-white">Ressourcen</th>
  163. <?php foreach ($sprintWorkers as $sw): $c = $capacity[$sw->id] ?? null; ?>
  164. <td class="px-2 py-2 text-center font-mono"
  165. data-cap-ressourcen data-sw-id="<?= (int) $sw->id ?>">
  166. <?= e(fmt_days($c['ressourcen'] ?? 0.0)) ?>
  167. </td>
  168. <?php endforeach; ?>
  169. </tr>
  170. <tr>
  171. <th class="text-left px-3 py-2 text-slate-700 font-medium sticky left-0 bg-white">− Reserven</th>
  172. <?php foreach ($sprintWorkers as $sw): $c = $capacity[$sw->id] ?? null; ?>
  173. <td class="px-2 py-2 text-center font-mono text-slate-600"
  174. data-cap-after-reserves data-sw-id="<?= (int) $sw->id ?>">
  175. <?= e(fmt_days($c['after_reserves'] ?? 0.0)) ?>
  176. </td>
  177. <?php endforeach; ?>
  178. </tr>
  179. <tr>
  180. <th class="text-left px-3 py-2 text-slate-700 font-semibold sticky left-0 bg-white">Available</th>
  181. <?php foreach ($sprintWorkers as $sw): $c = $capacity[$sw->id] ?? null; $av = (float) ($c['available'] ?? 0.0); ?>
  182. <td class="px-2 py-2 text-center font-mono font-semibold <?= $av < 0 ? 'text-red-700' : 'text-slate-900' ?>"
  183. data-cap-available data-sw-id="<?= (int) $sw->id ?>">
  184. <?= e(fmt_days($av)) ?>
  185. </td>
  186. <?php endforeach; ?>
  187. </tr>
  188. </tbody>
  189. </table>
  190. </section>
  191. <p class="text-xs text-slate-500">
  192. Numeric inputs snap to 0.5 (days) or 0.05 (RTB) on blur. Edits save automatically
  193. with a 400&nbsp;ms debounce; Available turns red if a worker is overcommitted.
  194. </p>
  195. <?php endif; ?>
  196. <div class="rounded-md border border-slate-200 bg-slate-50 px-4 py-3 text-xs text-slate-600">
  197. Task list lands in Phase 6.
  198. </div>
  199. </section>
  200. <script src="/assets/js/sprint-planner.js" defer></script>