@extends('layout.app')


@section('content')
    <div class="mt-2 card">
        <div class=" card-body">

            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead class="bg-dark">
                        <tr>
                            <th style="padding-left: 2px;padding-right: 2px;">ID</th>
                            <th style="padding-left: 2px;padding-right: 2px;max-width:60px">Total Bill</th>
                            <th style="padding-left: 2px;padding-right: 2px;max-width:90px">Total Payment Amount</th>
                            <th style="padding-left: 2px;padding-right: 2px;max-width:90px">Total Discound Amount</th>
                            <th style="padding-left: 2px;padding-right: 2px;max-width:100px">Total Due </th>


                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($clients as $r)
                            <tr>
                                <td>{{$r->id}}</td>
                                <td class="
                                @if ($r->generatedBill->sum('bill_amount') == $r->customerAccount->totalBillAmount)
                                    bg-success
                                @else
                                bg-danger @endif">{{$r->generatedBill->sum('bill_amount')}}</td>
                                <td class="  @if (($r->paymentBill->sum('paid_amount')  ) == ($r->customerAccount->totalPaid )) bg-success

                                            @else bg-danger  @endif">
                                            {{$r->paymentBill->sum('paid_amount') }}
                                            {{-- <br>
                                            {{$r->paymentBill->sum('paid_amount') + $r->paymentBill->sum('discount_amount') }}
                                            <br>
                                            {{$r->customerAccount->totalPaid + $r->customerAccount->totalDiscount}} --}}
                                        </td>
                                        <td class="  @if (( $r->paymentBill->sum('discount_amount') ) == ( $r->customerAccount->totalDiscount)) bg-success

                                            @else bg-danger  @endif">
                                            {{ $r->paymentBill->sum('discount_amount')}}
                                            {{-- <br>
                                            {{$r->paymentBill->sum('paid_amount') + $r->paymentBill->sum('discount_amount') }}
                                            <br>
                                            {{$r->customerAccount->totalPaid + $r->customerAccount->totalDiscount}} --}}
                                        </td>
                                <td class="@if (($r->generatedBill->sum('bill_amount') - ($r->paymentBill->sum('paid_amount') + $r->paymentBill->sum('discount_amount') )) == ($r->customerAccount->dueAmount - $r->balanceAdjustment->sum('amount')) )
                                    bg-success @else bg-danger  @endif">{{$r->customerAccount->dueAmount}}
                                    <br>
                                    {{$r->paymentBill->sum('discount_amount')}}
                                    <br>
                                    {{$r->balanceAdjustment->sum('amount')}}
                                    <br>
                                    {{($r->generatedBill->sum('bill_amount') - ($r->paymentBill->sum('paid_amount') + $r->paymentBill->sum('discount_amount')))}}

                                </td>

                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

        </div>



    </div>
    <style>
        .sub-menu li {
            font-size: 1em;
            padding: .25em 1em;
            line-height: 1em;
        }

        .sub-menu {
            padding: 0;
            max-height: 200px;
            /* 1.5 x 3 */
            overflow-y: auto;
        }

        li.selected {
            background: #17A2B8 !important;
        }
    </style>
@endsection
