@php
    $daycollect = $room->hostel->date_money;
@endphp
<form action="#" id="form-add-contract">
    {!! csrf_field() !!}
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-12">
                    <div class="text-center">
                        <h4><strong>Thông tin hợp đồng</strong></h4>
                    </div>
                    <!-- BEGIN Portlet PORTLET-->

                    <input type="hidden" name="room_id" value="{{ $room->id }}">
                    <input type="hidden" name="bed_id" value="{{ !empty($bedId)?$bedId:null }}">
                    <div class="form-body">
                        <div class="row">

                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Ngày khách vào <span class="required"
                                                                aria-required="true"> (*) </span></label>
                                    <input name="date_contract" type="text" class="form-control datepicker"
                                           value="{{ \Carbon\Carbon::now()->format('d/m/Y') }}">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Thời hạn hợp đồng <span class="required"
                                                                   aria-required="true"> (*) </span></label>
                                    <input name="end_date" type="text" class="form-control datepicker"
                                           value="{{ \Carbon\Carbon::now()->addDay(180)->format('d/m/Y') }}">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Mã hợp đồng tham chiếu </label>
                                    <input name="reference" type="text" class="form-control"
                                           value="">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Tiền phòng <span class="required" aria-required="true"> (*) </span></label>
                                    <input name="room_price" type="text" class="form-control price-r"
                                           value="{{ number_format($room->price, 0, '.', '.') }}">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Tiền cọc <span class="required" aria-required="true"> (*) </span></label>
                                    <input name="deposit" type="text" class="form-control price-r"
                                           @if(isset($reserve)) value="{{ number_format($reserve->deposit, 0, '.', '.') }}"
                                           @elseif(!empty($room->deposit)) value="{{ number_format($room->deposit, 0, '.', '.') }}"
                                           @else
                                           value="{{ number_format($room->price, 0, '.', '.') }}"
                                            @endif>
                                </div>
                            </div>

                           {{--@php $type_hostel =  \App\Models\Hostel::where('id', $room->hostel_id)->first() @endphp--}}
                            {{--@if($type_hostel->type_rent==\App\Models\Hostel::TYPE_RENT_EVERY)--}}
                            {{--<div class="col-md-3">--}}
                                {{--<div class="form-group">--}}
                                    {{--<label>Giường <span class="required" aria-required="true"> (*) </span></label>--}}
                                    {{--@php $room_bed = \App\Models\RoomBed::where('room_id',$room->id)->get()@endphp--}}
                                    {{--<select name="room_bed" id="room_bed" class="form-control" required>--}}
                                        {{--@foreach($room_bed as $bed)--}}
                                            {{--<option value="{{$bed->id}}">{{$bed->name}}</option>--}}
                                            {{--@endforeach--}}
                                    {{--</select>--}}
                                {{--</div>--}}
                            {{--</div>--}}
                            {{--@endif--}}
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Chu kỳ thanh toán</label>
                                    <select name="period" class="form-control">

                                        <option value="{{ \App\Models\Room::ONE_MONTH_PERIOD }}">1 tháng
                                        </option>
                                        <option value="{{ \App\Models\Room::TWO_MONTH_PERIOD }}">2 tháng
                                        </option>
                                        <option value="{{ \App\Models\Room::THREE_MONTH_PERIOD }}">3 tháng
                                        </option>
                                        <option value="{{ \App\Models\Room::FOUR_MONTH_PERIOD }}">4 tháng
                                        </option>
                                        <option value="{{ \App\Models\Room::FIVE_MONTH_PERIOD }}">5 tháng
                                        </option>
                                        <option value="{{ \App\Models\Room::SIX_MONTH_PERIOD }}">6 tháng
                                        </option>
                                        <option value="{{ \App\Models\Room::ONE_YEAR_PERIOD }}">1 năm</option>

                                    </select>
                                </div>
                            </div>

                        </div>
                        <div class="row">

                            {{--<div class="col-md-4">--}}
                            {{--<div class="form-group">--}}
                            {{--<label>Hình thức thuê</label>--}}
                            {{--<div class="mt-radio-inline">--}}
                            {{--<label class="mt-radio">--}}
                            {{--<input type="radio" name="type_rent" id="start_period"--}}
                            {{--value="{{ \App\Models\Room::START_PERIOD }}"--}}
                            {{--checked=""> Thu đầu kỳ--}}
                            {{--<span></span>--}}
                            {{--</label>--}}
                            {{--<label class="mt-radio">--}}
                            {{--<input type="radio" name="type_rent" id="last_period"--}}
                            {{--value="{{ \App\Models\Room::LAST_PERIOD }}"> Thu cuối kỳ--}}
                            {{--<span></span>--}}
                            {{--</label>--}}
                            {{--</div>--}}
                            {{--</div>--}}
                            {{--</div>--}}
                            <input type="hidden" name="type_rent" value="{{ \App\Models\Room::START_PERIOD }}">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Ngày chốt tiền phòng hàng tháng</label>
                                    <select class="form-control select2" name="day_collect">
                                        @for($i = 1; $i <=31; $i++)
                                            <option @if(!empty($daycollect) && $daycollect == $i) selected
                                                    @endif value="{{ $i }}">{{ $i }}</option>
                                        @endfor
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-8">
                                <div class="form-group" id="collected">

                                    <div class="row">
                                        <div class="col-md-6">
                                            <label>Đã thu tiền phòng</label>
                                            <div class="mt-checkbox-list">
                                                <label class="mt-checkbox">
                                                    <input type="checkbox" name="is_collected"
                                                           id="is_collected"> Có
                                                    <span></span>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-6" id="to_month" style="display: none">

                                            <div class="form-group">
                                                <label>Đến</label>
                                                <input type="text" class="form-control datepicker"
                                                       name="collect_to">
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>

                        </div>

                    </div>


                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <hr style="border-top: 1px dashed">
                </div>
                <div class="text-center">
                    <h4><strong>Thông tin khách hàng</strong></h4>
                </div>
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-4">

                            <div class="form-group">
                                <label class="">Ảnh đại diện khách hàng</label>
                                <div class="">
                                    <div class="fileinput fileinput-new" data-provides="fileinput" style="width: 100%">
                                        <div class="fileinput-new thumbnail" style="width: 100%;">
                                            <img src="/frontend3/assets/img/placeholder.png" alt=""/></div>
                                        <div class="fileinput-preview fileinput-exists thumbnail"
                                             style="width: 100%; max-height: 500px;"></div>
                                        <div>
                            <span class="btn default btn-file" style="width: 100%">
                                <span class="fileinput-new"> Chọn ảnh </span>
                                                                   <span class="fileinput-exists"> Thay đổi </span>
                                                                   <input type="file" name="image"> </span>
                                            <a href="javascript:;" class="btn red fileinput-exists fileinput-delete"
                                               data-dismiss="fileinput">
                                                Xóa </a>
                                        </div>
                                    </div>
                                    <div class="clearfix margin-top-10">

                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="col-md-8">
                            <!-- BEGIN Portlet PORTLET-->
                            @isset($reserve)
                                <input type="hidden" name="reserve_id" value="{{ $reserve->id }}">
                            @endisset

                            <div class="form-body">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>SĐT <span class="required" aria-required="true"> (*) </span></label>
                                            <input type="text" class="form-control" name="phone"
                                                   id="phone-contract"
                                                   @isset($reserve) value="{{ $reserve->phone }}" @endisset readonly>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>Họ tên <span class="required"
                                                                aria-required="true"> (*) </span></label>
                                            <input type="text" class="form-control" name="name"
                                                   @isset($reserve) value="{{ $reserve->name }}" @endisset readonly>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">

                                        <div class="form-group">
                                            <label>Email</label>
                                            <input type="text" class="form-control" name="email"
                                                   @isset($reserve) value="{{ $reserve->email }}" @endisset readonly>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>Ngày sinh</label>
                                            <input type="text" class="form-control datepicker" name="birthday">
                                        </div>
                                    </div>


                                </div>
                                <div class="row">
                                    <div class="col-md-6">

                                        <div class="form-group">
                                            <label>Tỉnh / thành phố</label>
                                            <select class="form-control select2" name="province_id" id="province1">
                                                <option value="" selected>Chọn tỉnh / thành phố</option>
                                                @php $provinces = \App\Components\Functions::getProvinces(); @endphp

                                                @foreach($provinces as $province)
                                                    <option value="{{ $province->provinceid }}">{{ $province->name }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6">

                                        <div class="form-group">
                                            <label>Quận / huyện</label>
                                            <select class="form-control select2" name="district_id" id="district1">
                                                <option value="" selected>Chọn quận / huyện</option>
                                            </select>
                                        </div>
                                    </div>


                                </div>
                                <div class="row">
                                    <div class="col-md-6">

                                        <div class="form-group">
                                            <label>Phường / Xã</label>
                                            <select class="form-control select2" name="ward_id" id="ward1">
                                                <option value="" selected>Chọn phường / xã</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>Địa chỉ</label>
                                            <input type="text" class="form-control" name="address"
                                                   @isset($reserve) value="{{ $reserve->address }}" @endisset>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">


                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>Ghi chú (mã vân tay,...)</label>
                                            <textarea name="note" class="form-control"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>Tạm trú</label>
                                            <select class="form-control" name="residence_status"
                                                    id="add-renter-residence-status">
                                                <option value="{{ \App\Models\RenterRoom::RESIDENCE_NOT_DECLARE }}"
                                                        selected>
                                                    Chưa khai báo
                                                </option>
                                                <option value="{{ \App\Models\RenterRoom::RESIDENCE_LIMIT }}">
                                                    Tạm trú có thời hạn
                                                </option>
                                                <option value="{{ \App\Models\RenterRoom::RESIDENCE_NOT_LIMIT }}">
                                                    Tạm trú không có thời hạn
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group" id="add-renter-date-end-residence"
                                             style="display: none">
                                            <label>Thời hạn tạm trú</label>
                                            <input type="text" class="form-control datepicker"
                                                   name="date_end_residence">
                                        </div>
                                    </div>
                                </div>


                                <div class="row">

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>CMTND / CCCD</label>
                                            <input type="text" class="form-control" name="id_number"
                                                   @isset($reserve) value="{{ $reserve->id_number }}" @endisset readonly>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>Ngày cấp CMTND / CCCD</label>
                                            <input type="text" class="form-control datepicker" name="id_number_date">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>Nơi cấp CMTND / CCCD</label>
                                            <input type="text" class="form-control" name="id_number_location">
                                        </div>
                                    </div>
                                </div>


                            </div>

                            <!-- END Portlet PORTLET-->
                        </div>

                    </div>

                </div>
            </div>
            <div class="row">
                <div class="col-md-4 col-md-offset-4">

                    <div class="form-group">
                        <label class="">Ảnh CMT mặt trước</label>
                        <div class="">
                            <div class="fileinput fileinput-new" data-provides="fileinput" style="width: 100%">
                                <div class="fileinput-new thumbnail" style="width: 100%;">
                                    <img src="/frontend3/assets/img/placeholder.png" alt=""/></div>
                                <div class="fileinput-preview fileinput-exists thumbnail"
                                     style="width: 100%; max-height: 500px;"></div>
                                <div>
                            <span class="btn default btn-file" style="width: 100%">
                                <span class="fileinput-new"> Chọn ảnh </span>
                                                                   <span class="fileinput-exists"> Thay đổi </span>
                                                                   <input type="file" name="id_number_front" onchange="get_cmnd_info()"> </span>
                                    <a href="javascript:;" class="btn red fileinput-exists fileinput-delete"
                                       data-dismiss="fileinput">
                                        Xóa </a>
                                </div>
                            </div>
                            <div class="clearfix margin-top-10">

                            </div>
                        </div>
                    </div>

                </div>
                <div class="col-md-4">

                    <div class="form-group">
                        <label class="">Ảnh CMT mặt sau</label>
                        <div class="">
                            <div class="fileinput fileinput-new" data-provides="fileinput" style="width: 100%">
                                <div class="fileinput-new thumbnail" style="width: 100%;">
                                    <img src="/frontend3/assets/img/placeholder.png" alt=""/></div>
                                <div class="fileinput-preview fileinput-exists thumbnail"
                                     style="width: 100%; max-height: 500px;"></div>
                                <div>
                            <span class="btn default btn-file" style="width: 100%">
                                <span class="fileinput-new"> Chọn ảnh </span>
                                                                   <span class="fileinput-exists"> Thay đổi </span>
                                                                   <input type="file" name="id_number_back" onchange="get_cmnd_info_back()"> </span>
                                    <a href="javascript:;" class="btn red fileinput-exists fileinput-delete"
                                       data-dismiss="fileinput">
                                        Xóa </a>
                                </div>
                            </div>
                            <div class="clearfix margin-top-10">

                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <hr style="border-top: 1px dashed">
                </div>
                <div class="text-center">
                    <h4><strong>Thông tin dịch vụ</strong></h4>
                </div>
                <div class="col-md-12">
                    <!-- BEGIN Portlet PORTLET-->
                    @php
                        $fees = \App\Models\HostelFee::where('hostel_id', $room->hostel->id)->get();
                $hostel = $room->hostel;
                    @endphp

                    <div class="table-scrollable">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th><label class="mt-checkbox">
                                        <input type="checkbox" class="checkbox-all-contract"> <span></span>
                                    </label>
                                </th>
                                <th> Tên</th>
                                <th> Loại phí</th>
                                <th> Đơn giá</th>
                                <th> Đơn vị</th>
                                <th> Số lượng</th>
                                <th>Chỉ số đầu</th>
                            </tr>
                            </thead>

                            <input type="hidden" name="hostel_id" value="{{ $hostel->id }}"/>
                            <tbody id="table-hostel-fees">
                            @foreach($fees as $fee)
                                <tr>
                                    <td>

                                        <label class="mt-checkbox">
                                            <input type="checkbox" class="checkbox-contract-fee-c-contract"
                                                   name="fee-contracts[]"
                                                   value="{{ $fee->id }}"> <span></span>
                                        </label>

                                    </td>
                                    <td> {{ $fee->name }} </td>
                                    <td> {{ $fee->type_text }} </td>
                                    <td>
                                        @if($fee->type == \App\Models\HostelFee::ELECTRIC || $fee->type == \App\Models\HostelFee::WATER || $fee->type == \App\Models\HostelFee::WATER_DYNAMIC
                                        || $fee->type == \App\Models\HostelFee::ELECTRIC_DYNAMIC
                                        )
                                            Biến động
                                        @else
                                            {{ number_format($fee->fee, 0, '.', '.' ) }}
                                        @endif
                                    </td>
                                    <td>{{ $fee->unit }}</td>
                                    <td>
                                        @if($fee->type != \App\Models\HostelFee::ELECTRIC && $fee->type != \App\Models\HostelFee::WATER
                                        && $fee->type != \App\Models\HostelFee::ELECTRIC_BY_CLOCK && $fee->type != \App\Models\HostelFee::WATER_BY_CLOCK)

                                            <input type="number" class="form-control" name="qty[{{ $fee->id }}][]"
                                                   value="1">
                                        @else
                                            <input type="number" class="form-control" disabled
                                                   value="0">
                                        @endif

                                    </td>
                                    <td>

                                        @if($fee->type != \App\Models\HostelFee::ELECTRIC && $fee->type != \App\Models\HostelFee::WATER
                                        && $fee->type != \App\Models\HostelFee::ELECTRIC_BY_CLOCK && $fee->type != \App\Models\HostelFee::WATER_BY_CLOCK
                                        )
                                            <input type="number" class="form-control" disabled
                                                   value="0">
                                        @else
                                            @php $ew = \App\Components\Functions::getEwRoomContract($room);@endphp
                                            @if(in_array($fee->type, [
    \App\Models\HostelFee::ELECTRIC,
     \App\Models\HostelFee::ELECTRIC_BY_CLOCK,
]))

                                            <input type="number" class="form-control" name="qty[{{ $fee->id }}][]"
                                                   value="{{ $ew['e'] }}">

                                                @else
                                                <input type="number" class="form-control" name="qty[{{ $fee->id }}][]"
                                                       value="{{ $ew['w'] }}">
                                                @endif
                                        @endif
                                    </td>

                                </tr>
                            @endforeach
                            </tbody>

                        </table>

                    </div>
                    <!-- END Portlet PORTLET-->
                </div>

            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label>Ghi chú hợp đồng</label>
                        <textarea name="contract_note" class="form-control" placeholder="Ghi chú giảm giá tiền, số lượng xe free..."></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>