GrafikRozlicz.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('UI');
  4. class Route_UrlAction_GrafikRozlicz extends RouteBase {
  5. function defaultAction() { UI::layout([ $this, 'defaultView' ]); }
  6. function defaultView() {
  7. $rows = DB::getPDO()->fetchAll("
  8. select
  9. g.DATE
  10. , g.L_APPOITMENT_USER
  11. , g.WORKER_COMMENT
  12. -- , g.*
  13. from GRAFIK_PRACY g
  14. where g.L_APPOITMENT_USER in ( 'sokol', 'm.kwiatkowski', 'kacper.klimanski' )
  15. and g.DATE like '2019-10-%'
  16. and g.WORKER_COMMENT != ''
  17. ");
  18. $rozliczList = array_reduce($rows, function ($ret, $item) {
  19. $splitTasks = explode("\n", $item['WORKER_COMMENT']);
  20. foreach ($splitTasks as $commentLine) {
  21. $commentLine = trim($commentLine);
  22. if (empty($commentLine)) continue;
  23. $ret[] = array_merge($item, [
  24. 'WORKER_COMMENT' => $commentLine,
  25. ]);
  26. }
  27. return $ret;
  28. }, []);
  29. // UI::table([
  30. // 'rows' => $rows,
  31. // ]);
  32. // UI::table([
  33. // 'rows' => $rozliczList,
  34. // ]);
  35. $rozliczByDayList = array_reduce($rozliczList, function ($ret, $item) {
  36. $day = $item['DATE'];
  37. if (array_key_exists($ret, $day)) $ret[$day] = [];
  38. $ret[$day][] = $item;
  39. return $ret;
  40. }, []); // [ day => [] ]
  41. ksort($rozliczByDayList);
  42. echo UI::h('div', [], array_map(function ($item, $day) {
  43. return UI::h('div', [], [
  44. UI::h('h3', [], "Dzień: {$day}"),
  45. UI::hTable([ 'rows' => $item ]),
  46. ]);
  47. }, $rozliczByDayList, array_keys($rozliczByDayList)));
  48. }
  49. }