#!/bin/bash
# ============================================================
# SaaS Accounting — Voucher Form Improvements
# Changes:
#   1. Remove DR/CR column — separate Debit & Credit columns
#   2. Add Cheque No + Cheque Date for Bank Payment/Receipt
#   3. Add Voucher No field (manual override) in all vouchers
#   4. Fix Select2 account dropdown
#
# Run: bash deploy_voucher_form.sh
# From: ~/public_html/saas-accounting/
# ============================================================
set -e
cd ~/public_html/saas-accounting

echo ""
echo "=============================================="
echo "  Voucher Form Improvements"
echo "=============================================="
echo ""

# ── 1. Update Voucher Model — add cheque fields to extra_data ─────────────────
echo "Step 1: Voucher model already supports extra_data JSON — OK"

# ── 2. Update AccountingVouchersController ────────────────────────────────────
echo "Step 2: Updating controller to handle new fields..."
python3 << 'PYEOF'
content = open('app/Http/Controllers/Company/Accounting/AccountingVouchersController.php').read()

# Add manual_number, cheque_no, cheque_date to store validation
old_store_validate = """            'reference'    => 'nullable|string|max:100',
            'currency_id'   => 'nullable|integer|exists:currencies,id',
            'exchange_rate' => 'nullable|numeric|min:0',
            'narration'     => 'nullable|string|max:500',"""

new_store_validate = """            'manual_number' => 'nullable|string|max:50',
            'reference'    => 'nullable|string|max:100',
            'cheque_no'    => 'nullable|string|max:50',
            'cheque_date'  => 'nullable|date',
            'currency_id'   => 'nullable|integer|exists:currencies,id',
            'exchange_rate' => 'nullable|numeric|min:0',
            'narration'     => 'nullable|string|max:500',"""

# Add to create array
old_create_array = """                'voucher_number' => $voucherNumber,
                'voucher_date'   => $validated['voucher_date'],
                'reference'      => $validated['reference'] ?? null,
                'currency_id'    => $validated['currency_id'] ?? null,
                'exchange_rate'  => $validated['exchange_rate'] ?? 1,
                'narration'      => $validated['narration'] ?? null,"""

new_create_array = """                'voucher_number' => !empty($validated['manual_number']) ? $validated['manual_number'] : $voucherNumber,
                'voucher_date'   => $validated['voucher_date'],
                'reference'      => $validated['reference'] ?? null,
                'currency_id'    => $validated['currency_id'] ?? null,
                'exchange_rate'  => $validated['exchange_rate'] ?? 1,
                'narration'      => $validated['narration'] ?? null,
                'extra_data'     => [
                    'cheque_no'   => $validated['cheque_no'] ?? null,
                    'cheque_date' => $validated['cheque_date'] ?? null,
                ],"""

# Add to update validation
old_update_validate = """            'reference'    => 'nullable|string|max:100',
            'currency_id'   => 'nullable|integer|exists:currencies,id',
            'exchange_rate' => 'nullable|numeric|min:0',
            'narration'     => 'nullable|string|max:500',"""

# Add to update array
old_update_array = """            'voucher_date'  => $validated['voucher_date'],
                'reference'     => $validated['reference'] ?? null,
                'currency_id'   => $validated['currency_id'] ?? null,
                'exchange_rate' => $validated['exchange_rate'] ?? 1,
                'narration'     => $validated['narration'] ?? null,"""

new_update_array = """            'voucher_date'  => $validated['voucher_date'],
                'reference'     => $validated['reference'] ?? null,
                'currency_id'   => $validated['currency_id'] ?? null,
                'exchange_rate' => $validated['exchange_rate'] ?? 1,
                'narration'     => $validated['narration'] ?? null,
                'extra_data'    => [
                    'cheque_no'   => $request->input('cheque_no'),
                    'cheque_date' => $request->input('cheque_date'),
                ],"""

# Also fix line dr_cr handling — separate debit/credit input
old_line_validation = """            'lines.*.dr_cr'      => 'required|in:dr,cr',"""
new_line_validation = """            'lines.*.dr_cr'      => 'nullable|in:dr,cr',
            'lines.*.debit'      => 'nullable|numeric|min:0',
            'lines.*.credit'     => 'nullable|numeric|min:0',"""

