Explorar el Código

added status column to scheduler

Alexander Musikhin hace 1 semana
padre
commit
f8ccc30dd4

+ 72 - 0
app/Http/Controllers/ScheduleController.php

@@ -65,6 +65,8 @@ class ScheduleController extends Controller
             ->whereBetween('installation_date', [$weekDates['mon'], $weekDates['sun']])
             ->with(['brigadier', 'district', 'area'])
             ->get();
+        $this->data['scheduleStatusMap'] = $this->buildScheduleStatusMap($result);
+
         foreach ($result as $schedule) {
             $schedules[$schedule->installation_date][] = $schedule;
         }
@@ -343,4 +345,74 @@ class ScheduleController extends Controller
             ->with(['success' => 'Задача генерации графика создана!']);
 
     }
+
+    private function buildScheduleStatusMap($schedules): array
+    {
+        $statusMap = [];
+        $orderIds = [];
+        $reclamationScheduleIds = [];
+
+        foreach ($schedules as $schedule) {
+            $statusMap[$schedule->id] = '-';
+
+            if ($schedule->source === 'Площадки' && $schedule->order_id) {
+                $orderIds[] = (int)$schedule->order_id;
+                continue;
+            }
+
+            if ($schedule->source === 'Рекламации') {
+                $reclamationId = $this->extractReclamationId((string)$schedule->address_code);
+                if ($reclamationId) {
+                    $reclamationScheduleIds[$reclamationId][] = $schedule->id;
+                }
+            }
+        }
+
+        if ($orderIds) {
+            $orderStatuses = Order::query()
+                ->withoutGlobalScopes()
+                ->whereIn('id', array_unique($orderIds))
+                ->pluck('order_status_id', 'id')
+                ->all();
+
+            foreach ($schedules as $schedule) {
+                if ($schedule->source !== 'Площадки' || !$schedule->order_id) {
+                    continue;
+                }
+
+                $statusId = $orderStatuses[(int)$schedule->order_id] ?? null;
+                if ($statusId) {
+                    $statusMap[$schedule->id] = Order::STATUS_NAMES[$statusId] ?? '-';
+                }
+            }
+        }
+
+        if ($reclamationScheduleIds) {
+            $reclamationStatuses = Reclamation::query()
+                ->withoutGlobalScopes()
+                ->whereIn('id', array_keys($reclamationScheduleIds))
+                ->pluck('status_id', 'id')
+                ->all();
+
+            foreach ($reclamationScheduleIds as $reclamationId => $scheduleIds) {
+                $statusId = $reclamationStatuses[$reclamationId] ?? null;
+                $statusName = $statusId ? (Reclamation::STATUS_NAMES[$statusId] ?? '-') : '-';
+
+                foreach ($scheduleIds as $scheduleId) {
+                    $statusMap[$scheduleId] = $statusName;
+                }
+            }
+        }
+
+        return $statusMap;
+    }
+
+    private function extractReclamationId(string $addressCode): ?int
+    {
+        if (preg_match('/^РЕКЛ-(\d+)$/u', $addressCode, $matches)) {
+            return (int)$matches[1];
+        }
+
+        return null;
+    }
 }

+ 2 - 6
resources/views/schedule/index.blade.php

@@ -89,7 +89,7 @@
                 <th>Кол-во позиций</th>
                 <th>Бригадир</th>
                 @if(hasRole('admin'))
-                    <th>Транспорт</th>
+                    <th>Статус площадки/рекламации</th>
                     <th>Комментарий</th>
                 @endif
                 <th>Примечание</th>
@@ -151,7 +151,7 @@
                                 class="align-middle">{{ $schedule->brigadier->name }}</td>
                             @if(hasRole('admin'))
                                 <td style="background: {{ $schedule->brigadier->color }}"
-                                    class="align-middle transport-{{ $schedule->id }}">{{ $schedule->transport }}</td>
+                                    class="align-middle">{{ $scheduleStatusMap[$schedule->id] ?? '-' }}</td>
                                 <td style="background: {{ $schedule->brigadier->color }}"
                                     class="align-middle admin-comment-{{ $schedule->id }}">{{ $schedule->admin_comment }}</td>
                             @endif
@@ -343,7 +343,6 @@
                                     @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы', 'required' => true])
                                     @include('partials.input',  ['name' => 'mafs_count', 'title' => 'Кол-во МАФ', 'type' => 'number', 'required' => true])
                                     @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'required' => true, 'first_empty' => true])
-                                    @include('partials.input',  ['name' => 'transport', 'title' => 'Транспорт'])
                                     @include('partials.textarea', ['name' => 'admin_comment', 'title' => 'Комментарий'])
                                     @include('partials.textarea', ['name' => 'comment', 'title' => 'Примечание'])
                                     <div class="text-center">
@@ -378,7 +377,6 @@
                 let scheduleBrigadier = $(this).attr('data-schedule-brigadier');
                 let scheduleAddress = $(this).attr('data-schedule-address');
                 let scheduleComment = $('.comment-' + scheduleId).text();
-                let scheduleTransport = $('.transport-' + scheduleId).text();
                 let scheduleAdminComment = $('.admin-comment-' + scheduleId).text();
                 let scheduleMafs = $('.mafs-' + scheduleId).text();
                 let scheduleObjectType = $('.object-type-' + scheduleId).text();
@@ -393,7 +391,6 @@
                 $('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 input[name=transport]').val(scheduleTransport);
                 $('form#scheduleEditForm textarea[name=admin_comment]').text(scheduleAdminComment);
                 $('form#scheduleEditForm textarea[name=mafs]').text(scheduleMafs);
                 $('form#scheduleEditForm input[name=mafs_count]').val(scheduleMafsCount);
@@ -421,7 +418,6 @@
                 $('form#scheduleEditForm select[name=area_id]').val('');
                 $('form#scheduleEditForm select[name=brigadier_id]').val('');
                 $('form#scheduleEditForm textarea[name=comment]').text('');
-                $('form#scheduleEditForm input[name=transport]').val('');
                 $('form#scheduleEditForm textarea[name=admin_comment]').text('');
                 $('form#scheduleEditForm textarea[name=mafs]').text('');
                 $('form#scheduleEditForm input[name=mafs_count]').val('');