#!/bin/bash
# ============================================================
# SaaS Accounting — Voucher Print Template (QBO style)
# Features:
#   - Professional print layout matching provided template
#   - Company logo + name + address in header
#   - Cheque No, Cheque Date, Voucher No, Voucher Date
#   - Account Name & Code | Memo | Debit | Credit table
#   - Total row
#   - Amount in Words
#   - Dynamic signatory from Company Settings
#   - Print button triggers print-only view
#
# Run: bash deploy_voucher_print.sh
# From: ~/public_html/saas-accounting/
# ============================================================
set -e
cd ~/public_html/saas-accounting

echo ""
echo "=============================================="
echo "  Voucher Print Template Deploy"
echo "=============================================="
echo ""

# ── 1. Update show() to pass settings + company ──────────────────────────────
echo "Step 1: Updating show() method to pass settings..."
python3 << 'PYEOF'
content = open('app/Http/Controllers/Company/Accounting/AccountingVouchersController.php').read()

old = """    // ── Show ──────────────────────────────────────────────────────────────────
    public function show(string $voucherType, Voucher $voucher)
    {
        $this->validateType($voucherType);
        $this->gate('vouchers', 'view');
        $this->sameCompany($voucher);

        $voucher->load(['lines.account','lines.taxCode','approvals.user',
                        'currency','fiscalYear','createdBy','approvedBy','postedBy']);

        $companyId   = auth()->user()->company_id;
        $approvalReq = Setting::get($companyId, 'voucher_approval_required', '1');
        $label       = VoucherNumberService::voucherTypes()[$voucherType];

        // FIX: Safe access to extra_data
        $extraData    = $voucher->extra_data ?? [];
        $isReversed   = !empty($extraData['reversed_by']);
        $reversedById = $extraData['reversed_by'] ?? null;

        return view('accounting.vouchers.show', compact(
            'voucher','voucherType','label','approvalReq','isReversed','reversedById'
        ));
    }"""

new = """    // ── Show ──────────────────────────────────────────────────────────────────
    public function show(string $voucherType, Voucher $voucher)
    {
        $this->validateType($voucherType);
        $this->gate('vouchers', 'view');
        $this->sameCompany($voucher);

        $voucher->load(['lines.account','lines.taxCode','approvals.user',
                        'currency','fiscalYear','createdBy','approvedBy','postedBy']);

        $companyId   = auth()->user()->company_id;
        $approvalReq = Setting::get($companyId, 'voucher_approval_required', '1');
        $label       = VoucherNumberService::voucherTypes()[$voucherType];

        // Safe access to extra_data
        $extraData    = $voucher->extra_data ?? [];
        $isReversed   = !empty($extraData['reversed_by']);
        $reversedById = $extraData['reversed_by'] ?? null;

        // Settings for print template
        $company  = auth()->user()->company;
        $settings = array_merge(\\App\\Models\\Setting::defaults(),
            \\App\\Models\\Setting::where('company_id', $companyId)
                ->get()->pluck('value','key')->toArray()
        );

        return view('accounting.vouchers.show', compact(
            'voucher','voucherType','label','approvalReq',
            'isReversed','reversedById','company','settings'
        ));
    }"""

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

# ── 2. Write the new show.blade.php ──────────────────────────────────────────
echo "Step 2: Writing new voucher show view with print template..."
cat > resources/views/accounting/vouchers/show.blade.php << 'BLADEEOF'
@extends('layouts.app')
@section('title', $voucher->voucher_number ?? 'Voucher')

@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">{{ $voucher->voucher_number }}</li>
@endsection

@push('styles')
<style>
/* ── Screen styles ─────────────────────────────────────────── */
.voucher-print-area { display:none; }

