@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' }}

Reset
@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

@forelse($todayFollowUps as $item)@empty@endforelse
TimeSubjectRelated ToAction
{{ $item->due_at?->format('H:i') }}{{ $item->subject }}{{ class_basename($item->followable_type) }}View
No follow-ups due today

Overdue Follow-ups

@forelse($overdueFollowUps as $item)@empty@endforelse
DueSubjectRelated ToAction
{{ $item->due_at?->format('Y-m-d H:i') }}{{ $item->subject }}{{ class_basename($item->followable_type) }}View
No overdue follow-ups
@endif

Pending Bills

@forelse($pendingBills as $bill) @empty @endforelse
Customer Invoice No. Due Amount Action
{{ $bill->customer?->name ?: ($bill->customer_name ?: '-') }} {{ $bill->invoice_no }} {{ \App\Models\SystemSetting::formatMoney($bill->balance_amount) }} View
No data available in table

Purchase Payment Due

@forelse($purchasePaymentDues as $purchase) @empty @endforelse
Supplier Reference No. Due Amount Action
{{ $purchase->supplier?->name ?: ($purchase->supplier_name ?: '-') }} {{ $purchase->purchase_no }} {{ \App\Models\SystemSetting::formatMoney($purchase->balance_amount) }} View
No data available in table

Product Stock Alert

@forelse($stockAlerts as $product) @empty @endforelse
Product Location Current Stock
{{ $product->name }}{{ $product->barcode ? ' ('.$product->barcode.')' : '' }} {{ $product->branch?->name ?: 'All branches' }} {{ number_format((float) $product->stock_quantity, 2) }} {{ $product->unitOfMeasure?->name ?: 'Pc(s)' }}
No data available in table

Sales Last 30 Days

End of day: {{ \App\Models\SystemSetting::formatMoney($salesTrend->last()['amount'] ?? 0) }}
@foreach($gridLines as $line) {{ number_format($line['value'] / 1000, $line['value'] >= 1000 ? 0 : 1) }}k @endforeach @foreach($trendPoints as $point) @php $barHeight = max(($chartTop + $plotHeight) - $point['y'], $point['amount'] > 0 ? 3 : 0); $barX = $point['x'] - ($barWidth / 2); @endphp @if($point['amount'] > 0) {{ number_format($point['amount'], 0) }} @endif {{ $point['label'] }} @endforeach Total Sales

Sales Current Financial Year

Year total: {{ \App\Models\SystemSetting::formatMoney($monthlySalesTrend->sum('amount')) }}
@foreach($monthGridLines as $line) {{ number_format($line['value'] / 1000, $line['value'] >= 1000 ? 0 : 1) }}k @endforeach @foreach($monthPoints as $point) @php $monthBarHeight = max(($monthChartTop + $monthPlotHeight) - $point['y'], $point['amount'] > 0 ? 3 : 0); $monthBarX = $point['x'] - ($monthBarWidth / 2); @endphp @if($point['amount'] > 0) {{ number_format($point['amount'], 0) }} @endif {{ $point['label'] }} @endforeach Total Sales

Payment Methods

@forelse($paymentSlices as $index => $slice)
{{ $slice['name'] }} {{ $slice['percent'] }}%
@empty
No payments 0%
@endforelse
@endsection