@php // Two distinct flows share this view: // - Closing an open shift (worker) // - Editing a reconciled shift (manager correction) // We branch labels, prefilled values, and the edit-reason field on this. $isManagerEdit = $shift->status === 'reconciled'; $pageTitle = $isManagerEdit ? 'تعديل الوردية #' . $shift->id : 'إنهاء الوردية #' . $shift->id; $pageDesc = $isManagerEdit ? 'تصحيح قراءات أو مبالغ وردية معتمدة (سيتم تسجيل التعديل في سجل المراجعة)' : 'إدخال قراءات الإغلاق والمبالغ المستلمة'; @endphp @section('title', $pageTitle) @section('page-title', $pageTitle) @section('page-description', $pageDesc)
{{-- Success/Error Messages --}} @if (session('success'))

{{ session('success') }}

@endif @if (session('error'))

{{ session('error') }}

@endif {{-- Manager-edit warning banner with time-window context --}} @if($isManagerEdit) @php // Compute remaining edit window. Tiers (from approved_at): // ≤ 48h → station_manager + company_owner // 48h-30d → company_owner only // > 30d → blocked (controller would have redirected) $hoursElapsed = $shift->approved_at ? (int) $shift->approved_at->diffInHours(now()) : null; $daysElapsed = $hoursElapsed !== null ? floor($hoursElapsed / 24) : null; $isTier1 = $hoursElapsed !== null && $hoursElapsed <= 48; $hoursLeftTier1 = $isTier1 ? max(0, 48 - $hoursElapsed) : 0; $daysLeftTier3 = $hoursElapsed !== null ? max(0, 30 - $daysElapsed) : null; $isOwner = auth()->user()->user_type === 'company_owner'; @endphp

أنت تعدل وردية معتمدة بالفعل

أي تعديل في القراءات أو المبالغ سيُطبَّق على عداد المسدس ومستوى الخزان والنقد المعلّق للمحطة فوراً. ولأنه قد توجد ورديات لاحقة معتمدة، فسيتم تعديل قراءة بدايتها (cascade) وتعويض الخزان والعداد لها أيضاً تلقائياً. كل التغييرات تُسجَّل في سجل المراجعة وسبب التعديل إجباري.

@if($hoursElapsed !== null)
منذ الاعتماد: {{ $hoursElapsed }} ساعة @if($daysElapsed >= 1) ({{ $daysElapsed }} يوم) @endif
@if($isTier1) المرحلة: عادية ({{ $hoursLeftTier1 }} ساعة متبقية) @else المرحلة: متأخرة (صاحب الشركة فقط) @endif
القفل النهائي: بعد {{ $daysLeftTier3 }} يوم
@endif @if(!$isTier1 && !$isOwner) {{-- Defensive: controller already blocks this combination, but if the user lands here via cached page or back-button the in-page warning is friendlier than a 500. --}}

⚠️ هذه الوردية تجاوزت 48 ساعة من الاعتماد. لن يُسمح بالحفظ من حسابك (مدير محطة) — صاحب الشركة فقط.

@endif
@endif {{-- Header --}}

{{ $pageTitle }}

{{ $shift->pump->name ?? "" }} - {{ $shift->user->name }}

بدأت في: {{ $shift->start_datetime->format('Y-m-d H:i') }}

{{-- Form --}}
@csrf @method('PUT') {{-- Calibration alert banner --}} @php $totalShiftCalibration = $shift->nozzleReadings->sum(fn ($r) => (float) ($r->calibration_volume ?? 0)); $hasCalibrations = $totalShiftCalibration > 0 || (isset($calibrationsByNozzle) && $calibrationsByNozzle->isNotEmpty()); @endphp @if($hasCalibrations)

هذه الوردية بها معايرات بإجمالي {{ number_format($totalShiftCalibration, 3) }} لتر

المسدس الذي خرجت منه كمية معايرة سيُظهر فرقاً بين "حركة العداد" و "الكمية المباعة فعلياً": المبلغ المحسوب على المبيعات الفعلية (= حركة العداد − كمية المعايرة)، وكمية المعايرة تعود للخزان فلا تُحاسَب على الموظف.

    @foreach($calibrationsByNozzle ?? collect() as $nozzleId => $calibrations) @php $reading = $shift->nozzleReadings->firstWhere('nozzle_id', $nozzleId); $nozzleName = $reading?->nozzle?->name ?? ('#' . $nozzleId); @endphp
  • المسدس {{ $nozzleName }}: @foreach($calibrations as $cal) {{ number_format($cal->calibrated_volume, 3) }} لتر ({{ $cal->status === \App\Models\NozzleCalibration::STATUS_OPEN ? 'مفتوحة' : 'مكتملة' }}{{ optional($cal->performedBy)->name ? ' — ' . $cal->performedBy->name : '' }})@if(! $loop->last)، @endif @endforeach
  • @endforeach
