index.blade.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. @extends('layouts.app')
  2. @section('content')
  3. <div class="p-0 m-0 table-responsive">
  4. <div class="row mb-3">
  5. <div class="col-md-6">
  6. <h3>График монтажей</h3>
  7. </div>
  8. <div class="col-md-6 text-end">
  9. <div class="d-flex flex-row justify-content-end">
  10. <div class="p-2">
  11. <button @disabled($weekNumber == 1) class="btn btn-sm btn-primary"
  12. onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber - 1]) }}'">
  13. <i class="bi bi-arrow-left"></i>
  14. </button>
  15. </div>
  16. <label class="p-2 d-none d-mb-block small mt-1" for="fromDate">Неделя №</label>
  17. <div class="p-2">
  18. <input type="number" style="width: 3rem" value="{{ $weekNumber }}"
  19. class="form-control form-control-sm" name="weekNumber"
  20. onchange="document.location = '{{ route('schedule.index') }}?week='+this.value"
  21. min="1" max="53" title="№ недели">
  22. </div>
  23. <div class="p-2">
  24. <input type="date" min="{{ year() . '-01-01' }}" max="{{ year() . '-12-31' }}"
  25. class="form-control form-control-sm" value="{{ $weekDates['mon'] }}"
  26. title="начало недели" name="monday" id="fromDate"
  27. onchange="document.location = '{{ route('schedule.index') }}?week=' + getWeekNumber(this.value)">
  28. </div>
  29. <div class="p-2 d-none d-md-block">
  30. <input type="date" disabled name="sunday"
  31. class="form-control form-control-sm" value="{{ $weekDates['sun'] }}"
  32. title="конец недели">
  33. </div>
  34. <div class="p-2">
  35. <button @disabled($weekNumber > 52) class="btn btn-sm btn-primary"
  36. onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber + 1]) }}'">
  37. <i class="bi bi-arrow-right"></i>
  38. </button>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <table class="table">
  44. <thead>
  45. <tr>
  46. <th class="text-center vertical">День недели</th>
  47. <th class="text-center vertical">Дата</th>
  48. <th>Код адр</th>
  49. <th>Округ</th>
  50. <th>Район</th>
  51. <th>Адрес</th>
  52. <th>Тип объекта</th>
  53. <th>Артикулы МАФ</th>
  54. <th>Кол-во позиций</th>
  55. <th>Бригадир</th>
  56. <th>Примечание</th>
  57. @if(hasRole('admin,manager'))
  58. <th></th>
  59. @endif
  60. </tr>
  61. </thead>
  62. <tbody>
  63. @foreach($schedules as $dow => $schs)
  64. <tr>
  65. <td rowspan="{{ ($schs) ? count($schs) : '1' }}"
  66. class="vertical">{{ \App\Helpers\DateHelper::getHumanDayOfWeek($dow) }}
  67. <i class="bi bi-calendar-plus text-primary ms-2 createSchedule"
  68. title="Новая запись" data-schedule-date="{{ $dow }}"></i>
  69. </td>
  70. <td rowspan="{{ ($schs) ? count($schs) : '1' }}"
  71. class="vertical">{{ \App\Helpers\DateHelper::getHumanDate($dow) }}</td>
  72. @if($schs)
  73. @foreach($schs as $schedule)
  74. {!! (!$loop->first) ? '<tr>':'' !!}
  75. <td style="background: {{ $schedule->brigadier->color }}"
  76. class="align-middle code-{{ $schedule->id }}">{{ $schedule->address_code }}</td>
  77. <td style="background: {{ $schedule->brigadier->color }}"
  78. class="align-middle">{{ $schedule->district->shortname }}</td>
  79. <td style="background: {{ $schedule->brigadier->color }}"
  80. class="align-middle">{{ $schedule->area->name }}</td>
  81. <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
  82. @if($schedule->order_id)
  83. <a href="{{ route('order.show', $schedule->order_id) }}">{{ $schedule->object_address }}</a>
  84. @else
  85. {{ $schedule->object_address }}
  86. @endif
  87. </td>
  88. <td style="background: {{ $schedule->brigadier->color }}"
  89. class="align-middle object-type-{{ $schedule->id }}">{{ $schedule->object_type }}</td>
  90. <td style="background: {{ $schedule->brigadier->color }}"
  91. class="align-middle mafs-{{ $schedule->id }}">{!! nl2br($schedule->mafs) !!}</td>
  92. <td style="background: {{ $schedule->brigadier->color }}"
  93. class="align-middle mafs-count-{{ $schedule->id }}">{{ $schedule->mafs_count }}</td>
  94. <td style="background: {{ $schedule->brigadier->color }}"
  95. class="align-middle">{{ $schedule->brigadier->name }}</td>
  96. <td style="background: {{ $schedule->brigadier->color }}"
  97. class="align-middle comment-{{ $schedule->id }}">{{ $schedule->comment }}</td>
  98. @if(hasRole('admin,manager'))
  99. <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
  100. <i class="bi bi-pencil p-1 m-1 cursor-pointer text-primary editSchedule"
  101. data-schedule-date="{{ $schedule->installation_date }}"
  102. data-schedule-address="{{ $schedule->object_address }}"
  103. data-schedule-district="{{ $schedule->district_id }}"
  104. data-schedule-brigadier="{{ $schedule->brigadier_id }}"
  105. data-schedule-area="{{ $schedule->area_id }}"
  106. data-schedule-id="{{ $schedule->id }}"></i>
  107. <i class="bi bi-trash text-danger p-1 m-1 deleteSchedule"
  108. data-schedule-id="{{ $schedule->id }}"></i>
  109. <div class="visually-hidden d-none">
  110. <form action="{{ route('schedule.delete', $schedule->id) }}" method="post"
  111. class="deleteForm-{{ $schedule->id }}">
  112. @csrf
  113. @method('DELETE')
  114. </form>
  115. </div>
  116. </td>
  117. @endif
  118. </tr>
  119. @endforeach
  120. @endif
  121. {!! (!$schs) ? '</tr>': '' !!}
  122. @endforeach
  123. </tbody>
  124. </table>
  125. <!-- Модальное окно редактирования графика -->
  126. <div class="modal fade" id="copySchedule" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  127. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  128. <div class="modal-content">
  129. <div class="modal-header">
  130. <h1 class="modal-title fs-5" id="addModalLabel">Изменить/создать запись в графике</h1>
  131. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  132. </div>
  133. <div class="modal-body">
  134. <form action="{{ route('schedule.update') }}" method="post" id="scheduleEditForm">
  135. @csrf
  136. <input type="hidden" name="id" value="0">
  137. <div>
  138. @include('partials.input', ['name' => 'installation_date', 'title' => 'Дата монтажа', 'type' => 'date'])
  139. @include('partials.input', ['name' => 'address_code', 'title' => 'Код адреса'])
  140. @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'first_empty' => true, 'required' => true])
  141. @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'required' => true, 'first_empty' => true])
  142. @include('partials.input', ['name' => 'object_address', 'title' => 'Адрес'])
  143. @include('partials.input', ['name' => 'object_type', 'title' => 'Тип объекта'])
  144. @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы'])
  145. @include('partials.input', ['name' => 'mafs_count', 'title' => 'Кол-во МАФ'])
  146. @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'required' => true, 'first_empty' => true])
  147. @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий'])
  148. <div class="text-center">
  149. <button type="submit" class="btn btn-primary btn-sm">Сохранить</button>
  150. </div>
  151. </div>
  152. </form>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. @if($errors->any())
  158. @dump($errors)
  159. @endif
  160. </div>
  161. @endsection
  162. @push('scripts')
  163. <script type="module">
  164. $('.editSchedule').on('click', function () {
  165. let scheduleId = $(this).attr('data-schedule-id');
  166. let scheduleDate = $(this).attr('data-schedule-date');
  167. let scheduleDistrict = $(this).attr('data-schedule-district');
  168. let scheduleArea = $(this).attr('data-schedule-area');
  169. let scheduleBrigadier = $(this).attr('data-schedule-brigadier');
  170. let scheduleAddress = $(this).attr('data-schedule-address');
  171. let scheduleComment = $('.comment-' + scheduleId).text();
  172. let scheduleMafs = $('.mafs-' + scheduleId).text();
  173. let scheduleObjectType = $('.object-type-' + scheduleId).text();
  174. let scheduleMafsCount = $('.mafs-count-' + scheduleId).text();
  175. let scheduleCode = $('.code-' + scheduleId).text();
  176. console.log(scheduleId, scheduleDate, scheduleDistrict, $(this).attr('data-schedule-brigadier'));
  177. $('form#scheduleEditForm input[name=id]').val(scheduleId);
  178. $('form#scheduleEditForm input[name=object_address]').val(scheduleAddress);
  179. $('form#scheduleEditForm input[name=object_type]').val(scheduleObjectType);
  180. $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
  181. $('form#scheduleEditForm select[name=district_id]').val(scheduleDistrict);
  182. $('form#scheduleEditForm select[name=area_id]').val(scheduleArea);
  183. $('form#scheduleEditForm select[name=brigadier_id]').val(scheduleBrigadier);
  184. $('form#scheduleEditForm textarea[name=comment]').text(scheduleComment);
  185. $('form#scheduleEditForm textarea[name=mafs]').text(scheduleMafs);
  186. $('form#scheduleEditForm input[name=mafs_count]').val(scheduleMafsCount);
  187. $('form#scheduleEditForm input[name=address_code]').val(scheduleCode);
  188. let myModalEditSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
  189. myModalEditSchedule.show();
  190. });
  191. $('.deleteSchedule').on('click', function () {
  192. if (confirm('Удалить запись?')) {
  193. let scheduleId = $(this).attr('data-schedule-id');
  194. $('.deleteForm-' + scheduleId).submit();
  195. }
  196. });
  197. $('.createSchedule').on('click', function () {
  198. let scheduleDate = $(this).attr('data-schedule-date');
  199. $('form#scheduleEditForm input[name=id]').val('');
  200. $('form#scheduleEditForm input[name=object_address]').val('');
  201. $('form#scheduleEditForm input[name=object_type]').val('');
  202. $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
  203. $('form#scheduleEditForm select[name=district_id]').val('');
  204. $('form#scheduleEditForm select[name=area_id]').val('');
  205. $('form#scheduleEditForm select[name=brigadier_id]').val('');
  206. $('form#scheduleEditForm textarea[name=comment]').text('');
  207. $('form#scheduleEditForm textarea[name=mafs]').text('');
  208. $('form#scheduleEditForm input[name=mafs_count]').val('');
  209. $('form#scheduleEditForm input[name=address_code]').val('');
  210. let myModalCreateSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
  211. myModalCreateSchedule.show();
  212. });
  213. // select order
  214. $('#search_order').on('keyup', function () {
  215. // search products on backend
  216. $.get('{{ route('order.search') }}?s=' + $(this).val(),
  217. function (data) {
  218. $('#select_order').children().remove()
  219. $.each(data, function (id, name) {
  220. $('#select_order').append('<option value=\'' + id + '\'>' + name + '</option>');
  221. });
  222. }
  223. );
  224. }).trigger('keyup');
  225. $('#district_id').on('change', function () {
  226. // load areas of selected district
  227. $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
  228. function (data) {
  229. $('#area_id').children().remove();
  230. $.each(data, function (id, name) {
  231. $('#area_id').append('<option value=\'' + id + '\'>' + name + '</option>');
  232. });
  233. }
  234. );
  235. });
  236. </script>
  237. <script type="text/javascript">
  238. function getWeekNumber(d) {
  239. // Copy date so don't modify original
  240. d = new Date(Date.parse(d));
  241. // Set to nearest Thursday: current date + 4 - current day number
  242. // Make Sunday's day number 7
  243. d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
  244. // Get first day of year
  245. let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
  246. // Calculate and return week number
  247. return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
  248. }
  249. </script>
  250. @endpush