<style>
    .red {
        color: #eb4034;
    }


    .uppercase {
        text-transform: uppercase
    }

    @if(isset($isExcel))
    #tb td, #tb th {
        border: 1px solid #000000;
    }

    td {
        text-align: center;
    }

    th {
        text-align: center;
    }
    @endif
</style>
<form id="form-money-info-contract">
    <table class="table table-striped table-bordered table-hover" id="tb">
        <tr>
            <th style="min-width: 40px"><input class="form-control checkbox" type="checkbox" id="select-all-money-contracts"></th>
            <th>
                Thao tác
            </th>
            <th>Nhà</th>
            <th>Phòng</th>
            <th>Khách</th>
            <th>Số tiền</th>
            <th>Tiền nhà</th>
            <th>Tiền dịch vụ</th>
            <th>Đã trả</th>
            <th>Giảm giá</th>
            <th>Còn lại</th>

        </tr>
        <tr>
            <th></th>
            <th>

            </th>
            <th></th>
            <th></th>
            <th></th>
            <th>{{ number_format($moneyInfos->sum('amount'), 0, '.', '.') }}</th>
            <th>{{ number_format($moneyInfos->whereIn('type', [\App\Models\MoneyInfo::VOUCHER_ROOM_PRICE, \App\Models\MoneyInfo::VOUCHER_CONTRACT])->sum('amount'), 0, '.', '.') }}</th>
            <th>{{ number_format($moneyInfos->where('type', \App\Models\MoneyInfo::VOUCHER_SERVICE)->sum('amount'), 0, '.', '.') }}</th>
            <th>{{ number_format($moneyInfos->sum('pay'), 0, '.', '.') }}</th>
            <th>{{ number_format($moneyInfos->sum('discount'), 0, '.', '.') }}</th>
            <th>{{ number_format($moneyInfos->sum('remain'), 0, '.', '.') }}</th>

        </tr>
        @foreach($contracts as $contract)
            @if($contract->moneyInfos->count() > 0)
                <tr>
                    <td><input class="form-control checkbox contract-checkbox" value="{{ $contract->id }}"
                               name="contract_ids[]" type="checkbox"></td>
                    <td style="width: 15%">
                        @if(auth('backend')->user()->can('view-money-info'))
                        <a data-id="{{ $contract->id }}" data-toggle="modal" href="#detail-money-info"
                           data-toggle="tooltip" title="Xem"
                           class="btn btn-icon-only purple detail-money-contract" data-toggle="tooltip"><i
                                    data-tooltip="Xem"
                                    class="fa fa-eye"></i></a>
                        @endif
                        @if($owner->type_display_money_info == \App\User::TYPE_DISPLAY_MONEY_INFO_PREVIOUS_MONTH)
                            <a target="_blank"
                               href="https://itro.vn/bill/print-money-info-room-service?web=1&contract_id={{ $contract->id }}&month={{ $month->copy()->format('m/Y') }}&token={{$owner->token}}"
                               class="btn btn-icon-only green detail-money" data-toggle="tooltip" title="In"><i
                                        class="fa fa-print"></i></a>
                        @else
                            <a target="_blank"
                               href="https://itro.vn/bill/print-money-info-contract?contract_id={{ $contract->id }}&month={{ $month->copy()->format('m/Y') }}&token={{$owner->token}}"
                               class="btn btn-icon-only green detail-money" data-toggle="tooltip" title="In"><i
                                        class="fa fa-print"></i></a>
                        @endif
                        @if(auth('backend')->user()->can('edit-money-info'))
                        <a data-id="{{ $contract->id }}" data-toggle="modal" href="#detail-money-info-contract"
                           class="btn btn-icon-only green-meadow edit-money-contract" data-toggle="tooltip"
                           title="Cập nhật"><i
                                    class="fa fa-edit"></i></a>
                        @endif
                        @if(auth('backend')->user()->can('add-payment'))
                        <a data-id="{{ $contract->id }}"
                           class="btn btn-icon-only green-meadow mark-paid-full-contract"><i
                                    class="fa fa-check" data-toggle="tooltip" title="Thanh toán hóa đơn"></i></a>
                        @endif

                        @if(auth('backend')->user()->can('send-voucher'))
                        <a data-id="{{ $contract->id }}" class="btn btn-icon-only blue send-zalo-contract"
                           data-toggle="tooltip" title="Gửi hóa đơn qua zalo"

                        ><i class="fa fa-comment"></i></a>
                        @endif

                        @if(auth('backend')->user()->can('delete-voucher'))
                        <a data-id="{{ $contract->id }}" class="btn btn-icon-only red delete-voucher-contract"
                           data-toggle="tooltip" title="Xóa"
                        ><i class="fa fa-trash"></i></a>
                            @endif
                    </td>
                    <td>{{ $contract->hostel->name }}</td>
                    <td>{{ $contract->room->name }}</td>
                    <td>{{ $contract->name }}</td>
                    <td>{{ number_format($contract->moneyInfos->sum('amount'), 0, '.', '.') }}</td>
                    <td>{{ number_format($contract->moneyInfos->whereIn('type', [\App\Models\MoneyInfo::VOUCHER_ROOM_PRICE, \App\Models\MoneyInfo::VOUCHER_CONTRACT])->sum('amount'), 0, '.', '.') }}</td>
                    <td>{{ number_format($contract->moneyInfos->where('type', \App\Models\MoneyInfo::VOUCHER_SERVICE)->sum('amount'), 0, '.', '.') }}</td>
                    <td>{{ number_format($contract->moneyInfos->sum('pay'), 0, '.', '.') }}</td>
                    <td>{{ number_format($contract->moneyInfos->sum('discount'), 0, '.', '.') }}</td>
                    <td>{{ number_format($contract->moneyInfos->sum('remain'), 0, '.', '.') }}</td>
                </tr>
            @endif
        @endforeach
    </table>
</form>