@php $fmt = fn ($n) => number_format((float) $n, 0); $summary = $summary ?? []; $priorSummary = $priorSummary ?? []; $comparison = $comparison ?? []; $insights = $insights ?? []; $operations = $operations ?? []; $flowChart = $flowChart ?? ['labels' => [], 'values' => []]; $monthlyPurchases = $monthlyPurchases ?? array_fill(0, 12, 0); $monthLabels = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; $heroTone = $insights['hero_tone'] ?? 'info'; $toneMap = ['success' => 'success', 'warning' => 'warning', 'info' => 'primary', 'secondary' => 'secondary']; $heroClass = 'alert-' . ($toneMap[$heroTone] ?? 'primary'); $pctBadge = function ($pct) { if ($pct === null) { return ''; } $up = $pct >= 0; $icon = $up ? 'bx-up-arrow-alt' : 'bx-down-arrow-alt'; $cls = $up ? 'text-success' : 'text-danger'; return ' ' . number_format(abs($pct), 1) . '% vs prior year'; }; @endphp
Insight for {{ $year }}

{{ $insights['hero'] ?? '' }}

@foreach($insights['alerts'] ?? [] as $alert)

{{ $alert['text'] }}

@endforeach
Management headline
{{ $fmt($summary['total_on_hand'] ?? 0) }} kg

{{ $insights['management_sub'] ?? '' }}

{!! $pctBadge($comparison['total_on_hand_pct'] ?? null) !!}

Purchased FAQ compared with outbound sales, beverage transfers, and estimated stock still on hand.

@if(($insights['screen18_months_supply'] ?? null) !== null)
At current Screen 18 sales pace, roughly {{ $insights['screen18_months_supply'] }} months of graded stock remain.
@endif
@foreach([ ['Cumulative coffee stock', 'cumulative_coffee_stock', 'kg', 'primary'], ['Total MC deduction', 'total_mc_deduction', 'kg', 'info'], ['Cumulative Screen 18', 'cumulative_screen18_stock', 'kg', 'success'], ['FAQ purchased', 'faq_purchased', 'kg', 'primary'], ['Coffee sold', 'gross_sold', 'kg', 'success'], ['To beverage', 'transferred_out', 'kg', 'info'], ['On hand (est.)', 'total_on_hand', 'kg', 'warning'], ] as [$label, $key, $unit, $color]) @php $value = str_starts_with($key, 'cumulative_') || $key === 'total_mc_deduction' ? ($operations[$key] ?? 0) : ($summary[$key] ?? 0); $priorValue = str_starts_with($key, 'cumulative_') || $key === 'total_mc_deduction' ? null : ($priorSummary[$key] ?? 0); $pct = str_starts_with($key, 'cumulative_') || $key === 'total_mc_deduction' ? null : ($comparison[$key . '_pct'] ?? null); @endphp
{{ $label }}
{{ $fmt($value) }} {{ $unit }}
@if($priorValue !== null)
{{ $year - 1 }}: {{ $fmt($priorValue) }} {{ $unit }}
{!! $pctBadge($pct) !!}
@endif
@endforeach
FAQ purchased from farmers
{{ $fmt($summary['faq_purchased'] ?? 0) }} kg
{!! $pctBadge($comparison['faq_purchased_pct'] ?? null) !!}
@can('payment_valuation_final.view') Open payment vouchers @endcan
MC deducted at purchase
{{ $fmt($summary['mc_deducted_at_purchase'] ?? 0) }} kg
{!! $pctBadge($comparison['mc_deducted_pct'] ?? null) !!}
MC still in stock
{{ $fmt($summary['mc_remaining_in_stock'] ?? 0) }} kg
Moisture not yet released through sales.
Coffee sold (gross)
{{ $fmt($summary['gross_sold'] ?? 0) }} kg
{!! $pctBadge($comparison['gross_sold_pct'] ?? null) !!}
@can('coffee_sales.view') View all sales @endcan
How green bean stock flows
  1. Purchase — GRN & payment voucher record FAQ weight after moisture adjustment.
  2. Processing — Raw stock milled into Screen 18 or processed ungraded lots.
  3. Sale / transfer — Sold to buyers or transferred to the beverage unit.
@php $chartData = [ 'flow' => $flowChart, 'monthly' => ['labels' => $monthLabels, 'values' => $monthlyPurchases], ]; @endphp