content = content.replace(old_store_validate, new_store_validate)
content = content.replace(old_create_array, new_create_array)
content = content.replace(old_update_array, new_update_array)
content = content.replace(old_line_validation, new_line_validation, 1)

# Fix line processing to handle separate debit/credit fields
old_line_loop = """            foreach ($request->input('lines', []) as $lineData) {
                    if (empty($lineData['account_id'])) continue;
                    $amount = (float)($lineData['amount'] ?? 0);
                    if ($amount <= 0) continue;"""

new_line_loop = """            foreach ($request->input('lines', []) as $lineData) {
                    if (empty($lineData['account_id'])) continue;
                    // Support both separate debit/credit OR combined amount+dr_cr
                    $debit  = (float)($lineData['debit']  ?? 0);
                    $credit = (float)($lineData['credit'] ?? 0);
                    if ($debit > 0) {
                        $lineData['dr_cr']  = 'dr';
                        $lineData['amount'] = $debit;
                    } elseif ($credit > 0) {
                        $lineData['dr_cr']  = 'cr';
                        $lineData['amount'] = $credit;
                    } else {
                        // fallback: use amount + dr_cr
                        $lineData['amount'] = (float)($lineData['amount'] ?? 0);
                    }
                    $amount = (float)($lineData['amount'] ?? 0);
                    if ($amount <= 0) continue;"""

content = content.replace(old_line_loop, new_line_loop, 1)

# Same fix for update line loop
content = content.replace(old_line_loop, new_line_loop, 1)

open('app/Http/Controllers/Company/Accounting/AccountingVouchersController.php', 'w').write(content)
print("  Controller updated.")
PYEOF

# ── 3. Rewrite _line_row.blade.php ───────────────────────────────────────────
echo "Step 3: Rewriting _line_row.blade.php with separate Debit/Credit columns..."
cat > resources/views/accounting/vouchers/_line_row.blade.php << 'BLADEEOF'
@php
    $drAmt = '';
    $crAmt = '';
    if (isset($line) && $line) {
        if ($line->dr_cr === 'dr') $drAmt = number_format((float)$line->line_total, 2, '.', '');
        else                        $crAmt = number_format((float)$line->line_total, 2, '.', '');
    }
