{{-- Financial Performance Overview Section --}}
{{ __('insights.financial_performance_overview') }}
@if(empty($insights))
{{ __('insights.no_insights_data') }}
@else
@php
/**
* Recursively render metric details as an unordered list so we never miss nested information.
*
* @param array|string|int|float $data
*/
$renderMetric = function ($data) use (&$renderMetric) {
if (!is_array($data)) {
echo e($data);
return;
}
};
// Currency symbol helper - returns SAR icon image or text symbol from settings
$currencySymbol = $currency === 'SAR'
? ' '
: json_decode(__('settings::currencies.' . $currency), true);
// Smaller symbol variant for breakdown boxes
$smallCurrencySymbol = str_contains($currencySymbol, ' ' . $currencySymbol . '';
@endphp
{{-- Financial Performance Metrics --}}
@foreach($insights['metrics'] ?? [] as $metric => $details)
@if(in_array($metric, ['revenue', 'expenses', 'purchases', 'net_profit']))
{{-- Custom card design for business growth metrics --}}
@php
// Get comparison data for current metric
$previousWeekData = $insights['comparisons'][$metric] ?? null;
$previousTotal = $previousWeekData['previous_week'] ?? 0;
$percentageChange = $previousWeekData['percentage_change'] ?? 0;
$trend = $previousWeekData['trend'] ?? 'neutral';
// Metric-specific configurations
$metricConfig = [
'new_customers' => [
'title' => __('insights.new_customers'),
'icon' => 'đĨ',
'color' => '#ff7300',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => true // positive growth is good
],
'invoices_sent' => [
'title' => __('insights.invoices_sent'),
'icon' => 'đ',
'color' => '#ff7300',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => true // more invoices is good
],
'revenue' => [
'title' => __('insights.revenue'),
'icon' => 'đ°',
'currency' => $currency,
'color' => '#4a90e2',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => true // more revenue is good
],
'expenses' => [
'title' => __('insights.expenses'),
'icon' => 'đ¸',
'currency' => $currency,
'color' => '#4a90e2',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => false // more expenses is bad
],
'purchases' => [
'title' => __('insights.purchase_calculation_including_returns'),
'icon' => 'đ',
'currency' => $currency,
'color' => '#4a90e2',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => false // more purchases might be bad (depends on context)
],
'net_profit' => [
'title' => __('insights.net_profit'),
'icon' => 'đ',
'currency' => $currency,
'color' => '#4a90e2',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => true // more profit is good
],
'overdue_payments' => [
'title' => __('insights.overdue_payments_calculation'),
'icon' => 'đ',
'currency' => $currency,
'color' => '#ff7300',
'current' => $details['count'] ?? 0, // count of overdue payments
'total_amount' => $details['total'] ?? 0, // total monetary value
'showBreakdown' => true,
'categories' => $details['categories'] ?? [],
'isPositiveTrend' => false // more overdue payments is bad
]
];
$config = $metricConfig[$metric];
if ($metric === 'overdue_payments') {
$countDisplay = $config['current'];
$amountDisplay = number_format($config['total_amount'], 2);
$currentTotal = $countDisplay.' | '.$amountDisplay;
} else {
$currentTotal = $config['current'];
}
// Categories data for overdue payments
if ($config['showBreakdown']) {
$categories = $config['categories'];
$zeroToSeven = $categories['0-7_days'] ?? ['count' => 0, 'total' => 0];
$eightToThirty = $categories['8-30_days'] ?? ['count' => 0, 'total' => 0];
$overThirty = $categories['over_30_days'] ?? ['count' => 0, 'total' => 0];
}
// Determine trend arrow and color based on metric context
$trendSymbol = $trend === 'up' ? 'â˛' : ($trend === 'down' ? 'âŧ' : 'â');
// Color logic based on whether positive trend is good for this metric
if ($config['isPositiveTrend']) {
// For metrics where increase is good (e.g., revenue, customers)
$changeColor = $trend === 'up' ? '#27ae60' : ($trend === 'down' ? '#e74c3c' : '#95a5a6');
} else {
// For metrics where increase is bad (expenses, overdue payments, purchases)
$changeColor = $trend === 'up' ? '#e74c3c' : ($trend === 'down' ? '#27ae60' : '#95a5a6');
}
@endphp
{{-- Main Card Container --}}
{{-- Header with Orange Accent --}}
{{ $config['icon'] }} {{ $config['title'] }}
{{ $startDate->toFormattedDateString() }} — {{ $endDate->toFormattedDateString() }}
|
{{-- Main Content Area --}}
{{-- Left Section: Main Metric --}}
|
{{-- Main Number --}}
@if($metric === 'overdue_payments')
{!! $currencySymbol !!} {{ number_format($config['total_amount'], 2) }}
{{ $config['icon'] }} {{ $config['current'] }} {{ __('insights.invoices') }}
@else
{{ $config['icon'] }} {!! isset($config['currency']) ? $currencySymbol : '' !!} {{ $currentTotal }}
@endif
@if($metric !== 'overdue_payments')
{{ __('insights.this_week') }}
@endif
{{-- Comparison with Previous Week --}}
@if($previousWeekData)
|
{{ __('insights.from_last_week') }}
{{ $trendSymbol }} {{ $previousTotal }}
|
{{ __('insights.change') }}
{{ $trendSymbol }} {{ number_format(abs($percentageChange), 1) }}%
|
@endif
|
|
{{-- Right Section: Breakdown (only for overdue payments) --}}
@if($config['showBreakdown'])
{{-- 0-7 Days --}}
{{ __('insights.0_7_days_overdue') }}
{!! $smallCurrencySymbol !!} {{ number_format($zeroToSeven['total'],2) }}
|
{{-- 8-30 Days --}}
{{ __('insights.8_30_days_overdue') }}
{!! $smallCurrencySymbol !!} {{ number_format($eightToThirty['total'],2) }}
|
{{-- More than 30 Days --}}
{{ __('insights.more_than_30_days_overdue') }}
{!! $smallCurrencySymbol !!} {{ number_format($overThirty['total'],2) }}
|
|
@endif
|
@endif
@endforeach
{{-- Business Growth Insights Section --}}
{{ __('insights.business_growth_insights') }}
{{-- Business Growth Metrics --}}
@foreach($insights['metrics'] ?? [] as $metric => $details)
@if(in_array($metric, ['new_customers', 'invoices_sent', 'overdue_payments']))
{{-- Custom card design for business growth metrics --}}
@php
// Get comparison data for current metric
$previousWeekData = $insights['comparisons'][$metric] ?? null;
$previousTotal = $previousWeekData['previous_week'] ?? 0;
$percentageChange = $previousWeekData['percentage_change'] ?? 0;
$trend = $previousWeekData['trend'] ?? 'neutral';
// Metric-specific configurations
$metricConfig = [
'new_customers' => [
'title' => __('insights.new_customers'),
'icon' => 'đĨ',
'color' => '#ff7300',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => true // positive growth is good
],
'invoices_sent' => [
'title' => __('insights.invoices_sent'),
'icon' => 'đ',
'color' => '#ff7300',
'current' => $details['total'] ?? 0,
'showBreakdown' => false,
'isPositiveTrend' => true // more invoices is good
],
'overdue_payments' => [
'title' => __('insights.overdue_payments_calculation'),
'icon' => 'đ',
'color' => '#ff7300',
'current' => $details['count'] ?? 0, // count
'total_amount' => $details['total'] ?? 0, // money
'showBreakdown' => true,
'categories' => $details['categories'] ?? [],
'isPositiveTrend' => false // more overdue payments is bad
]
];
$config = $metricConfig[$metric];
$currentTotal = $config['current'];
// Categories data for overdue payments
if ($config['showBreakdown']) {
$categories = $config['categories'];
$zeroToSeven = $categories['0-7_days'] ?? ['count' => 0, 'total' => 0];
$eightToThirty = $categories['8-30_days'] ?? ['count' => 0, 'total' => 0];
$overThirty = $categories['over_30_days'] ?? ['count' => 0, 'total' => 0];
}
// Determine trend arrow and color based on metric context
$trendSymbol = $trend === 'up' ? 'â˛' : ($trend === 'down' ? 'âŧ' : 'â');
// Color logic based on whether positive trend is good for this metric
if ($config['isPositiveTrend']) {
// Increase is beneficial
$changeColor = $trend === 'up' ? '#27ae60' : ($trend === 'down' ? '#e74c3c' : '#95a5a6');
} else {
// Increase is harmful
$changeColor = $trend === 'up' ? '#e74c3c' : ($trend === 'down' ? '#27ae60' : '#95a5a6');
}
@endphp
{{-- Main Card Container --}}
{{-- Header with Orange Accent --}}
{{ $config['icon'] }} {{ $config['title'] }}
@if($metric === 'overdue_payments')
{{ app()->getLocale() === 'ar' ? 'ØØĒŲ ' : 'Until ' }}{{ $endDate->toFormattedDateString() }}
@else
{{ $startDate->toFormattedDateString() }} — {{ $endDate->toFormattedDateString() }}
@endif
|
{{-- Main Content Area --}}
{{-- Left Section: Main Metric --}}
|
{{-- Main Number --}}
@if($metric === 'overdue_payments')
{!! $currencySymbol !!} {{ number_format($config['total_amount'], 2) }}
{{ $config['icon'] }} {{ $config['current'] }} {{ __('insights.invoices') }}
@else
{{ $config['icon'] }} {!! isset($config['currency']) ? $currencySymbol : '' !!} {{ $currentTotal }}
@endif
@if($metric !== 'overdue_payments')
{{ __('insights.this_week') }}
@endif
{{-- Comparison with Previous Week --}}
@if($previousWeekData)
|
{{ __('insights.from_last_week') }}
{{ $trendSymbol }} {{ $previousTotal }}
|
{{ __('insights.change') }}
{{ $trendSymbol }} {{ number_format(abs($percentageChange), 1) }}%
|
@endif
|
|
{{-- Right Section: Breakdown (only for overdue payments) --}}
@if($config['showBreakdown'])
{{-- 0-7 Days --}}
{{ __('insights.0_7_days_overdue') }}
{!! $smallCurrencySymbol !!} {{ number_format($zeroToSeven['total'],2) }}
|
{{-- 8-30 Days --}}
{{ __('insights.8_30_days_overdue') }}
{!! $smallCurrencySymbol !!} {{ number_format($eightToThirty['total'],2) }}
|
{{-- More than 30 Days --}}
{{ __('insights.more_than_30_days_overdue') }}
{!! $smallCurrencySymbol !!} {{ number_format($overThirty['total'],2) }}
|
|
@endif
|
@endif
@endforeach
{{ __('insights.report_details') }}
{{ __('insights.generated_at') }}: {{ isset($insights['generated_at']) ? \Carbon\Carbon::parse($insights['generated_at'])->toDayDateTimeString() : 'N/A' }}
@if(!empty($insights['warnings']))
{{ __('insights.warnings_alerts') }}
@foreach($insights['warnings'] as $warning)
{{ $warning['severity'] === 'critical' ? 'đ¨' : ($warning['severity'] === 'high' ? 'â ī¸' : 'âšī¸') }}
{{ __('insights.warning_titles.' . $warning['type']) }}
{{ $warning['message'] }}
@if(isset($warning['action']))
đĄ {{ $warning['action'] }}
@endif
@endforeach
@endif
@endif
|
{{-- Footer Section --}}