@endif {{-- Nozzle Readings Section --}}

قراءات المسدسات

@foreach ($shift->nozzleReadings as $index => $reading) @php $rowCalibration = (float) ($reading->calibration_volume ?? 0); @endphp {{-- "حركة العداد" = closing - opening (الإجمالي الفيزيائي) --}} {{-- كمية المعايرة (يعود للخزان، لا يُحاسَب عليه) --}} {{-- "الكمية المباعة فعلياً" = حركة العداد - المعايرة --}} @endforeach
المسدس نوع الوقود قراءة البداية قراءة الإغلاق * حركة العداد كمية المعايرة الكمية المباعة فعلياً السعر/لتر المبلغ الإجمالي
{{ $reading->nozzle->name }}
{{ $reading->nozzle->code }}
@if($rowCalibration > 0) معايرة @endif
{{ $reading->nozzle->tank->fuelType->name }}
{{ number_format($reading->opening_reading, 3) }} @error("nozzle_readings.{$index}.closing_reading")

{{ $message }}

@enderror
0.000 لتر @if($rowCalibration > 0) {{ number_format($rowCalibration, 3) }} لتر @else — @endif 0.000 لتر {{ number_format($fuelPrices[$reading->fuel_type_id] ?? 0, 3) }} ر.س 0.00 ر.س
{{-- Financial Section --}}
{{-- Cash & Card Amounts --}}

المبالغ المستلمة

ر.س
@error('cash_received_amount')

{{ $message }}

@enderror
@php // POS devices configured for this station are the // canonical card-payment input. The manual field // exists only as a fallback for stations that // don't have POS hardware. Disable it by default // whenever POS devices exist so the operator // cannot accidentally double-enter the same total. $hasPaymentDevices = $paymentDevices->count() > 0; @endphp
ر.س
@error('card_received_amount')

{{ $message }}

@enderror
{{-- Summary Card --}}

ملخص العملية

مقارنة المبيعات مع المبالغ المستلمة

إجمالي المبيعات المحسوب:
0.00 ر.س

حسب القراءات وأسعار الوقود الحالية

النقد المستلم:
0.00 ر.س
البطاقات المستلمة:
0.00 ر.س
إجمالي المستلم:
0.00 ر.س
الفرق:
0.00 ر.س
المبيعات - المستلم = الفرق
{{-- Notes Section --}}

ملاحظات

@error('notes')

{{ $message }}

@enderror
{{-- Edit Reason — only when manager is correcting a reconciled shift --}} @if($isManagerEdit)

سبب التعديل

اشرح بإيجاز سبب تعديل هذه الوردية المعتمدة (إجباري — يُحفظ في سجل المراجعة)

@error('edit_reason')

{{ $message }}

@enderror
@endif {{-- Validation Alerts --}} {{-- Payment Devices Section --}} @if($paymentDevices->count() > 0)

قراءات مكائن الدفع الإلكتروني

أدخل القراءات النهائية لكل مكينة مع إرفاق المستندات (اختياري)

@error('payment_readings')

خطأ في قراءات مكائن الدفع

{{ $message }}

@enderror
@foreach($paymentDevices as $device)

{{ $device->name }}

{{ $device->device_code }}

{{-- Hidden Device ID --}} {{-- Amount Input --}} @php // Pre-fill from old() on validation failure (kept the user from // re-entering all POS amounts when the form was rejected for shortage). // Falls back to any existing reading on the shift (manager-edit mode). $existingReading = $shift->paymentReadings ?? collect(); $existingAmount = optional( is_iterable($existingReading) ? collect($existingReading)->firstWhere('payment_device_id', $device->id) : null )->total_amount; @endphp

اترك الحقل فارغاً إذا لم يتم استخدام المكينة

{{-- Receipt Upload --}}

صورة أو PDF (حد أقصى: 10MB)

{{-- Notes --}} @php $existingNotes = optional( is_iterable($existingReading) ? collect($existingReading)->firstWhere('payment_device_id', $device->id) : null )->notes; @endphp
@endforeach
{{-- Payment Devices Summary --}}
إجمالي مكائن الدفع: 0.00 ر.س
@else

لا توجد مكائن دفع نشطة

يمكن إضافة مكائن دفع من لوحة تحكم الشركة

@endif {{-- Action Buttons --}}
إلغاء
@push('scripts') @endpush