@extends('layouts.finance') @section('title', $mode === 'create' ? 'Add Bank Account' : 'Edit Bank Account') @section('subtitle', 'Create and maintain database-backed bank accounts') @push('styles') @endpush @section('content') @php $isCreate = $mode === 'create'; $action = $isCreate ? route('finance.accounts.store') : route('finance.accounts.update', $account); $countryFor = fn($currency) => $currency === 'PKR' ? 'Pakistan' : ($currency === 'AUD' ? 'Australia' : 'United States'); $logoColorFor = fn($currency) => $currency === 'PKR' ? '#1e3a8a' : ($currency === 'AUD' ? '#0d9488' : '#dc2626'); $shortFor = fn($bank) => strtoupper(substr(preg_replace('/[^A-Za-z0-9]/', '', $bank->bank_name ?: $bank->name), 0, 4)) ?: 'BANK'; $maskedAccount = fn($bank) => $bank->account_number ? '****'.substr($bank->account_number, -4) : 'No #'; $cardShortFor = fn($card) => strtoupper(substr(preg_replace('/[^A-Za-z0-9]/', '', $card->short_name ?: $card->issuer ?: $card->card_name), 0, 4)) ?: 'CARD'; $cardMaskedAccount = fn($card) => $card->card_name ? $card->card_name : 'Credit Card'; $linkGroups = $linkableAccounts->groupBy(fn($bank) => $countryFor($bank->currency)); $cardLinkGroups = $linkableCreditCards->groupBy(fn($card) => $countryFor($card->currency)); $creditLinkIdsByAccount = $account->exists ? $account->creditSources->mapWithKeys(fn($bank) => [$bank->id => $bank->pivot->id]) : collect(); $debitLinkIdsByAccount = $account->exists ? $account->debitDestinations->mapWithKeys(fn($bank) => [$bank->id => $bank->pivot->id]) : collect(); $creditCardLinkIdsByCard = $account->exists ? $account->creditCardSources->mapWithKeys(fn($card) => [$card->id => $card->pivot->id]) : collect(); $debitCardLinkIdsByCard = $account->exists ? $account->debitCardDestinations->mapWithKeys(fn($card) => [$card->id => $card->pivot->id]) : collect(); $transactionCategories = \App\Models\BankAccount::query() ->whereNotNull('transaction_category') ->distinct() ->orderBy('transaction_category') ->pluck('transaction_category') ->merge(['Pak Banks', 'Wallets', 'US Banks', 'AUS Banks']) ->filter() ->unique() ->values(); // Currency implied by each category (built-in mapping + currencies of // existing accounts), so selecting a category can auto-pick its currency. $categoryCurrencies = $transactionCategories ->mapWithKeys(fn($category) => [$category => \App\Models\BankAccount::defaultCurrencyForCategory($category)]) ->filter(); @endphp

{{ $isCreate ? 'New Bank Account' : 'Edit Bank Account' }}

This account is used across dashboard totals, transaction routing, reports, and cash flow.
Back
@csrf @unless($isCreate) @method('PUT') @endunless
@php($selectedCategory = old('transaction_category', $account->transactionCategory()))
Categories automatically appear on the Transactions page.
@if($account->exists)
Current balance is calculated from database transactions: {{ app(\App\Support\FinanceSuiteMetrics::class)->money($account->current_balance, $account->currency) }}
@endif
Used for balances and exchange calculations.
Optional snapshot rate for this account.
@foreach([ 'credit_source_ids' => [ 'title' => 'Credit Sources', 'selected' => collect(old('credit_source_ids', $selectedCreditSourceIds->all()))->map(fn($id) => (int) $id), 'cardField' => 'credit_source_card_ids', 'selectedCards' => collect(old('credit_source_card_ids', $selectedCreditSourceCardIds->all()))->map(fn($id) => (int) $id), 'hint' => 'accounts that send money INTO this account', 'linkIds' => $creditLinkIdsByAccount, 'cardLinkIds' => $creditCardLinkIdsByCard, 'deletePrefix' => 'credit', ], 'debit_destination_ids' => [ 'title' => 'Debit Destinations', 'selected' => collect(old('debit_destination_ids', $selectedDebitDestinationIds->all()))->map(fn($id) => (int) $id), 'cardField' => 'debit_destination_card_ids', 'selectedCards' => collect(old('debit_destination_card_ids', $selectedDebitDestinationCardIds->all()))->map(fn($id) => (int) $id), 'hint' => 'accounts this account sends money TO', 'linkIds' => $debitLinkIdsByAccount, 'cardLinkIds' => $debitCardLinkIdsByCard, 'deletePrefix' => 'debit', ], ] as $field => $list)
@endforeach
@if($account->exists) @foreach($creditLinkIdsByAccount as $bankId => $linkId) @endforeach @foreach($debitLinkIdsByAccount as $bankId => $linkId) @endforeach @endif
@endsection @push('scripts') @endpush