@extends('layouts.app') @section('title', __('accounting.journal_entry') . ' ' . $journal_entry->entry_no) @section('content')

{{ __('accounting.journal_entry') }} {{ $journal_entry->entry_no }}

@if(session('status')) @php $msg = session('status'); @endphp
{{ $msg['msg'] }}
@endif @if(auth()->user()->can('view_journal_entries') || auth()->user()->can('account.access')) @php $status_map = [ 'posted' => ['class' => 'tw-dw-badge-success', 'label' => __('accounting.status_posted'), 'icon' => 'check-circle'], 'draft' => ['class' => 'tw-dw-badge-warning', 'label' => __('accounting.status_draft'), 'icon' => 'edit'], 'reversed' => ['class' => 'tw-dw-badge-info', 'label' => __('accounting.status_reversed'), 'icon' => 'undo'], 'void' => ['class' => 'tw-dw-badge-error', 'label' => __('accounting.status_void'), 'icon' => 'ban'], ]; $approval_map = [ 'not_required' => ['class' => 'tw-dw-badge-ghost', 'label' => __('accounting.approval_not_required')], 'draft' => ['class' => 'tw-dw-badge-ghost', 'label' => __('accounting.approval_draft')], 'pending' => ['class' => 'tw-dw-badge-warning', 'label' => __('accounting.approval_pending')], 'approved' => ['class' => 'tw-dw-badge-success', 'label' => __('accounting.approval_approved')], 'rejected' => ['class' => 'tw-dw-badge-error', 'label' => __('accounting.approval_rejected')], ]; $st = $status_map[$journal_entry->status] ?? ['class' => 'tw-dw-badge-ghost', 'label' => $journal_entry->status, 'icon' => 'circle']; $apr = $approval_map[$journal_entry->approval_status ?? 'not_required'] ?? ['class' => 'tw-dw-badge-ghost', 'label' => $journal_entry->approval_status]; @endphp
{{-- العمود الرئيسي --}}
{{-- بطاقة تفاصيل القيد --}}

{{ __('accounting.entry_details') }}

{{ $st['label'] }} {{ $apr['label'] }}
{{ __('accounting.entry_no') }} {{ $journal_entry->entry_no }}
{{ __('accounting.date') }} {{ $journal_entry->entry_date->format('Y-m-d') }}
{{ __('accounting.period') }} {{ optional($journal_entry->period)->name ?: '—' }}
@php $source_type_labels = [ 'transaction' => 'فاتورة', 'transaction_payment' => 'دفعة مالية', 'stock_adjustment' => 'تسوية مخزون', 'manual_journal' => 'قيد يدوي', 'opening_balance' => 'أرصدة افتتاحية', 'reversal' => 'عكس قيد', ]; @endphp
{{ __('accounting.source') }}{{ $source_type_labels[$journal_entry->source_type] ?? ($journal_entry->source_type ? str_replace('_',' ',$journal_entry->source_type) : '—') }}
{{ __('accounting.reference') }} {{ $journal_entry->source_reference ?: '—' }}
{{ __('accounting.memo') }} {{ $journal_entry->memo ?: '—' }}
@if($journal_entry->reversalEntry || $journal_entry->reversesEntry)
@if($journal_entry->reversalEntry) {{ __('accounting.reversal_entry') }}: {{ $journal_entry->reversalEntry->entry_no }} @endif @if($journal_entry->reversesEntry) {{ __('accounting.reverses_entry') }}: {{ $journal_entry->reversesEntry->entry_no }} @endif
@endif
{{-- بنود القيد --}}

{{ __('accounting.lines') }}

@php $debit_total = 0; $credit_total = 0; @endphp @foreach($journal_entry->lines as $line) @php $is_debit = $line->type === 'debit'; $debit_total += $is_debit ? $line->amount : 0; $credit_total += !$is_debit ? $line->amount : 0; @endphp @endforeach
{{ __('accounting.line_no') }} {{ __('accounting.account') }} {{ __('accounting.debit') }} {{ __('accounting.credit') }} {{ __('accounting.memo') }}
{{ $line->line_no }} @if(optional($line->account)->account_number) {{ $line->account->account_number }} @endif {{ optional($line->account)->display_name }} {{ $is_debit ? number_format($line->amount, 2) : '' }} {{ !$is_debit ? number_format($line->amount, 2) : '' }} {{ $line->memo ?: '—' }}
{{ __('accounting.total') }} {{ number_format($debit_total, 2) }} {{ number_format($credit_total, 2) }} @if(round($debit_total, 4) === round($credit_total, 4)) {{ __('accounting.balanced') }} @else {{ __('accounting.not_balanced') }} @endif
{{-- سجل التعديلات --}}

{{ __('accounting.audit_trail') }}

@forelse($journal_entry->audits as $audit) @empty @endforelse
{{ __('accounting.date') }} {{ __('accounting.actions') }} {{ __('accounting.created_by') }} {{ __('accounting.notes') }}
{{ $audit->created_at->format('Y-m-d H:i') }} {{ ucfirst(str_replace('_',' ', $audit->action)) }} {{ optional($audit->createdBy)->user_full_name ?: '—' }} {{ $audit->note ?: '—' }} @if($audit->after_values)
JSON
{{ json_encode($audit->after_values, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}
@endif
{{ __('accounting.no_records') }}
{{-- الشريط الجانبي للإجراءات --}}

{{ __('accounting.actions') }}

{{ __('accounting.back') }} {{-- إرسال للموافقة --}} @if($journal_entry->status === 'draft' && $journal_entry->requiresApproval() && in_array($journal_entry->approval_status, ['draft', 'rejected']) && (auth()->user()->can('create_manual_journal') || auth()->user()->can('account.access')))

{{ __('accounting.submit_for_approval') }}

@csrf
@endif {{-- موافقة ورفض --}} @if($journal_entry->status === 'draft' && $journal_entry->approval_status === 'pending' && (auth()->user()->can('approve_journal_entries') || auth()->user()->can('account.access')))

{{ __('accounting.approve_and_post') }}

@csrf

{{ __('accounting.reject_entry') }}

@csrf
@endif {{-- إلغاء المسودة --}} @if($journal_entry->status === 'draft' && (auth()->user()->can('create_manual_journal') || auth()->user()->can('account.access')))

{{ __('accounting.void_draft') }}

@csrf
@endif {{-- عكس القيد --}} @if($journal_entry->status === 'posted' && empty($journal_entry->reversal_journal_entry_id) && (auth()->user()->can('reverse_journal_entries') || auth()->user()->can('account.access')))

{{ __('accounting.reverse_entry') }}

@csrf
@endif
@endif
@endsection