@extends('template.app')

@section('title', 'Cash Receipt')

@php
    use Carbon\Carbon;
    $date = Carbon::now()->format('d/m/Y');
@endphp

@section('content')
    <style>
        @media screen {
            #print-area {
                color: white !important;
                border-color: white !important;
            }
    
            #print-area * {
                color: white !important;
                border-color: white !important;
            }
        }
    
        @media print {
            #print-button {
                display: none;
            }
    
            #print-area {
                color: black !important;
                border: 1px solid black !important;
            }
    
            #print-area * {
                color: black !important;
                border-color: black !important;
            }
        }
    </style>

    <div class="container-fluid" id="content-to-print">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body" style="padding: 40px;">
                        <div id="print-area" style="font-family: DejaVu Sans, sans-serif; font-size: 12px; width: 210mm; margin: auto; border: 1px solid; padding: 10px;">
                            <table style="width: 100%; border-collapse: collapse;">
                                <tr>
                                    <td style="width: 60%; text-align: center; font-size: 42px; font-weight: bold;">
                                        SHIVAM KIA
                                    </td>
                                </tr>
                            </table>
                        
                            <h2 style="text-align:center; font-weight: bold; margin-top: 10px;">NEW CAR SALES PAYMENT RECEIPT</h2>
                        
                            <table style="width: 100%; margin-top: 10px; border-collapse: collapse;">
                                <tr>
                                    <td style="width: 70%; border-right: 1px solid; padding: 5px;">
                                        <b>Received With Thanks From:</b> {{ $data->customer_name }}<br>
                                        <b>Mobile No.:</b> {{ $data->contact_number ?? 'N/A' }}<br>
                                        {{ $data->address ?? '' }}
                                    </td>
                                    <td style="width: 30%; padding: 5px;">
                                        <b>Branch:</b> {{ strtoupper($data->branch_name) }}<br>
                                        <b>Receipt No.:</b> {{ $receipt_no }}<br>
                                        <b>Receipt Type:</b> {{ $receipt_type }}<br>
                                        <b>Receipt Date:</b> {{ optional($cashReceipt->created_at)->format('d/m/Y') ?? $date }}
                                    </td>
                                </tr>
                            </table>
                        
                            <table style="width: 100%; margin-top: 10px; border-collapse: collapse; border: 1px solid;">
                                <tr>
                                    <td style="width: 70%; border-right: 1px solid; padding: 5px;">
                                        <b>Model:</b> {{ $data->car_model_name ?? $data->product }} | {{ $data->car_varient_name }}<br>
                                        <b>Color:</b> {{ $data->exteriorcolor_name ?? 'N/A' }} | {{ $data->interiorcolor_name ?? 'N/A' }}<br>
                                        <b>KEC / Executive:</b> {{ $data->sales_person_name }}<br>
                                        <b>Receipt Remark:</b> {{ $cashReceipt->cash_remark ?? 'N/A' }}
                                    </td>
                                    <td style="width: 30%; padding: 5px;">
                                        <b>Payment Detail</b><br>
                                        Payment Type: {{ $payment_method }}<br>
                                        <b>Hyp/H:</b> {{ $data->finance_name ?? 'N/A' }}<br>
                                        Transaction No: {{ $cashReceipt->transaction_no ?? 'N/A' }}
                                    </td>
                                </tr>
                                <tr>
                                    <td style="border-top: 1px solid; border-right: 1px solid; padding: 5px;">
                                        <b>Rupees in words:</b> {{ $amount_word }} ONLY
                                    </td>
                                    <td style="border-top: 1px solid; text-align: right; padding: 5px;">
                                        <b>Rs.</b> {{ number_format($cashReceipt->cash_receipt_amount, 2) }}/-
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding: 5px;">
                                        <b>GST No.:</b> 24ABACS4515J1ZH
                                    </td>
                                    <td style="text-align: right; padding: 5px;">
                                        <b>{{ $data->branch_name }}</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding: 5px;">
                                        Price prevailing at the time of delivery will be applicable.<br>
                                        Rs. 500/- will be charged from customer as Cheque return charges.<br>
                                        Rs. 500/- will be charged from the customer against booking cancellation.<br>
                                        Consumer/Corporate offers are subject to change without prior notice.<br>
                                        If payment by cheque, then payment is subject to realization.
                                    </td>
                                    <td style="text-align: right; font-size: 10px; padding: 5px;">
                                        <br><br><br><br><br><br>Authorized Signatory
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding: 5px;">
                                        <br><br><b>Customer Signature</b>
                                    </td>
                                    <td></td>
                                </tr>
                            </table>
                            
                            <div style="text-align: center; margin-top: 20px;">
                                <button id="print-button" class="btn btn-primary" onclick="printReceipt()">Print Receipt</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function printReceipt() {
            window.print();
        }
    </script>
@endsection
