Advertisement
Guest User

Pres

a guest
Feb 21st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\ChildrenPresent;
  6. use App\WorkingDays;
  7. use DateTime;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Auth;
  10. use Illuminate\Support\Facades\Response;
  11.  
  12. class PresenceController extends Controller
  13. {
  14. public function presence(Request $request)
  15. {
  16.  
  17. $publishDates = ChildrenPresent::where('CHILDREN_ID', Auth::user()->CHILDREN_ID)
  18. //->where('YYYYMM', date('Ym', $request->input('to') / 1000))
  19. ->get();
  20.  
  21. $output = [];
  22. $record = count($publishDates );
  23.  
  24. if ($record >= 1) {
  25. foreach ($publishDates as $publishDate ) {
  26. $year = substr($publishDate ->YYYYMM, 0, 4);
  27. $month = substr($publishDate ->YYYYMM, -2, 2);
  28.  
  29. $thework = WorkingDays::where('MM', $month)
  30. ->where('YYYY', $year)
  31. ->where('GARDEN_ID', $publishDate ->GARDEN_ID)
  32. ->get();
  33.  
  34. foreach ($thework as $work) {
  35. $workdays = str_split($work->DAY_STATUS);
  36. }
  37.  
  38. $days = str_split($publishDate ->DAY_STATUS);
  39. }
  40. $status = array(
  41. '0' => 'Непопълнен ден',
  42. '1' => 'Присъства',
  43. '2' => 'Отсъства по болест',
  44. '3' => 'Карантина',
  45. '4' => 'Отсъства по домашни причини',
  46. '5' => 'Отпуск',
  47. '6' => 'Служебно отсъствие',
  48. '7' => 'Неизвинено отсъствие'
  49. );
  50.  
  51. $color = array(
  52. '0' => '#E0EBF8',
  53. '1' => '#b9f6ca',
  54. '2' => '#fce4ec',
  55. '3' => '#ffab91',
  56. '4' => '#b3e5fc',
  57. '5' => '#ede7f6',
  58. '6' => '#efebe9',
  59. '7' => '#ffecb3'
  60. );
  61. $i = 0;
  62.  
  63. foreach ($workdays as $item) {
  64. $today = $i + 1;
  65.  
  66. setlocale(LC_TIME, 'bg.UTF-8');
  67. if (strtotime($today . '-' . substr($publishDate ->YYYYMM, -2) . '-' .
  68. substr($publishDate ->YYYYMM, 0, -2)) < strtotime(date('d-m-Y'))) {
  69.  
  70. if ($item == 1) {
  71. $day_by_day[$i] = array(
  72. 'today' => $today . '.' . $month . '.' . $year,
  73. 'status' => $status[$days[$i]]
  74. );
  75.  
  76. $output[] = array(
  77. 'id' => $publishDate->YYYYMM . $i,
  78. 'title' => $day_by_day[$i]['status'],
  79. 'color' => $color[$days[$i]],
  80. 'start' => date("Y-m-d H:i:s", strtotime($day_by_day[$i]['today'])),
  81. 'end' => date("Y-m-d H:i:s", strtotime($day_by_day[$i]['today'] . "+1 day" . "-1 second"))
  82. );
  83. }
  84. }
  85.  
  86. $i = $i + 1;
  87.  
  88. }
  89.  
  90. return response()->json($output);
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement