
<div class="card style_table shadow-none" style="margin-bottom:0.8rem;">
    <div class="card-header d-flex align-items-center justify-content-between">
            <h6 class="mb-0">Total Journal Voucher Entries ({!! isset($data['edit_journal_voucher_entries']) ? count($data['edit_journal_voucher_entries']) : '0' !!})</h6>
            <?php /*
            @if($page == 0)
            <a href="{!! route('cart-billing') !!}" type="button" class="btn btn-outline-primary" id="checkout" ><i class="bx bx-plus"></i> Add New</a>
            @endif
            */ ?>
        </div>
    <div class="card-body pb-0">
        <div class="table-responsive">
            <table id="example" class="table table-bordered align-middle" style="width:100%">
                <thead class="table-light">
                    <tr>
                        <th class="text-start">Sr No.</th>
                        <th class="text-start">Account Name</th>
                        <th>Narration</th>
                        <th style="text-align: right;">Debit Amount</th>
                        <th style="text-align: right;">Credit Amount</th>
                        <th class="thbutton">Delete</th>
                    </tr>
                </thead>
                <tbody>
                    @php 
                    $i = 1;
                    $debitAmount = 0; 
                    $creditAmount = 0; 
                    @endphp
                    @if(isset($data['edit_journal_voucher_entries']) && count($data['edit_journal_voucher_entries']) > 0)
                        @foreach($data['edit_journal_voucher_entries'] as $key => $list)
                            <tr class="cart-products" data-patient_id="{{$list['account_id']}}">
                                <td class="text-start">{{ $i }}</td>
                                <td class="text-start">{{$list['account_name'] ?? ''}}</td>
                                @if($page == 0)
                                    <td><input type="text" name="details_narration[]" data-patient_id="{{$list['account_id']}}" class="form-control bg-white" value="{{$list['details_narration'] ?? ''}}" placeholder="Narration"></td>       
                                    <td><input type="text" name="debit[]" data-patient_id="{{$list['account_id']}}" class="form-control bg-white" value="{{isset($list['debit'])&&$list['debit']>0 ? $list['debit'] : 0 }}" style="text-align: right;"></td>
                                    <td><input type="text" name="credit[]" data-patient_id="{{$list['account_id']}}" class="form-control bg-white" value="{{ isset($list['credit'])&&$list['credit']>0 ? $list['credit'] : 0 }}" style="text-align: right;"></td>
                                @else
                                    <td>{{$list['details_narration'] ?? ''}}</td>
                                    <td align="right">{{$list['debit'] ?? ''}}</td>
                                    <td align="right" >{{$list['credit'] ?? ''}}</td>
                                @endif
                                <td style="text-align: center;">
                                    <a style="line-height:24px;" data-url="{{route('edit-journal-voucher-entry-remove')}}" data-id="{{$key}}" data-patient_id="{{$list['account_id']}}" class="btn btn-danger deleteDataCustom" href="#" class="text-danger" data-bs-toggle="tooltip" data-bs-placement="left" title="Delete">
                                        <i class="bi bi-trash text-white"></i>
                                    </a>
                                </td>
                                @php 
                                $debitAmount += preg_replace("/[^0-9.]/", "", (int) $list['debit']); 
                                $creditAmount += preg_replace("/[^0-9.]/", "", (int) $list['credit']); 
                                @endphp
                            </tr>
                            @php $i++; @endphp
                        @endforeach
                            <tr style="background-color: #d4e6ff;font-size: 16px;">
                                <td class="text-start"></td>
                                <td class="text-start"></td>
                                <td class="text-start">TOTAL</td>
                                <td align="right" id="totalDebit"><strong>Debit: {{$debitAmount}}</strong></td>
                                <td align="right" id="totalCredit"><strong>Credit: {{$creditAmount}}</strong></td>
                                <td></td>
                            </tr>
                    @else
                        <tr>
                            <td colspan="9">No Data Found</td>
                        </tr>
                    @endif
                    
                </tbody>
            </table>
        </div>
        <?php /*
        @if($page == 0)
        <a href="javascript:;" type="button" class="btn btn-outline-primary" id="checkout" ><i class="bx bx-plus"></i> Submit</a>
        @endif
        */ ?>
    </div>
</div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        /*$('#checkout').html('Total Amount $amount  <i class="bi bi-cart-fill"></i> Checkout')*/
    });
</script>