/* ── Print styles ──────────────────────────────────────────── */
@media print {
    #sidebar, #topbar, .page-header,
    .screen-only, .modal { display:none !important; }
    #main { margin-left:0 !important; padding-top:0 !important; }
    body  { background:#fff !important; font-size:12px; }
    .voucher-print-area { display:block !important; }
    .page-content { padding:0 !important; }

    /* Print area styling */
    .vp-wrap {
        width:100%; max-width:800px; margin:0 auto;
        font-family:'Segoe UI',Arial,sans-serif; font-size:12px; color:#000;
    }
    .vp-header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:12px; }
    .vp-company-name { font-size:16px; font-weight:700; margin:0 0 2px; }
    .vp-company-addr { font-size:11px; color:#333; margin:0; line-height:1.5; }
    .vp-voucher-title { font-size:14px; font-weight:700; text-align:center; margin:8px 0 14px; border-bottom:2px solid #000; padding-bottom:4px; }
    .vp-meta { display:grid; grid-template-columns:1fr 1fr; gap:4px 20px; margin-bottom:12px; font-size:12px; }
    .vp-meta-row { display:flex; gap:6px; }
    .vp-meta-label { font-weight:600; white-space:nowrap; min-width:90px; }
    .vp-meta-value { border-bottom:1px dotted #999; flex:1; }
    .vp-table { width:100%; border-collapse:collapse; margin-bottom:10px; font-size:12px; }
    .vp-table th { background:#000; color:#fff; padding:5px 8px; text-align:left; font-weight:600; border:1px solid #000; }
    .vp-table th.text-right { text-align:right; }
    .vp-table td { padding:4px 8px; border:1px solid #999; vertical-align:top; }
    .vp-table td.text-right { text-align:right; }
    .vp-table tr:nth-child(even) td { background:#f9f9f9; }
    .vp-table tfoot td { font-weight:700; border-top:2px solid #000; border:1px solid #999; padding:5px 8px; }
    .vp-table tfoot td.text-right { text-align:right; }
    .vp-words { font-size:11.5px; margin:6px 0 16px; }
    .vp-words strong { font-weight:600; }
    .vp-sig { display:flex; gap:30px; margin-top:40px; }
    .vp-sig-block { flex:1; text-align:center; }
    .vp-sig-line { border-top:1px solid #000; padding-top:4px; font-size:11.5px; font-weight:600; margin-top:30px; }
    .vp-logo { max-height:55px; max-width:160px; object-fit:contain; }
    .vp-status-stamp { position:absolute; top:80px; right:40px; border:3px solid; border-radius:6px; padding:4px 14px; font-size:22px; font-weight:900; transform:rotate(-15deg); opacity:.35; text-transform:uppercase; }
}
</style>
@endpush

@section('content')
@php
    [$sbg,$sfg] = $voucher->getStatusColor();
    $user        = auth()->user();
    $totalDebit  = $voucher->lines->where('dr_cr','dr')->sum('line_total');
    $totalCredit = $voucher->lines->where('dr_cr','cr')->sum('line_total');
    $isBalanced  = abs($totalDebit - $totalCredit) < 0.01;
    $extraData   = $voucher->extra_data ?? [];
    $chequeNo    = $extraData['cheque_no']   ?? '';
    $chequeDate  = $extraData['cheque_date'] ?? '';

    // Signatory labels from settings
    $sig1 = $settings['signatory_prepared_by'] ?? 'Prepared By';
    $sig2 = $settings['signatory_checked_by']  ?? 'Checked By';
    $sig3 = $settings['signatory_custom1']     ?? '';
    $sig4 = $settings['signatory_custom2']     ?? '';
    $sig5 = $settings['signatory_approved_by'] ?? 'Approved By';

    // Amount in words helper
    function numberToWords(float $num, string $lang = 'en'): string {
        $ones = ['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine',
                 'Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen',
                 'Seventeen','Eighteen','Nineteen'];
        $tens = ['','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'];
        $intPart  = (int) $num;
        $decPart  = (int) round(($num - $intPart) * 100);
        function convert(int $n, array $ones, array $tens): string {
            if ($n === 0) return '';
            if ($n < 20)  return $ones[$n];
            if ($n < 100) return $tens[(int)($n/10)] . ($n%10 ? ' '.$ones[$n%10] : '');
            return $ones[(int)($n/100)] . ' Hundred' . ($n%100 ? ' '.convert($n%100,$ones,$tens) : '');
        }
        function convertLarge(int $n, array $ones, array $tens): string {
            $result = '';
            if ($n >= 10000000) { $result .= convert((int)($n/10000000),$ones,$tens).' Crore '; $n %= 10000000; }
            if ($n >= 100000)   { $result .= convert((int)($n/100000),  $ones,$tens).' Lakh ';  $n %= 100000;   }
            if ($n >= 1000)     { $result .= convert((int)($n/1000),    $ones,$tens).' Thousand '; $n %= 1000;  }
            if ($n > 0)         { $result .= convert($n,$ones,$tens).' '; }
            return trim($result);
        }
        $words = convertLarge($intPart, $ones, $tens);
        $currency = $settings['currency_code'] ?? 'USD';
        if ($currency === 'BDT') { $main='Taka'; $cent='Paisa'; }
        elseif ($currency === 'GBP') { $main='Pound'; $cent='Pence'; }
        elseif ($currency === 'EUR') { $main='Euro'; $cent='Cent'; }
        else { $main='Dollar'; $cent='Cent'; }
        $result = ($words ?: 'Zero') . ' ' . $main;
        $result .= ' and ' . ($decPart ? convertLarge($decPart,$ones,$tens) . ' ' . $cent : $cent . ' Zero');
        return $result . ' only';
    }

    $amountInWords = numberToWords((float)$voucher->grand_total);
@endphp

{{-- ═══════════════════════════════════════════════════════════════════════════ --}}
{{-- SCREEN VIEW                                                                  --}}
{{-- ═══════════════════════════════════════════════════════════════════════════ --}}
<div class="screen-only">

{{-- Page Header --}}
<div class="page-header flex-wrap gap-3">
    <div class="d-flex align-items-center gap-2 flex-wrap">
        <div>
            <h1 class="page-title mb-0">{{ $voucher->voucher_number }}</h1>
            <p class="page-subtitle mb-0">{{ $label }} — {{ $voucher->voucher_date->format('d M Y') }}</p>
        </div>
        <span class="badge px-3 py-2" style="background:{{ $sbg }};color:{{ $sfg }};font-size:13px">
            {{ ucfirst($voucher->status) }}
        </span>
        @if($isReversed)
        <span class="badge px-3 py-2" style="background:#f8d7da;color:#842029;font-size:12px">
            <i class="bi bi-arrow-repeat me-1"></i>Reversed
        </span>
        @endif
    </div>

    <div class="d-flex gap-2 align-items-center flex-wrap">
        <button type="button" class="btn btn-primary btn-sm" onclick="window.print()">
            <i class="bi bi-printer me-1"></i>Print Voucher
        </button>
        @if($voucher->isEditable() && $user->hasPermission('vouchers','edit'))
        <a href="{{ route('vouchers.edit',[$voucherType,$voucher]) }}" class="btn btn-outline-secondary btn-sm">
            <i class="bi bi-pencil me-1"></i>Edit
        </a>
        @endif
        @if($voucher->isDraft() && $user->hasPermission('vouchers','submit'))
        <form method="POST" action="{{ route('vouchers.submit',[$voucherType,$voucher]) }}">
            @csrf<button type="submit" class="btn btn-outline-primary btn-sm"><i class="bi bi-send me-1"></i>Submit</button>
        </form>
        @endif
        @if($voucher->isSubmitted() && $user->hasPermission('vouchers','approve'))
        <button class="btn btn-outline-success btn-sm" data-bs-toggle="modal" data-bs-target="#approveModal">
            <i class="bi bi-check-circle me-1"></i>Approve
        </button>
        <button class="btn btn-outline-warning btn-sm" data-bs-toggle="modal" data-bs-target="#rejectModal">
            <i class="bi bi-x-circle me-1"></i>Reject
        </button>
        @endif
        @if(($voucher->isApproved() || ($voucher->isDraft() && !$approvalReq)) && $user->hasPermission('vouchers','post'))
        <form method="POST" action="{{ route('vouchers.post',[$voucherType,$voucher]) }}">
            @csrf<button type="submit" class="btn btn-primary btn-sm" @if(!$isBalanced) disabled @endif>
                <i class="bi bi-journal-check me-1"></i>Post to Ledger
            </button>
        </form>
        @endif
        @if($voucher->isPosted() && !$isReversed && $user->hasPermission('vouchers','post'))
        <button class="btn btn-outline-warning btn-sm" data-bs-toggle="modal" data-bs-target="#reverseModal">
            <i class="bi bi-arrow-repeat me-1"></i>Reverse
        </button>
        @endif
        @if(!$voucher->isPosted() && !$voucher->isCancelled() && $user->hasPermission('vouchers','cancel'))
        <button class="btn btn-outline-danger btn-sm" data-bs-toggle="modal" data-bs-target="#cancelModal">
            <i class="bi bi-ban me-1"></i>Cancel
        </button>
        @endif
    </div>
</div>

{{-- Screen summary card --}}
<div class="row g-4">
    <div class="col-12 col-xl-8">
        <div class="card mb-4">
            <div class="card-header fw-semibold"><i class="bi bi-info-circle me-2 text-primary"></i>Voucher Details</div>
            <div class="card-body">
                <div class="row g-3" style="font-size:13.5px">
                    <div class="col-6 col-md-3"><div class="text-muted mb-1" style="font-size:12px">Voucher No</div><div class="fw-semibold">{{ $voucher->voucher_number }}</div></div>
                    <div class="col-6 col-md-3"><div class="text-muted mb-1" style="font-size:12px">Date</div><div class="fw-semibold">{{ $voucher->voucher_date->format('d M Y') }}</div></div>
                    @if($chequeNo)
                    <div class="col-6 col-md-3"><div class="text-muted mb-1" style="font-size:12px">Cheque No</div><div class="fw-semibold">{{ $chequeNo }}</div></div>
                    @endif
                    @if($chequeDate)
                    <div class="col-6 col-md-3"><div class="text-muted mb-1" style="font-size:12px">Cheque Date</div><div class="fw-semibold">{{ \Carbon\Carbon::parse($chequeDate)->format('d M Y') }}</div></div>
                    @endif
                    @if($voucher->reference)
                    <div class="col-6 col-md-3"><div class="text-muted mb-1" style="font-size:12px">Reference</div><div>{{ $voucher->reference }}</div></div>
                    @endif
                    @if($voucher->narration)
                    <div class="col-12"><div class="text-muted mb-1" style="font-size:12px">Narration</div><div>{{ $voucher->narration }}</div></div>
                    @endif
                </div>
            </div>
        </div>

        {{-- Lines table --}}
        <div class="card">
            <div class="card-header fw-semibold"><i class="bi bi-table me-2 text-primary"></i>Journal Lines</div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table mb-0" style="font-size:13.5px">
                        <thead class="table-light">
                            <tr>
                                <th class="ps-3">#</th>
                                <th>Account</th>
                                <th class="d-none d-md-table-cell">Description</th>
                                <th class="text-end" style="color:#198754">Debit</th>
                                <th class="text-end" style="color:#dc3545">Credit</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($voucher->lines as $i => $line)
                            <tr>
                                <td class="ps-3 text-muted">{{ $i+1 }}</td>
                                <td>
                                    <div class="fw-semibold">{{ $line->account->name ?? '—' }}</div>
                                    @if($line->account->code ?? false)
                                    <div class="text-muted" style="font-size:12px">{{ $line->account->code }}</div>
                                    @endif
                                </td>
                                <td class="d-none d-md-table-cell text-muted">{{ $line->description ?? '' }}</td>
                                <td class="text-end fw-semibold" style="color:#198754">
                                    {{ $line->dr_cr === 'dr' ? number_format($line->line_total,2) : '' }}
                                </td>
                                <td class="text-end fw-semibold" style="color:#dc3545">
                                    {{ $line->dr_cr === 'cr' ? number_format($line->line_total,2) : '' }}
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                        <tfoot class="table-light">
                            <tr>
                                <td colspan="3" class="ps-3 fw-bold">Total</td>
                                <td class="text-end fw-bold" style="color:#198754">{{ number_format($totalDebit,2) }}</td>
                                <td class="text-end fw-bold" style="color:#dc3545">{{ number_format($totalCredit,2) }}</td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
            <div class="card-footer bg-white d-flex justify-content-between align-items-center flex-wrap gap-2">
                <div style="font-size:13px">
                    <span class="text-muted me-2">Amount in Words:</span>
                    <span class="fw-semibold text-primary">{{ $amountInWords }}</span>
                </div>
                <span class="badge px-3 py-2" style="font-size:12px;background:{{ $isBalanced ? '#d1e7dd':'#f8d7da' }};color:{{ $isBalanced ? '#0a3622':'#842029' }}">
                    {{ $isBalanced ? 'Balanced' : 'Not Balanced' }}
                </span>
            </div>
        </div>
    </div>

    {{-- Side info --}}
    <div class="col-12 col-xl-4">
        <div class="card mb-4">
            <div class="card-header fw-semibold"><i class="bi bi-clock-history me-2 text-primary"></i>Workflow</div>
            <div class="card-body p-0">
                <table class="table table-sm mb-0" style="font-size:13px">
                    <tr><td class="text-muted ps-3 py-2">Status</td>
                        <td class="py-2"><span class="badge" style="background:{{ $sbg }};color:{{ $sfg }}">{{ ucfirst($voucher->status) }}</span></td></tr>
                    @if($voucher->createdBy)
                    <tr><td class="text-muted ps-3 py-2">Created By</td><td class="py-2">{{ $voucher->createdBy->name }}</td></tr>
                    @endif
                    @if($voucher->approvedBy)
                    <tr><td class="text-muted ps-3 py-2">Approved By</td><td class="py-2">{{ $voucher->approvedBy->name }}</td></tr>
                    @endif
                    @if($voucher->posted_at)
                    <tr><td class="text-muted ps-3 py-2">Posted At</td><td class="py-2">{{ $voucher->posted_at->format('d M Y H:i') }}</td></tr>
                    @endif
                </table>
            </div>
        </div>
    </div>
</div>
</div>{{-- end screen-only --}}

{{-- ═══════════════════════════════════════════════════════════════════════════ --}}
{{-- PRINT AREA — only visible when printing                                      --}}
{{-- ═══════════════════════════════════════════════════════════════════════════ --}}
<div class="voucher-print-area">
<div class="vp-wrap" style="position:relative">

    {{-- Status stamp (cancelled/reversed) --}}
    @if($voucher->isCancelled())
    <div class="vp-status-stamp" style="color:#dc3545;border-color:#dc3545">CANCELLED</div>
    @elseif($isReversed)
    <div class="vp-status-stamp" style="color:#f57c00;border-color:#f57c00">REVERSED</div>
    @endif

    {{-- Company Header --}}
    <div class="vp-header">
        <div>
            @if($company->logo)
            <img src="{{ public_path('storage/'.$company->logo) }}" class="vp-logo" alt="Logo"
                 onerror="this.style.display='none'">
            @endif
            <p class="vp-company-name" style="{{ $company->logo ? 'margin-top:4px' : '' }}">
                {{ $company->name }}
            </p>
            @if($company->address)
            <p class="vp-company-addr">{{ nl2br(e($company->address)) }}</p>
            @endif
        </div>
        <div style="text-align:right;font-size:11px;color:#333">
            @if($company->phone)<div>Tel: {{ $company->phone }}</div>@endif
            @if($company->email)<div>{{ $company->email }}</div>@endif
            @if($company->website)<div>{{ $company->website }}</div>@endif
        </div>
    </div>

    {{-- Voucher Title --}}
    <div class="vp-voucher-title">{{ $label }}</div>

    {{-- Meta info grid --}}
    <div class="vp-meta">
        @if($chequeNo)
        <div class="vp-meta-row">
            <span class="vp-meta-label">Check No</span>
            <span class="vp-meta-value">: {{ $chequeNo }}</span>
        </div>
        @endif
        <div class="vp-meta-row">
            <span class="vp-meta-label">Voucher No</span>
            <span class="vp-meta-value">: {{ $voucher->voucher_number }}</span>
        </div>
        @if($chequeDate)
        <div class="vp-meta-row">
            <span class="vp-meta-label">Check Date</span>
            <span class="vp-meta-value">: {{ \Carbon\Carbon::parse($chequeDate)->format('d-M-y') }}</span>
        </div>
        @endif
        <div class="vp-meta-row">
            <span class="vp-meta-label">Voucher Date</span>
            <span class="vp-meta-value">: {{ $voucher->voucher_date->format('d-M-y') }}</span>
        </div>
        @if($voucher->reference)
        <div class="vp-meta-row">
            <span class="vp-meta-label">Reference</span>
            <span class="vp-meta-value">: {{ $voucher->reference }}</span>
        </div>
        @endif
        @if($voucher->narration)
        <div class="vp-meta-row" style="grid-column:1/-1">
            <span class="vp-meta-label">Narration</span>
            <span class="vp-meta-value">: {{ $voucher->narration }}</span>
        </div>
        @endif
    </div>

    {{-- Lines Table --}}
    <table class="vp-table">
        <thead>
            <tr>
                <th style="width:28%">Account Name &amp; Code</th>
                <th>Memo</th>
                <th class="text-right" style="width:12%">Debit</th>
                <th class="text-right" style="width:12%">Credit</th>
            </tr>
        </thead>
        <tbody>
            @foreach($voucher->lines as $line)
            <tr>
                <td>
                    {{ $line->account->name ?? '—' }}
                    @if($line->account->code ?? false)
                    {{ $line->account->code }}
                    @endif
                </td>
                <td>{{ $line->description ?? '' }}</td>
                <td class="text-right">
                    @if($line->dr_cr === 'dr')
                        {{ number_format($line->line_total, 2) }}
                    @endif
                </td>
                <td class="text-right">
                    @if($line->dr_cr === 'cr')
                        {{ number_format($line->line_total, 2) }}
                    @endif
                </td>
            </tr>
            @endforeach
        </tbody>
        <tfoot>
            <tr>
                <td colspan="2" class="text-right">Total</td>
                <td class="text-right">{{ number_format($totalDebit, 2) }}</td>
                <td class="text-right">{{ number_format($totalCredit, 2) }}</td>
            </tr>
        </tfoot>
    </table>

    {{-- Amount in Words --}}
    <div class="vp-words">
        <strong>Amount in word :</strong>
        <span style="border-bottom:1px solid #999;padding-bottom:1px">
            {{ $amountInWords }}
        </span>
    </div>

    {{-- Signatories --}}
    <div class="vp-sig">
        <div class="vp-sig-block">
            <div class="vp-sig-line">{{ $sig1 ?: 'Prepared By' }}</div>
        </div>
        <div class="vp-sig-block">
            <div class="vp-sig-line">{{ $sig2 ?: 'Checked By' }}</div>
        </div>
        @if($sig3)
        <div class="vp-sig-block">
            <div class="vp-sig-line">{{ $sig3 }}</div>
        </div>
        @endif
        @if($sig4)
        <div class="vp-sig-block">
            <div class="vp-sig-line">{{ $sig4 }}</div>
        </div>
        @endif
        <div class="vp-sig-block">
            <div class="vp-sig-line">{{ $sig5 ?: 'Approved By' }}</div>
        </div>
    </div>

</div>
</div>{{-- end print area --}}

{{-- ── Modals ────────────────────────────────────────────────────────────────── --}}

{{-- Approve --}}
<div class="modal fade screen-only" id="approveModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered"><div class="modal-content">
        <div class="modal-header border-0 pb-0"><h5 class="modal-title fw-semibold"><i class="bi bi-check-circle me-2 text-success"></i>Approve Voucher</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
        <form method="POST" action="{{ route('vouchers.approve',[$voucherType,$voucher]) }}">@csrf
        <div class="modal-body">
            <div class="rounded-2 p-3 mb-3" style="background:#f8f9fa;font-size:13.5px"><div><strong>{{ $voucher->voucher_number }}</strong></div><div class="text-muted">{{ $voucher->voucher_date->format('d M Y') }}</div></div>
            <label class="form-label fw-semibold">Comments <span class="text-muted fw-normal">(optional)</span></label>
            <textarea name="comments" class="form-control" rows="2" placeholder="Any notes for this approval…"></textarea>
        </div>
        <div class="modal-footer border-0 pt-0"><button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button><button type="submit" class="btn btn-success px-4"><i class="bi bi-check-circle me-1"></i>Approve</button></div>
        </form>
    </div></div>
</div>

{{-- Reject --}}
<div class="modal fade screen-only" id="rejectModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered"><div class="modal-content">
        <div class="modal-header border-0 pb-0"><h5 class="modal-title fw-semibold"><i class="bi bi-x-circle me-2 text-warning"></i>Reject Voucher</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
        <form method="POST" action="{{ route('vouchers.reject',[$voucherType,$voucher]) }}">@csrf
        <div class="modal-body"><label class="form-label fw-semibold">Reason for Rejection <span class="text-danger">*</span></label><textarea name="reason" class="form-control" rows="3" required placeholder="Explain the issue…"></textarea></div>
        <div class="modal-footer border-0 pt-0"><button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button><button type="submit" class="btn btn-warning px-4"><i class="bi bi-x-circle me-1"></i>Reject</button></div>
        </form>
    </div></div>
</div>

{{-- Reverse --}}
<div class="modal fade screen-only" id="reverseModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered"><div class="modal-content">
        <div class="modal-header border-0 pb-0"><h5 class="modal-title fw-semibold"><i class="bi bi-arrow-repeat me-2 text-warning"></i>Reverse Voucher</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
        <form method="POST" action="{{ route('vouchers.reverse',[$voucherType,$voucher]) }}">@csrf
        <div class="modal-body">
            <div class="alert alert-warning py-2 mb-3 d-flex gap-2" style="font-size:13px"><i class="bi bi-info-circle flex-shrink-0 mt-1"></i><div>A reversal voucher will be created with swapped Dr/Cr. Original will be marked Reversed.</div></div>
            <div class="mb-3"><label class="form-label fw-semibold">Reversal Date <span class="text-danger">*</span></label><input type="date" name="reversal_date" class="form-control" value="{{ date('Y-m-d') }}" required></div>
            <div><label class="form-label fw-semibold">Reason <span class="text-danger">*</span></label><textarea name="reason" class="form-control" rows="2" required placeholder="Reason for reversal…"></textarea></div>
        </div>
        <div class="modal-footer border-0 pt-0"><button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button><button type="submit" class="btn btn-warning px-4"><i class="bi bi-arrow-repeat me-1"></i>Create Reversal</button></div>
        </form>
    </div></div>
</div>

{{-- Cancel --}}
<div class="modal fade screen-only" id="cancelModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered"><div class="modal-content">
        <div class="modal-header border-0 pb-0"><h5 class="modal-title fw-semibold"><i class="bi bi-ban me-2 text-danger"></i>Cancel Voucher</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
        <form method="POST" action="{{ route('vouchers.cancel',[$voucherType,$voucher]) }}">@csrf
        <div class="modal-body"><label class="form-label fw-semibold">Reason <span class="text-danger">*</span></label><textarea name="reason" class="form-control" rows="2" required placeholder="Reason for cancellation…"></textarea></div>
        <div class="modal-footer border-0 pt-0"><button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button><button type="submit" class="btn btn-danger px-4"><i class="bi bi-ban me-1"></i>Cancel Voucher</button></div>
        </form>
    </div></div>
</div>

@endsection
BLADEEOF
echo "  Done."

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

echo ""
echo "=============================================="
echo "  DEPLOY COMPLETE!"
echo "=============================================="
echo ""
echo "  Print template features:"
echo "  ✅ Company logo + name + address + contact"
echo "  ✅ Voucher title (e.g. Bank Payment Voucher)"
echo "  ✅ Check No / Check Date (bank vouchers)"
echo "  ✅ Voucher No / Voucher Date"
echo "  ✅ Reference / Narration"
echo "  ✅ Account Name & Code | Memo | Debit | Credit"
echo "  ✅ Total row"
echo "  ✅ Amount in Words (BDT/USD/GBP/EUR)"
echo "  ✅ Dynamic signatories from Settings"
echo "     (Prepared By / Checked By / Custom 1 /"
echo "      Custom 2 / Approved By)"
echo "  ✅ CANCELLED / REVERSED stamp on print"
echo "  ✅ Print button on show page"
echo "=============================================="
