|
|
@@ -16,6 +16,7 @@ use App\Models\Dictionary\District;
|
|
|
use App\Models\Order;
|
|
|
use App\Models\ProductSKU;
|
|
|
use App\Models\Reclamation;
|
|
|
+use App\Models\ReclamationStatus;
|
|
|
use App\Models\Role;
|
|
|
use App\Models\Schedule;
|
|
|
use App\Models\User;
|
|
|
@@ -65,6 +66,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 +346,84 @@ class ScheduleController extends Controller
|
|
|
->with(['success' => 'Задача генерации графика создана!']);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private function buildScheduleStatusMap($schedules): array
|
|
|
+ {
|
|
|
+ $statusMap = [];
|
|
|
+ $orderIds = [];
|
|
|
+ $reclamationScheduleIds = [];
|
|
|
+
|
|
|
+ foreach ($schedules as $schedule) {
|
|
|
+ $statusMap[$schedule->id] = [
|
|
|
+ 'name' => '-',
|
|
|
+ 'color' => 'secondary',
|
|
|
+ ];
|
|
|
+
|
|
|
+ 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] = [
|
|
|
+ 'name' => Order::STATUS_NAMES[$statusId] ?? '-',
|
|
|
+ 'color' => Order::STATUS_COLOR[$statusId] ?: 'secondary',
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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] ?? '-') : '-';
|
|
|
+ $statusColor = $statusId ? (ReclamationStatus::STATUS_COLOR[$statusId] ?? 'secondary') : 'secondary';
|
|
|
+
|
|
|
+ foreach ($scheduleIds as $scheduleId) {
|
|
|
+ $statusMap[$scheduleId] = [
|
|
|
+ 'name' => $statusName,
|
|
|
+ 'color' => $statusColor,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $statusMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function extractReclamationId(string $addressCode): ?int
|
|
|
+ {
|
|
|
+ if (preg_match('/^РЕКЛ-(\d+)$/u', $addressCode, $matches)) {
|
|
|
+ return (int)$matches[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|