@extends('layout')
@section('content')
<style>
    .invoice-table {
        width: 100%;
        border-collapse: collapse;
    }
    .invoice-table th, .invoice-table td {
        border: 1px solid #ddd;
        padding: 8px;
        text-align: left;
    }
    .invoice-table th {
        background-color: #f2f2f2;
    }
    .form-control {
        width: 100%;
        padding: 8px;
        border: 1px solid #ddd;
        border-radius: 4px;
    }
    .checkbox-label {
        display: flex;
        align-items: center;
        margin-bottom: 8px;
    }
    .summary-box {
        border: 1px solid #ddd;
        padding: 15px;
        margin-top: 20px;
        background-color: #f9f9f9;
    }
    .char-count {
        font-size: 12px;
        color: #6c757d;
    }
    .btn {
        padding: 8px 16px;
        margin-right: 10px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }
    .btn-primary {
        background-color: #007bff;
        color: white;
    }
    .btn-secondary {
        background-color: #6c757d;
        color: white;
    }
    .btn-danger {
        background-color: #dc3545;
        color: white;
    }
    .btn-success {
        background-color: #28a745;
        color: white;
    }
    .action-buttons {
        margin-bottom: 15px;
    }
</style>
<main class="main-content">
    <div class="container px-2">
        <h2>Advance Payment Received</h2>
        <div class="page-header">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb ">
                    <li class="breadcrumb-item"><a href="{{ asset('dashboard') }}">{{ __('message.dashboard') }}</a></li>
                    <li class="breadcrumb-item"><a href="{{ asset('account/advance-payment') }}">Advance Payment</a></li>
                    <li class="breadcrumb-item active" aria-current="page">{{ __('message.add') }}</li>
                </ol>
            </nav>
        </div>

        <div class="card">
            <x-flashMessage />
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
            
            <form action="{{asset('account/add-advance-payment-receive')}}" method="post">
                @csrf
                <input type="hidden" name="advance_payment_id" value="{{$payment->id}}">
                
                <div class="row align-items-center mb-3 px-3 pt-3">
                    <div class="col-md-6">
                        <div class="form-group row align-items-center">
                            <label class="col-md-4 col-form-label font-weight-bold">Client Name</label>
                            <div class="col-md-8">                                
                                    <select class="form-control client_change_option select2" name="client_vendor_id" required>
                                        <option selected disabled>Select</option>
                                        @foreach($clients as $cus)
                                            <option value="{{$cus->id}}" {{$cus->id == $payment->client_vendor_id ? 'selected' : ''}}>{{$cus->name}}</option>
                                        @endforeach
                                    </select>                                   
                                
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card-header py-4">
                    
                    
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <div class="form-group row ">
                                <label class="col-md-5 col-form-label font-weight-bold">Number</label>
                                <div class="col-md-2 px-0">
                                    <input type="text" class="form-control" name="number_prefix" value="{{$payment->number_prefix}}" >
                                </div>
                                <div class="col-md-5">
                                    <input type="number" class="form-control" name="payment_number" value="{{$payment->payment_number}}" required>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group row align-items-center">
                                <label class="col-md-3 col-form-label font-weight-bold">Date</label>
                                <div class="col-md-9">
                                    <input type="date" class="form-control" name="date" value="{{$payment->date}}" required>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group row align-items-center">
                                <label class="col-md-4 col-form-label font-weight-bold">Method</label>
                                <div class="col-md-8">
                                    <select class="form-control select2" name="payment_method" required>
                                        <option value="cash" {{$payment->payment_method == "cash" ? "selected" : ""}}>Cash</option>
                                        <option value="bank_transfer" {{$payment->payment_method == "bank_transfer" ? "selected" : ""}}>Bank Transfer</option>
                                        <option value="payment_gateway" {{$payment->payment_method == "payment_gateway" ? "selected" : ""}}>Payment Gateway</option>
                                        <option value="upi" {{$payment->payment_method == "upi" ? "selected" : ""}}>UPI</option>
                                        <option value="qr_code" {{$payment->payment_method == "qr_code" ? "selected" : ""}}>QR Code</option>
                                        
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group row align-items-center">
                                <label class="col-md-5 col-form-label font-weight-bold">Amount</label>
                                <div class="col-md-7 pl-0">
                                    <input type="number" class="form-control" id="enter_amount" value="{{$payment->amount}}" name="amount" required>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group row align-items-center">
                                <label class="col-md-4 col-form-label font-weight-bold">Reference</label>
                                <div class="col-md-8">
                                    <input type="text" name="reference" class="form-control" value="{{$payment->reference}}">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group row align-items-center">
                                <label class="col-md-5 col-form-label font-weight-bold">Bank Charge</label>
                                <div class="col-md-7">
                                    <input type="number" class="form-control" name="bank_charge" value="{{$payment->bank_charge}}">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row py-3">
                        <div class="col-md-6"></div>
                        <div class="col-md-6 d-flex justify-content-between">
                            <h5>Amount Received</h5>
                            <h5 id="received_amount">₹ {{$payment->amount}}</h5>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    
                    <div class="mt-4">
                        <h6>Memo/notes</h6>
                        <textarea class="form-control" name="note" rows="3" placeholder="Enter any additional notes here...">{{$payment->note}}</textarea>
                    </div>

                    <div class="d-flex justify-content-end mt-4">
                        
                        <div>
                            
                            <button type="submit" class="btn btn-primary">Save & View Receipt</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <!-- The Modal -->
    <div class="modal" id="invoiceModal">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header bg-success rounded-0">
                <h4 class="modal-title">Add Expense</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- Modal body -->
            <div class="modal-body">
                
                <form action="{{ asset('account/add-account-expense') }}" method="post">
                    @csrf
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>Expense Name</label>
                                <input type="text" name="name" class="form-control">
                            </div>
                        </div>
                    </div>
                    
                    <div class="d-flex justify-content-end">
                        <button type="submit" class="btn btn-success">Submit</button>
                    </div>
                </form>
            </div>

            

            </div>
        </div>
    </div>
</main>
@endsection

@push('footer-script')

<script>
    $(document).ready(function() {



        //amount code
        $("#enter_amount").on("input",function(){
            var amount = $(this).val();
            $("#received_amount").text("₹ "+amount);
        });
        
        
    });
</script>
@endpush