| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- @extends('layouts.app')
- @section('content')
- <div class="p-0 m-0 table-responsive">
- <div class="row mb-3">
- <div class="col-md-6">
- <h3>График монтажей</h3>
- </div>
- <div class="col-md-6 text-end">
- <div class="d-flex flex-row justify-content-end">
- <div class="p-2">
- <button @disabled($weekNumber == 1) class="btn btn-sm btn-primary"
- onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber - 1]) }}'">
- <i class="bi bi-arrow-left"></i>
- </button>
- </div>
- <label class="p-2 d-none d-mb-block small mt-1" for="fromDate">Неделя №</label>
- <div class="p-2">
- <input type="number" style="width: 3rem" value="{{ $weekNumber }}"
- class="form-control form-control-sm" name="weekNumber"
- onchange="document.location = '{{ route('schedule.index') }}?week='+this.value"
- min="1" max="53" title="№ недели">
- </div>
- <div class="p-2">
- <input type="date" min="{{ year() . '-01-01' }}" max="{{ year() . '-12-31' }}"
- class="form-control form-control-sm" value="{{ $weekDates['mon'] }}"
- title="начало недели" name="monday" id="fromDate"
- onchange="document.location = '{{ route('schedule.index') }}?week=' + getWeekNumber(this.value)">
- </div>
- <div class="p-2 d-none d-md-block">
- <input type="date" disabled name="sunday"
- class="form-control form-control-sm" value="{{ $weekDates['sun'] }}"
- title="конец недели">
- </div>
- <div class="p-2">
- <button @disabled($weekNumber > 52) class="btn btn-sm btn-primary"
- onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber + 1]) }}'">
- <i class="bi bi-arrow-right"></i>
- </button>
- </div>
- @if(hasRole('admin'))
- <div class="p-2 ms-3">
- <form action="{{ route('schedule.export') }}" method="post">
- @csrf
- <input type="hidden" name="start_date" value="{{ $weekDates['mon'] }}">
- <input type="hidden" name="end_date" value="{{ $weekDates['sun'] }}">
- <input type="hidden" name="week" value="{{ $weekNumber }}">
- <button type="submit" class="btn btn-sm btn-primary" id="exportScheduleButton">Экспорт</button>
- </form>
- </div>
- @endif
- </div>
- </div>
- </div>
- <table class="table">
- <thead>
- <tr>
- <th class="text-center vertical">День недели</th>
- <th class="text-center vertical">Дата</th>
- <th>Код адр</th>
- <th>Округ</th>
- <th>Район</th>
- <th>Адрес</th>
- <th>Тип объекта</th>
- <th>Артикулы МАФ</th>
- <th>Кол-во позиций</th>
- <th>Бригадир</th>
- <th>Примечание</th>
- @if(hasRole('admin'))
- <th></th>
- @endif
- </tr>
- </thead>
- <tbody>
- @foreach($schedules as $dow => $schs)
- <tr>
- <td rowspan="{{ ($schs) ? count($schs) : '1' }}"
- class="vertical">{{ \App\Helpers\DateHelper::getHumanDayOfWeek($dow) }}
- @if(hasRole('admin'))
- <i class="bi bi-calendar-plus text-primary ms-2 createSchedule"
- title="Новая запись" data-schedule-date="{{ $dow }}"></i>
- @endif
- </td>
- <td rowspan="{{ ($schs) ? count($schs) : '1' }}"
- class="vertical">{{ \App\Helpers\DateHelper::getHumanDate($dow) }}</td>
- @if($schs)
- @foreach($schs as $schedule)
- {!! (!$loop->first) ? '<tr>':'' !!}
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle code-{{ $schedule->id }}">{{ $schedule->address_code }}</td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle">{{ $schedule->district->shortname }}</td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle">{{ $schedule->area->name }}</td>
- <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
- @if($schedule->order_id)
- <a href="{{ route('order.show', $schedule->order_id) }}">{{ $schedule->object_address }}</a>
- @else
- {{ $schedule->object_address }}
- @endif
- </td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle object-type-{{ $schedule->id }}">{{ $schedule->object_type }}</td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle mafs-{{ $schedule->id }}">{!! nl2br($schedule->mafs) !!}</td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle mafs-count-{{ $schedule->id }}">{{ $schedule->mafs_count }}</td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle">{{ $schedule->brigadier->name }}</td>
- <td style="background: {{ $schedule->brigadier->color }}"
- class="align-middle comment-{{ $schedule->id }}">{{ $schedule->comment }}</td>
- @if(hasRole('admin'))
- <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
- <i class="bi bi-pencil p-1 m-1 cursor-pointer text-primary editSchedule"
- data-schedule-date="{{ $schedule->installation_date }}"
- data-schedule-address="{{ $schedule->object_address }}"
- data-schedule-district="{{ $schedule->district_id }}"
- data-schedule-brigadier="{{ $schedule->brigadier_id }}"
- data-schedule-area="{{ $schedule->area_id }}"
- data-schedule-id="{{ $schedule->id }}"></i>
- <i class="bi bi-trash text-danger p-1 m-1 deleteSchedule"
- data-schedule-id="{{ $schedule->id }}"></i>
- <div class="visually-hidden d-none">
- <form action="{{ route('schedule.delete', $schedule->id) }}" method="post"
- class="deleteForm-{{ $schedule->id }}">
- @csrf
- @method('DELETE')
- </form>
- </div>
- </td>
- @endif
- </tr>
- @endforeach
- @endif
- {!! (!$schs) ? '</tr>': '' !!}
- @endforeach
- </tbody>
- </table>
- <!-- Модальное окно редактирования графика -->
- <div class="modal fade" id="copySchedule" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
- <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
- <div class="modal-content">
- <div class="modal-header">
- <h1 class="modal-title fs-5" id="addModalLabel">Изменить/создать запись в графике</h1>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
- </div>
- <div class="modal-body">
- <form action="{{ route('schedule.update') }}" method="post" id="scheduleEditForm">
- @csrf
- <input type="hidden" name="id" value="0">
- <div>
- @include('partials.input', ['name' => 'installation_date', 'title' => 'Дата монтажа', 'type' => 'date'])
- @include('partials.input', ['name' => 'address_code', 'title' => 'Код адреса'])
- @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'first_empty' => true, 'required' => true])
- @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'required' => true, 'first_empty' => true])
- @include('partials.input', ['name' => 'object_address', 'title' => 'Адрес'])
- @include('partials.input', ['name' => 'object_type', 'title' => 'Тип объекта'])
- @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы'])
- @include('partials.input', ['name' => 'mafs_count', 'title' => 'Кол-во МАФ'])
- @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'required' => true, 'first_empty' => true])
- @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий'])
- <div class="text-center">
- <button type="submit" class="btn btn-primary btn-sm">Сохранить</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- @if($errors->any())
- @dump($errors)
- @endif
- </div>
- @endsection
- @push('scripts')
- <script type="module">
- $('.editSchedule').on('click', function () {
- let scheduleId = $(this).attr('data-schedule-id');
- let scheduleDate = $(this).attr('data-schedule-date');
- let scheduleDistrict = $(this).attr('data-schedule-district');
- let scheduleArea = $(this).attr('data-schedule-area');
- let scheduleBrigadier = $(this).attr('data-schedule-brigadier');
- let scheduleAddress = $(this).attr('data-schedule-address');
- let scheduleComment = $('.comment-' + scheduleId).text();
- let scheduleMafs = $('.mafs-' + scheduleId).text();
- let scheduleObjectType = $('.object-type-' + scheduleId).text();
- let scheduleMafsCount = $('.mafs-count-' + scheduleId).text();
- let scheduleCode = $('.code-' + scheduleId).text();
- console.log(scheduleId, scheduleDate, scheduleDistrict, $(this).attr('data-schedule-brigadier'));
- $('form#scheduleEditForm input[name=id]').val(scheduleId);
- $('form#scheduleEditForm input[name=object_address]').val(scheduleAddress);
- $('form#scheduleEditForm input[name=object_type]').val(scheduleObjectType);
- $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
- $('form#scheduleEditForm select[name=district_id]').val(scheduleDistrict);
- $('form#scheduleEditForm select[name=area_id]').val(scheduleArea);
- $('form#scheduleEditForm select[name=brigadier_id]').val(scheduleBrigadier);
- $('form#scheduleEditForm textarea[name=comment]').text(scheduleComment);
- $('form#scheduleEditForm textarea[name=mafs]').text(scheduleMafs);
- $('form#scheduleEditForm input[name=mafs_count]').val(scheduleMafsCount);
- $('form#scheduleEditForm input[name=address_code]').val(scheduleCode);
- let myModalEditSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
- myModalEditSchedule.show();
- });
- $('.deleteSchedule').on('click', function () {
- if (confirm('Удалить запись?')) {
- let scheduleId = $(this).attr('data-schedule-id');
- $('.deleteForm-' + scheduleId).submit();
- }
- });
- $('.createSchedule').on('click', function () {
- let scheduleDate = $(this).attr('data-schedule-date');
- $('form#scheduleEditForm input[name=id]').val('');
- $('form#scheduleEditForm input[name=object_address]').val('');
- $('form#scheduleEditForm input[name=object_type]').val('');
- $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
- $('form#scheduleEditForm select[name=district_id]').val('');
- $('form#scheduleEditForm select[name=area_id]').val('');
- $('form#scheduleEditForm select[name=brigadier_id]').val('');
- $('form#scheduleEditForm textarea[name=comment]').text('');
- $('form#scheduleEditForm textarea[name=mafs]').text('');
- $('form#scheduleEditForm input[name=mafs_count]').val('');
- $('form#scheduleEditForm input[name=address_code]').val('');
- let myModalCreateSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
- myModalCreateSchedule.show();
- });
- // select order
- $('#search_order').on('keyup', function () {
- // search products on backend
- $.get('{{ route('order.search') }}?s=' + $(this).val(),
- function (data) {
- $('#select_order').children().remove()
- $.each(data, function (id, name) {
- $('#select_order').append('<option value=\'' + id + '\'>' + name + '</option>');
- });
- }
- );
- }).trigger('keyup');
- $('#district_id').on('change', function () {
- // load areas of selected district
- $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
- function (data) {
- $('#area_id').children().remove();
- $.each(data, function (id, name) {
- $('#area_id').append('<option value=\'' + id + '\'>' + name + '</option>');
- });
- }
- );
- });
- </script>
- <script type="text/javascript">
- function getWeekNumber(d) {
- // Copy date so don't modify original
- d = new Date(Date.parse(d));
- // Set to nearest Thursday: current date + 4 - current day number
- // Make Sunday's day number 7
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
- // Get first day of year
- let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
- // Calculate and return week number
- return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
- }
- </script>
- @endpush
|