<div class="col-md-12" id="contract-items">
    <!-- BEGIN Portlet PORTLET-->
    @foreach($items as $item)
        <div class="portlet box @if($item->status == \App\Models\Contract::VALIDATED) green-jungle @else red @endif">
            <div class="portlet-title">
                <div class="row" style="margin-top: 10px; font-size: 14px">
                    <div class="col-md-6">

                        Hợp đồng {{$item->code}} - {{ $item->name }}
                        @if($item->status == \App\Models\Contract::VALIDATED) (Còn hiệu
                        lực) @else (ĐÃ thanh lý) @endif
                        <br>

                        Phòng: {{ $item->room->name }} - {{ $item->room->hostel->name }}

                    </div>
                    <div class="col-md-6">
                        Thời hạn hợp đồng: Từ ngày {{ $item->start_date->format('d/m/Y') }} đến
                        ngày {{ $item->end_date->format('d/m/Y') }}
                    </div>

                </div>
                <div class="tools" style="padding: 0px 0 0px;">
                    <a href="javascript:;" class="collapse" data-original-title="" title=""> </a>
                </div>
            </div>
            <div class="portlet-body" style="display: block;">
                <div class="row">
                    <div class="col-md-3">
                        @if(!empty($item->reference))
                            <p>Mã hợp đồng tham chiếu: <strong>{{ $item->reference }}</strong></p>
                        @endif
                        {{--<p>Ngày hợp đồng: {{ $item->date_contract->format('d/m/Y') }}</p>--}}
                        {{--<p>Ngày hiệu lực: {{ $item->date_enable->format('d/m/Y') }}</p>--}}
                        <p>Thuê từ ngày: {{ $item->start_date->format('d/m/Y') }}</p>
                        <p>Thuê đến ngày: {{ $item->end_date->format('d/m/Y') }}</p>
                        <p>Giá phòng: {{ number_format($item->room_price, 0, '.', '.') }}</p>
                        <p>Chu kỳ trả tiền phòng: {{ $item->period_text }}</p>
                            @if($item->status == App\Models\Contract::LIQUIDATED)
                                @if(!empty($item->date_end_contract))
                                    <p>Ngày thanh lý hợp đồng: {{ Carbon\Carbon::createFromFormat('Y-m-d', $item->date_end_contract)->format('d/m/Y') }}</p>
                                @endif
                            @endif
                    </div>
                    <div class="col-md-3">


                        <p>Hình thức thuê: {{ $item->type_rent_text }}</p>
                        <p>Đã thu tiền phòng: {{ $item->is_collected ? 'Có' : 'Không' }}</p>
                        @if($item->is_collected)
                            <p>
                                Đến: {{ !($item->is_collected) ? '' : \Carbon\Carbon::createFromFormat('Y-m-d', $item->collect_to)->format('d/m/Y') }}</p>
                        @endif
                        <p>Tiền cọc: {{ number_format($item->deposit, 0, '.', '.') }}</p>
                        <p>Ngày thu tiền: {{ $item->day_collect }}</p>
                    </div>
                    <div class="col-md-4">
                        <p>Họ tên: {{ $item->name }}</p>
                        <p>CMTND: {{ $item->id_number }}</p>
                        <p>Số điện thoại: {{ $item->phone }}</p>
                        <p>Email: {{ $item->email }}</p>
                        {{--<p>Ngày vào: {{ empty($item->date_join)? null : $item->date_join->format('d/m/Y') }}</p>--}}
                    </div>
                    <div class="col-md-2">
                        @if(!empty($item->customer_image))
                            <img src="/files/{{ $item->customer_image }}" style="max-width: 100%">
                        @endif
                    </div>
                </div>
                @if($item->room_price > 0)
                    @if($item->status != \App\Models\Contract::LIQUIDATED)
                        <div class="row">
                            <div class="col-md-12">
                                <p>Ngày thu tiền tiếp theo: <span
                                            id="next-invoice-date">{{ $item->last_invoice_at_text }}</span>
                                    @if(auth('backend')->user()->can('create-room-money-info'))
                                    <a href="#"
                                                                                                               style="margin-left: 15px"
                                                                                                               class="btn red-flamingo"
                                                                                                               id="btn-gen-invoice"
                                                                                                               data-contract="{{ $item->id }}">
                                        <i class="fa fa-inbox"></i>
                                        Sinh hóa đơn tiền nhà</a>
                                @endif
                                </p>

                            </div>

                        </div>
                    @endif
                @endif
                <div class="row">
                    <div class="col-md-12">
                        <a target="_blank"
                           href="{{ url('admin2/setting/print-contract', ['id' => $item->id]) }}"
                           class="btn green">
                            <i class="fa fa-print"></i>
                            In hợp đồng</a>

                        @if($item->status != \App\Models\Contract::LIQUIDATED)
                        <a target="_blank"
                           href="{{ url('admin2/money/print-all-unpaid-contract', ['id' => $item->id]) }}"
                           class="btn green-haze">
                            <i class="fa fa-print"></i>
                            In hóa đơn chưa thanh toán</a>
                        @endif
                        @php
                            $dateEndContract = null;
                    try {
                    $dateEndContract  = Carbon\Carbon::createFromFormat('Y-m-d', $item->date_end_contract)->format('d/m/Y');

                    }catch (\Exception $exception)
                    {
                    }
                        @endphp
                        <a target="_blank" href="{{ url('admin2/money/print-end-contract/'.$item->id.'?is_return_money_info='.$item->is_return_money_info.'&is_return_deposit='.$item->is_return_deposit.'&date_end_contract='.$dateEndContract) }}"
                           class="btn red">
                            <i class="fa fa-print"></i>
                            In hóa đơn thanh lý</a>
                        <a target="_blank"
                           href="{{ url('admin2/setting/print-contract?type=download', ['id' => $item->id]) }}"
                           class="btn blue">
                            <i class="fa fa-download"></i>
                            Tải hợp đồng</a>
                        @if($item->status != \App\Models\Contract::LIQUIDATED)
                            @if(auth('backend')->user()->can('extend-contract'))
                                <button data-target="#extend-contract" data-toggle="modal"
                                        class="btn yellow-lemon btn-extend-contract"
                                        data-contract="{{ $item->id }}">
                                    <i class="fa fa-thumbs-o-up"></i>
                                    Gia hạn hợp đồng
                                </button>
                            @endif
                                @if(auth('backend')->user()->can('end-contract'))
                            <button class="btn red btn-end-contract" data-contract="{{ $item->id }}">
                                <i class="fa fa-hand-stop-o"></i>
                                Thanh lý hợp đồng
                            </button>
                                    @endif
                        @endif
                        @if(auth('backend')->user()->can('attach-file'))
                        <a target="#" href="#add-contract-attachment" data-contract="{{ $item->id }}"
                           class="btn yellow-gold btn-add-attach-contract" data-toggle="modal">
                            <i class="fa fa-file-archive-o"></i>
                            Đính kèm file</a>
                        @endif
                        <a target="#" data-contract="{{ $item->id }}"
                           class="btn purple-studio btn-send-mail-contract" style="margin-top: 5px">
                            <i class="fa fa-paper-plane-o"></i>
                            Gửi mail hợp đồng cho khách hàng</a>
                        {{--<a class="btn green-meadow btn-rating-contract" data-toggle="modal" href="#rating" data-contract="{{ $item->id }}">Đánh giá người thuê</a>--}}
                    </div>
                </div>
            </div>
        </div>
@endforeach
<!-- END Portlet PORTLET-->
</div>