<div class="content-wrapper">
    <div class="container-xxl flex-grow-1 container-p-y">
        <div class="row">
            <div class="col-12" id="txtGenCard">
                <div class="card shadow">
                    <div class="card-header text-uppercase custom-header bg-primary text-bg-info fw-bold d-flex justify-content-between">
                        <span><i class="menu-icon ti ti-device-desktop-cog"></i> Manage Loan Repayments</span>
                        
                    </div>
                    <div class="card-body">
                        <div class="row mt-3">
                            <div class="col-md-6 col-sm-12">
                                <div class="form-group">
                                    <label>Payment Date</label>
                                    <input type="date" class="form-control" id="txtPaymentDate" value="{{ date('Y-m-d') }}">
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-12">
                                <div class="form-group">
                                    <label>Member</label>
                                    <select class="selectize" id="txtMember">
                        <option value="">---Select---</option>
                        @foreach ($getAllMemberData as $member)
                            @if (auth()->user()->userType == 'superAdmin')
                                <option value="{{ $member->id }}">{{ $member->firstName }} {{ $member->lastName }} / {{ $member->oldAccountNumber }}/ {{ $member->nicNumber }}</option>
                            @else
                                @php
                                    $divArray = auth()->user()->division;
                                    $vilArray = auth()->user()->village;
                                @endphp
                                @if ($divArray != '' || $divArray != null || $vilArray != '' || $vilArray != null)
                                    @if (in_array($member->divisionId, json_decode(auth()->user()->division)) &&
                                            in_array($member->villageId, json_decode(auth()->user()->village)))
                                             <option value="{{ $member->id }}">{{ $member->firstName }} {{ $member->lastName }} / {{ $member->oldAccountNumber }}/ {{ $member->nicNumber }}</option>
                                    @endif
                                @endif
                            @endif

                        @endforeach
                    </select>
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-12 mt-2">
                                <div class="form-group">
                                    <label>Loans</label>
                                    <select class="form-control" id="txtLoan"></select>
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-12 mt-4 d-flex align-items-end">
                                <button type="button" class="btn btn-primary w-100" id="btnAddLoandata">Add</button>
                            </div>
                            <hr class="mt-4">
                            <div class="col-12">
                                <div class="table-responsive">
                                    <table class="table table-striped table-bordered" id="tblLoanRepayment">
                                        <thead class="table-primary">
                                            <tr>
                                                <th>#</th>
                                                <th>Loan Id</th>
                                                <th class="text-end">Loan Amount</th>
                                                <th class="text-end">Days</th>
                                                <th class="text-end">Interest</th>
                                                <th class="text-end">Interest Arrears</th>
                                                <th class="text-end">Principal Amount</th>
                                                <th class="text-end">Total Payment</th>
                                                <th class="text-end">Balance Payment</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <!-- Dynamic rows by JS -->
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            
                            <!-- Pay Amount Field -->
                            <div class="col-md-6 col-sm-12 mt-4">
                                <div class="form-group">
                                    <label>Loan Amount</label>
                                    <input type="text" class="form-control" id="txtPayAmount">
                                </div>
                            </div>
                            
                            <hr class="mt-4">
                            <div class="col-md-6 col-sm-12">
                                <div class="form-group">
                                    <label>Saving Amount</label>
                                    <input type="text" class="form-control" id="txtSavingAmount">
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-12">
                                <div class="form-group">
                                    <label>Old Receipt Number</label>
                                    <input type="text" class="form-control" id="txtOldReceiptNumber">
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-12 mt-4 d-flex justify-content-end">
                                <button class="btn btn-primary" id="txtRepaymentAmount">Pay</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>