@endphp
<tr class="voucher-line" data-index="{{ $i }}">

    {{-- # --}}
    <td class="line-num ps-3 text-muted" style="font-size:12px;vertical-align:middle">
        {{ is_int($i) ? $i + 1 : 1 }}
    </td>

    {{-- Account --}}
    <td style="vertical-align:middle;min-width:200px">
        <select name="lines[{{ $i }}][account_id]"
                class="form-select form-select-sm account-select" required>
            <option value="">— Select Account —</option>
            @foreach($accounts as $acc)
                <option value="{{ $acc->id }}"
                    {{ isset($line) && $line->account_id == $acc->id ? 'selected' : '' }}>
                    {{ $acc->code ? "[{$acc->code}] " : "" }}{{ $acc->name }}
                </option>
            @endforeach
        </select>
    </td>

    {{-- Debit --}}
    <td style="vertical-align:middle;width:130px">
        <input type="number"
               name="lines[{{ $i }}][debit]"
               class="form-control form-control-sm text-end debit-input"
               value="{{ $drAmt }}"
               step="0.01" min="0" placeholder="0.00">
    </td>

    {{-- Credit --}}
    <td style="vertical-align:middle;width:130px">
        <input type="number"
               name="lines[{{ $i }}][credit]"
               class="form-control form-control-sm text-end credit-input"
               value="{{ $crAmt }}"
               step="0.01" min="0" placeholder="0.00">
    </td>

    {{-- Description --}}
    <td class="d-none d-md-table-cell" style="vertical-align:middle">
        <input type="text"
               name="lines[{{ $i }}][description]"
               class="form-control form-control-sm"
               value="{{ $line->description ?? '' }}"
               placeholder="Optional narration">
    </td>

    {{-- Tax Code --}}
    @if(count($taxCodes) > 0)
    <td class="d-none d-xl-table-cell" style="vertical-align:middle;width:130px">
        <select name="lines[{{ $i }}][tax_code_id]" class="form-select form-select-sm">
            <option value="">No Tax</option>
            @foreach($taxCodes as $tax)
                <option value="{{ $tax->id }}"
                    {{ isset($line) && $line->tax_code_id == $tax->id ? 'selected' : '' }}>
                    {{ $tax->code }} ({{ $tax->rate }}%)
                </option>
            @endforeach
        </select>
    </td>
    @endif

    {{-- Remove --}}
    <td style="vertical-align:middle;width:36px">
        <button type="button" class="btn btn-link text-danger p-1 remove-line" title="Remove line">
            <i class="bi bi-x-circle-fill" style="font-size:16px"></i>
        </button>
    </td>
</tr>
BLADEEOF
echo "  Done."

# ── 4. Rewrite create.blade.php ──────────────────────────────────────────────
echo "Step 4: Rewriting voucher create/edit view..."
cat > resources/views/accounting/vouchers/create.blade.php << 'BLADEEOF'
@extends('layouts.app')
@section('title', isset($voucher) ? 'Edit '.$label : 'New '.$label)

@section('breadcrumb')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
    <li class="breadcrumb-item"><a href="{{ route('vouchers.index', $voucherType) }}">{{ $label }}</a></li>
    <li class="breadcrumb-item active">{{ isset($voucher) ? 'Edit' : 'New' }}</li>
@endsection

@push('styles')
<style>
.debit-input  { border-left:3px solid #198754 !important; }
.credit-input { border-left:3px solid #dc3545 !important; }
.debit-input:focus  { box-shadow:0 0 0 .2rem rgba(25,135,84,.15) !important; }
.credit-input:focus { box-shadow:0 0 0 .2rem rgba(220,53,69,.15) !important; }
</style>
@endpush

@section('content')
<div class="page-header">
    <div>
        <h1 class="page-title">{{ isset($voucher) ? 'Edit '.$label : 'New '.$label }}</h1>
        @if(isset($voucher))
            <p class="page-subtitle text-muted"><code>{{ $voucher->voucher_number }}</code></p>
        @endif
    </div>
    <a href="{{ route('vouchers.index', $voucherType) }}" class="btn btn-outline-secondary">
        <i class="bi bi-arrow-left me-1"></i>Back
    </a>
</div>

@if($errors->any())
<div class="alert alert-danger d-flex gap-2 align-items-start mb-3">
    <i class="bi bi-exclamation-triangle fs-5 flex-shrink-0 mt-1"></i>
    <div>
        <strong>Please fix the errors below:</strong>
        @foreach($errors->all() as $err)<div style="font-size:13.5px">{{ $err }}</div>@endforeach
    </div>
</div>
@endif

<form method="POST"
      action="{{ isset($voucher) ? route('vouchers.update',[$voucherType,$voucher]) : route('vouchers.store',$voucherType) }}"
      id="voucherForm">
@csrf
@if(isset($voucher)) @method('PUT') @endif

{{-- ── Voucher Header ────────────────────────────────────────────────────────── --}}
<div class="card mb-4">
    <div class="card-header fw-semibold d-flex align-items-center justify-content-between">
        <span><i class="bi bi-receipt me-2 text-primary"></i>Voucher Header</span>
        @if(!isset($voucher))
        <span class="text-muted" style="font-size:12px">
            Auto No: <code class="text-primary fw-semibold">{{ $preview }}</code>
        </span>
        @endif
    </div>
    <div class="card-body">
        <div class="row g-3">

            {{-- Voucher Date --}}
            <div class="col-12 col-sm-6 col-md-2">
                <label class="form-label fw-semibold">Voucher Date <span class="text-danger">*</span></label>
                <input type="date" name="voucher_date" required
                       class="form-control @error('voucher_date') is-invalid @enderror"
                       value="{{ old('voucher_date', isset($voucher) ? $voucher->voucher_date->format('Y-m-d') : date('Y-m-d')) }}">
                @error('voucher_date')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>

            {{-- Voucher No (manual override) --}}
            <div class="col-12 col-sm-6 col-md-2">
                <label class="form-label fw-semibold">Voucher No</label>
                <input type="text" name="manual_number"
                       class="form-control"
                       value="{{ old('manual_number', $voucher->voucher_number ?? '') }}"
                       placeholder="{{ $preview ?? 'Auto-generated' }}"
                       style="font-family:monospace">
                <div class="form-text" style="font-size:11px">Leave blank for auto number</div>
            </div>

            {{-- Reference --}}
            <div class="col-12 col-sm-6 col-md-2">
                <label class="form-label fw-semibold">Reference</label>
                <input type="text" name="reference"
                       class="form-control"
                       value="{{ old('reference', $voucher->reference ?? '') }}"
                       placeholder="Invoice no, PO no…">
            </div>

            {{-- Cheque No (Bank Payment / Bank Receipt only) --}}
            @if(in_array($voucherType, ['bank_payment','bank_receipt']))
            <div class="col-12 col-sm-6 col-md-2">
                <label class="form-label fw-semibold">Cheque No</label>
                <input type="text" name="cheque_no"
                       class="form-control"
                       value="{{ old('cheque_no', $voucher->extra_data['cheque_no'] ?? '') }}"
                       placeholder="Cheque number">
            </div>
            <div class="col-12 col-sm-6 col-md-2">
                <label class="form-label fw-semibold">Cheque Date</label>
                <input type="date" name="cheque_date"
                       class="form-control"
                       value="{{ old('cheque_date', $voucher->extra_data['cheque_date'] ?? '') }}">
            </div>
            @endif

            {{-- Currency --}}
            @if(count($currencies) > 1)
            <div class="col-12 col-sm-6 col-md-2">
                <label class="form-label fw-semibold">Currency</label>
                <select name="currency_id" id="currencyId" class="form-select">
                    <option value="">Base Currency</option>
                    @foreach($currencies as $cur)
                        <option value="{{ $cur->id }}"
                            {{ old('currency_id', $voucher->currency_id ?? '') == $cur->id ? 'selected':'' }}>
                            {{ $cur->code }}
                        </option>
                    @endforeach
                </select>
            </div>
            <div class="col-12 col-sm-6 col-md-2" id="exchangeRateRow" style="display:none">
                <label class="form-label fw-semibold">Exchange Rate</label>
                <input type="number" name="exchange_rate" id="exchangeRate"
                       class="form-control"
                       value="{{ old('exchange_rate', $voucher->exchange_rate ?? 1) }}"
                       step="0.000001" min="0.000001">
            </div>
            @endif

            {{-- Narration --}}
            <div class="col-12 col-md-4">
                <label class="form-label fw-semibold">Narration</label>
                <input type="text" name="narration"
                       class="form-control"
                       value="{{ old('narration', $voucher->narration ?? '') }}"
                       placeholder="Brief description of this voucher">
            </div>
        </div>
    </div>
</div>

{{-- ── Journal Lines ─────────────────────────────────────────────────────────── --}}
<div class="card mb-4">
    <div class="card-header fw-semibold">
        <i class="bi bi-table me-2 text-primary"></i>Journal Lines
        <span class="text-muted fw-normal ms-2" style="font-size:12px">— Debit and Credit must balance</span>
    </div>

    {{-- Balance bar --}}
    <div class="p-3 border-bottom" style="background:#f8f9fa">
        <div class="row g-2 align-items-center">
            <div class="col-4">
                <div style="font-size:11px;color:#6c757d;font-weight:700;text-transform:uppercase;letter-spacing:.4px">Total Debit</div>
                <div id="totalDebitDisplay" class="fw-bold" style="font-size:18px;color:#0a3622;line-height:1.2">0.00</div>
            </div>
            <div class="col-4">
                <div style="font-size:11px;color:#6c757d;font-weight:700;text-transform:uppercase;letter-spacing:.4px">Total Credit</div>
                <div id="totalCreditDisplay" class="fw-bold" style="font-size:18px;color:#842029;line-height:1.2">0.00</div>
            </div>
            <div class="col-4 text-end">
                <span id="balanceBadge" class="badge px-3 py-2" style="font-size:12px;background:#e9ecef;color:#495057">
                    <i class="bi bi-dash-circle me-1"></i>Not Balanced
                </span>
            </div>
        </div>
    </div>

    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table mb-0" id="linesTable" style="min-width:580px">
                <thead class="table-light">
                    <tr>
                        <th class="ps-3" style="width:32px">#</th>
                        <th style="min-width:200px">Account <span class="text-danger">*</span></th>
                        <th class="text-end" style="width:130px">
                            <span style="color:#198754">Debit</span>
                        </th>
                        <th class="text-end" style="width:130px">
                            <span style="color:#dc3545">Credit</span>
                        </th>
                        <th class="d-none d-md-table-cell">Description</th>
                        @if(count($taxCodes) > 0)
                        <th class="d-none d-xl-table-cell" style="width:130px">Tax Code</th>
                        @endif
                        <th style="width:36px"></th>
                    </tr>
                </thead>
                <tbody id="linesBody">
                    @php $existingLines = isset($voucher) ? $voucher->lines : collect(); @endphp
                    @if($existingLines->count() > 0)
                        @foreach($existingLines as $i => $line)
                        @include('accounting.vouchers._line_row', [
                            'i'        => $i,
                            'line'     => $line,
                            'accounts' => $accounts,
                            'taxCodes' => $taxCodes,
                            'isNew'    => false,
                        ])
                        @endforeach
                    @else
                        @include('accounting.vouchers._line_row', ['i'=>0,'line'=>null,'accounts'=>$accounts,'taxCodes'=>$taxCodes,'isNew'=>true])
                        @include('accounting.vouchers._line_row', ['i'=>1,'line'=>null,'accounts'=>$accounts,'taxCodes'=>$taxCodes,'isNew'=>true])
                    @endif
                </tbody>
            </table>
        </div>
    </div>

    <div class="card-footer bg-white d-flex justify-content-between align-items-center flex-wrap gap-2">
        <div class="d-flex align-items-center gap-3">
            <button type="button" class="btn btn-outline-primary btn-sm" id="addLine">
                <i class="bi bi-plus-circle me-1"></i>Add Line
            </button>
            <span id="minLinesMsg" class="text-danger" style="display:none;font-size:12.5px">
                <i class="bi bi-exclamation-triangle me-1"></i>At least one line is required.
            </span>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ route('vouchers.index', $voucherType) }}" class="btn btn-outline-secondary">Cancel</a>
            <button type="submit" class="btn btn-primary px-4" id="saveBtn">
                <i class="bi bi-floppy me-1"></i>
                {{ isset($voucher) ? 'Save Changes' : 'Save as Draft' }}
            </button>
        </div>
    </div>
</div>

</form>

{{-- JS line template --}}
<script type="text/template" id="lineTemplate">
    @include('accounting.vouchers._line_row', ['i'=>'__IDX__','line'=>null,'accounts'=>$accounts,'taxCodes'=>$taxCodes,'isNew'=>true])
</script>
@endsection

@push('scripts')
<script>
let lineIndex = document.querySelectorAll('.voucher-line').length;

// ── Balance recalc ────────────────────────────────────────────────────────────
function recalcBalance() {
    let totalDr = 0, totalCr = 0;
    document.querySelectorAll('.voucher-line').forEach(row => {
        const dr = parseFloat(row.querySelector('.debit-input')?.value  || 0) || 0;
        const cr = parseFloat(row.querySelector('.credit-input')?.value || 0) || 0;
        totalDr += dr;
        totalCr += cr;
    });

    document.getElementById('totalDebitDisplay').textContent  = totalDr.toFixed(2);
    document.getElementById('totalCreditDisplay').textContent = totalCr.toFixed(2);

    const diff    = Math.abs(totalDr - totalCr);
    const badge   = document.getElementById('balanceBadge');
    const balanced = diff < 0.01 && totalDr > 0;

    if (balanced) {
        badge.style.cssText = 'background:#d1e7dd;color:#0a3622;font-size:12px';
        badge.innerHTML     = '<i class="bi bi-check-circle me-1"></i>Balanced';
    } else if (totalDr === 0 && totalCr === 0) {
        badge.style.cssText = 'background:#e9ecef;color:#495057;font-size:12px';
        badge.innerHTML     = '<i class="bi bi-dash-circle me-1"></i>Not Balanced';
    } else {
        badge.style.cssText = 'background:#f8d7da;color:#842029;font-size:12px';
        badge.innerHTML     = '<i class="bi bi-exclamation-triangle me-1"></i>Diff: ' + diff.toFixed(2);
    }
}

// ── Mutual exclusion: entering debit clears credit and vice versa ─────────────
document.addEventListener('input', e => {
    if (e.target.classList.contains('debit-input')) {
        if (parseFloat(e.target.value) > 0) {
            const row = e.target.closest('tr');
            if (row) { const cr = row.querySelector('.credit-input'); if (cr) cr.value = ''; }
        }
        recalcBalance();
    }
    if (e.target.classList.contains('credit-input')) {
        if (parseFloat(e.target.value) > 0) {
            const row = e.target.closest('tr');
            if (row) { const dr = row.querySelector('.debit-input'); if (dr) dr.value = ''; }
        }
        recalcBalance();
    }
});

// ── Renumber ──────────────────────────────────────────────────────────────────
function renumberRows() {
    document.querySelectorAll('.voucher-line').forEach((row, i) => {
        const c = row.querySelector('.line-num');
        if (c) c.textContent = i + 1;
    });
}

// ── Select2 init ──────────────────────────────────────────────────────────────
function initSelect2OnRow(row) {
    if (typeof $ === 'undefined' || !$.fn || !$.fn.select2) return;
    $(row).find('.account-select').each(function() {
        if ($(this).hasClass('select2-hidden-accessible')) $(this).select2('destroy');
        $(this).select2({
            placeholder: '— Select Account —',
            allowClear: true,
            width: '100%',
            dropdownParent: $('body'),
        });
    });
}

// ── Add Line ──────────────────────────────────────────────────────────────────
document.getElementById('addLine').addEventListener('click', () => {
    const tmpl = document.getElementById('lineTemplate').textContent || document.getElementById('lineTemplate').innerHTML;
    const html  = tmpl.replaceAll('__IDX__', lineIndex);
    document.getElementById('linesBody').insertAdjacentHTML('beforeend', html);
    const newRow = document.querySelector(`.voucher-line[data-index="${lineIndex}"]`);
    if (newRow) initSelect2OnRow(newRow);
    lineIndex++;
    renumberRows();
    recalcBalance();
});

// ── Remove Line ───────────────────────────────────────────────────────────────
document.addEventListener('click', e => {
    const btn = e.target.closest('.remove-line');
    if (!btn) return;
    const rows = document.querySelectorAll('.voucher-line');
    if (rows.length <= 1) {
        const msg = document.getElementById('minLinesMsg');
        if (msg) { msg.style.display = ''; setTimeout(() => msg.style.display = 'none', 3000); }
        return;
    }
    btn.closest('tr').remove();
    renumberRows();
    recalcBalance();
});

// ── Currency toggle ───────────────────────────────────────────────────────────
const currEl = document.getElementById('currencyId');
if (currEl) {
    function toggleExchangeRow() {
        const row = document.getElementById('exchangeRateRow');
        if (row) row.style.display = currEl.value ? '' : 'none';
    }
    currEl.addEventListener('change', toggleExchangeRow);
    toggleExchangeRow();
}

// ── Submit spinner ────────────────────────────────────────────────────────────
document.getElementById('voucherForm').addEventListener('submit', function() {
    const b = document.getElementById('saveBtn');
    b.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Saving…';
    b.disabled  = true;
});

// ── Init Select2 on load ──────────────────────────────────────────────────────
$(document).ready(function() {
    document.querySelectorAll('.voucher-line').forEach(row => initSelect2OnRow(row));
    recalcBalance();
});
</script>
@endpush
BLADEEOF
echo "  Done."

# ── 5. Copy create to edit ────────────────────────────────────────────────────
echo "Step 5: Copying create view to edit view..."
cp resources/views/accounting/vouchers/create.blade.php \
   resources/views/accounting/vouchers/edit.blade.php
echo "  Done."

# ── 6. Clear cache ────────────────────────────────────────────────────────────
echo "Step 6: Clearing cache..."
php artisan view:clear
php artisan optimize

echo ""
echo "=============================================="
echo "  DEPLOY COMPLETE!"
echo "=============================================="
echo ""
echo "  Changes applied to all vouchers:"
echo "  ✅ DR/CR column removed"
echo "  ✅ Separate Debit (green) and Credit (red) columns"
echo "     - Entering Debit auto-clears Credit"
echo "     - Entering Credit auto-clears Debit"
echo "  ✅ Voucher No field (leave blank = auto)"
echo ""
echo "  Bank Payment & Bank Receipt only:"
echo "  ✅ Cheque No field"
echo "  ✅ Cheque Date field"
echo ""
echo "  Account dropdown Select2 fixed"
echo "=============================================="
