@extends('layouts.app') @section('title', 'تفاصيل فاتورة الشراء') @section('content') @php $invoice = $data['invoice'] ?? null; $items = $data['items'] ?? collect(); $payments = $data['payments'] ?? collect(); $remaining = $data['remaining_balance'] ?? (($invoice->total_amount ?? 0) - ($invoice->paid_amount ?? 0)); $paymentStatus = $invoice->payment_status ?? 'pending'; $approvalStatus = $invoice->status ?? 'pending'; $paymentStatusMap = [ 'paid' => ['label' => 'مدفوعة', 'class' => 'bg-green-100 text-green-700', 'dot' => 'bg-green-500'], 'partial' => ['label' => 'مدفوعة جزئياً', 'class' => 'bg-yellow-100 text-yellow-700', 'dot' => 'bg-yellow-500'], 'overdue' => ['label' => 'متأخرة', 'class' => 'bg-red-100 text-red-700', 'dot' => 'bg-red-500'], 'sent' => ['label' => 'مُرسلة', 'class' => 'bg-blue-100 text-blue-700', 'dot' => 'bg-blue-500'], 'approved'=> ['label' => 'معتمدة', 'class' => 'bg-green-100 text-green-700', 'dot' => 'bg-green-500'], 'pending' => ['label' => 'معلقة', 'class' => 'bg-gray-100 text-black', 'dot' => 'bg-gray-500'], ]; $paymentBadge = $paymentStatusMap[$paymentStatus] ?? ['label' => ucfirst($paymentStatus ?: 'معلقة'), 'class' => 'bg-gray-100 text-black', 'dot' => 'bg-gray-500']; $approvalMap = [ 'approved' => ['label' => 'معتمدة', 'class' => 'bg-green-100 text-green-700'], 'rejected' => ['label' => 'مرفوضة', 'class' => 'bg-red-100 text-red-700'], 'cancelled' => ['label' => 'ملغاة', 'class' => 'bg-red-100 text-red-700'], 'draft' => ['label' => 'مسودة', 'class' => 'bg-gray-100 text-black'], 'pending' => ['label' => 'قيد المراجعة', 'class' => 'bg-yellow-100 text-yellow-700'], ]; $approvalBadge = $approvalMap[$approvalStatus] ?? ['label' => ucfirst($approvalStatus ?: '-'), 'class' => 'bg-gray-100 text-black']; @endphp
@if(session('success'))

{{ session('success') }}

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

{{ session('error') }}

@endif

تفاصيل فاتورة الشراء

رقم الفاتورة: {{ $invoice->invoice_number ?? '-' }}

إجمالي الفاتورة

{{ number_format($invoice->total_amount ?? 0, 2) }} ر.س

المدفوع

{{ number_format($invoice->paid_amount ?? 0, 2) }} ر.س

المتبقي

{{ number_format($remaining, 2) }} ر.س

عدد البنود

{{ $items->count() }}

معلومات الفاتورة

رقم الفاتورة {{ $invoice->invoice_number ?? '-' }}
تاريخ الإصدار {{ $invoice->invoice_date ? $invoice->invoice_date->format('Y-m-d') : '-' }}
تاريخ الاستحقاق {{ $invoice->due_date ? $invoice->due_date->format('Y-m-d') : '-' }}
المستودع {{ $invoice->warehouse->name ?? '—' }}
حالة الاعتماد {{ $approvalBadge['label'] }}
حالة الدفع {{ $paymentBadge['label'] }}

المورد

الاسم {{ $invoice->supplier->name ?? '—' }}
@if(!empty($invoice->supplier->code ?? null))
كود المورد {{ $invoice->supplier->code }}
@endif @if(!empty($invoice->supplier->phone ?? null))
الهاتف {{ $invoice->supplier->phone }}
@endif @if(!empty($invoice->supplier->email ?? null))
البريد الإلكتروني {{ $invoice->supplier->email }}
@endif @if(!empty($invoice->supplier->city ?? null))
المدينة {{ $invoice->supplier->city }}
@endif

الملخص المالي

المجموع الفرعي {{ number_format($invoice->subtotal ?? 0, 2) }} ر.س
قيمة الضريبة {{ number_format($invoice->tax_amount ?? 0, 2) }} ر.س
الإجمالي {{ number_format($invoice->total_amount ?? 0, 2) }} ر.س
@php $paid = (float) ($invoice->paid_amount ?? 0); $total = (float) ($invoice->total_amount ?? 0); $paidPct = $total > 0 ? min(100, round(($paid / $total) * 100, 1)) : 0; @endphp
المدفوع {{ number_format($paid, 2) }} ر.س ({{ $paidPct }}%)
المتبقي {{ number_format($remaining, 2) }} ر.س
نسبة السداد {{ $paidPct }}%
@if($invoice && !empty($invoice->notes))

ملاحظات

{{ $invoice->notes }}

@endif

بنود الفاتورة ({{ $items->count() }} بند)

@forelse($items as $item) @empty @endforelse @if($items->count() > 0) @endif
# الصنف الوصف الكمية سعر الوحدة الخصم الضريبة الإجمالي
{{ $loop->iteration }} {{ $item->item->name ?? ($item->item_id ? '#'.$item->item_id : '—') }} {{ $item->description ?: '—' }} {{ number_format($item->quantity ?? 0, 2) }} {{ number_format($item->unit_price ?? 0, 2) }} {{ number_format($item->discount_amount ?? 0, 2) }} {{ number_format($item->tax_amount ?? 0, 2) }} {{ number_format($item->line_total ?? 0, 2) }}

لا توجد بنود لهذه الفاتورة

إجمالي البنود {{ number_format($items->sum('line_total'), 2) }} ر.س
@if($payments->count() > 0)

سجل الدفعات ({{ $payments->count() }} دفعة)

@foreach($payments as $payment) @endforeach
# رقم الدفعة تاريخ الدفع طريقة الدفع المرجع المبلغ
{{ $loop->iteration }} {{ $payment->payment_number ?? '—' }} {{ $payment->payment_date ? $payment->payment_date->format('Y-m-d') : '—' }} {{ $payment->payment_method ?? '—' }} {{ $payment->reference_number ?? '—' }} {{ number_format($payment->amount ?? 0, 2) }} ر.س
إجمالي المدفوع {{ number_format($payments->sum('amount'), 2) }} ر.س
@endif
@endsection @push('scripts') @endpush