startOfDay(); // 1. Prioritás: Beszállítói felülbírálás (Override) $override = DeliveryCalendarOverride::where('supplier_id', $supplier->id) ->whereDate('date', $date) ->first(); if ($override) { return $override->is_delivery_day; } // 2. Prioritás: Hivatalos ünnepnap (WorkCalendar) // Ha aznap nem hivatalos munkanap van, akkor nincs szállítás (kivéve ha az 1. pont felülbírálta). if (! $this->workCalendarService->isWorkDay($date)) { return false; } // 3. Prioritás: Heti sablon (Schedule) $assignment = ProfitCenterSupplierSchedule::where('profit_center_id', $pc->id) ->where('supplier_id', $supplier->id) ->with('deliverySchedule') ->first(); if (! $assignment || ! $assignment->deliverySchedule || ! $assignment->deliverySchedule->is_active) { return false; } $dayOfWeek = strtolower($date->format('l')); // 'monday', 'tuesday', etc. return (bool) $assignment->deliverySchedule->{$dayOfWeek}; } /** * Visszaadja az elérhető szállítási napokat egy adott időszakban. * * @return Collection */ public function getAvailableDeliveryDates(ProfitCenter $pc, Supplier $supplier, Carbon $start, Carbon $end): Collection { $dates = collect(); $current = $start->copy()->startOfDay(); $end = $end->copy()->startOfDay(); while ($current <= $end) { if ($this->isDeliveryDay($pc, $supplier, $current)) { $dates->push($current->copy()); } $current->addDay(); } return $dates; } }