<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Retail Order & Booking Form</title>
        <style>
            body {
              font-family: Arial, sans-serif;
              margin: 0;
              padding: 20px;
              background: #fff;
            }
            .container {
              width: 850px;
              margin: auto;
              border: 2px solid #000;
              padding: 20px;
            }
            .container_two {
                width: 850px;
                margin: auto;
                padding: 20px;
            }
            .header {
              text-align: center;
              background-color: #0d2c54;
              color: white;
              padding: 5px 0;
              font-weight: bold;
            }
            .section {
              border: 1px solid #000;
              margin: 10px 0;
            }
            .row {
              display: flex;
              flex-wrap: wrap;
              border-top: 1px solid #000;
            }
            .row div {
              flex: 1;
              padding: 4px 8px;
              /*border-right: 1px solid #000;*/
              font-size: 13px;
            }
            .row div:last-child {
              border-right: none;
            }
            .row:first-child {
              border-top: none;
            }
            .sub-header {
              background: #0d2c54;
              color: white;
              text-align: center;
              padding: 4px 8px;
              font-size: 14px;
              font-weight: bold;
            }
            .table-container {
              display: flex;
              justify-content: space-between;
              gap: 20px; 
            }
        
            table {
              width: 100%; 
              border-collapse: collapse;
              font-size: 13px;
            }
            
            th, td {
              padding: 6px;
              text-align: left;
            }
            
            th {
              background: #0d2c54;
              color: #fff;
            }
            
            .totals td {
              font-weight: bold;
              background: #0d2c54;
              color: #fff;
            }
            
            .table-1 .totals td {
              font-weight: bold;
              background: #0d2c54;
              color: #fff;
            }
            
            .table-1 {
              background-color: #fff; 
              font-size: 12px;
            }
            .table-2 {
              background-color: #fff; 
              font-size: 12px;
            }
            
            .table-2 th {
              display: inline-block;
              background-color: #000;
              color: #fff;
              padding: 14px 10px;
              font-weight: bold;
              border-radius: 0px;
            }
        
        
            .signature-section {
              display: flex;
              justify-content: space-between;
              gap: 20px;
              margin-top: 30px;
            }
            
            .signature-wrapper {
              display: flex;
              flex-direction: column;
              align-items: center;
            }
            
            .signature-label {
              font-weight: bold;
              margin-bottom: 4px;
              font-size: 10px;
              text-align: center;
            }
            
            .signature-box {
              width: 270px;
              height: 60px;
              border: 1px solid #000;
            }
        
        
            .disclaimer {
              font-size: 11px;
              margin-top: 20px;
            }
            .kia-header-bar {
                display: flex;
                align-items: center;
                padding: 10px 20px;
            }
            
            .gp_logo {
                height: 20px;
                margin-right: 20px;
                vertical-align: middle;
            }
            
            .shivam-kia-heading {
              font-family: 'Arial Black', sans-serif;
              font-size: 14px;
              font-weight: 600;
              color: white;
              text-transform: uppercase;
              margin: 0;
              line-height: 1.5;
              padding: 10px 0;
              background: linear-gradient(to right, black, #444, #777, #bbb, white);
              width: 100%;
              text-align: left;
            }
            .header-row {
                display: flex;
                align-items: right;
                font-size: 14px;
                gap: 225px;
                margin-bottom: -8px;
            }
            
            .header-1 {
              /*display: inline-block;*/
              background-color: #000;
              color: #fff;
              padding: 4px 68px;
              font-weight: bold;
              border-radius: 0px;
            }
            .header-2 {
                display: inline-block;
                background-color: #000;
                color: #fff;
                padding: 4px 1px;
                font-weight: bold;
                border-radius: 0px;
            }
            .t1{
                background-color: #fff;
                color: #000;
            }
            .payment-header {
              text-align: center;
              font-weight: bold;
              font-size: 16px;
              margin-bottom: 10px;
            }
            
            .payment-tables {
              display: flex;
              gap: 20px;
              justify-content: center;
              flex-wrap: wrap;
            }
            
            .payment-table {
              width: 100%;
              max-width: 400px;
              border-collapse: collapse;
              font-size: 13px;
            }
            
            .payment-table td {
              border: 1px solid #000;
              padding: 6px;
            }
            
            .payment-table .totals td {
              font-weight: bold;
              background: #0d2c54;
            }
        
            .table-1 td {
                text-align: center;
            }
            
            .table-2 td {
                text-align: center;
            }
            
            .car-on-road-table {
                width: 100%;
                border-collapse: collapse;
                font-size: 14px;
            }
        
            .car-on-road-table th, .car-on-road-table td {
                padding: 8px;
                vertical-align: top;
            }
        
            .car-on-road-table .spacer {
                border: none !important;
                background-color: #fff;
                width: 30px;
            }
        
            .car-on-road-table thead th {
                background-color: #0d3e5f;
                color: #fff;
                text-align: center;
            }
        
            .car-on-road-table .label {
                font-weight: bold;
                background-color: #f2f2f2;
            }
        
            .car-on-road-table .highlight-row {
                background-color: #0d3e5f;
                color: #fff;
                font-weight: bold;
            }
            
            .right_border {
                width: 200px;
                border-right: 1px solid #000000;
                text-align: right;
            }
            
            .left_border {
                width: 100px;
                border-left: 1px solid #000000;
                text-align: right;
            }
            
            .padding_words{
                padding: 7px;
                letter-spacing: 1px;
            }
            
            .custom_section{
                margin-top: 2px;
                border-bottom: 1px solid #000;
            }
            
            .text-center {
                text-align: center;   
            }
            
            @media print {
                body {
                    -webkit-print-color-adjust: exact;
                    print-color-adjust: exact;
                }
                
                body {
                  font-family: Arial, sans-serif;
                  margin: 0;
                  padding: 20px;
                  background: #fff;
                }
                .container {
                  width: 850px;
                  margin: auto;
                  border: 2px solid #000;
                }
                .container_two {
                    width: 850px;
                    margin: auto;
                    padding: 20px;
                }
                .header {
                  text-align: center;
                  background-color: #0d2c54;
                  color: white;
                  padding: 5px 0;
                  font-weight: bold;
                }
                .section {
                  border: 1px solid #000;
                  margin: 10px 0;
                }
                .row {
                  display: flex;
                  flex-wrap: wrap;
                  border-top: 1px solid #000;
                }
                .row div {
                  flex: 1;
                  padding: 4px 8px;
                  /*border-right: 1px solid #000;*/
                  font-size: 10px;
                }
                .row div:last-child {
                  border-right: none;
                }
                .row:first-child {
                  border-top: none;
                }
                .sub-header {
                  background: #0d2c54;
                  color: white;
                  text-align: center;
                  padding: 4px 8px;
                  font-size: 14px;
                  font-weight: bold;
                }
                .table-container {
                  display: flex;
                  justify-content: space-between;
                  gap: 20px; 
                }
            
                table {
                  width: 100%; 
                  border-collapse: collapse;
                  font-size: 13px;
                }
                
                th, td {
                  padding: 6px;
                  text-align: left;
                }
                
                th {
                  background: #0d2c54;
                  color: #fff;
                }
                
                .totals td {
                  font-weight: bold;
                  background: #0d2c54;
                  color: #fff;
                }
                
                .table-1 .totals td {
                  font-weight: bold;
                  background: #0d2c54;
                  color: #fff;
                }
                
                .table-1 {
                  background-color: #fff; 
                  font-size: 12px;
                }
                .table-2 {
                  background-color: #fff; 
                  font-size: 12px;
                }
                
                .table-2 th {
                  display: inline-block;
                  background-color: #000;
                  color: #fff;
                  padding: 14px 10px;
                  font-weight: bold;
                  border-radius: 0px;
                }
            
            
                .signature-section {
                  display: flex;
                  justify-content: space-between;
                  gap: 20px;
                  margin-top: 30px;
                }
                
                .signature-wrapper {
                  display: flex;
                  flex-direction: column;
                  align-items: center;
                }
                
                .signature-label {
                  font-weight: bold;
                  margin-bottom: 4px;
                  font-size: 13px;
                  text-align: center;
                }
                
                .signature-box {
                  width: 270px;
                  height: 60px;
                  border: 1px solid #000;
                }
            
            
                .disclaimer {
                  font-size: 11px;
                  margin-top: 20px;
                }
                .kia-header-bar {
                    display: flex;
                    align-items: center;
                    padding: 10px 20px;
                }
                
                .gp_logo {
                    height: 20px;
                    margin-right: 20px;
                    vertical-align: middle;
                }
                
                .shivam-kia-heading {
                  font-family: 'Arial Black', sans-serif;
                  font-size: 14px;
                  font-weight: 600;
                  color: white;
                  text-transform: uppercase;
                  margin: 0;
                  line-height: 1.5;
                  padding: 10px 0;
                  background: linear-gradient(to right, black, #444, #777, #bbb, white);
                  width: 100%;
                  text-align: left;
                }
                .header-row {
                    display: flex;
                    align-items: right;
                    font-size: 14px;
                    gap: 225px;
                    margin-bottom: -8px;
                }
                
                .header-1 {
                  /*display: inline-block;*/
                  background-color: #000;
                  color: #fff;
                  padding: 4px 68px;
                  font-weight: bold;
                  border-radius: 0px;
                }
                .header-2 {
                    display: inline-block;
                    background-color: #000;
                    color: #fff;
                    padding: 4px 1px;
                    font-weight: bold;
                    border-radius: 0px;
                }
                .t1{
                    background-color: #fff;
                    color: #000;
                }
                .payment-header {
                  text-align: center;
                  font-weight: bold;
                  font-size: 16px;
                  margin-bottom: 10px;
                }
                
                .payment-tables {
                  display: flex;
                  gap: 20px;
                  justify-content: center;
                  flex-wrap: wrap;
                }
                
                .payment-table {
                  width: 100%;
                  max-width: 400px;
                  border-collapse: collapse;
                  font-size: 13px;
                }
                
                .payment-table td {
                  border: 1px solid #000;
                  padding: 6px;
                }
                
                .payment-table .totals td {
                  font-weight: bold;
                  background: #0d2c54;
                }
            
                .table-1 td {
                    text-align: center;
                }
                
                .table-2 td {
                    text-align: center;
                }
                
                .car-on-road-table {
                    width: 100%;
                    border-collapse: collapse;
                    font-size: 7px;
                }
            
                .car-on-road-table th, .car-on-road-table td {
                    padding: 8px;
                    vertical-align: top;
                }
            
                .car-on-road-table .spacer {
                    border: none !important;
                    background-color: #fff;
                    width: 30px;
                }
            
                .car-on-road-table thead th {
                    background-color: #0d3e5f;
                    color: #fff;
                    text-align: center;
                }
            
                .car-on-road-table .label {
                    font-weight: bold;
                    background-color: #f2f2f2;
                }
            
                .car-on-road-table .highlight-row {
                    background-color: #0d3e5f;
                    color: #fff;
                    font-weight: bold;
                }
                
                .right_border {
                    width: 200px;
                    border-right: 1px solid #000000;
                    text-align: right;
                }
                
                .left_border {
                    width: 100px;
                    border-left: 1px solid #000000;
                    text-align: right;
                }
                
                .padding_words{
                    padding: 7px;
                    letter-spacing: 1px;
                }
                
                .custom_section{
                    margin-top: 2px;
                    border-bottom: 1px solid #000;
                }
                
                .text-center {
                    text-align: center;   
                }
                
                .column-left {
                    line-height: 4px;
                }
                
                .column-right{
                    line-height: 4px;
                }
            }
            h3 {
              margin-top: 1em;
              margin-bottom: 0.5em;
              background-color: #000;
              color: #fff;
              padding: 4px 8px;
              -webkit-print-color-adjust: exact;
              print-color-adjust: exact;
            }
            h2{
                margin-top: 1em;
                margin-bottom: 0.5em;
                background-color: red;
                color: white;
                text-align: center;
                padding: 6px 10px;
                -webkit-print-color-adjust: exact;
                print-color-adjust: exact;
            }
        </style>
    </head>
    <body>
        <div class="container" id="content-to-print">
          
            <div class="kia-header-bar">
                @php $logo_1 = $images->gatepass_logo1 ?? ''; @endphp
                <img class="gp_logo" src="{{ asset('uploads/global_configuration/gatepass_logo_one/' . $logo_1) }}" alt="Kia Logo">
                <div class="shivam-kia-heading"><span style="margin-left:20px;">Shivam Kia ( IB Group)</span></div>
            </div>
            
            <div class="header">RETAIL ORDER & BOOKING FORM</div>
    
            <div class="section">
                <div class="row">
                    <div><b>Booking Dt.:</b> {{ \Carbon\Carbon::parse($data->booking_date)->format('d-m-Y') }}</div>
                    <div><b>Branch:</b> {{ $data->branch_name }}</div>
                    <div><b>Tentative Delivery Date:</b> {{ \Carbon\Carbon::parse($data->tentetive_delivery_date)->format('d-m-Y') }}</div>
                </div>
            </div>
            
            <div class="header-row">
                <div class="header-2">Bill To:</div>
                <div>PAN No.: {{ $data->pan_number }}</div>
                <div>PAN Aadhar Link Status.: {{ ucwords($data->aadhar_pan_link) }}</div>
            </div>
            
            <div class="section">
                <div class="row">
                    <div><b>Customer Name:</b> {{ $data->customer_name }}</div>
                    <div><b>GST Required.:</b> {{ $data->gst_required }}</div>
                    <div><b>Mobile No.:</b> {{ $data->contact_number }}</div>
                </div>
            
                <div class="row">
                    <div><b>Company Name:</b> {{ $data->company_name }}</div>
                    <div><b>GST No.:</b> {{ $data->gst }}</div>
                    <div><b>PAN No.:</b> {{ $data->pan_number }}</div>
                </div>
                
                <div class="row">
                    <div><b>Registration Correspondence:</b><br> {{ $data->address }}</div>
                    <div>
                        <b>e-Invoice Applicable:</b> {{ ucwords($data->einvoicing_applicable) }}
                        <br>
                            <b>Occupation:-</b> {{ $data->occupation }}
                        <br>
                            <b>Date of Birth :-</b> {{ \Carbon\Carbon::parse($data->dob)->format('d-m-Y') }}
                    </div>
                </div>
                
                <div class="row">
                    <div><b>City:</b> {{ $data->city_name }}</div>
                    <div><b>District:</b> {{ $data->district_name }}</div>
                    <div><b>State:</b> {{ $data->state_name }}</div>
                </div>
            </div>
        
            <div class="header-2">Ship To:</div>
            
            <div class="section" style="margin-top:-2px;">
                <div class="row">
                    <div><b>Customer/Company Name:</b> {{ $data->ship_to_customer_name }}</div>
                    <!--<div><b>PAN No.:</b> {{ $data->pan_number }}</div>-->
                </div>
                <div class="row">
                    <div><b>Registration Correspondence:</b><br> {{ $data->ship_to_address }}</div>
                    <div><b>GST No.:</b> {{ $data->gst }}</div>
                </div>
            </div>
            
            <div class="section">
                <div class="row">
                    <div><b>City:</b> {{ $data->ship_to_city_name }}</div>
                    <div><b>District:</b> {{ $data->ship_to_district_name }}</div>
                    <div><b>State:</b> {{ $data->ship_to_state_name }}</div>
                </div>
            </div>
            
            <div class="header-2">Nominee Details:</div>
            <div class="section" style="margin-top:-2px;">
                <div class="row">
                    <div><b>Name:</b> {{ $data->nominee_name }}</div>
                    <div><b>Date of Birth:</b> {{ $data->nominee_dob ? \Carbon\Carbon::parse($data->nominee_dob)->format('d-m-Y') : '' }}</div>
                    <div><b>Relation:</b> {{ $data->nominee_reletion }}</div>
                    <div><b>Nominee Age:</b> {{ $data->nominee_age }}</div>
                </div>
            </div>
    
            <div class="section">
                <div class="sub-header">Car Details</div>
                    <div class="row">
                        <div class="column-left">
                          <div><b>Car Model:</b> {{ $data->car_model_name }}</div>
                          <div><b>Car Variant:</b> {{ $data->car_varient_name }}</div>
                          <div><b>Exterior Color:</b> {{ $data->exteriorcolor_name }}</div>
                          <div><b>Interior Color:</b> {{ $data->interiorcolor_name }}</div>
                          <div><b>Fuel Type:</b> {{ $data->fule_type }}</div>
                        </div>
                        <div class="column-right">
                          <div><b>VIN Number:</b> {{ $data->vin_number }}</div>
                          <div><b>Engine Number:</b> {{ $data->engine_number }}</div>
                          <div><b>Key Number:</b> {{ $data->key_number }}</div>
                          <div><b>MFG Year:</b> {{ $data->manufacturing_year }}</div>
                        </div>
                    </div>
                    <div class="sub-header">Sales Person Name :-{{ $data->sales_person_name }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Team Leader Name :-{{ $data->team_name }}</div>
                </div>
        
            <div class="sub-header">Car On Road Price</div>
            
            <div class="table-container">
                <table class="car-on-road-table">
                    <tbody>
                        @php
                            $rto = (float) ($data->registration_tax_id ?? 0) + (float) ($data->rto_custom_handling_charges ?? 0);
                            $on_road_price = (float) ($data->ex_showroom_price ?? 0) + (float) ($data->tcs_tax_id ?? 0) + $rto
                                            + (float) ($data->municipal_tax_id ?? 0) + (float) ($data->municipal_custom_handling_charges ?? 0) 
                                            +(float) ($data->insurance_id ?? 0) + $data->rsa_amount 
                                            + $data->ccs_amount + (float) ($data->extand_warranties_amount ?? 0)
                                            + (float) ($data->mcp_amount ?? 0) + (float) ($data->fasttag_amount ?? 0)
                                            + (float) ($accessory_sum ?? 0) + (float) ($data->other_accesssories_prise ?? 0);
                        
                            $total_discount = (float) ($data->offer_ib_amount ?? 0) + (float) ($data->offer_kin_amount ?? 0)
                                            + (float) ($data->exchange_bonus ?? 0) + (float) ($data->finance_discount ?? 0)
                                            + (float) ($data->way_off ?? 0) + (float) ($data->tl_discount ?? 0) 
                                            + (float) ($data->sm_discount ?? 0) + (float) ($data->gm_discount ?? 0)
                                            + (float) ($data->bh_discount ?? 0) + (float) ($data->ceo_discount ?? 0)
                                            + (float) ($data->md_discount ?? 0)+ (float) ($data->foc_accessories ?? 0);
                        
                            // Calculate final deal on-road price
                            $final_deal_on_road = $on_road_price - $total_discount;
                        @endphp

                        <tr>
                            <th class="black-header right_border">Particular</th>
                            <td></td>
                            <th class="black-header left_border">Amount</th>
                            <td rowspan="18" style="width:60px;"></td>
                            <th class="black-header" colspan="3" rowspan="2">Price List Wef. :- {{ $data->price_list_name }}</th>
                        </tr>
                        <tr>
                            <td class="right_border">Standard Ex-Showroom Price</td>
                            <td></td>
                            <td class="left_border">{{ $data->ex_showroom_price ?? 0 }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">TCS</td><td>1%</td><td class="left_border">{{ $data->tcs_tax_id ?? 0 }}</td>
                            <td>Pan Aadhar Link</td><td>{{ ucwords($data->aadhar_pan_link) }}</td>
                            <!---->
                        </tr>
                        <tr>
                            <td class="right_border">Registration Tax</td><td></td><td class="left_border">{{ $rto }}</td>
                            <td>RTO Type</td><td>{{ ucwords(str_replace('_', ' ', $data->customer_type)) }}</td>
                        </tr>
                        <tr>
                            <td class="right_border"></td><td></td><td class="left_border"></td>
                            <td>Customer Type</td><td>{{ $data->customer_type_name }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Municiple Tax</td><td></td><td class="left_border">{{ $data->municipal_tax_id ?? 0 }}</td>
                            <td>RMC Status</td><td>{{ ucwords(str_replace('_', '-', $data->municipal_tax_type)) }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Municipal Custom Handling Charges</td><td></td><td class="left_border">{{ $data->municipal_custom_handling_charges ?? 0 }}</td>
                            <td></td><td></td><td></td>
                        </tr>
                        <tr>
                            <td class="right_border">Insurance</td><td></td><td class="left_border">{{ $data->insurance_id ?? 0 }}</td>
                            <td>Insurance Company</td><td>{{ $data->insurance_company_name }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Road Side Assistance (RSA)</td><td></td><td class="left_border">{{ $data->rsa_amount ?? 0 }}</td>
                            <td>Package (RSA)</td><td>{{ $data->rsa_name ?? 'N/A' }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">CCS</td><td></td><td class="left_border">{{ $data->ccs_amount ?? 0 }}</td>
                            <td>Package (CCS)</td><td>{{ $data->ccs_name ?? 'N/A' }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Extended Warranty</td><td></td><td class="left_border">{{ $data->extand_warranties_amount ?? 0 }}</td>
                            <td>Package (EW)</td><td>{{ $data->extand_warranties_years }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">MCP / MCP+</td><td></td><td class="left_border">{{ $data->mcp_amount ?? 0 }}</td>
                            <td>Package (MCP/MCP+)</td><td>{{ $data->mcp_name }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Fastag</td><td></td><td class="left_border">{{ $data->fasttag_amount ?? 0 }}</td>
                            <td>Package (Fastag)</td><td>{{ $data->fasttage_name }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Accessories</td><td></td><td class="left_border">{{ $accessory_sum ?? 0 }}</td>
                            <td>Package (Accessories)</td><td>{{ $accessory_names }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Other Accessories</td><td></td><td class="left_border">{{ $data->other_accesssories_prise ?? 0 }}</td>
                            <td>Package (Other Accessories)</td><td>{{ $data->other_accesssories_detail }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Other Value Add Service_01</td><td></td><td class="left_border">{{ $data->other_one_name ?? 0 }}</td>
                            <td>Insurance Remark</td><td>{{ $data->step3_remarks ?? '-' }}</td>
                        </tr>
                        <tr>
                            <td class="right_border">Other Value Add Service_02</td><td></td><td class="left_border">{{ $data->other_two_name ?? 0 }}</td>
                            <td class="text-center" colspan="2"><b>KEC Remarks</b></td><td></td>
                        </tr>
                        <tr>
                            <td class="sub-header">On Road Price (A)</td><td class="sub-header"></td><td class="sub-header">{{ $on_road_price }}</td>
                            <td colspan="2" rowspan="3" style="border:3px solid black;">{{ $data->step1_remarks }}</td>
                        </tr>
                        <tr>
                            <td class="sub-header">Less: Total Discount (B)</td><td class="sub-header"></td><td class="sub-header">{{ $total_discount }}</td>
                        </tr>
                        <tr>
                            <td class="sub-header">Final Deal On Road (A - B = C)</td><td class="sub-header"></td><td class="sub-header">{{ $final_deal_on_road }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <div class="custom_section">
                @php
                    function convertNumberToWords($number) {
                        $words = array(
                            '0'=> '', '1'=> 'One', '2'=> 'Two', '3'=> 'Three', '4'=> 'Four', '5'=> 'Five',
                            '6'=> 'Six', '7'=> 'Seven', '8'=> 'Eight', '9'=> 'Nine', '10'=> 'Ten',
                            '11'=> 'Eleven', '12'=> 'Twelve', '13'=> 'Thirteen', '14'=> 'Fourteen',
                            '15'=> 'Fifteen', '16'=> 'Sixteen', '17'=> 'Seventeen', '18'=> 'Eighteen',
                            '19'=> 'Nineteen', '20'=> 'Twenty', '30'=> 'Thirty', '40'=> 'Forty',
                            '50'=> 'Fifty', '60'=> 'Sixty', '70'=> 'Seventy', '80'=> 'Eighty', '90'=> 'Ninety'
                        );
                    
                        $digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
                        $number = round($number);
                        if ($number == 0) {
                            return 'Zero Rupees Only';
                        }
                    
                        $str = [];
                        $i = 0;
                        while ($number > 0) {
                            $divider = ($i == 1) ? 10 : 100;
                            $numberPart = $number % $divider;
                            $number = (int)($number / $divider);
                    
                            if ($numberPart) {
                                $prefix = '';
                                if ($numberPart < 21) {
                                    $prefix = $words[$numberPart];
                                } else {
                                    $tens = (int)($numberPart / 10) * 10;
                                    $units = $numberPart % 10;
                                    $prefix = $words[$tens] . ($units ? ' ' . $words[$units] : '');
                                }
                                $str[] = $prefix . ' ' . $digits[$i];
                            }
                            $i++;
                        }
                    
                        return implode(' ', array_reverse($str)) . ' Rupees Only';
                    }
        
                @endphp
                <div class="padding_words"><b>On Road Price (In Words) :</b> {{ convertNumberToWords($final_deal_on_road) }}</div>
            </div>
            
            <div class="section payment-section">
                <div class="payment-header">Customer Payment Status</div>
                <div class="payment-tables">
              
                    <!-- First Table -->
                    <table class="payment-table">
                        <tbody>
                            @php
                                $total_payment_received = ($data->booking_amount ?? 0) + ($data->dp_amount ?? 0) + ($data->net_disbusment ?? 0) + ($data->total_exchange_amount ?? 0);
                                $finance_dis = ($data->offer_ib_amount ?? 0) + ($data->offer_kin_amount ?? 0)  + ($data->finance_discount ?? 0) + ($data->way_off ?? 0) + ($data->tl_discount ?? 0) + ($data->sm_discount ?? 0) + ($data->gm_discount ?? 0) + ($data->bh_discount ?? 0) + ($data->ceo_discount ?? 0) + ($data->md_discount ?? 0)+ ($data->foc_accessories ?? 0);
                                $due_amount = $data->on_road_price - $total_payment_received - $finance_dis;
                            @endphp
                            <tr><td>Booking Amount</td><td>{{ $data->booking_amount ?? 0 }}</td></tr>
                            <tr><td>Down Payment</td><td>{{ $data->dp_amount ?? 0 }}</td></tr>
                            <tr><td>Finance Disbursed</td><td>{{ $data->net_disbusment ?? 0 }}</td></tr>
                            <tr><td>Exchange Amount</td><td>{{ $data->total_exchange_amount ?? 0 }}</td></tr>
                            <tr><td>Other Amount Received</td><td>0</td></tr>
                            <tr class="totals"><td>Total Payment Received (D)</td><td>{{ $total_payment_received }}</td></tr>
                            <tr class="totals"><td>Due Amount (-) / Refund (+) (C - D)</td><td>{{ $due_amount }}</td></tr>
                        </tbody>
                    </table>
                
                    <!-- Second Table -->
                    <table class="payment-table">
                        <tbody>
                            <tr><td>Finance By :- </td><td>{{ $data->finance_name}}</td></tr>
                            <tr><td>Finance Type :-</td><td>{{ ucwords(str_replace('_', ' ', $data->finance_type)) }}</td></tr>
                            <tr><td style="border-left: none;border-right: none;"></td><td style="border-left: none;border-right: none;"></td></tr>
                            <tr><td>Ex. Car Name :- </td><td>{{ $data->exchange_company_name }}<span style="margin-left: 80px;">MFG Year :- {{ $data->manufacturing_year }}</span></td></tr>
                            <tr><td>Ex.Car Variant :-</td><td>{{ $data->exchange_car_name }}</td></tr>
                            <tr><td>Ex. Car Reg. No. :-</td><td> {{ $data->registration_number }}</td></tr>
                        </tbody>
                    </table>
                </div>
            </div>
    
            <div class="disclaimer">
              I/We have read the terms and conditions related to the above contract as attached in annexure and accept the same.<br>
              I/We further understand that this agreement of sale of the above vehicle is between both of us & that KIN is not a party to this booking & is not liable in any manner.
            </div>
            
            <div class="disclaimer"><strong>** Please find the enclosed terms and conditions for order and booking form for Kia India Ltd. in the back page.</strong></div>
    
            <div class="signature-section">
                    <div class="signature-wrapper">
                        <div class="signature-label">Customer Signature</div>
                        <div class="signature-box"></div>
                    </div>
                    <div class="signature-wrapper">
                        <div class="signature-label">KEC / TL Signature</div>
                        <div class="signature-box"></div>
                    </div>
                    <div class="signature-wrapper">
                        <div class="signature-label">SM : GM : BH Signature</div>
                        <div class="signature-box"></div>
                    </div>
                </div> 
            <html lang="en">
            <head>
              <meta charset="UTF-8">
              <title>Retail Order & Booking Form</title>
              <style>
                <!DOCTYPE html>
                <html lang="en">
                <head>
                  <meta charset="UTF-8" />
                  <meta name="viewport" content="width=device-width, initial-scale=1" />
                  <title>Terms and Conditions</title>
                  <style>
                    @page {
                      size: A4;
                      margin: 0.3cm;
                    }
                    
                    html, body {
                      font-family: Arial, sans-serif;
                      font-size: 5pt;              /* Smaller base font */
                      line-height: 1.1;            /* Tighter line height */
                      color: #000;
                      print-color-adjust: exact !important;
                    }
                    
                    body {
                      padding: 0.3cm;              /* Less padding */
                      box-sizing: border-box;
                    }
                    
                    h2 {
                      margin: 0.3em 0;
                      font-size: 6.5pt;            /* Smaller heading */
                      background-color: red;
                      color: white;
                      text-align: center;
                      padding: 2px 4px;            /* Reduced padding */
                    }
                    
                    h3 {
                      margin: 0.3em 0 0.2em 0;
                      font-size: 5.5pt;            /* Smaller subheading */
                      background-color: black;
                      color: white;
                      padding: 1.5px 4px;
                    }
                    
                    ul, ol {
                      margin: 0 0 0.3em 1em;       /* Reduced margin */
                      padding: 0;
                    }
                    
                    li {
                      font-size: 8.7pt;            /* Smaller list items */
                      margin-bottom: 0.1em;        /* Tight spacing */
                    }
                    
                    p {
                      margin: 0.2em 0;
                    }
                    
                    .signature-section {
                      margin-top: 3px;
                      display: flex;
                      justify-content: space-between;
                      gap: 3px;
                      margin-bottom: -3px;
                    }
                    
                    .signature-wrapper {
                      flex: 1;
                    }
                    
                    .signature-label {
                      font-weight: bold;
                      font-size: 5pt;              /* Smaller label */
                      margin-bottom: 1px;
                    }
                    
                    .signature-box {
                      border: 1px solid #000;
                      height: 30px;                /* Much smaller height */
                      width: 100%;
                    }
                    
                    .terms-container {
                      page-break-before: always;
                      page-break-inside: avoid;
                      break-before: page;
                      break-inside: avoid;
                    }
                  </style>
                </head>
                <body>
                <div class="terms-container">
                
                  <h2>Terms and Conditions for RETAIL ORDER & BOOKING FORM</h2>
                
                  <h3>1. Definitions</h3>
                  <ul>
                    <li>Kia Motors India is having its registered office In India.</li>
                    <li>"Shivam Kia", is a legal entity authorized by KMI for undertaking Sale and Service of the KIA Vehicles in the non-exclusive territory of responsibility.</li>
                    <li>“Customer” means buyer who intends to purchase a KIA Vehicle from the Dealer.</li>
                    <li> “Retail & Booking Form” means the date of realization of the initial Demand Draft / Pay Order / Cheque provided by the Customer to Dealer alongwith the Booking Order Form towards the booking of the KIA Vehicle.</li>
                    <li> “(CKD) Vehicles / Cars” means KIA Vehicles that are constructed and configured as per specific customer requirements outlined at the time of booking and / or ordered / imported as fully built units for sale to that specific customer.</li>
                  </ul>
                
                  <h3>2. Conditions for acceptance of Order</h3>
                  <ul>
                    <li>Particulars of Sales Contract form should be filled out by Customer in English language only. The Sales Contract form must be filled in duplicate, one copy thereof duly acknowledged and stamped with the date and time or 
                        receipt shall be given by the Dealer to the Customer.</li>
                    <li> The Customer should obtain his / her copy of the Sales Contract from the Dealer duly stamped after submitting the completed Sales Contract and making payment of prescribed booking amount.</li>
                    <li> A Customer may place an order for only a single KIA Vehicle in a Sales Contract. If a Customer wishes to place an Order for more than one KIA Vehicle, the order for each KIA Vehicle should be made in a separate Sales Contract bearing new order number. The Sales Contract should clearly indicate the specifications of the KIA Vehicle ordered by the Customer.</li>
                    <li> An order shall only be considered binding when accepted in writing by the Dealer and signed by the Customer.</li>
                    <li>Sales Contracts which are incomplete in any respect, or which are not properly signed by the Customer may be rejected by the Dealer. If at any point of time, it is found that any of information / documents given for booking of the vehicle are incorrect, the Dealer shall have the right to cancel the booking and refund the money to the Customer (if applicable) as per the Dealer’s refund policy, without any further claims on the Dealer.</li>
                    <li> The nominee designated by the applicant in the Sales Contract shall not be a minor in the event of the death of the applicant the Order may be transferred to the nominee of the deceased or to the legal representative 
                        upon satisfactory evidence being provided.</li>
                    <li>Orders will be accepted by the Dealer based on the number of KIA Vehicles likely to be received from the Manufacturer.</li>
                  </ul>
                
                  <h3>3. Payment</h3>
                  <ol type="a">
                    <li> The price taxes, duties, etc payable will be applicable on the basis of the prices ruling on the date and city of delivery.</li>
                    <li>  An advance payment of minimum Rs. 25000  shall be made along with the Sales Contract by the way of a DD/ONLINE/Cheque in Favour of the SAVAN IB AUTOMOTIVE PVT. LTD. Advance payment will be adjusted against the price of the KIA Vehicle ruling at the time of the delivery.</li>
                    <li>Based on the communication from the Manufacturer, the Dealer shall intimate the status regarding the vehicle allotment and its readiness to the applicant through a written notice / Whatss App./ electronic mail. The applicant will be required to make the balance payment within 7 working days from the date of this intimation, failing which the Sales Contract shall be cancelled. Upon cancellation of the Sales Contract the advance paid will be forfeited in accordance with the terms contained under clause-4.</li>
                    <li> State Entry Tax, if any leviable, will be charged extra on the customer.</li>
                    <li>Any applicable increase in the price of vehicle, excise Duty, Surcharge, Central and Sales Tax, GST Tax, Ces, transportation charges and or any governmental levies which comes into force and is communicated to the dealer before / by the date of delivery / dispatch of the vehicle(s) to the customer shall be payable by the customer.</li>
                    <li>All deliveries shall only be made against realization of 100% payment.</li>
                    <li>In the event of the cheque for the advance payments submitted by the customer is rejected by the bank for any reason whatsoever, the Sales contract stands cancelled and the customer is liable to pay any charges the Dealer may suffer.</li>
                    <li> In the event of customer’s cheque for the balance payment is rejected by the bank for any reason whatsoever, the customer can make the payment within 3 working days through a DD only. Further, the customer shall also intimate the Dealer for any damages suffered by the Dealer for the rejection of the customers cheque by the Bank should the customer not be able to make the required payments in 3 working days, the Sales contract would be deemed to be cancelled and would lead to forfeiture of the advance paid in accordance with the terms contained under Clause 4.</li>
                  </ol>
                
                  <h3>4. Cancellation</h3>
                  <ol type="a">
                    <li> In the event of cancellation of the Sales Contract in accordance with the terms contained herein, the following cancellation charges apply. Dealer shall be entitled to deduct the same from the advance paid by the applicant 
                        depending upon the model of the vehicle ordered. In case of Model (a) Seltos - 2500, (b) Carnival - 5000, (c) Sonet / Carens / Carens Clavis / Syros /- 2000, (d) EV6 - 25000 Upon forfeiting of such amounts as mentioned 
                        herein above by the Dealer from the advance paid by the customer, the remaining balance amount shall be returned to the customer.
                    </li>
                  </ol>
                  <h3>5. Interest</h3>
                  <ol type="a">
                    <li>The advance payment received towards the vehicle by the Dealer, shall not carry any interest</li>
                  </ol>
                
                  <h3>6. Delivery</h3>
                  <ol type="a">
                    <li>Dealer stock vehicles will be delivered within 4 working days from the date of realization of 100% payment. Vehicle will be not delivered without number plate fitted.</li>
                    <li>The applicant shall not be entitled to claim any damages or losses of any kind for delay in the delivery or non delivery of the KIA Vehicle due to natural causes, war or civil strike, labour strike or unrest, natural calamities,etc.</li>
                    <li> The specification and price of the KIA Vehicle are subject to change without prior notice and the price ruling at the time of delivery will be applicable.</li>
                    <li>The company will not be responsible for any damage or shortage reported after the delivery and after obtaining the signature of the customer or his authorized representative (including transport contractor through whom the vehicle is transported) on the delivery receipt</li>
                  </ol>
                
                  <h3>7. General</h3>
                  <ol type="a">
                    <li>The Dealer will not be responsible for delay, loss or rejection of the Sales Contract, or for safe custody or transmission of any Demand Draft/pay order or any other payment or documents sent to the Dealer by post/courier.</li>
                    <li>Vehicles once sold will not be taken back under any circumstances.</li>
                    <li> The supply against order will be governed by statutory orders, rules and regulations imposed by Central and State Government from time to time.</li>
                    <li> All vehicles carry maker’s standard warranty. No warranty other than that given by the makers shall be stipulated as applicable to this purchase.</li>
                    <li>The company shall not permit in relation to any contracts or intended contracts, any act(s) constituting attempts of inducements to favour or bribe any employee of SAVAN IB AUTOMOTIVE PRIVATE LIMITED and reserves the right to cancel or refuse to deal with any person(s) attempting to do so. Company encourages the report to any such misconduct immediately to appropriate authorities.</li>
                    <li>All legal proceedings in respect of any matter covered under the Sales Contract shall be governed in accordance with the laws of India. The courts situated in RAJKOT shall have the jurisdiction to settle the disputes arising under these terms and conditions to the exclusion of any other court.</li>
                    <li> As per the order of RTO and Transport commissioner Gujarat, the delivery of new vehicle will not be done without a number plate. Once the RTO tax porcess is completed no cahnges will be made in the Model, vareint and colour. I also aggre that address proof provided by me will not be changed under any circumstances, I also agree that Dealership will not be responsible for the choice number. My delivery.</li>
                    <li> I am providing all the documents pertaining to KYC/RTO registration are genuine and valid.</li>
                    <li> I am also informed that Any DISCOUNT offered to me will be adjusted from Ex. Showroom Price, TCS, RTO & Municipal Tax if applicable.</li>
                  </ol>
                
                  <h3>8. Customer Data</h3>
                  <ol type="a">
                    <li> By signing the Sales contract the customer is informed that his details will be shared with KIA Motors India.</li>
                  </ol>
                
                  <div class="signature-section">
                    <div class="signature-wrapper">
                      <div class="signature-label">Customer Signature</div>
                      <div class="signature-box"></div>
                    </div>
                    <div class="signature-wrapper">
                      <div class="signature-label"> KEC / Team Leader</div>
                      <div class="signature-box"></div>
                    </div>
                    <div class="signature-wrapper">
                      <div class="signature-label">GM / BH</div>
                      <div class="signature-box"></div>
                    </div>
                  </div>
                </div>
                </body>
                </html>
        </div>  
        
        <div class="container_two">
            <div class="row">
                <div class="row col-sm-12">
                    <div class="col-sm-4"></div>
                    <div class="col-sm-4 text-center">
                        <div class="customize-input float-right">
                            <button onclick="printDiv('content-to-print')" style="color: #4e73df; border-color: #4e73df; font-size: 30px; background-color: transparent; font-weight: 700; border-radius: 0.35rem;">
                                Print Content
                            </button>
                        </div>
                    </div>
                    <div class="col-sm-4"></div>
                </div>    
            </div>   
        </div>    
    </body>
    
    <script>
        function printDiv(divId) {
    var content = document.getElementById(divId).innerHTML;

    var printWindow = window.open('', '', 'height=600,width=800');

    var stylesheets = document.querySelectorAll('link[rel="stylesheet"], style');

    var watermarkURL = "{{ asset('uploads/global_configuration/gatepass_logo_one/' . ($images->gatepass_logo1 ?? '')) }}";

    printWindow.document.write('<html><head><title>Print Content</title>');

    stylesheets.forEach(function(style) {
        if (style.tagName === 'LINK') {
            printWindow.document.write('<link rel="stylesheet" href="' + style.href + '" type="text/css">');
        } else {
            printWindow.document.write('<style>' + style.innerHTML + '</style>');
        }
    });

    printWindow.document.write(`
        <style>
            /* Base and global */
        * {
            box-sizing: border-box;
        }
        
        body {
            font-family: Arial, sans-serif;
            font-size: 10px;          /* Slightly smaller base font */
            margin: 2.5px;             /* Slightly smaller margin */
            padding: 0;
            position: relative;
            line-height: 1.18;         /* Slightly tighter line height */
        }
        
        .section {
            margin-bottom: 1.2px;      /* Reduced vertical spacing */
            font-size: 7px;
        }
        
        .row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 0.8px;      /* Reduced spacing */
        }
        
        /* Car Details columns inside row get small font */
        .row > .column-left,
        .row > .column-right {
            font-size: 3.75px !important;  /* Slightly smaller font */
        }
        
        .header-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 1.6px;
            font-size: 7px;
            font-weight: bold;
            line-height: 1.18;
        }
        
        .header-row > div {
            flex: 1;
            margin-right: 2.5px;       /* Reduced margin */
        }
        
        .header-2 {
            font-weight: bold;
            font-size: 7px;
            margin: 1.5px 0 3px 0;
        }
        
        .table-container {
            width: 100%;
            overflow: hidden;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 7px;           /* Slightly smaller font inside tables */
            line-height: 1.18;
            margin-bottom: 2.5px;
        }
        
        td, th {
            padding: 0.8px 2.8px;       /* Slightly smaller padding */
            border: 1px solid #000;
            vertical-align: top;
        }
        
        .sub-header {
            font-size: 10px;
            padding: 0.8px;
            font-weight: bold;
            margin-bottom: 2.5px;
        }
        
        .custom_section {
            margin: 1.6px 0;
            font-size: 5px;
        }
        
        .car-on-road-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 10px;             /* Smaller font size */
            margin: 0;
            padding: 0;
            line-height: 1.05;
            font-weight: normal;
            color: #000;                /* Default text color black */
        }
        
        .car-on-road-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 10px;               /* Slightly smaller font */
            margin: 0;
            padding: 0;
            line-height: 1.1;
            font-weight: normal;
            color: #000;                  /* Default text color black */
        }
        
        .car-on-road-table th.black-header {
            background-color: #000 !important; /* Black background */
            color: #fff !important;            /* White text */
            font-weight: bold;
            text-align: center;
            padding: 2px 4px;
            border: none;
        }

        .car-on-road-table .sub-header {
            background-color: #003366; /* Black background */
            color: white;              /* White font */
            font-weight: bold;
            padding: 2px 4px;
            border: none;
        }
        
        .car-on-road-table td {
            border: none;              /* Remove borders */
            padding: 2px 4px;          /* Tight spacing */
            vertical-align: middle;
            text-align: right;
            color: black;              /* Black font */
        }
        
        .car-on-road-table td.text-left {
            text-align: left;
        }
        
        .car-on-road-table td.text-center {
            text-align: center;
        }
        .car-on-road-table tr {
            height: 5px;              /* Smaller row height */
        }
        .payment-section {
            page-break-inside: avoid;
            break-inside: avoid;
            padding: 3.5px;            
            background: white;
            border-radius: 3px;
            font-size: 10px;
        }
        
        .payment-tables {
            display: flex;
            justify-content: space-between;
            gap: 2.5px;                /* Slightly smaller gap */
        }
        
        .payment-table {
            flex: 1 1 0;
            width: 49%;
            max-width: 49%;
            font-size: 10px;
            border-collapse: collapse;
            margin: 0;
            box-sizing: border-box;
        }
        
        .payment-table td {
            padding: 1.3px 2.7px;       /* Slightly smaller padding */
            border: 1px solid #ccc;
            vertical-align: top;
        }
        
        .payment-table .totals td,
        .totals {
            font-weight: bold;
            background-color: #003366;
            color: white;
        }
        
        .disclaimer {
            font-size: 6.2px;
            margin-top: 2.5px;
        }
        
        /* Signature section - smaller and tighter */
        .signature-section {
            margin-top: 4px;
            display: flex;
            justify-content: space-between;
            gap: 4px;
            margin-bottom: -4px;
        }
        
        .signature-wrapper {
            flex: 1;
            font-size: 5.5px; /* Slightly smaller font */
        }
        
        .signature-label {
            font-weight: bold;
            font-size: 10pt;
            margin-bottom: 1.5px;
        }
        
        .signature-box {
            border: 1px solid #000;
            height: 10px;          
            width: 100%;
        }
        
        /* Car Details columns */
        .column-left, .column-right {
            flex: 1;
        }
        
        .column-left > div,
        .column-right > div {
            margin-bottom: 0.8px;
        }
        
        /* Watermark */
        .watermark {
            position: fixed !important;
            width: 180px;
            opacity: 0.04;
            z-index: -1 !important;
            pointer-events: none;
            transform: rotate(-30deg);
        }
        
        .wm1 { top: 12%; left: 4%; }
        .wm2 { top: 28%; left: 22%; }
        .wm3 { top: 46%; left: 42%; }
        .wm4 { top: 64%; left: 62%; }
        
        .print-content {
            position: relative;
            z-index: 1;
            padding: 3.5px;           /* Slightly smaller padding */
            box-sizing: border-box;
        }
        
        @media print {
            body {
                -webkit-print-color-adjust: exact !important;
                print-color-adjust: exact !important;
                font-size: 6.7px;
            }
        
            .watermark {
                display: block !important;
            }
        
            .payment-section,
            .payment-table,
            .car-on-road-table {
                break-inside: avoid !important;
                page-break-inside: avoid !important;
            }
        }
        </style>
    `);

    printWindow.document.write('</head><body>');
    
    printWindow.document.write(`
        <img src="${watermarkURL}" class="watermark wm1">
        <img src="${watermarkURL}" class="watermark wm2">
        <img src="${watermarkURL}" class="watermark wm3">
        <img src="${watermarkURL}" class="watermark wm4">
    `);

    printWindow.document.write('<div class="print-content">');
    printWindow.document.write(content);
    printWindow.document.write('</div></body></html>');

    printWindow.document.close();

    printWindow.onload = function () {
        printWindow.focus();
        printWindow.print();
        printWindow.close();
    };
}

    </script>
</html>
