<?php
    $daycollect = $room->hostel->date_money;
?>
<form action="#" id="form-add-contract">
    <?php echo 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="<?php echo e($room->id); ?>">
                    <input type="hidden" name="bed_id" value="<?php echo e(!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="<?php echo e(\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="<?php echo e(\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="<?php echo e(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"
                                           <?php if(isset($reserve)): ?> value="<?php echo e(number_format($reserve->deposit, 0, '.', '.')); ?>"
                                           <?php elseif(!empty($room->deposit)): ?> value="<?php echo e(number_format($room->deposit, 0, '.', '.')); ?>"
                                           <?php else: ?>
                                           value="<?php echo e(number_format($room->price, 0, '.', '.')); ?>"
                                            <?php endif; ?>>
                                </div>
                            </div>

                           
                            
                            
                                
                                    
                                    
                                    
                                        
                                            
                                            
                                    
                                
                            
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Chu kỳ thanh toán</label>
                                    <select name="period" class="form-control">

                                        <option value="<?php echo e(\App\Models\Room::ONE_MONTH_PERIOD); ?>">1 tháng
                                        </option>
                                        <option value="<?php echo e(\App\Models\Room::TWO_MONTH_PERIOD); ?>">2 tháng
                                        </option>
                                        <option value="<?php echo e(\App\Models\Room::THREE_MONTH_PERIOD); ?>">3 tháng
                                        </option>
                                        <option value="<?php echo e(\App\Models\Room::FOUR_MONTH_PERIOD); ?>">4 tháng
                                        </option>
                                        <option value="<?php echo e(\App\Models\Room::FIVE_MONTH_PERIOD); ?>">5 tháng
                                        </option>
                                        <option value="<?php echo e(\App\Models\Room::SIX_MONTH_PERIOD); ?>">6 tháng
                                        </option>
                                        <option value="<?php echo e(\App\Models\Room::ONE_YEAR_PERIOD); ?>">1 năm</option>

                                    </select>
                                </div>
                            </div>

                        </div>
                        <div class="row">

                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            <input type="hidden" name="type_rent" value="<?php echo e(\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">
                                        <?php for($i = 1; $i <=31; $i++): ?>
                                            <option <?php if(!empty($daycollect) && $daycollect == $i): ?> selected
                                                    <?php endif; ?> value="<?php echo e($i); ?>"><?php echo e($i); ?></option>
                                        <?php 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-->
                            <?php if(isset($reserve)): ?>
                                <input type="hidden" name="reserve_id" value="<?php echo e($reserve->id); ?>">
                            <?php endif; ?>

                            <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"
                                                   <?php if(isset($reserve)): ?> value="<?php echo e($reserve->phone); ?>" <?php endif; ?> 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"
                                                   <?php if(isset($reserve)): ?> value="<?php echo e($reserve->name); ?>" <?php endif; ?> 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"
                                                   <?php if(isset($reserve)): ?> value="<?php echo e($reserve->email); ?>" <?php endif; ?> 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(); ?>

                                                <?php $__currentLoopData = $provinces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $province): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($province->provinceid); ?>"><?php echo e($province->name); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </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"
                                                   <?php if(isset($reserve)): ?> value="<?php echo e($reserve->address); ?>" <?php endif; ?>>
                                        </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="<?php echo e(\App\Models\RenterRoom::RESIDENCE_NOT_DECLARE); ?>"
                                                        selected>
                                                    Chưa khai báo
                                                </option>
                                                <option value="<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>">
                                                    Tạm trú có thời hạn
                                                </option>
                                                <option value="<?php echo e(\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"
                                                   <?php if(isset($reserve)): ?> value="<?php echo e($reserve->id_number); ?>" <?php endif; ?> 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;
                    ?>

                    <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="<?php echo e($hostel->id); ?>"/>
                            <tbody id="table-hostel-fees">
                            <?php $__currentLoopData = $fees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td>

                                        <label class="mt-checkbox">
                                            <input type="checkbox" class="checkbox-contract-fee-c-contract"
                                                   name="fee-contracts[]"
                                                   value="<?php echo e($fee->id); ?>"> <span></span>
                                        </label>

                                    </td>
                                    <td> <?php echo e($fee->name); ?> </td>
                                    <td> <?php echo e($fee->type_text); ?> </td>
                                    <td>
                                        <?php 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
                                        <?php else: ?>
                                            <?php echo e(number_format($fee->fee, 0, '.', '.' )); ?>

                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo e($fee->unit); ?></td>
                                    <td>
                                        <?php 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[<?php echo e($fee->id); ?>][]"
                                                   value="1">
                                        <?php else: ?>
                                            <input type="number" class="form-control" disabled
                                                   value="0">
                                        <?php endif; ?>

                                    </td>
                                    <td>

                                        <?php 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">
                                        <?php else: ?>
                                            <?php $ew = \App\Components\Functions::getEwRoomContract($room);?>
                                            <?php if(in_array($fee->type, [
    \App\Models\HostelFee::ELECTRIC,
     \App\Models\HostelFee::ELECTRIC_BY_CLOCK,
])): ?>

                                            <input type="number" class="form-control" name="qty[<?php echo e($fee->id); ?>][]"
                                                   value="<?php echo e($ew['e']); ?>">

                                                <?php else: ?>
                                                <input type="number" class="form-control" name="qty[<?php echo e($fee->id); ?>][]"
                                                       value="<?php echo e($ew['w']); ?>">
                                                <?php endif; ?>
                                        <?php endif; ?>
                                    </td>

                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </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>