@extends('layouts.app')
@section('content')
@php
$userName = auth()->user()?->name ?: 'Admin';
$kpis = [
['label' => 'Total Sales', 'value' => \App\Models\SystemSetting::formatMoney($totalSales), 'icon' => '🛒', 'tone' => 'blue'],
['label' => 'Net Cash', 'value' => \App\Models\SystemSetting::formatMoney($netTotal), 'icon' => 'â–¤', 'tone' => 'green'],
['label' => 'Pending Bills', 'value' => \App\Models\SystemSetting::formatMoney($invoiceDue), 'icon' => '!', 'tone' => 'orange'],
['label' => 'Stock Value', 'value' => \App\Models\SystemSetting::formatMoney($stockValue), 'icon' => 'â–¥', 'tone' => 'blue'],
['label' => 'Total Purchase', 'value' => \App\Models\SystemSetting::formatMoney($totalPurchase), 'icon' => '💵', 'tone' => 'blue'],
['label' => 'Purchase Due', 'value' => \App\Models\SystemSetting::formatMoney($purchaseDue), 'icon' => '!', 'tone' => 'orange'],
[
'label' => 'Payment Methods',
'value' => \App\Models\SystemSetting::formatMoney($paymentMethodSummaryTotal),
'icon' => 'â–¤',
'tone' => 'green',
'lines' => $paymentMethodSummary->map(fn ($row) => $row->name.': '.\App\Models\SystemSetting::formatMoney($row->total_amount))->values()->all(),
],
['label' => 'Expense', 'value' => \App\Models\SystemSetting::formatMoney($expenseTotal), 'icon' => '−', 'tone' => 'red'],
];
$paymentSlices = $paymentMethodSummary->map(function ($row) use ($paymentMethodSummaryTotal) {
return [
'name' => $row->name,
'value' => (float) $row->total_amount,
'percent' => $paymentMethodSummaryTotal > 0 ? round(((float) $row->total_amount / (float) $paymentMethodSummaryTotal) * 100, 1) : 0,
];
})->values();
$pieColors = ['#18c4dd', '#2dca83', '#ffad3d', '#f3345b', '#1E4FA8', '#6b7280'];
$startPercent = 0;
$pieSegments = [];
foreach ($paymentSlices as $index => $slice) {
$endPercent = $startPercent + $slice['percent'];
$pieSegments[] = $pieColors[$index % count($pieColors)].' '.$startPercent.'% '.$endPercent.'%';
$startPercent = $endPercent;
}
$pieBackground = $paymentMethodSummaryTotal > 0 ? implode(', ', $pieSegments) : '#e5e7eb 0% 100%';
$chartWidth = 1180;
$chartHeight = 360;
$chartLeft = 54;
$chartRight = 24;
$chartTop = 30;
$chartBottom = 70;
$plotWidth = $chartWidth - $chartLeft - $chartRight;
$plotHeight = $chartHeight - $chartTop - $chartBottom;
$maxTrendAmount = max($salesTrend->max('amount'), 1);
$targetGridLines = 5;
$rawInterval = $maxTrendAmount / $targetGridLines;
$niceIntervals = [500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000];
$axisInterval = collect($niceIntervals)->first(fn ($interval) => $interval >= $rawInterval) ?? ceil($rawInterval / 1000000) * 1000000;
$axisMax = max(ceil($maxTrendAmount / $axisInterval) * $axisInterval, $axisInterval);
$pointCount = max($salesTrend->count() - 1, 1);
$trendPoints = $salesTrend->values()->map(function ($row, $index) use ($chartLeft, $chartTop, $plotWidth, $plotHeight, $pointCount, $axisMax) {
$x = $chartLeft + (($plotWidth / $pointCount) * $index);
$y = $chartTop + ($plotHeight - (((float) $row['amount'] / $axisMax) * $plotHeight));
return $row + ['x' => round($x, 2), 'y' => round($y, 2)];
});
$barWidth = max(($plotWidth / max($salesTrend->count(), 1)) * .58, 10);
$gridCount = max((int) ($axisMax / $axisInterval), 1);
$gridLines = collect(range(0, $gridCount))->map(function ($step) use ($chartTop, $plotHeight, $axisMax, $axisInterval, $gridCount) {
$value = $axisMax - ($axisInterval * $step);
$y = $chartTop + (($plotHeight / $gridCount) * $step);
return ['y' => round($y, 2), 'value' => $value];
});
$monthChartWidth = 1180;
$monthChartHeight = 360;
$monthChartLeft = 54;
$monthChartRight = 24;
$monthChartTop = 30;
$monthChartBottom = 58;
$monthPlotWidth = $monthChartWidth - $monthChartLeft - $monthChartRight;
$monthPlotHeight = $monthChartHeight - $monthChartTop - $monthChartBottom;
$maxMonthlyAmount = max($monthlySalesTrend->max('amount'), 1);
$monthRawInterval = $maxMonthlyAmount / $targetGridLines;
$monthAxisInterval = collect($niceIntervals)->first(fn ($interval) => $interval >= $monthRawInterval) ?? ceil($monthRawInterval / 1000000) * 1000000;
$monthAxisMax = max(ceil($maxMonthlyAmount / $monthAxisInterval) * $monthAxisInterval, $monthAxisInterval);
$monthPointCount = max($monthlySalesTrend->count() - 1, 1);
$monthPoints = $monthlySalesTrend->values()->map(function ($row, $index) use ($monthChartLeft, $monthChartTop, $monthPlotWidth, $monthPlotHeight, $monthPointCount, $monthAxisMax) {
$x = $monthChartLeft + (($monthPlotWidth / $monthPointCount) * $index);
$y = $monthChartTop + ($monthPlotHeight - (((float) $row['amount'] / $monthAxisMax) * $monthPlotHeight));
return $row + ['x' => round($x, 2), 'y' => round($y, 2)];
});
$monthBarWidth = max(($monthPlotWidth / max($monthlySalesTrend->count(), 1)) * .48, 24);
$monthGridCount = max((int) ($monthAxisMax / $monthAxisInterval), 1);
$monthGridLines = collect(range(0, $monthGridCount))->map(function ($step) use ($monthChartTop, $monthPlotHeight, $monthAxisMax, $monthAxisInterval, $monthGridCount) {
$value = $monthAxisMax - ($monthAxisInterval * $step);
$y = $monthChartTop + (($monthPlotHeight / $monthGridCount) * $step);
return ['y' => round($y, 2), 'value' => $value];
});
@endphp
Welcome {{ strtoupper($userName) }},
Business day: {{ $businessDayStart ? $businessDayStart->format('Y-m-d H:i') : 'All time' }} to {{ $businessDayEnd ? $businessDayEnd->format('Y-m-d H:i') : 'All time' }}
@foreach($kpis as $kpi)
{{ $kpi['icon'] }}
{{ $kpi['label'] }}
{{ $kpi['value'] }}
@if(!empty($kpi['note']))
{{ $kpi['note'] }}
@endif
@if(!empty($kpi['lines']))
@foreach($kpi['lines'] as $line)
{{ $line }}
@endforeach
@endif
@endforeach
@if(auth()->user()->canAccessModule('leads-management') && auth()->user()->hasPermission('follow_ups.view'))
Today's Follow-ups
| Time | Subject | Related To | Action |
@forelse($todayFollowUps as $item)| {{ $item->due_at?->format('H:i') }} | {{ $item->subject }} | {{ class_basename($item->followable_type) }} | View |
@empty| No follow-ups due today |
@endforelse
Overdue Follow-ups
| Due | Subject | Related To | Action |
@forelse($overdueFollowUps as $item)| {{ $item->due_at?->format('Y-m-d H:i') }} | {{ $item->subject }} | {{ class_basename($item->followable_type) }} | View |
@empty| No overdue follow-ups |
@endforelse
@endif
Pending Bills
| Customer |
Invoice No. |
Due Amount |
Action |
@forelse($pendingBills as $bill)
| {{ $bill->customer?->name ?: ($bill->customer_name ?: '-') }} |
{{ $bill->invoice_no }} |
{{ \App\Models\SystemSetting::formatMoney($bill->balance_amount) }} |
View |
@empty
| No data available in table |
@endforelse
Purchase Payment Due
| Supplier |
Reference No. |
Due Amount |
Action |
@forelse($purchasePaymentDues as $purchase)
| {{ $purchase->supplier?->name ?: ($purchase->supplier_name ?: '-') }} |
{{ $purchase->purchase_no }} |
{{ \App\Models\SystemSetting::formatMoney($purchase->balance_amount) }} |
View |
@empty
| No data available in table |
@endforelse
Product Stock Alert
| Product |
Location |
Current Stock |
@forelse($stockAlerts as $product)
| {{ $product->name }}{{ $product->barcode ? ' ('.$product->barcode.')' : '' }} |
{{ $product->branch?->name ?: 'All branches' }} |
{{ number_format((float) $product->stock_quantity, 2) }} {{ $product->unitOfMeasure?->name ?: 'Pc(s)' }} |
@empty
| No data available in table |
@endforelse
Sales Last 30 Days
End of day: {{ \App\Models\SystemSetting::formatMoney($salesTrend->last()['amount'] ?? 0) }}
Sales Current Financial Year
Year total: {{ \App\Models\SystemSetting::formatMoney($monthlySalesTrend->sum('amount')) }}
Payment Methods
@forelse($paymentSlices as $index => $slice)
{{ $slice['name'] }}
{{ $slice['percent'] }}%
@empty
No payments
0%
@endforelse
@endsection