@extends('layouts.master') @section('title') معالج الإقفال السنوي — {{ $year->name }} @endsection @section('page-header') @endsection @section('content') @include('financial_years.partials.alerts') {{-- 1. اختيار السنة --}}
1السنة المالية
الفترة{{ $year->startDate() }} → {{ $year->endDate() }}
الحالة @if ($year->isClosed())مغلقة@elseمفتوحة@endif
حساب الأرباح المتراكمة{{ $preview['retained_earnings']->name ?? ($year->retained_earnings_account_id ?? '-') }}
الفحوصات المانعة @if (count($blocking)){{ count($blocking) }} غير ناجحة@elseكلها ناجحة@endif
@foreach ([2 => 'فحص سلامة البيانات', 3 => 'الفحص المحاسبي (القيود، الحسابات، العملاء، الموردون)', 4 => 'فحص المخزون', 5 => 'فحص ضريبة القيمة المضافة و ZATCA'] as $step => $title)
{{ $step }}{{ $title }}
@include('financial_years.partials.checks', ['step' => $step])
@endforeach {{-- 6. ميزان المراجعة --}}
6ميزان المراجعة (حركة السنة — الأستاذ الرسمي)
@php $typeNames = [1 => 'أصول', 2 => 'خصوم', 3 => 'إيرادات', 4 => 'مصروفات', 5 => 'حقوق ملكية']; @endphp @foreach ($trialBalance['rows'] as $r) missing) class="table-danger" @endif> @endforeach
رقم الحسابالحسابالنوعمديندائنرصيد مدينرصيد دائن
{{ $r->account_number }}{{ $r->name }}{{ $typeNames[$r->type] ?? '?' }} {{ number_format($r->debit, 2) }}{{ number_format($r->credit, 2) }} {{ number_format($r->balance_debit, 2) }}{{ number_format($r->balance_credit, 2) }}
الإجمالي {{ number_format($trialBalance['total_debit'], 2) }}{{ number_format($trialBalance['total_credit'], 2) }} {{ number_format($trialBalance['balance_debit'], 2) }}{{ number_format($trialBalance['balance_credit'], 2) }}
الفرق (مدين − دائن): {{ number_format($trialBalance['difference'], 2) }}
{{-- 7. قائمة الدخل --}}
7قائمة الدخل (الأرباح والخسائر)
الإيرادات
@foreach ($income['revenue'] as $r)@endforeach
{{ $r->number }} - {{ $r->name }}{{ number_format($r->amount, 2) }}
إجمالي الإيرادات{{ number_format($income['total_revenue'], 2) }}
التكاليف والمصروفات
@foreach ($income['expenses'] as $r)@endforeach
{{ $r->number }} - {{ $r->name }}{{ number_format($r->amount, 2) }}
إجمالي التكاليف والمصروفات{{ number_format($income['total_expenses'], 2) }}
صافي {{ $income['net_profit'] >= 0 ? 'الربح' : 'الخسارة' }} للسنة: {{ number_format(abs($income['net_profit']), 2) }}

الإيرادات − (تكلفة المبيعات + المصروفات) = صافي الربح — محسوبة من الأستاذ الرسمي بنوع الحساب الرئيسي.

{{-- 8. الميزانية --}}
8الميزانية العمومية في {{ $year->endDate() }}
@foreach (['assets' => 'الأصول', 'liabilities' => 'الخصوم', 'equity' => 'حقوق الملكية'] as $key => $label)
{{ $label }}
@foreach ($balanceSheet[$key] as $r)@endforeach
{{ $r->number }} - {{ $r->name }}{{ number_format($r->amount, 2) }}
@endforeach
@include('financial_years.partials.checks', ['step' => 8])
إجمالي الأصول{{ number_format($balanceSheet['total_assets'], 2) }}
إجمالي الخصوم{{ number_format($balanceSheet['total_liabilities'], 2) }}
إجمالي حقوق الملكية{{ number_format($balanceSheet['total_equity'], 2) }}
أرباح غير مقفلة (تراكمية){{ number_format($balanceSheet['unclosed_profit'], 2) }}
الأصول − (الخصوم + حقوق الملكية + الأرباح){{ number_format($balanceSheet['difference'], 2) }}
{{-- 9. معاينة قيد الإقفال --}}
9معاينة قيد الإقفال
@if ($year->isClosed())

السنة مغلقة — قيد الإقفال رقم {{ $year->closing_record_id }} (قيد يومي من نوع إقفال سنة).

@elseif ($previewError)
{{ $previewError }}
@elseif ($preview)

يُصفَّر رصيد كل حساب إيرادات ومصروفات (لكل فرع) حتى {{ $year->endDate() }}، ويُرحَّل الصافي إلى {{ $preview['retained_earnings']->name }}. لا يُحذف أو يُعدَّل أي قيد قديم.

@foreach ($preview['lines'] as $l) @endforeach
الحسابالفرعمديندائن
{{ $l['account_id'] }} - {{ $l['name'] }}{{ $branchNames[$l['branch']] ?? $l['branch'] }} {{ number_format($l['debit'], 2) }}{{ number_format($l['credit'], 2) }}
الإجمالي{{ number_format($preview['total_debit'], 2) }}{{ number_format($preview['total_credit'], 2) }}
صافي ما يُرحَّل للأرباح المتراكمة: {{ number_format($preview['net_profit'], 2) }}
@endif
{{-- 10. تأكيد الإقفال --}}
10تأكيد الإقفال
@if ($year->isClosed())

تم الإقفال في {{ optional($year->closed_at)->format('Y-m-d H:i') }} بواسطة {{ optional($year->closedBy)->name }}.

@elseif (count($blocking))
لا يمكن الإقفال قبل معالجة الفحوصات المانعة:
    @foreach ($blocking as $b)
  • {{ $b['title'] }} — {{ $b['message'] }}
  • @endforeach
@else @can('financial_year_close')
@csrf
@else

ليست لديك صلاحية الإقفال (financial_year_close).

@endcan @endif
{{-- 11. الأرصدة الافتتاحية --}}
11الأرصدة الختامية = الافتتاحية للسنة التالية

الأصول والخصوم وحقوق الملكية فقط تنتقل للسنة الجديدة (حسابات الإيرادات والمصروفات صُفّرت بقيد الإقفال). الأستاذ تراكمي، لذلك هذه لقطة للتدقيق وليست قيداً مكرراً.

@if ($openingBalances->isEmpty())

تُنشأ بعد تنفيذ الإقفال.

@else @foreach ($openingBalances as $b) @endforeach
رقمالحسابمديندائن
{{ $b->account_number }}{{ $b->name }}{{ number_format($b->debit, 2) }}{{ number_format($b->credit, 2) }}
الإجمالي{{ number_format($openingBalances->sum('debit'), 2) }}{{ number_format($openingBalances->sum('credit'), 2) }}
@endif
{{-- 12. القفل / إعادة الفتح / السجل --}}
12قفل السنة وسجل التدقيق

{{ $year->isClosed() ? 'السنة مقفلة: لا يمكن إنشاء أو تعديل أو حذف أي حركة بتاريخ داخلها.' : 'السنة مفتوحة.' }}

@if ($year->isClosed()) @can('financial_year_reopen')
@csrf
@endcan @endif
سجل العمليات على السنة
@forelse ($logs as $log) @empty @endforelse
التاريخالمستخدمالعمليةمنإلىالسببIP
{{ $log->created_at }}{{ optional($log->user)->name }}{{ $log->action }}{{ $log->old_status }}{{ $log->new_status }}{{ $log->reason }}{{ $log->ip }}
لا يوجد.
@endsection