@extends('layouts.app')
@section('title', 'التقارير المالية')
@section('content')
📊
لا توجد بيانات مالية للفترة المحددة
@else
@php
$allCurrencies = ['EGP' => 'جنيه مصري', 'USD' => 'دولار أمريكي', 'TRY' => 'ليرة تركية'];
$currencyIcons = ['EGP' => '🇪🇬', 'USD' => '🇺🇸', 'TRY' => '🇹🇷'];
$currencyClasses = [
'EGP' => ['header' => 'from-primary-500/5', 'badge' => 'bg-primary-500/10 text-primary-600', 'bar' => 'from-primary-500 to-primary-400', 'ring' => 'ring-primary-500'],
'USD' => ['header' => 'from-success/5', 'badge' => 'bg-success/10 text-success', 'bar' => 'from-success to-success/70', 'ring' => 'ring-success'],
'TRY' => ['header' => 'from-amber-500/5', 'badge' => 'bg-amber-500/10 text-amber-600', 'bar' => 'from-amber-500 to-amber-400', 'ring' => 'ring-amber-500'],
];
@endphp
{{-- ==================== ملخص العملات ==================== --}}
💱
ملخص حسب العملة
@php
$currenciesWithIncome = $incomeByCurrency->pluck('currency')->toArray();
$currenciesWithExpenses = $expensesByCurrency->pluck('currency')->toArray();
$allActiveCurrencies = array_unique(array_merge($currenciesWithIncome, $currenciesWithExpenses));
sort($allActiveCurrencies);
@endphp
@if(!empty($allActiveCurrencies))
@foreach($allActiveCurrencies as $cur)
@php
$curIncome = $incomeByCurrency->where('currency', $cur)->sum('total');
$curExpenses = $expensesByCurrency->where('currency', $cur)->sum('total');
$curNet = $curIncome - $curExpenses;
$classes = $currencyClasses[$cur] ?? ['header' => 'from-gray-500/5', 'badge' => 'bg-gray-500/10 text-gray-600', 'bar' => 'from-gray-500 to-gray-400'];
$total = $curIncome + $curExpenses;
$incomePct = $total > 0 ? round($curIncome / $total * 100) : 0;
$expensePct = $total > 0 ? round($curExpenses / $total * 100) : 0;
@endphp
الإيرادات
{{ $incomePct }}%
المصروفات
{{ $expensePct }}%
@endforeach
@endif
{{-- ==================== الإيرادات والمصروفات الشهرية ==================== --}}
@php
$monthsIncome = $monthlyIncome->groupBy('currency');
$monthsExpenses = $monthlyExpenses->groupBy('currency');
@endphp
@if($monthsIncome->isNotEmpty() || $monthsExpenses->isNotEmpty())
📈
الإيرادات والمصروفات الشهرية
@php $allMonthCurrencies = array_unique(array_merge($monthsIncome->keys()->toArray(), $monthsExpenses->keys()->toArray())); @endphp
@foreach($allMonthCurrencies as $cur)
@php
$curMonthlyIncome = $monthsIncome->get($cur, collect());
$curMonthlyExpenses = $monthsExpenses->get($cur, collect());
$allMonths = $curMonthlyIncome->pluck('month')->merge($curMonthlyExpenses->pluck('month'))->unique()->sort()->values();
$classes = $currencyClasses[$cur] ?? ['header' => 'from-gray-500/5', 'badge' => 'bg-gray-500/10 text-gray-600'];
@endphp
{{ $currencyIcons[$cur] ?? '💱' }} {{ $allCurrencies[$cur] ?? $cur }}
{{ $allMonths->count() }} شهر
@if($allMonths->isEmpty())
لا توجد بيانات شهرية
@else
@php
$maxVal = max(
$curMonthlyIncome->max('total') ?? 0,
$curMonthlyExpenses->max('total') ?? 0
);
@endphp
@foreach($allMonths as $month)
@php
$inc = $curMonthlyIncome->where('month', $month)->first()->total ?? 0;
$exp = $curMonthlyExpenses->where('month', $month)->first()->total ?? 0;
$wInc = $maxVal > 0 ? ($inc / $maxVal) * 100 : 0;
$wExp = $maxVal > 0 ? ($exp / $maxVal) * 100 : 0;
@endphp
{{ $month }}
إيراد
{{ number_format($inc, 0) }}
مصروف
{{ number_format($exp, 0) }}
@endforeach
@endif
@endforeach
@endif
{{-- ==================== تحليل التصنيفات ==================== --}}
{{-- الإيرادات حسب طريقة الدفع --}}
💳 الإيرادات حسب طريقة الدفع
@if ($incomeByCategory->isEmpty())
لا توجد بيانات متاحة
@else
@php $incomeCatTotal = $incomeByCategory->sum('total'); @endphp
@foreach ($incomeByCategory->groupBy('currency') as $cur => $rows)
@php $curTotal = $rows->sum('total'); @endphp
{{ $currencyIcons[$cur] ?? '💱' }}
{{ $allCurrencies[$cur] ?? $cur }}
— الإجمالي: {{ number_format($curTotal, 2) }}
@foreach ($rows as $row)
@php $pct = $curTotal > 0 ? round($row->total / $curTotal * 100) : 0; @endphp
{{ $row->payment_method ?? '—' }}
{{ number_format($row->total, 2) }}
@endforeach
@endforeach
@endif
{{-- المصروفات حسب التصنيف --}}
🏷️ المصروفات حسب التصنيف
@if ($expensesByCategory->isEmpty())
لا توجد بيانات متاحة
@else
@foreach ($expensesByCategory->groupBy('currency') as $cur => $rows)
@php $curTotal = $rows->sum('total'); @endphp
{{ $currencyIcons[$cur] ?? '💱' }}
{{ $allCurrencies[$cur] ?? $cur }}
— الإجمالي: {{ number_format($curTotal, 2) }}
@foreach ($rows as $row)
@php $pct = $curTotal > 0 ? round($row->total / $curTotal * 100) : 0; @endphp
{{ $row->category ?? '—' }}
{{ number_format($row->total, 2) }}
@endforeach
@endforeach
@endif
{{-- ==================== العمولات ==================== --}}
🏦
تفاصيل الخزائن
أرصدة وحركات كل خزنة على حدة
@php
$cashboxStatsGrouped = $cashboxStats->groupBy('cashbox_id');
$cashboxExpensesGrouped = $expensesByCashbox->groupBy('cashbox_id');
@endphp
@forelse($cashboxes as $cb)
@php
$cbStats = $cashboxStatsGrouped->get($cb->id, collect());
$cbExpenses = $cashboxExpensesGrouped->get($cb->id, collect());
$cbHasData = $cbStats->isNotEmpty() || $cbExpenses->isNotEmpty() || ($cb->balance_egp ?? 0) > 0 || ($cb->balance_usd ?? 0) > 0 || ($cb->balance_try ?? 0) > 0;
@endphp
@if($cbHasData)
💰 {{ $cb->name }}
@if($cbStats->isNotEmpty())
{{ $cbStats->sum('movements_count') }} حركة
@endif
{{-- الأرصدة --}}
الأرصدة الحالية
جنيه مصري
{{ number_format($cb->balance_egp ?? 0, 2) }}
دولار أمريكي
{{ number_format($cb->balance_usd ?? 0, 2) }}
ليرة تركية
{{ number_format($cb->balance_try ?? 0, 2) }}
{{-- الحركات --}}
الحركات خلال الفترة
@if($cbStats->isEmpty())
لا توجد حركات
@else
@foreach($cbStats->groupBy('currency') as $cur => $rows)
@php
$curIn = $rows->sum('total_in');
$curOut = $rows->sum('total_out');
$curCount = $rows->sum('movements_count');
@endphp
{{ $currencyIcons[$cur] ?? '💱' }}
{{ $allCurrencies[$cur] ?? $cur }}
({{ $curCount }} حركة)
📥 وارد
+{{ number_format($curIn, 2) }}
📤 صادر
-{{ number_format($curOut, 2) }}
@endforeach
@endif
{{-- المصروفات --}}
المصروفات من هذه الخزنة
@if($cbExpenses->isEmpty())
لا توجد مصروفات
@else
@foreach($cbExpenses->groupBy('currency') as $cur => $rows)
{{ $currencyIcons[$cur] ?? '💱' }}
{{ $allCurrencies[$cur] ?? $cur }}
إجمالي المصروفات
{{ number_format($rows->sum('total'), 2) }}
@endforeach
@endif
@endif
@empty
@endforelse
{{-- ==================== جدول الحركات التفصيلية ==================== --}}
📋 حركات الخزنة التفصيلية
@if($cashboxMovements->count())
{{ $cashboxMovements->count() }} حركة
@endif
@if($cashboxMovements->isEmpty())
لا توجد حركات خلال الفترة
@else
| التاريخ |
الخزنة |
النوع |
المبلغ |
العملة |
الوصف |
بواسطة |
@foreach($cashboxMovements as $m)
| {{ $m->created_at ? \Carbon\Carbon::parse($m->created_at)->format('Y-m-d H:i') : '—' }} |
{{ $m->cashbox_name ?? '—' }}
|
@if($m->type === 'in')
📥 إيداع
@else
📤 سحب
@endif
|
{{ $m->type === 'in' ? '+' : '-' }}{{ number_format($m->amount, 2) }}
|
{{ $m->currency }} |
{{ $m->description ?? '—' }} |
{{ $m->creator_name ?? '—' }} |
@endforeach
@endif
@endif
@endsection