{{ __('Manage Chronic Fundrising') }} {{ __('Manage the chronic fund cycle stages, then run pharmacy settlements and payouts.') }}
@if(session('success'))
{{ session('success') }}
@endif @if(session('warning'))
{{ session('warning') }}
@endif @if($errors->any())
{{ __('Please fix the errors below.') }}
    @foreach($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif
{{ __('Fund Balance') }}: {{ number_format((float) ($fundBalance ?? 0), 2) }}
{{ __('Cycle Stage') }}: {{ isset($cycle) ? ucwords(str_replace('_', ' ', (string) $cycle->stage)) : '-' }}
{{ __('Approved recipients') }}: {{ number_format((int) ($approvedRecipientsCount ?? 0)) }} @if(!empty($cycle?->target_recipients_count)) / {{ number_format((int) $cycle->target_recipients_count) }} @endif
{{ __('Annual need (calculated)') }}: {{ number_format((float) ($cycle?->annual_need_total ?? 0), 2) }}
{{ __('Budget') }}: {{ number_format((float) ($cycle?->budget_amount ?? 0), 2) }}
{{ __('Donations total') }}: {{ number_format((float) ($donationsTotal ?? 0), 2) }}
{{ __('Workflow steps') }}
1
{{ __('Target recipients') }}
{{ empty($cycle?->target_recipients_count) ? __('Not set') : __('Set') }}
{{ __('Set how many approved beneficiaries are required to proceed.') }}
2
{{ __('Calculate annual needs') }}
{{ __('Locked') }}
{{ __('Annual need = 12 × SUM(monthly dose × unit price).') }}
@csrf
3
{{ __('Open fundraising') }}
{{ ($cycle?->stage ?? null) === 'fundraising_open' ? __('Open') : __('Closed') }}
{{ __('Set budget, then allow donations to start.') }}
4
{{ __('Start dispensing') }}
{{ ($cycle?->stage ?? null) === 'dispensing' ? __('Active') : __('Inactive') }}
{{ __('Allows pharmacies to dispense for approved recipients.') }}
@csrf
5
{{ __('Start settlements') }}
{{ ($cycle?->stage ?? null) === 'settlements' ? __('Active') : __('Inactive') }}
{{ __('Enables draft/confirm/payout settlement operations.') }}
@csrf
{{ __('Settlement operations') }}
@if(!($cycle?->canRunSettlements()))
{{ __('Settlements are disabled until the cycle reaches the settlements stage.') }}
@endif
{{ __('Generate drafts') }}
{{ __('Aggregate logs into one draft per pharmacy/month.') }}
@if($cycle?->canRunSettlements()) @else @endif
{{ __('Confirm settlement') }}
{{ __('Locks the settlement and prevents edits/regeneration.') }}
@if($cycle?->canRunSettlements()) @else @endif
{{ __('Record payout') }}
{{ __('Payouts are explicit and may be partial.') }}
@if($cycle?->canRunSettlements()) @else @endif
{{ __('New cycle') }}
{{ __('Start a new chronic fund cycle') }}
{{ __('Creates a new cycle and resets the workflow back to registration. Use after completing the current cycle.') }}
@if(($cycle?->stage ?? null) === 'settlements')
@csrf
@else @endif
@php $confirmedSettlements = collect($settlements ?? [])->filter(function ($s) { return !empty($s->confirmed_at); })->values(); @endphp
{{ __('Confirmed settlements') }}
@forelse($confirmedSettlements as $tx) @php $paid = (float) ($tx->paid_amount ?? 0); $total = (float) ($tx->total_amount ?? 0); $outstanding = max(0, $total - $paid); $seq = (int) ($tx->sequence ?? 1); @endphp @empty @endforelse
{{ __('Pharmacy') }} {{ __('Settlement') }} {{ __('Total Amount') }} {{ __('Paid') }} {{ __('Outstanding') }} {{ __('Confirmed At') }}
{{ optional($tx->pharmacy)->pharmacy_name ?? ('#' . $tx->pharmacy_id) }} {{ $tx->month_year }} #{{ $seq }} {{ number_format($total, 2) }} {{ number_format($paid, 2) }} {{ number_format($outstanding, 2) }} {{ $tx->confirmed_at ? $tx->confirmed_at->format('Y-m-d H:i') : '-' }}
{{ __('No confirmed settlements for this month.') }}
{{ __('Payments (payouts)') }}
@forelse(($payouts ?? []) as $p) @php $settlement = $p->settlement; $seq = (int) (($settlement?->sequence) ?? 1); @endphp @empty @endforelse
{{ __('Executed At') }} {{ __('Pharmacy') }} {{ __('Settlement') }} {{ __('Amount') }} {{ __('Reference') }} {{ __('Recorded By') }}
{{ $p->executed_at ? $p->executed_at->format('Y-m-d') : '-' }} {{ optional($settlement?->pharmacy)->pharmacy_name ?? ($settlement ? ('#' . $settlement->pharmacy_id) : '-') }} {{ $settlement ? ($settlement->month_year . ' #' . $seq) : '-' }} {{ number_format((float) $p->amount, 2) }} {{ $p->reference ?? '-' }} {{ optional($p->createdBy)->name ?? ('#' . $p->created_by_user_id) }}
{{ __('No payments for this month.') }}
{{-- Modals --}} @php $settlementsPayload = collect($settlements ?? [])->map(function ($s) { $paid = (float) ($s->paid_amount ?? 0); $total = (float) ($s->total_amount ?? 0); $outstanding = max(0.0, $total - $paid); return [ 'id' => $s->id, 'pharmacy' => optional($s->pharmacy)->pharmacy_name ?? ('#' . $s->pharmacy_id), 'month' => (string) $s->month_year, 'sequence' => (int) ($s->sequence ?? 1), 'total' => (float) $total, 'paid' => (float) $paid, 'outstanding' => (float) $outstanding, 'confirmed_at' => $s->confirmed_at ? (string) $s->confirmed_at : null, 'confirm_url' => route('chronic.settlements.confirm', $s), 'payout_url' => route('chronic.settlements.payouts.store', $s), ]; })->values(); @endphp