@extends('layouts.finance') @section('title', 'Monthly Closing') @section('subtitle', 'Close each month to lock its Sale, Profit, Expense and Net Worth') @section('content') @php $preview = $preview ?? ['currency' => 'PKR', 'total_sale' => 0, 'profit' => 0, 'expense' => 0, 'net_profit' => 0, 'net_worth' => 0]; $closings = $closings ?? collect(); $cur = $preview['currency'] ?? 'PKR'; $closureStatus = $closureStatus ?? ['rows' => collect(), 'closed_count' => 0, 'required_count' => 0, 'remaining_count' => 0, 'can_close' => false, 'can_manage' => false]; @endphp @if(session('success'))
{{ session('success') }}
@endif {{-- SELECT + PREVIEW / CLOSE --}}
Closing Month
{{ $closingMonth->format('F Y') }}
@if($existing)
Closed {{ $existing->closed_at?->format('d M Y, H:i') }}{{ $existing->is_auto ? ' · auto' : '' }} — snapshot is fixed.
@else
Closing period: {{ $closureStatus['period_start']->format('d M Y') }} to {{ $closureStatus['period_end']->format('d M Y') }}. You can close this month later, but the data range always stays inside this selected month only.
@endif
Total Sale
{{ $metrics->money($preview['total_sale'], $cur) }}
Profit (before expense)
{{ $metrics->money($preview['profit'], $cur) }}
Expense
{{ $metrics->money($preview['expense'], $cur) }}
Profit / Loss (after expense)
{{ $metrics->money($preview['net_profit'], $cur) }}
Company Net Worth
{{ $metrics->money($preview['net_worth'], $cur) }}
Captured at the moment you close
@csrf
@if($existing)
@csrf @method('DELETE')
@endif {{ $closureStatus['closed_count'] }}/{{ $closureStatus['required_count'] }} accounts closed @if(! $closureStatus['can_manage']) Only past months can be manually closed @endif

Manual Bank / Wallet / Credit Closings

{{ $closingMonth->format('F Y') }} cycle · {{ $closureStatus['period_start']->format('d M') }} to {{ $closureStatus['period_end']->format('d M Y') }}
@forelse($closureStatus['rows'] as $row) @empty @endforelse
Account Type Period Status Action
{{ $row['name'] }}
{{ $row['subtitle'] }}
{{ $row['kind'] === 'bank' ? 'Bank / Wallet' : 'Credit Card' }} {{ $row['period_start']->format('d M Y') }} to {{ $row['period_end']->format('d M Y') }} @if($row['is_closed']) Closed {{ $row['closing']?->closed_at?->format('d M Y, H:i') }} @else Open @endif @if($row['is_closed']) Done @elseif($closureStatus['can_manage'])
@csrf
@else Unavailable @endif
No active banks, wallets, or credit cards found.
{{-- CLOSED MONTHS TABLE --}}

Closed Months

Fixed snapshots · newest first
@forelse($closings as $row) @empty @endforelse
Month Total Sale Profit Expense Profit / Loss (after expense) Company Net Worth Status
{{ $row->month->format('F Y') }} {{ $metrics->money($row->total_sale, $row->currency) }} {{ $metrics->money($row->profit, $row->currency) }} {{ $metrics->money($row->expense, $row->currency) }} {{ $row->isProfit() ? '' : '-' }}{{ $metrics->money(abs((float) $row->net_profit), $row->currency) }} {{ $metrics->money($row->net_worth, $row->currency) }} {{ $row->accounts_closed_count }}/{{ $row->accounts_required_count }} closed
No months closed yet. Pick a month above and press Close.
@endsection