

<?php $__env->startSection('styles'); ?>
    <link href="/assets/global/plugins/fancybox/source/jquery.fancybox.css" rel="stylesheet" type="text/css"/>

    <link href="/assets/global/plugins/jquery-file-upload/blueimp-gallery/blueimp-gallery.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/jquery-file-upload/css/jquery.fileupload.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/jquery-file-upload/css/jquery.fileupload-ui.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-lightbox/lightbox.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-sweetalert/sweetalert.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
    <style>
        .br-theme-fontawesome-stars .br-widget {
            height: 28px;
            white-space: nowrap;
        }

        .br-theme-fontawesome-stars .br-widget a {
            font: normal normal normal 20px/1 FontAwesome;
            text-rendering: auto;
            -webkit-font-smoothing: antialiased;
            text-decoration: none;
            margin-right: 2px;
        }

        .br-theme-fontawesome-stars .br-widget a:after {
            content: '\f005';
            color: #d2d2d2;
        }

        .br-theme-fontawesome-stars .br-widget a.br-active:after {
            color: #EDB867;
        }

        .br-theme-fontawesome-stars .br-widget a.br-selected:after {
            color: #EDB867;
        }

        .br-theme-fontawesome-stars .br-widget .br-current-rating {
            display: none;
        }

        .br-theme-fontawesome-stars .br-readonly a {
            cursor: default;
        }

        @media  print {
            .br-theme-fontawesome-stars .br-widget a:after {
                content: '\f006';
                color: black;
            }

            .br-theme-fontawesome-stars .br-widget a.br-active:after,
            .br-theme-fontawesome-stars .br-widget a.br-selected:after {
                content: '\f005';
                color: black;
            }
        }

        .pac-container {
            z-index: 10052 !important;
        }

        #map {
            width: auto !important;
            height: 500px !important;
        }

        #map_edit {
            width: auto !important;
            height: 500px !important;
        }

        tfoot {
            display: table-header-group;
        }

        .dataTables_filter {
            display: none;
        }

        #orders-table_length {
            display: none;
        }

        .ws-nr {
            width: 100% !important;
        }

        #edit-hostel .modal-dialog {
            overflow-y: initial !important
        }

        #edit-hostel .modal-body {
            height: 800px;
            overflow-y: auto;
        }

        #add-hostel .modal-dialog {
            overflow-y: initial !important
        }

        #add-hostel .modal-body {
            height: 800px;
            overflow-y: auto;
        }

        #hostel-fee-config .modal-lg {
            width: 1200px;
        }

    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

    <?php echo $__env->make('admin.flash_message', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <div class="row"
         style="padding-bottom: 15px; margin-right: 0px; margin-left: 0px; padding-top: 15px; margin-bottom: 15px; border-bottom: 1px solid #e7ecf1; background-color: #EFF2F5">
        <div class="col-md-3">
            <div class="row">
                <div class="col-md-3 ">
                    <label class="control-label">Nhà</label>
                </div>
                <div class="col-md-9">
                    <select class="form-control" id="hostels">
                        <?php $__currentLoopData = $hostels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $hostel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option
                                    <?php if(request()->has('hostel')): ?>
                                    <?php if(request()->input('hostel') == $hostel->id): ?>
                                    selected
                                    <?php endif; ?>
                                    <?php else: ?>
                                    <?php if(isset($_COOKIE['room-hostel-id'])): ?> <?php if($_COOKIE['room-hostel-id'] == $hostel->id): ?> selected
                                    <?php endif; ?> <?php endif; ?>
                                    <?php endif; ?>

                                    value="<?php echo e($hostel->id); ?>"><?php echo e($hostel->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-md-9">

            <div class="row">
                <div class="col-md-12" id="hostels-button">

                </div>
            </div>
        </div>


    </div>
    <div class="row">
        <div class="col-md-12">
            <!-- BEGIN SAMPLE FORM PORTLET-->

            <div id="hostel-detail">

            </div>
        </div>
    </div>

    <div class="modal fade bs-modal-lg" id="detail-room" aria-hidden="true">
        <div class="modal-dialog modal-lg" style="width: 1000px !important">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title" id="title-detail-room">Chi tiết phòng</h4>
                </div>
                <div class="modal-body" id="detail-room-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


    <div class="modal fade bs-modal-lg" id="move-item-room" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title" id="title-detail-room">Chuyển tài sản</h4>
                </div>
                <div class="modal-body" id="move-item-room-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-move-item-room">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


    <div class="modal fade bs-modal-lg" id="rating" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Đánh giá người thuê trọ</h4>
                </div>
                <div class="modal-body" id="rating-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="save-rating">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>



    <div class="modal fade bs-modal-lg" id="import-hostel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Nhập dữ liệu nhà</h4>
                </div>
                <div class="modal-body" id="import-hostel-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="gen-invoice" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Sinh hóa đơn tự động</h4>
                </div>
                <div class="modal-body" id="gen-invoice-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-gen-invoice-all">Lưu</button>
                </div>

            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="detail-reserve" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Chi tiết thông tin giữ chỗ</h4>
                </div>
                <div class="modal-body" id="detail-reserve-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <?php if(auth('backend')->user()->can('edit-deposit')): ?>
                        <button type="button" class="btn green" id="btn-save-detail-reserve">Lưu</button>
                    <?php endif; ?>
                    <?php if(auth('backend')->user()->can('delete-deposit')): ?>
                        <button type="button" class="btn red" id="btn-delete-reserve">Xóa</button>
                    <?php endif; ?>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="back-reserve" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">
                        Trả lại tiền đặt cọc giữ chỗ
                    </h4>
                </div>
                <div class="modal-body" id="back-reserve-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn red" id="btn-delete-reserve-back">Xóa</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="update-money-info-modal" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">
                        Cập nhật thông tin hóa đơn
                    </h4>
                </div>
                <div class="modal-body" id="update-money-info-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn red" id="btn-save-money-info-update">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="reserve" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Giữ chỗ</h4>
                </div>
                <div class="modal-body" id="reserve-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-reserve">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>



    <div class="modal fade" id="add-item-room" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm tài sản vào phòng</h4>
                </div>
                <div class="modal-body" id="add-item-room-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-item-room">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


    <div class="modal fade" id="add-break-history" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm lịch sử sửa chữa</h4>
                </div>
                <div class="modal-body" id="add-break-history-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-break-history-room">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="edit-break" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cập nhật lịch sử sửa chữa</h4>
                </div>
                <div class="modal-body" id="edit-break-history-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-edit-break-history-room">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="extend-contract" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Gia hạn hợp đồng</h4>
                </div>
                <div class="modal-body" id="extend-contract-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-extend-contract">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="edit-renter" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cập nhật thông tin người thuê</h4>
                </div>
                <div class="modal-body" id="edit-renter-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                    <button type="button" class="btn green" id="btn-save-edit-renter">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="edit-hostel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cập nhật nhà</h4>
                </div>
                <div class="modal-body" id="edit-hostel-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-edit-hostel">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="edit-room" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cập nhật phòng</h4>
                </div>
                <div class="modal-body" id="edit-room-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-edit-room">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="room-type-config" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cấu hình loại phòng</h4>
                </div>
                <div class="modal-body" id="room-type-config-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-room-type-config">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal  bs-modal-lg fade" id="detail-history" aria-hidden="true" style="z-index: 999999">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Lịch sử thanh toán</h4>
                </div>
                <div class="modal-body" id="detail-history-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Đóng
                    </button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="hostel-fee-quota" aria-hidden="true" style="z-index: 99999">
        <div class="modal-dialog modal-full">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Điều chỉnh giá</h4>
                </div>
                <div class="modal-body" id="hostel-fee-quota-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-hostel-fee-quota">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="hostel-fee-config" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cấu hình bảng giá</h4>
                </div>
                <div class="modal-body" id="hostel-fee-config-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-hostel-fee-config">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="edit-hostel" aria-hidden="true">
        <div class="modal-dialog modal-full">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cập nhật nhà</h4>
                </div>
                <div class="modal-body" id="edit-hostel-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="save_fund">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="detail-room" aria-hidden="true">
        <div class="modal-dialog modal-full">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Chi tiết phòng</h4>
                </div>
                <div class="modal-body" id="detail-room-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="save_fund">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>



    <div class="modal fade bs-modal-lg" id="add-contract" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm hợp đồng</h4>
                </div>
                <div class="modal-body" id="add-contract-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-contract">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="add-contract-reserve" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm hợp đồng</h4>
                </div>
                <div class="modal-body" id="add-contract-reserve-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-contract">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="add-room" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm phòng</h4>
                </div>
                <div class="modal-body" id="add-room-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-room">Lưu</button>
                    <button type="button" class="btn green" id="btn-save-room-continue">Lưu và thêm phòng khác</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


    <div class="modal fade bs-modal-lg" id="add-room-excel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm phòng từ file excel</h4>
                </div>
                <div class="modal-body" id="add-room-excel-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-room-excel">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="ew" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Chốt số điện nước</h4>
                </div>
                <div class="modal-body" id="ew-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-ew-save">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        v
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="voucher" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content ">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title" id="voucher-title">Lập hóa đơn dịch vụ</h4>
                </div>
                <div class="modal-body" id="voucher-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-voucher-save">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="voucher-all" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content ">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title" id="voucher-title">Lập hóa đơn dịch vụ</h4>
                </div>
                <div class="modal-body" id="voucher-all-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-voucher-save-all">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


    <div class="modal fade bs-modal-lg" id="end-contract-money" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cần thanh toán các hóa đơn trước khi thanh lý hợp đồng</h4>
                </div>
                <div class="modal-body" id="end-contract-money-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="add-renter" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Thêm người phụ thuộc</h4>
                </div>
                <div class="modal-body" id="add-renter-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-add-renter-save">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


    <div class="modal fade bs-modal-lg" id="add-contract-attachment" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Tải lên tập tin</h4>
                </div>
                <div class="modal-body">

                    <div class="row">
                        <div class="col-md-12">
                            <form id="fileupload" action="<?php echo e(url('admin2/contract/upload-file')); ?>" method="POST"
                                  enctype="multipart/form-data">
                                <input type="hidden" name="contract_id" id="form-contract-id"/>
                                <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
                                <div class="row fileupload-buttonbar">
                                    <div class="col-lg-12">
                                        <!-- The fileinput-button span is used to style the file input field as button -->
                                        <span class="btn green fileinput-button">
                                                <i class="fa fa-plus"></i>
                                                <span> Thêm tập tin ... </span>
                                                <input type="file" name="files[]" multiple=""> </span>
                                        <button type="submit" class="btn blue start">
                                            <i class="fa fa-upload"></i>
                                            <span> Tải lên tất cả </span>
                                        </button>
                                        
                                        
                                        
                                        
                                        <button type="reset" class="btn warning cancel">
                                            <i class="fa fa-ban-circle"></i>
                                            <span> Hủy tải lên </span>
                                        </button>
                                        <button type="button" class="btn red delete">
                                            <i class="fa fa-trash"></i>
                                            <span> Xóa </span>
                                        </button>
                                        <input type="checkbox" class="toggle">
                                        <!-- The global file processing state -->
                                        <span class="fileupload-process"> </span>
                                    </div>
                                    <!-- The global progress information -->
                                    <div class="col-lg-5 fileupload-progress fade">
                                        <!-- The global progress bar -->
                                        <div class="progress progress-striped active" role="progressbar"
                                             aria-valuemin="0"
                                             aria-valuemax="100">
                                            <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                                        </div>
                                        <!-- The extended global progress information -->
                                        <div class="progress-extended"> &nbsp;</div>
                                    </div>
                                </div>
                                <!-- The table listing the files available for upload/download -->
                                <table role="presentation" class="table table-striped clearfix">
                                    <tbody class="files"></tbody>
                                </table>
                            </form>
                            <!-- The blueimp Gallery widget -->
                            <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls"
                                 data-filter=":even">
                                <div class="slides"></div>
                                <h3 class="title"></h3>
                                <a class="prev"> ‹ </a>
                                <a class="next"> › </a>
                                <a class="close white"> </a>
                                <a class="play-pause"> </a>
                                <ol class="indicator"></ol>
                            </div>
                            <!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
                            <script id="template-upload" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %}
                            <tr class="template-upload fade">
                                <td>
                                    <span class="preview"></span>
                                </td>
                                <td>
                                    <p class="name">{%=file.name%}</p>
                                    <strong class="error label label-danger"></strong>
                                </td>
                                <td>
                                    <p class="size">Đang xử lý...</p>
                                    <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                                        <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                                    </div>
                                </td>
                                <td> {% if (!i && !o.options.autoUpload) { %}
                                    <button class="btn blue start" disabled>
                                        <i class="fa fa-upload"></i>
                                        <span>Tải lên</span>
                                    </button> {% } %} {% if (!i) { %}
                                    <button class="btn red cancel">
                                        <i class="fa fa-ban"></i>
                                        <span>Hủy</span>
                                    </button> {% } %} </td>
                            </tr> {% } %}























































                            </script>
                            <!-- The template to display files available for download -->
                            <script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %}
                            <tr class="template-download fade">
                                <td>
                                    <span class="preview"> {% if (file.thumbnailUrl) { %}
                                        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery>
                                            <img style="max-width: 100px" src="{%=file.thumbnailUrl%}">
                                        </a> {% } %} </span>
                                </td>
                                <td>
                                    <p class="name"> {% if (file.url) { %}
                                        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl? 'data-gallery': ''%}>{%=file.name%}</a> {% } else { %}
                                        <span>{%=file.name%}</span> {% } %} </p> {% if (file.error) { %}
                                    <div>
                                        <span class="label label-danger">Error</span> {%=file.error%}</div> {% } %} </td>
                                <td>
                                    <span class="size">{%=o.formatFileSize(file.size)%}</span>
                                </td>
                                <td> {% if (file.deleteUrl) { %}
                                    <button class="btn red delete btn-sm" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}" {% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}' {% } %}>
                                        <i class="fa fa-trash-o"></i>
                                        <span>Xóa</span>
                                    </button>
                                    <input type="checkbox" name="delete" value="1" class="toggle"> {% } else { %}
                                    <button class="btn yellow cancel btn-sm">
                                        <i class="fa fa-ban"></i>
                                        <span>Hủy</span>
                                    </button> {% } %} </td>
                            </tr> {% } %}























































                            </script>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <h4>Danh sách tài liệu</h4>
                        </div>
                        <div class="col-md-12" id="contract-documents">
                        </div>
                    </div>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal">Đóng</button>
                </div>
            </div>

        </div>
        <!-- /.modal-content -->
    </div>

    <div class="modal fade" id="import-service" tabindex="-1" role="basic" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Import hóa đơn dịch vụ</h4>
                </div>

                <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">

                <div class="modal-body" id="import-service-content">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>Tháng </label>
                                <input type="text" class="form-control" placeholder="" id="month-sample"
                                       value="<?php echo e(\Carbon\Carbon::now()->format('m/Y')); ?>">
                            </div>
                        </div>
                    </div>
                    <a href="#" class="btn green-meadow"
                       id="download-sample-service">Tải file mẫu</a>

                    <form action="<?php echo e(url('admin/lead/excel')); ?>" method="post" id="form-import-service"
                          enctype="multipart/form-data">
                        <div class="form-group">
                            <label>Chọn file<span class="required" aria-required="true"> (*) </span></label>
                            <input type="file" id="nhap-mvd-input" name="file">
                            <p class="help-block"> (.xls, .xlsx) </p>
                            <input type="hidden" name="hostel" id="hostel-id-import">
                        </div>
                    </form>

                </div>
                <div class="modal-footer">

                    <button type="button" class="btn dark btn-outline" data-dismiss="modal">Đóng</button>
                    <button type="submit" class="btn green" id="btn-save-import-service">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>



    <div class="modal fade" id="import-contract" tabindex="-1" role="basic" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Import hợp đồng</h4>
                </div>

                <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">

                <div class="modal-body" id="import-contract-content">
                    <a href="#" class="btn green-meadow"
                       id="download-sample-contract">Tải file mẫu</a>

                    <form action="<?php echo e(url('admin/lead/excel')); ?>" method="post" id="form-import-contract"
                          enctype="multipart/form-data">
                        <div class="form-group">
                            <label>Chọn file<span class="required" aria-required="true"> (*) </span></label>
                            <input type="file" id="nhap-mvd-input" name="file">
                            <p class="help-block"> (.xls, .xlsx) </p>
                            <input type="hidden" name="hostel" id="hostel-id-import-contract">
                        </div>
                    </form>

                </div>
                <div class="modal-footer">

                    <button type="button" class="btn dark btn-outline" data-dismiss="modal">Đóng</button>
                    <button type="submit" class="btn green" id="btn-save-import-contract">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script src="/assets/global/plugins/amcharts/amcharts/amcharts.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amcharts/serial.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amcharts/pie.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amcharts/radar.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amcharts/themes/light.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amcharts/themes/patterns.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amcharts/themes/chalk.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/ammap/ammap.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/ammap/maps/js/worldLow.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/amcharts/amstockcharts/amstock.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-validation/js/additional-methods.min.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js" type="text/javascript"></script>


    <script src="/assets/global/plugins/fancybox/source/jquery.fancybox.pack.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/vendor/jquery.ui.widget.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/vendor/tmpl.min.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/vendor/load-image.min.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/vendor/canvas-to-blob.min.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/blueimp-gallery/jquery.blueimp-gallery.min.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.iframe-transport.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload-process.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload-image.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload-audio.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload-video.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload-validate.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-file-upload/js/jquery.fileupload-ui.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-lightbox/lightbox2.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/dropzone/dropzone.min.js" type="text/javascript"></script>
    <script src="/assets/pages/scripts/form-dropzone.min.js" type="text/javascript"></script>
    <script src="/assets/js/barrating.js" type="text/javascript"></script>


    <script type="text/javascript"
            src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCydLs7dhJPuozABFQjJO-uk1PITW18oo8&libraries=places&region=vi&language=vi&sensor=false"></script>
    <script type="text/javascript" src="/js/gmap.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
    <script>

        $(document).on('click', '[data-toggle-2="lightbox"]', function (event) {
            event.preventDefault();
            $(this).ekkoLightbox();
        });

        $(document).on('click', '.btn-rating-contract', function (e) {
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/renter/rating')); ?>',
                type: 'get',
                data: {
                    contract_id: $(this).attr('data-contract')
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#rating-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#rating-content').removeClass('ht-on-loading').html(response.data);
                }
            });
        });


        $(document).on('click', '#btn-save-gen-invoice-all', function (e) {
            e.preventDefault();
            var hostel_id = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/gen-invoice-all')); ?>',
                type: 'post',
                data: $('#form-gen-invoice').serialize(),
                dataType: 'json',
                success: function (response) {
                    swal('Thành công', 'Hệ thống đã tiến hành tạo hóa đơn. Xin vui lòng kiểm tra lại sau', 'success');
                }
            });


        });


        $(document).on('click', '#btn-gen-invoice-all', function (e) {
            e.preventDefault();
            var hostel_id = $(this).attr('data-hostel');
            $('#gen-invoice').modal('show');
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/gen-invoice-view')); ?>',
                type: 'get',
                data: {
                    hostel_id: hostel_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#gen-invoice-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#gen-invoice-content').removeClass('ht-on-loading').html(response.data);
                    $('#month-invoice').datepicker({
                        format: 'mm/yyyy',
                        autoclose: true,
                        viewMode: "months",
                        minViewMode: "months",
                    });
                }
            });

        });

        $(document).on('click', '#btn-import', function (e) {
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/import-view')); ?>',
                type: 'get',
                data: {
                    hostel_id: $(this).attr('data-hostel')
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#import-hostel-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#import-hostel-content').removeClass('ht-on-loading').html(response.data);
                    $('#month-sample').datepicker({
                        format: 'mm/yyyy',
                        autoclose: true,
                        viewMode: "months",
                        minViewMode: "months",
                    }).on('changeDate', function () {
                        var hostel_id = $('#btn-import-service').attr('data-hostel');
                        var url = '<?php echo e(url('admin2/hostel/download-sample-import-service')); ?>' + '/' + hostel_id + '?month=' + $('#month-sample').val();
                        $('#download-sample-service').attr('href', url);
                    });
                }
            });
        });

        $(document).on('click', '.btn-send-mail-contract', function (e) {
            e.preventDefault();
            var contract_id = $(this).attr('data-contract');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn gửi hợp đồng này tới khách hàng qua email ?",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/contract/send-mail')); ?>',
                            type: 'post',
                            data: {
                                contract_id: contract_id
                            },
                            dataType: 'json',
                            beforeSend: function () {
                                $('#detail-room-content').addClass('ht-on-loading');
                            },
                            success: function (response) {
                                $('#detail-room-content').removeClass('ht-on-loading').modal('hide');
                                swal('Thành công', 'Email đã được gửi đi', 'success');
                            }
                        });
                    }
                }
            });

        });


        $(document).on('click', '.btn-add-attach-contract', function (e) {
            $('#form-contract-id').val($(this).attr('data-contract'));

            $.ajax({
                url: '<?php echo e(url('admin2/contract/attachments')); ?>' + '/' + $(this).attr('data-contract'),
                type: 'get',
                beforeSend: function () {
                    $('#contract-documents').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#contract-documents').removeClass('ht-on-loading').html(response);
                }
            });

        });

        function delete_file(id, user_id) {
            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/contract/delete-file')); ?>' + '/' + id,
                            dataType: "json",
                            type: 'post',
                            context: $("#fileupload")[0],
                            beforeSend: function () {
                                $('#contract-documents').addClass('ht-on-loading');
                            },
                            success: function () {
                                $.ajax({
                                    url: '<?php echo e(url('admin2/contract/attachments')); ?>' + '/' + $('#form-contract-id').val(),
                                    type: 'get',
                                    beforeSend: function () {
                                        $('#contract-documents').addClass('ht-on-loading');
                                    },
                                    success: function (response) {
                                        $('#contract-documents').removeClass('ht-on-loading').html(response);
                                    }
                                });
                            }
                        });
                    }
                }
            });

        }

        var FormFileUpload = function () {
            return {
                init: function () {
                    var that = this;
                    $("#fileupload").fileupload({
                        disableImageResize: !1,
                        autoUpload: !1,
                        disableImageResize: /Android(?!.*Chrome)|Opera/.test(window.navigator.userAgent),
                        maxFileSize: 5e6,
                        acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx|txt)$/i,
                        done: function (e) {
                            var id = $('#form-contract-id').val();
                            $('.template-upload').remove();

                            $.ajax({
                                url: '<?php echo e(url('admin2/contract/attachments')); ?>' + '/' + id,
                                type: 'get',
                                beforeSend: function () {
                                    $('#contract-documents').addClass('ht-on-loading');
                                },
                                success: function (response) {
                                    $('#contract-documents').removeClass('ht-on-loading').html(response);
                                }
                            });


                        }
                    }), $("#fileupload").fileupload("option", "redirect", window.location.href.replace(/\/[^\/]*$/, "/cors/result.html?%s")), $.support.cors && $.ajax({
                        type: "HEAD"
                    }).fail(function () {
                        $('<div class="alert alert-danger"/>').text("Upload server currently unavailable - " + new Date).appendTo("#fileupload")
                    }), $("#fileupload").addClass("fileupload-processing"), $.ajax({
                        url: $("#fileupload").attr("action"),
                        dataType: "json",
                        context: $("#fileupload")[0],
                    }).always(function () {
                        $(this).removeClass("fileupload-processing");


                    }).done(function (e) {

                        $(this).fileupload("option", "done").call(this, $.Event("done"), {
                            result: e
                        })
                    })
                }
            }
        }();
        jQuery(document).ready(function () {
            FormFileUpload.init()
        });

        $.validator.addMethod("checkPhone",
            function (value, element, param) {
                var flag = false;
                var phone = value; // ID của trường Số điện thoại
                phone = phone.replace('(+84)', '0');
                phone = phone.replace('+84', '0');
                phone = phone.replace('0084', '0');
                phone = phone.replace(/ /g, '');
                if (phone != '') {
                    var firstNumber = phone.substring(0, 2);
                    if ((firstNumber == '09' || firstNumber == '08' || firstNumber == '03') && phone.length == 10) {
                        if (phone.match(/^\d{10}/)) {
                            flag = true;
                        }
                    } else if (firstNumber == '01' && phone.length == 11) {
                        if (phone.match(/^\d{11}/)) {
                            flag = true;
                        }
                    }
                }
                return flag;
            }
        );
    </script>
    <script>

        $(document).on('click', '.btn-delete-room-item', function () {
            var id = $(this).attr('data-id');
            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa tài sản này khỏi phòng",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {

                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete-item')); ?>',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                id: id,
                            },
                            success: function (response) {
                                if (response.status == 1) {
                                    swal('Thành công', 'Tài sản đã được xóa khỏi phòng', 'success');
                                    item_table.ajax.reload();
                                }
                            }
                        });
                    }
                }
            });
        });

        $(document).on('click', '.btn-move-room-item', function () {
            var id = $(this).attr('data-id');
            var room_id = $(this).attr('data-room');
            $.ajax({
                url: '<?php echo e(url('admin2/room/move-item')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    id: id,
                    room_id: room_id
                },
                beforeSend: function () {
                    $('#move-item-room-content').addClass('ht-on-loading');
                    $('#move-item-room').modal('show');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#move-item-room-content').removeClass('ht-on-loading').html(response.data);
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });

        $(document).on('click', '#btn-save-move-item-room', function () {
            var data = $('#form-move-item-room').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/move-item')); ?>',
                type: 'post',
                dataType: 'json',
                data: data,
                beforeSend: function () {
                    $('#move-item-room-content').addClass('ht-on-loading');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#move-item-room-content').removeClass('ht-on-loading');

                        $('#move-item-room').modal('hide');
                        swal('Thành công', 'Tài sản đã được thêm vào phòng', 'success');
                        item_table.ajax.reload();
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });


        $(document).on('click', '#btn-save-item-room', function () {
            var data = $('#form-add-item-room').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/add-item')); ?>',
                type: 'post',
                dataType: 'json',
                data: data,
                beforeSend: function () {
                    $('#add-item-room-content').addClass('ht-on-loading');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-item-room-content').removeClass('ht-on-loading');

                        $('#add-item-room').modal('hide');
                        swal('Thành công', 'Tài sản đã được thêm vào phòng', 'success');
                        item_table.ajax.reload();
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });

        $(document).on('click', '.btn-edit-room-break', function () {

            var id = $(this).attr('data-id');
            $.ajax({
                url: '<?php echo e(url('admin2/room/edit-break-history')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    id: id
                },
                beforeSend: function () {
                    $('#edit-break-history-content').addClass('ht-on-loading');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#edit-break-history-content').removeClass('ht-on-loading').html(response.data);
                        $('.select2').select2();
                        $('.date-picker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true
                        });
                        Dropzone.autoDiscover = false;
                        $('#edit-dropzone-break').dropzone({
                            url: '<?php echo e(url('admin2/room/upload-image-break')); ?>',
                            dictDefaultMessage: "",
                            init: function () {
                                this.on("success", function (file, response) {
                                    var name = string_to_slug(file.name);
                                    $('#edit_break_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                                }).on("addedfile", function (e) {
                                    var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                        t = this;
                                    n.addEventListener("click", function (n) {
                                        n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                                    }), e.previewElement.appendChild(n)
                                }).on("removedfile", function (file) {
                                    var name = string_to_slug(file.name);
                                    $('#' + name).remove();
                                })


                            },
                            acceptedFiles: 'image/*',
                            headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                        });
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });


        $(document).on('click', '.money-info-email', function () {
            var money_info_id = $(this).attr('data-money-info');
            $.ajax({
                url: '<?php echo e(url('admin2/money/send-mail-money-info')); ?>',
                type: 'post',
                dataType: 'json',
                data: {
                    money_info_id: money_info_id
                },
                success: function (response) {
                    if (response.status == 1) {
                        swal('Thành công', 'Email đã được gửi. Vui lòng kiểm tra hòm thư spam nếu không thấy trong hộp thư đến', 'success');
                    }
                }
            });
        });

        $(document).on('click', '.money-info-message', function () {
            var money_info_id = $(this).attr('data-money-info');
            $.ajax({
                url: '<?php echo e(url('admin2/money/send-message-money-info')); ?>',
                type: 'post',
                dataType: 'json',
                data: {
                    money_info_id: money_info_id
                },
                success: function (response) {
                    if (response.status == 1) {
                        window.open('<?php echo e(url('chat')); ?>', '_blank');
                    }
                }
            });
        });

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

        $(document).on('click', '#save-rating', function () {
            var data = $('#form-add-rating').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/renter/rating')); ?>',
                type: 'post',
                dataType: 'json',
                data: data,
                beforeSend: function () {
                    $('#rating-content').addClass('ht-on-loading');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#rating-content').removeClass('ht-on-loading');
                        $('#rating').modal('hide');
                        swal('Thành công', 'Thông tin đánh giá đã được lưu lại', 'success');
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });

        $(document).on('click', '#btn-add-item-room', function () {
            var room_id = $(this).attr('data-room');
            $.ajax({
                url: '<?php echo e(url('admin2/room/add-item')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    room_id: room_id
                },
                beforeSend: function () {
                    $('#add-item-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-item-room-content').removeClass('ht-on-loading').html(response.data);
                        $('.select2').select2();
                    }
                }
            });
        });

        $(document).on('click', '.set-empty', function (e) {
            e.preventDefault();
            $(this).parent().parent().find('input').val('');
        });

        $(document).on('click', '#btn-add-break-history-room', function () {
            var room_id = $(this).attr('data-room');
            $.ajax({
                url: '<?php echo e(url('admin2/room/add-break-history')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    room_id: room_id
                },
                beforeSend: function () {
                    $('#add-break-history-content').addClass('ht-on-loading');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-break-history-content').removeClass('ht-on-loading').html(response.data);
                        $('.select2').select2();
                        $('.date-picker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true
                        });
                        Dropzone.autoDiscover = false;
                        $('#dropzone-break').dropzone({
                            url: '<?php echo e(url('admin2/room/upload-image-break')); ?>',
                            dictDefaultMessage: "",
                            init: function () {
                                this.on("success", function (file, response) {
                                    var name = string_to_slug(file.name);
                                    $('#break_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                                }).on("addedfile", function (e) {
                                    var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                        t = this;
                                    n.addEventListener("click", function (n) {
                                        n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                                    }), e.previewElement.appendChild(n)
                                }).on("removedfile", function (file) {
                                    var name = string_to_slug(file.name);
                                    $('#' + name).remove();
                                })


                            },
                            acceptedFiles: 'image/*',
                            headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                        });
                    }
                }
            });
        });
        $(document).on('click', '#btn-print-all-unpaid', function (e) {
            e.preventDefault();
            var hostel_id = $(this).attr('data-hostel');
            window.open('<?php echo e(url('admin2/money/print-all-unpaid-contract-by-hostel/')); ?>' + '/' + hostel_id, "_blank");
        });

        $(document).on('click', '#btn-import-service', function (e) {
            e.preventDefault();
            $('#import-service').modal('show');
            var hostel_id = $(this).attr('data-hostel');
            var url = '<?php echo e(url('admin2/hostel/download-sample-import-service')); ?>' + '/' + hostel_id + '?month=' + $('#month-sample').val();
            $('#download-sample-service').attr('href', url);

            $('#hostel-id-import').val(hostel_id);
        });

        $(document).on('click', '#btn-import-contract', function (e) {
            e.preventDefault();
            $('#import-contract').modal('show');
            var hostel_id = $(this).attr('data-hostel');
            var url = '<?php echo e(url('admin2/hostel/download-sample-import-contract')); ?>' + '/' + hostel_id;
            $('#download-sample-contract').attr('href', url);

            $('#hostel-id-import-contract').val(hostel_id);
        });

        $(document).on('click', '#btn-send-all-unpaid', function (e) {
            e.preventDefault();
            var hostel_id = $(this).attr('data-hostel');
            $.confirm({
                title: 'Gửi hóa đơn!',
                content: 'Gửi hóa đơn chưa thanh toán của nhà.',
                buttons: {
                    confirm: {
                        text: 'Xác nhận',
                        btnClass: 'btn-green',
                        action: function () {
                            $.ajax({
                                url: '<?php echo e(url('admin2/money/send-all-unpaid-by-hostel')); ?>',
                                type: 'get',
                                data: {'hostel_id': hostel_id},
                                dataType: 'json',
                                success: function (response) {
                                    if (response.status == 1) {
                                        swal('Thông báo', response.message, 'success');
                                    }
                                }
                            });
                        }
                    },
                    showList: {
                        text: 'Xem danh sách',
                        btnClass: 'btn-blue',
                        keys: ['enter', 'shift'],
                        action: function () {
                            $.ajax({
                                url: '<?php echo e(url('admin2/money/list-all-unpaid-by-hostel')); ?>',
                                type: 'get',
                                data: {'hostel_id': hostel_id},
                                dataType: 'json',
                                success: function (response) {
                                    if (response.status == 1) {
                                        window.open(response.data);
                                        //swal('Thông báo', response.message, 'success');
                                    }
                                }
                            });
                        }
                    },
                    cancel: {
                        text: 'Hủy',
                    },
                }
            });

        });

        $(document).on('click', '#btn-add-room-excel', function () {
            var hostel_id = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/room/add-room-excel')); ?>',
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#add-room-excel-content').addClass('ht-on-loading');

                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-room-excel-content').removeClass('ht-on-loading').html(response.data);
                        $('#add-room-excel-hostel').val(hostel_id);
                    }
                }
            });
        });


        $(document).on('click', '.floor-detail', function (e) {
            $('.floor-detail').removeClass('active');
            $(this).addClass('active');
        });

        $.validator.addMethod("greaterThan",
            function (value, element, param) {
                var $otherElement = $(param);
                return parseInt(value, 10) >= parseInt($otherElement.val(), 10);
            }
        );

        var roomId = '';
        var hostelId = '';
        var blockGlobalName = '';
        var map;
        var table;
        var cur_lat = null;
        var cur_lng = null;


        $(document).on('click', '.btn-detail-contract', function (e) {
            var id_contract = $(this).attr('data-contract');
            roomId = $(this).attr('data-room');
            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-room')); ?>' + '/' + roomId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#detail-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#detail-room-content').removeClass('ht-on-loading').html(response.data);
                    $('#title-detail-room').text(response.name);
                    $.ajax({
                        url: '<?php echo e(url('admin2/room/contracts')); ?>' + '/' + roomId,
                        type: 'get',
                        data: {
                            contract_id: id_contract,
                        },
                        dataType: 'json',
                        beforeSend: function () {
                            $('#tab_1_5').addClass('ht-on-loading');
                        },
                        success: function (response) {
                            $("#tabs").find('li').removeClass('active');
                            $("#tabs").find('li').first().next().next().next().addClass('active');
                            $('.tab-content').find('.tab-pane').removeClass('active in');
                            $('.tab-content').find('.tab-pane').first().next().next().next().next().addClass('active in');
                            $('#tab_1_5').removeClass('ht-on-loading').html(response.data);
                            $('.monthpicker').datepicker({
                                format: 'mm/yyyy',
                                autoclose: true,
                                viewMode: "months",
                                minViewMode: "months",
                            });
                        }
                    });
                }
            });
        });


        $(document).on('change', '#item_type_id', function (e) {
            var item_type = $(this).val();
            var warehouse_id = $('#warehouse_id').val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/select-item')); ?>',
                type: 'get',
                data: {
                    item_type: item_type,
                    room_id: roomId,
                    warehouse_id: warehouse_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#add-item-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-item-room-content').removeClass('ht-on-loading');
                        $('[name="item_id[]"]').html(response.data);
                    }
                }
            });
        });

        $(document).on('change', '#warehouse_id', function (e) {
            var warehouse_id = $(this).val();
            var item_type = $('#item_type_id').val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/select-item')); ?>',
                type: 'get',
                data: {
                    item_type: item_type,
                    room_id: roomId,
                    warehouse_id: warehouse_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#add-item-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-item-room-content').removeClass('ht-on-loading');
                        $('[name="item_id[]"]').html(response.data);
                    }
                }
            });
        });


        $(document).on('change', '#renter-voucher', function (e) {
            var renter_id = $(this).val();
            var room_id = $(this).attr('data-room');
            var month = $('#month-voucher').val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-renter-fee')); ?>',
                type: 'get',
                data: {
                    renter_id: renter_id,
                    room_id: room_id,
                    month: month
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-body').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#voucher-body').removeClass('ht-on-loading').html(response.data);
                    } else {
                        $('#voucher-body').removeClass('ht-on-loading').html('');
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });
        });

        $(document).on('change', '#month-voucher', function (e) {
            e.preventDefault();

            var renter_id = $('#renter-voucher').val();
            var room_id = $('#renter-voucher').attr('data-room');
            var month = $(this).val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-renter-fee')); ?>',
                type: 'get',
                data: {
                    renter_id: renter_id,
                    room_id: room_id,
                    month: month
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-body').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#voucher-body').removeClass('ht-on-loading').html(response.data);
                    } else {
                        $('#voucher-body').removeClass('ht-on-loading').html('');
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });

        });

        $(document).on('click', '#btn-save-extend-contract', function (e) {
            e.preventDefault();
            var data = $('#form-extend-contract').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/extend-contract')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#extend-contract-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#extend-contract-content').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        swal('Thành công', 'Thông tin đã được lưu lại', 'success');
                        $('#extend-contract').modal('hide');
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });
        });


        $(document).on('click', '#btn-save-break-history-room', function (e) {
            e.preventDefault();
            var data = $('#form-add-break-room').serialize();

            var formStatus = $('#form-add-break-room').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'content': "required",
                },
                messages: {
                    'content': "Không được bỏ trống nội dung",
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {

                $.ajax({
                    url: '<?php echo e(url('admin2/room/create-break-history')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    beforeSend: function () {
                        $('#add-break-history-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#add-break-history-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thành công', 'Dữ liệu được thêm thành công', 'success');
                            $('#add-break-history').modal('hide');


                            fix_table.ajax.reload();
                        } else if (response.status == 0) {
                            swal('Thông báo', response.message, 'warning');
                        } else if (response.status == 2) {
                            swal('Thông báo', response.message, 'info');
                        }
                    }
                });
            }
        });

        $(document).on('click', '#btn-save-room-continue', function (e) {
            e.preventDefault();
            var data = $('#form-add-room').serialize();

            var formStatus = $('#form-add-room').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'type': "required",
                    'name': "required",
                    //  'amenities[]': "required",
                    'size': {
                        required: true,
                        number: true
                    },
                    'block_name': {
                        required: true,
                    },
                    'max_renters': {
                        required: true,
                        number: true
                    },
                    'price': {
                        required: true,
                    }
                },
                messages: {
                    'type': "Không được bỏ trống loại phòng",
                    'name': "Không được bỏ trống tên",
                    'size': "Không được bỏ trống diện tích",
                    'width': "Không được bỏ trống chiều rộng",
                    'block_name': "Không được bỏ trống tầng / khu / dãy",
                    'max_renters': "Không được bỏ trống số người tối đa",
                    'price': {
                        required: "Không được bỏ trống giá",
                    }
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {

                $.ajax({
                    url: '<?php echo e(url('admin2/room/create')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    beforeSend: function () {
                        $('#add-room-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#add-room-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            var hostel_id = response.hostel_id;
                            swal('Thành công', 'phòng của bạn đã được lưu lại', 'success');
                            $('#hostels').trigger('change');
                            $('button[data-block-name="' + blockGlobalName + '"]').click();
                            $.ajax({
                                url: '<?php echo e(url('admin2/room/create')); ?>',
                                type: 'get',
                                data: {
                                    hostel_id: hostel_id,
                                },
                                dataType: 'json',
                                beforeSend: function () {
                                    $('#add-room-content').addClass('ht-on-loading');
                                },
                                success: function (response) {
                                    $('#add-room-content').removeClass('ht-on-loading').html(response.data);
                                    $('#add-room-type').trigger('change');
                                    $('datepicker').datepicker({
                                        format: 'dd/mm/yyyy',
                                        autoclose: true
                                    });
                                }
                            });
                        } else if (response.status == 0) {
                            swal('Thông báo', response.message, 'warning');
                        } else if (response.status == 2) {
                            swal('Thông báo', response.message, 'info');
                        }
                    }
                });
            }
        });

        $(document).on('click', '#btn-save-room', function (e) {
            e.preventDefault();

            var formStatus = $('#form-add-room').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'type': "required",
                    'name': "required",
                    //  'amenities[]': "required",
                    'size': {
                        required: true,
                        number: true
                    },
                    'block_name': {
                        required: true,
                    },
                    'max_renters': {
                        required: true,
                        number: true
                    },
                    'price': {
                        required: true,
                    }
                },
                messages: {
                    'type': "Không được bỏ trống loại phòng",
                    'name': "Không được bỏ trống tên",
                    'size': "Không được bỏ trống diện tích",
                    'block_name': "Không được bỏ trống tầng / khu / dãy",
                    'max_renters': "Không được bỏ trống số người tối đa",
                    'price': {
                        required: "Không được bỏ trống giá",
                    }
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {

                var data = new FormData($('#form-add-room')[0]);
                $.ajax({
                    url: '<?php echo e(url('admin2/room/create')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    processData: false,
                    contentType: false,
                    beforeSend: function () {
                        $('#add-room-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#add-room-content').removeClass('ht-on-loading');
                        $('#add-room').modal('hide');
                        if (response.status == 1) {
                            swal('Thành công', 'phòng của bạn đã được lưu lại', 'success');
                            $('#hostels').trigger('change');
                            $('button[data-block-name="' + blockGlobalName + '"]').click();
                        } else if (response.status == 0) {
                            swal('Thông báo', response.message, 'warning');
                        } else if (response.status == 2) {
                            swal('Thông báo', response.message, 'info');
                        }
                    }
                });
            }
        });

        $(document).on('click', '.btn-detail-reserve', function (e) {
            e.preventDefault();
            var reserve_id = $(this).attr('data-reserve');
            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-reserve')); ?>',
                type: 'get',
                data: {
                    reserve_id: reserve_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#detail-reserve-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#detail-reserve-content').removeClass('ht-on-loading').html(response.data);
                }
            });
        });

        $(document).on('click', '#btn-add-renter-save', function (e) {
            e.preventDefault();


            var formStatus = $('#form-add-renter').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'name': "required",
                    //  'amenities[]': "required",
                    'phone': {
                        required: true,
                        //  checkPhone: true
                    },
                    // 'date_join': {
                    //     required: true,
                    // },
                    // 'residence_status': {
                    //     required: true,
                    // },
                },
                messages: {
                    'name': "Không được bỏ trống tên",
                    'phone': {
                        'required': "Không được bỏ trống SĐT",
                        // 'checkPhone': "Số điện thoại phải đúng định dạng"
                    },
                    //'date_join': "Không được bỏ trống ngày vào",
                    //'residence_status': "Không được bỏ trống khai báo tạm trú",
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            var form = $('#form-add-renter')[0];
            var data = new FormData(form);

            if (formStatus) {

                $.ajax({
                    url: '<?php echo e(url('admin2/room/create-renter')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    cache: false,
                    contentType: false,
                    processData: false,
                    beforeSend: function () {
                        $('#add-renter-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#add-renter-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thành công', 'Dữ liệu của bạn đã được lưu lại', 'success');
                            $('#add-renter').modal('hide');
                            $('#tabs').find('li.active > a').click();
                        }
                    }
                });
            }
        });


        $(document).on('click', '#btn-save-edit-break-history-room', function (e) {
            e.preventDefault();

            var formStatus = $('#form-edit-break-room').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'content': "required",
                },
                messages: {
                    'content': "Không được bỏ trống nội dung",
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {

                var data = $('#form-edit-break-room').serialize();
                $.ajax({
                    url: '<?php echo e(url('admin2/room/edit-break')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    beforeSend: function () {
                        $('#edit-break-history-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#edit-break-history-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thành công', 'Thông tin đã được lưu lại', 'success');
                            fix_table.ajax.reload();
                            $('#edit-break').modal('hide');
                        } else {
                            swal('Thông báo', response.message, 'warning');
                        }
                    }
                });
            }
        });

        $(document).on('click', '#btn-save-edit-room', function (e) {
            e.preventDefault();

            var formStatus = $('#form-edit-room').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'type': "required",
                    'name': "required",
                    //  'amenities[]': "required",
                    'size': {
                        required: true,
                        number: true
                    },
                    'block_name': {
                        required: true,
                    },
                    'max_renters': {
                        required: true,
                        number: true
                    },
                    'price': {
                        required: true,
                        //  number: true
                    }
                },
                messages: {
                    'type': "Không được bỏ trống loại phòng",
                    'name': "Không được bỏ trống tên",
                    'size': "Không được bỏ trống diện tích",
                    'block_name': "Không được bỏ trống tầng / khu / dãy",
                    'max_renters': "Không được bỏ trống số người tối đa",
                    'price': {
                        required: "Không được bỏ trống giá",
                    }
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {

                var data = new FormData($('#form-edit-room')[0]);
                $.ajax({
                    url: '<?php echo e(url('admin2/room/edit')); ?>' + '/' + roomId,
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    processData: false,
                    contentType: false,
                    beforeSend: function () {
                        $('#edit-room-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#edit-room-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thành công', 'phòng của bạn đã được lưu lại', 'success');
                            $('button[data-block-name="' + blockGlobalName + '"]').click();
                            $('#edit-room').modal('hide');
                        } else {
                            swal('Thông báo', response.message, 'warning');
                        }
                    }
                });
            }
        });


        $('#btn-save-edit-hostel').click(function (e) {
            e.preventDefault();

            var formStatus = $('#form-edit-hostel').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'type': "required",
                    'name': "required",
                    //  'amenities[]': "required",
                    'type_rent': {
                        required: true,
                        number: true
                    },
                    'address': {
                        required: true,
                    },
                    'province_id': {
                        required: true,
                    },
                    'district_id': {
                        required: true,
                    },
                    'ward_id': {
                        required: true,
                    },
                    'owner_name': {
                        required: true,
                    },
                    'owner_id_number': {
                        required: true,
                    },
                    'owner_phone': {
                        required: true,
                    },
                    'owner_email': {
                        email: true,
                    },
                    'date_ew': {
                        required: true,
                    },
                    'date_money': {
                        required: true,
                        //greaterThan: '#edit-hostel-date-ew'
                    },
                },
                messages: {
                    'type': "Không được bỏ trống Loại nhà",
                    'name': "Không được bỏ trống tên",
                    'type_rent': "Không được bỏ trống loại cho thuê",
                    'address': "Không được bỏ trống địa chỉ",
                    'province_id': "Không được bỏ trống tỉnh / thành phố",
                    'district_id': "Không được bỏ trống quận / huyện",
                    'ward_id': "Không được bỏ trống phường / xã",
                    'owner_name': "Không được bỏ trống tên chủ sở hữu",
                    'owner_id_number': "Không được bỏ trống cmnd chủ sở hữu",
                    'owner_phone': "Không được bỏ trống SDT chủ sở hữu",

                    'owner_email': {
                        "email": "Email phải đúng định dạng"
                    },
                    'date_ew': "Không được bỏ trống ngày chốt điện nước",
                    'date_money': {
                        required: "Không được bỏ trống ngày chốt sổ, tính phí",
                        //greaterThan: "Ngày chốt sổ phải lớn hơn ngày chốt điện nước"
                    }
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {
                var data = new FormData($('#form-edit-hostel')[0]);
                var ck = $('#form-edit-hostel').find('[name="desc"]').val();
                data.append('desc', ck);
                $.ajax({
                    url: '<?php echo e(url('admin2/hostel/edit')); ?>' + '/' + hostelId,
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    processData: false,
                    contentType: false,
                    beforeSend: function () {
                        $('#edit-hostel-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#edit-hostel-content').removeClass('ht-on-loading');
                        //    $('#')

                        if (response.status == 1) {
                            swal('Thành công', 'Thông tin được lưu thành công', 'success');
                            $('#hostel-table-info').html(response.info);
                            $('#edit-hostel').modal('hide');
                        } else {
                            swal('Thông báo', response.message, 'warning');
                        }

                    }
                });
            }
        });

        $(document).ready(function () {
            var hostelId = $('#hostels').val();

            $.ajax({
                url: '<?php echo e(url('admin2/hostel/detail-hostel-room')); ?>' + '/' + hostelId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#hostel-detail').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#hostel-detail').removeClass('ht-on-loading').html(response.data);
                    $('#hostels-button').html(response.buttons);
                    $('#floor-rooms').find('button').first().click();
                    var chart = AmCharts.makeChart("pie-room", {
                        "hideCredits": true,
                        "type": "pie",
                        "theme": "dark",
                        "dataProvider": response.chart_room,
                        "colorField": "color",
                        "valueField": "value",
                        "titleField": "name",
                        "titles": [
                            {
                                "text": "Tỷ lệ đầy phòng",
                                "size": 15
                            }
                        ],
                        //"labelsEnabled": false,
                        autoMargins: false,
                        marginTop: 0,
                        marginBottom: 0,
                        marginLeft: 0,
                        marginRight: 0,
                        pullOutRadius: 0,
                        radius: 80
//                    "balloon": {
//                        "fixedPosition": true
//                    },
//                    "export": {
//                        "enabled": true
//                    }
                    });

                    var chart2 = AmCharts.makeChart("pie-payment", {
                        "hideCredits": true,
                        "type": "pie",
                        "theme": "dark",
                        "dataProvider": response.chart_payment,
                        "colorField": "color",
                        "valueField": "value",
                        "titleField": "name",
                        "titles": [
                            {
                                "text": "Tỷ lệ thanh toán",
                                "size": 15
                            }
                        ],
                        //"labelsEnabled": false,
                        autoMargins: false,
                        marginTop: 0,
                        marginBottom: 0,
                        marginLeft: 0,
                        marginRight: 0,
                        pullOutRadius: 0,
                        radius: 80
                        //    pullOutRadius: '12%',
//                    "balloon": {
//                        "fixedPosition": true
//                    },
//                    "export": {
//                        "enabled": true
//                    }
                    });
                }
            });
        });

        $('.btn-detail-room').click(function () {
            $('#detail-room-content').addClass('ht-on-loading');
        });

        $('#btn-edit-room').click(function () {
            $('#edit-room-content').addClass('ht-on-loading');
        });

        $(document).on('click', '.btn-delete-amenity', function (e) {
            e.preventDefault();
            $(this).parent().parent().parent().remove();
        });

        function getPaymentEndContractStat(is_return_deposit, is_return_money_info) {
            $.ajax({
                url: '<?php echo e(url('admin2/room/payment-end-contract-stat')); ?>',
                type: 'get',
                data: {
                    contract_id: contractId,
                    end_contract_date: $('#date-end-contract').val(),
                    is_return_deposit: is_return_deposit,
                    is_return_money_info: is_return_money_info,
                    amount_return_deposit: $('#amount_return_deposit').val()
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#payment-end-contract').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#payment-end-contract').removeClass('ht-on-loading').html(response.data);
                    } else {
                        swal('Thông báo', response.message, 'warning');
                        $('#payment-end-contract').removeClass('ht-on-loading');
                    }
                }
            });
        }

        $(document).on('change', '#return-deposit, #return-money-info', function (e) {
            var is_return_deposit = 0;
            var is_return_money_info = 0;

            if ($('#return-deposit').is(":checked")) {
                is_return_deposit = 1;
            }

            if ($('#return-money-info').is(":checked")) {
                is_return_money_info = 1;
            }

            getPaymentEndContractStat(is_return_deposit, is_return_money_info);
        });

        $(document).on('blur', '#amount_return_deposit', function (e) {
            var is_return_deposit = 0;
            var is_return_money_info = 0;

            if ($('#return-deposit').is(":checked")) {
                is_return_deposit = 1;
            }

            if ($('#return-money-info').is(":checked")) {
                is_return_money_info = 1;
            }

            getPaymentEndContractStat(is_return_deposit, is_return_money_info);
        });


        $(document).on('click', '.btn-end-contract', function (e) {

            e.preventDefault();

            contractId = $(this).attr('data-contract');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn thanh lý hợp đồng này",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {

                        $.ajax({
                            url: '<?php echo e(url('admin2/room/check-ew')); ?>',
                            type: 'get',
                            dataType: 'json',
                            data: {
                                contract_id: contractId
                            },
                            success: function (response) {

                                if (response.data == 0) {
                                    bootbox.confirm({
                                        message: response.message,
                                        buttons: {
                                            confirm: {
                                                label: 'Có',
                                                className: 'btn-success'
                                            },
                                            cancel: {
                                                label: 'Không',
                                                className: 'btn-danger'
                                            }
                                        },

                                        callback: function (result) {
                                            if (result == true) {
                                                window.location.href = '<?php echo e(url('admin2/ew')); ?>';
                                            } else {
                                                end_contract_payment(contractId);
                                            }
                                        }
                                    });
                                } else {
                                    end_contract_payment(contractId);
                                }
                            }
                        });


                    }
                }
            });

        });

        function end_contract_payment(contractId) {
            $.ajax({
                url: '<?php echo e(url('admin2/room/end-contract')); ?>' + '/' + contractId,
                type: 'post',
                dataType: 'json',
                cache: false,
                beforeSend: function () {
                    $('#contract-items').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#contract-items').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        swal('Thành công', 'Hợp đồng đã được thanh lý', 'success');
                        rating(contractId);
                        $('#tabs').find('li.active > a').click();
                        $('button[data-block-name="' + blockGlobalName + '"]').click();
                    } else if (response.status == 2) {
                        $('#end-contract-money').modal('show');
                        $('#end-contract-money-content').html(response.data);
                        $('#date-end-contract').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true

                        }).on('changeDate', function (e) {

                            var is_return_deposit = 0;
                            var is_return_money_info = 0;

                            if ($('#return-deposit').is(":checked")) {
                                is_return_deposit = 1;
                            }

                            if ($('#return-money-info').is(":checked")) {
                                is_return_money_info = 1;
                            }

                            $.ajax({
                                url: '<?php echo e(url('admin2/room/payment-end-contract-stat')); ?>',
                                type: 'get',
                                data: {
                                    contract_id: contractId,
                                    end_contract_date: e.format(),
                                    is_return_deposit: is_return_deposit,
                                    is_return_money_info: is_return_money_info
                                },
                                dataType: 'json',
                                beforeSend: function () {
                                    $('#payment-end-contract').addClass('ht-on-loading');
                                },
                                success: function (response) {
                                    if (response.status == 1) {
                                        $('#payment-end-contract').removeClass('ht-on-loading').html(response.data);
                                    } else {
                                        swal('Thông báo', response.message, 'warning');
                                    }
                                }
                            });
                        });
                    }
                }

            });
        }

        $(document).on('click', '#btn-add-edit-image-hostel', function (e) {
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-image-room')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#hostel_images_list').append(response.data);
                    $('.dropzone').dropzone({
                        url: '<?php echo e(url('admin2/room/upload-image')); ?>',
                        dictDefaultMessage: "",
                        dictMaxFilesExceeded: 'Bạn chỉ được tải lên 1 file',
                        init: function () {
                            this.on("success", function (file, response) {
                                var name = string_to_slug(file.name);
                                $('#room_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                            }).on("addedfile", function (e) {
                                var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                    t = this;
                                n.addEventListener("click", function (n) {
                                    n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                                }), e.previewElement.appendChild(n)
                            }).on("removedfile", function (file) {
                                var name = string_to_slug(file.name);
                                $('#' + name).remove();
                            })


                        },
                        acceptedFiles: 'image/*',
                        maxFiles: 1,
                        headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                    });
                }
            });

        });

        $(document).on('click', '#btn-get-current-position-edit', function (e) {
            GMaps.geolocate({
                success: function (position) {
                    map.setCenter(position.coords.latitude, position.coords.longitude);
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat-e').val(lat);
//                        $('#lng-e').val(lng);
//                    },
//                });
                    $('#lat-e').val(position.coords.latitude);
                    $('#lng-e').val(position.coords.longitude);
                },
                error: function (error) {
                    map.setCenter('21.028511', '105.804817');
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat-e').val(lat);
//                        $('#lng-e').val(lng);
//                    },
//                });
                },
                not_supported: function () {
                    map.setCenter('21.028511', '105.804817');
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat-e').val(lat);
//                        $('#lng-e').val(lng);
//                    },
//                });
                },
            });
        });

        function geo_input_edit() {
            var input = document.getElementById('query_place_edit');
            var autocomplete = new google.maps.places.Autocomplete(input, {
                types: ["geocode"],
                componentRestrictions: {country: "vn"}
            });

            google.maps.event.addListener(autocomplete, 'place_changed', function () {
                var place = autocomplete.getPlace();
                var lat_place = place.geometry.location.lat();
                var lng_place = place.geometry.location.lng();
                $('#lat-e').val(lat_place);
                $('#lng-e').val(lng_place);
                map.setCenter(lat_place, lng_place)
            });
        }

        function getCoor(id, type) {
            $.ajax({
                url: '<?php echo e(url('get-location-coor')); ?>',
                type: 'get',
                data: {
                    'id': id,
                    'type': type
                },
                dataType: 'json',
                success: function (response) {
                    if (map) {
                        map.setCenter(
                            response.lat,
                            response.lng
                        );
                    }

                    cur_lat = response.lat;
                    cur_lng = response.lng;

                }
            });
        }

        $(document).on('click', '.btn-edit-hostel', function (e) {

            e.preventDefault();

            hostelId = $(this).attr('data-hostel');

            $("#edit-hostel").on("shown.bs.modal", function (e) {
                $.ajax({
                    url: '<?php echo e(url('admin2/hostel/edit')); ?>' + '/' + hostelId,
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#edit-hostel-content').addClass('ht-on-loading');
                        $('#add-hostel-content').html('');
                    },
                    success: function (response) {
                        $('#edit-hostel-content').removeClass('ht-on-loading').html(response.data);
                        $('.nav-tabs').tab();
                        $('.select2').select2();

                        var lat = 21.0277644;
                        var lng = 105.8341598;

                        if (response.lat && response.lng) {
                            lat = response.lat;
                            lng = response.lng;
                        }

                        if (cur_lat != null && cur_lng != null) {
                            lat = cur_lat;
                            lng = cur_lng;
                        }

                        map = new GMaps({
                            div: '#map_edit',
                            lat: lat,
                            lng: lng
                        });
                        map.addMarker({
                            lat: lat,
                            lng: lng,
                            draggable: true,
                            dragend: function (event) {
                                var lat = event.latLng.lat();
                                var lng = event.latLng.lng();
                                $('#lat').val(lat);
                                $('#lng').val(lng);
                            },
                        });


                        $('.nav-tabs a').on('shown.bs.tab', function (event) {

                            var lat = 21.0277644;
                            var lng = 105.8341598;


                            if (response.lat && response.lng) {
                                lat = response.lat;
                                lng = response.lng;
                            }
                            if (cur_lat != null && cur_lng != null) {
                                lat = cur_lat;
                                lng = cur_lng;
                            }
                            map.refresh();
                            map = new GMaps({
                                div: '#map_edit',
                                lat: lat,
                                lng: lng,
                                center_changed: function () {
                                    var lat = map.getCenter().lat();
                                    var lng = map.getCenter().lng();
                                    $('#lat-e').val(lat);
                                    $('#lng-e').val(lng);
                                }
                            });


                            $('<div/>').addClass('centerMarker').appendTo(map.getDiv())
                                //do something onclick
                                .click(function () {
                                    var that = $(this);
                                    if (!that.data('win')) {
                                        that.data('win', new google.maps.InfoWindow({
                                            content: 'Vị trí được chọn'
                                        }));
                                        that.data('win').bindTo('position', map.map, 'center');
                                    }
                                    that.data('win').open(map.map);
                                });
                        });
                        $('.ckeditor').ckeditor();
                        geo_input_edit();
                    }
                });
            });

        });

        $(document).on('click', '#btn-save-room-excel', function () {
            $('.simple_form').submit();
        });

        $(document).on('change', '#province_id', function (e) {
            $.ajax({
                url: '<?php echo e(url('get-sub-location')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'province'
                },
                dataType: 'html',
                success: function (response) {
                    $('#district_id').html(response);
                    $('#ward_id').html('');
                    getCoor();
                }
            });
        });

        $(document).on('change', '#district_id', function (e) {
            $.ajax({
                url: '<?php echo e(url('get-sub-location')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'district'
                },
                dataType: 'html',
                success: function (response) {
                    $('#ward_id').html(response);
                    getCoor();

                }

            });
        });

        $(document).on('change', '#ward_id', function (e) {
            getCoor();
        });

        $(document).on('click', '.btn-delete-room-type-aj', function (e) {
            e.preventDefault();
            $(this).parent().parent().remove();
        });

        $(document).on('click', '.btn-delete-hostel-fee-aj', function (e) {
            e.preventDefault();
            $(this).parent().parent().remove();
        });

        $(document).on('click', '.btn-hostel-fee-aj', function (e) {
            e.preventDefault();
            $(this).parent().parent().remove();
        });

        $(document).on('click', '.btn-delete-room-type', function (e) {
            e.preventDefault();
            var room_type_id = $(this).attr('data-room-type');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {

                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete-room-type')); ?>',
                            type: 'post',
                            data: {
                                room_type_id: room_type_id,
                            },
                            dataType: 'json',
                            beforeSend: function () {
                                $('#table-room-types').html('');
                                $('#table-room-types').addClass('ht-on-loading');
                            },
                            success: function (response) {
                                if (response.status == 1) {
                                    $('#table-room-types').removeClass('ht-on-loading').html(response.data);
                                } else if (response.status == 2) {
                                    swal('Thông báo', response.message, 'info');
                                } else {
                                    $('#table-room-types').removeClass('ht-on-loading').html(response.data);
                                    swal('Thông báo', response.message, 'warning');
                                }

                            }
                        });

                    }
                }
            });
        });

        function noRoomTypeAlert() {
            swal('Thông báo', 'Bạn cần tạo loại phòng trước khi tạo phòng', 'info');
            return;
        }


        $(document).ajaxSuccess(function () {

            var cnt = $('.price-r').length;

            if (cnt > 0) {
                var cleave = new Cleave('.price-r', {
                    numeral: true,
                    numeralThousandsGroupStyle: 'thousand',
                    numeralDecimalMark: ',',
                    delimiter: '.'
                });
            }

            var rating = $('.bar-rating').length;
            if (rating > 0) {
                $('.bar-rating').barrating({
                    theme: 'fontawesome-stars'
                });
            }
        });


        $(document).on('click', '.btn-edit-room-type', function (e) {
            e.preventDefault();
            e.preventDefault();
            var id = $(this).attr('data-room-type');
            var that = this;
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-edit-room-type')); ?>',
                type: 'get',
                data: {
                    id: id,
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }

                    if (response.status == 1) {
                        $(that).closest('tr').html(response.data);
                    }
                }
            });
        });

        $(document).on('click', '.btn-edit-fee', function (e) {
            e.preventDefault();
            e.preventDefault();
            var id = $(this).attr('data-fee');
            var that = this;
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-edit-fee')); ?>',
                type: 'get',
                data: {
                    id: id,
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        $(that).closest('tr').html(response.data);
                    }

                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });

        $(document).on('click', '.btn-edit-bikes', function (e) {
            e.preventDefault();
            var id = $(this).attr('data-id');
            var that = this;
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-edit-bike')); ?>',
                type: 'get',
                data: {
                    id: id,
                },
                dataType: 'json',
                success: function (response) {
                    $(that).closest('tr').html(response.data);
                }
            });


        });

        $(document).on('click', '#btn-add-image-hostel', function (e) {
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-image-room')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#hostel_images').append(response.data);
                    $('.dropzone').dropzone({
                        url: '<?php echo e(url('admin2/room/upload-image')); ?>',
                        dictDefaultMessage: "",
                        dictMaxFilesExceeded: 'Bạn chỉ được tải lên 1 file',
                        init: function () {
                            this.on("success", function (file, response) {
                                var name = string_to_slug(file.name);
                                $('#room_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                            }).on("addedfile", function (e) {
                                var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                    t = this;
                                n.addEventListener("click", function (n) {
                                    n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                                }), e.previewElement.appendChild(n)
                            }).on("removedfile", function (file) {
                                var name = string_to_slug(file.name);
                                $('#' + name).remove();
                            })


                        },
                        acceptedFiles: 'image/*',
                        maxFiles: 1,
                        headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                    });
                }
            });

        });


        $(document).on('click', '.btn-delete-room-break', function (e) {

            e.preventDefault();

            var id = $(this).attr('data-id');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete-break')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                fix_table.ajax.reload();
                            }
                        });
                    }
                }
            });

        });

        $(document).on('click', '.btn-delete-break-image', function (e) {

            e.preventDefault();

            var id = $(this).attr('data-id');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete-break-image')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                $('#break_images_list').html(response.data);
                            }
                        });
                    }
                }
            });

        });

        $(document).on('click', '.btn-delete-hostel-image', function (e) {

            e.preventDefault();

            var id = $(this).attr('data-id');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/hostel/delete-image')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                $('#hostel_images').html(response.data);
                            }
                        });
                    }
                }
            });

        });

        $(document).on('click', '#btn-add-policy-edit-hostel', function (e) {

            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-user-policy')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#user_policies').append(response.data);
                }
            });
        });

        $(document).on('click', '.btn-delete-fee', function (e) {
            e.preventDefault();
            var fee_id = $(this).attr('data-fee');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {

                        $.ajax({
                            url: '<?php echo e(url('admin2/hostel/delete-hostel-fee')); ?>',
                            type: 'post',
                            data: {
                                fee_id: fee_id,
                            },
                            dataType: 'json',
                            beforeSend: function () {
                                $('#table-hostel-fees').html('');
                                $('#table-hostel-fees').addClass('ht-on-loading');
                            },
                            success: function (response) {
                                if (response.status == 1) {
                                    $('#table-hostel-fees').removeClass('ht-on-loading').html(response.data);
                                }

                                if (response.status == 2) {
                                    swal('Thông báo', response.message, 'info');
                                }
                            }
                        });

                    }
                }
            });
        });


        $(document).on('change', '.checkbox-contract-fee', function (e) {
            calculateVoucher();
        });
        $(document).on('change', '.checkbox-contract-fee-all', function (e) {
            calculateVoucherAll();
        });
        $(document).on('change', '.checkbox-all-contract', function (e) {
            if ($(this).is(":checked")) {
                $('.checkbox-contract-fee-c-contract').prop('checked', true);
            } else {
                $('.checkbox-contract-fee-c-contract').prop('checked', false);
            }
        });

        function calculateVoucher() {
            var data = $('#form-voucher').serialize();
            data.append
            $.ajax({
                url: '<?php echo e(url('admin2/room/calculate-voucher')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-body').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#voucher-body').removeClass('ht-on-loading').html(response.data);
                }
            });

        }

        function calculateVoucherAll() {
            var data = $('#form-voucher-all').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/calculate-voucher-all')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-body-all').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#voucher-body-all').removeClass('ht-on-loading').html(response.data);
                }
            });

        }

        $(document).on('change', '.checkbox-all', function (e) {
            if ($(this).is(":checked")) {
                $('.checkbox-contract-fee').prop('checked', true);
                $('.checkbox-contract-fee-all').prop('checked', true);
            } else {
                $('.checkbox-contract-fee').prop('checked', false);
                $('.checkbox-contract-fee-all').prop('checked', false);
            }
        });

        $(document).on('click', '.print-money-info', function (e) {
            e.preventDefault();
            var month = $(this).attr('data-date');
            var id = $(this).attr('data-money-info');

            $.ajax({

                url: '<?php echo e(url('admin2/money/check-number-money-info')); ?>',
                type: 'get',
                data: {
                    id: id
                },
                dataType: 'json',
                success: function (response) {
                    if (response.data > 1) {
                        bootbox.confirm({
                            message: "Bạn có muốn in gộp toàn bộ hoá đơn của tháng " + month + " không ?",
                            buttons: {
                                confirm: {
                                    label: 'Có',
                                    className: 'btn-success'
                                },
                                cancel: {
                                    label: 'Không',
                                    className: 'btn-danger'
                                }
                            },


                            callback: function (result) {
                                if (result == true) {
                                    window.open('<?php echo e(url('admin/money/print-all/')); ?>' + '/' + id);
                                } else {
                                    window.open('<?php echo e(url('admin/money/print/')); ?>' + '/' + id);
                                }
                            }
                        });
                    } else {
                        window.open('<?php echo e(url('admin/money/print/')); ?>' + '/' + id);
                    }
                }

            });


        });


        $(document).on('click', '#btn-add-amenity-edit-hostel', function (e) {

            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-user-amenity')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#user_edit_amenities').append(response.data);
                }
            });
        });


        $(document).on('click', '#btn-voucher-save', function (e) {
            e.preventDefault();
            var data = $('#form-voucher').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-voucher')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-body').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#voucher').modal('hide');
                    if (response.status == 1) {
                        swal('Thành công', 'Tạo phiếu thành công', 'success');
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });
        });

        $(document).on('click', '#btn-voucher-save-all', function (e) {
            e.preventDefault();
            var data = $('#form-voucher-all').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-voucher-all')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-body-all').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#voucher-all').modal('hide');
                    if (response.status == 1) {
                        swal('Thành công', 'Tạo phiếu thành công', 'success');
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });
        });

        $(document).on('blur', '.voucher-ew-end', function (e) {

            calculateVoucherAll();

        });

        $(document).on('blur', '.voucher-ew-start', function (e) {

            calculateVoucherAll();

        });


        $(document).on('blur', '.voucher-fee', function (e) {

            calculateVoucher();

        });

        $(document).on('blur', '.voucher-fee-all', function (e) {

            calculateVoucherAll();

        });

        $(document).on('blur', '.fee-dynamic', function (e) {

            //calculateVoucherAll();
            setTimeout(function () {
                calculateVoucherAll();
            }, 1);

        });

        $(document).on('blur', function (e) {

            calculateVoucherAll();

        });
        $(document).on('keypress', function (e) {
            var key = (e.keyCode ? e.keyCode : e.which);
            if (key == '13') {
                calculateVoucherAll();
            }
        })
        $(document).on('blur', '.fee-dynamic-e', function (e) {

            calculateVoucher();

        });

        $(document).on('blur', '.discount', function (e) {

            calculateVoucher();

        });

        $(document).on('blur', '.discount-all', function (e) {

            calculateVoucherAll();

        });

        $(document).on('blur', 'input[name="voucher-ew-start"]', function (e) {

            calculateVoucherAll();

        });

        $(document).on('blur', 'input[name="voucher-ew-end"]', function (e) {

            calculateVoucherAll();

        });

        $(document).on('click', '#btn-delete-reserve', function (e) {
            e.preventDefault();

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {

                        var data = $('#form-edit-reserve').serialize();
                        var deposit_amount = $('#edit-reserve-amount').val();
                        //  console.log(deposit_amount);
                        if (deposit_amount != 0) {
                            $.ajax({
                                url: '<?php echo e(url('admin2/room/back-reserve')); ?>',
                                type: 'post',
                                data: data,
                                dataType: 'json',
                                success: function (response) {
                                    $('#back-reserve').modal('show');
                                    if (response.status == 1) {
                                        $('#back-reserve-content').removeClass('ht-on-loading').html(response.data);
                                    } else {
                                        swal('Thông báo', response.message, 'info');
                                    }
                                }
                            });
                        } else {
                            $.ajax({
                                url: '<?php echo e(url('admin2/room/delete-reserve')); ?>',
                                type: 'post',
                                data: data,
                                dataType: 'json',
                                success: function (response) {
                                    $('#detail-reserve').modal('hide');
                                    if (response.status == 1) {

                                        swal('Thông tin giữ chỗ được xóa thành công', '', 'success');
                                        $('#reserve').modal('hide');
                                        $('button[data-block-name="' + blockGlobalName + '"]').click();
                                    } else {
                                        swal('Thông báo', response.message, 'info');
                                    }
                                }
                            });
                        }

                    }
                }
            });

        });

        $(document).on('click', '#btn-delete-reserve-back', function (e) {
            e.preventDefault();

            var data = $('#form-back-reserve').serialize();

            $.ajax({
                url: '<?php echo e(url('admin2/room/delete-reserve')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                success: function (response) {

                    if (response.status == 1) {
                        $('#detail-reserve').modal('hide');
                        swal('Thông tin giữ chỗ được xóa thành công', '', 'success');
                        $('#reserve').modal('hide');
                        $('#back-reserve').modal('hide');
                        $('button[data-block-name="' + blockGlobalName + '"]').click();
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });


        });


        $(document).on('click', '#btn-save-detail-reserve', function (e) {

            var formStatus = $('#form-edit-reserve').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'name': "required",
                    'phone': "required",
                    //  'amenities[]': "required",
                    'date_join': {
                        required: true,
                    },
                },
                messages: {
                    'name': "Không được bỏ trống tên",
                    'phone': "Không được bỏ trống SĐT",
                    'date_join': "Không được bỏ trống ngày vào",
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {
                var data = $('#form-edit-reserve').serialize();
                $.ajax({
                    url: '<?php echo e(url('admin2/room/edit-reserve')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    beforeSend: function () {
                        $('#reserve-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#reserve-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thông tin giữ chỗ được cập nhật thành công', '', 'success');
                            $('#reserve').modal('hide');
                            $('#detail-reserve').modal('hide');
                            $('button[data-block-name="' + blockGlobalName + '"]').click();
                        } else {
                            swal('Thông báo', response.message, 'warning');
                        }
                    }
                });
            }
        });

        $(document).on('click', '#btn-save-reserve', function (e) {

            var formStatus = $('#form-save-reserve').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'name': "required",
                    'phone': "required",
                    //  'id_number': "required",
                    //  'amenities[]': "required",
                    'date_join': {
                        required: true,
                    },
                },
                messages: {
                    'name': "Không được bỏ trống tên",
                    'phone': "Không được bỏ trống SĐT",
                    'id_number': "Không được bỏ trống CMND",
                    'date_join': "Không được bỏ trống ngày vào",
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {
                var data = $('#form-save-reserve').serialize();
                $.ajax({
                    url: '<?php echo e(url('admin2/room/create-reserve')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    beforeSend: function () {
                        $('#reserve-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#reserve-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thông tin giữ chỗ được lưu thành công', '', 'success');
                            $('#reserve').modal('hide');
                            $('button[data-block-name="' + blockGlobalName + '"]').click();
                        } else {
                            swal('Thông báo', response.message, 'warning');
                        }
                    }
                });
            }
        });

        $(document).on('click', '.btn-reserve', function (e) {
            e.preventDefault();
            var room_id = $(this).attr('data-room');
            var bed_id = $(this).attr('data-bed');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-reserve')); ?>',
                type: 'get',
                data: {
                    room_id: room_id,
                    bed_id: bed_id,
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#reserve-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }

                    if (response.is_reserve == 1) {

                        $('#btn-save-reserve').hide();
                    } else {
                        $('#btn-save-reserve').show();
                    }
                    if (response.status == 1) {
                        $('#reserve-content').removeClass('ht-on-loading').html(response.data);
                        $('.datepicker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true,
                        });
                    }
                }
            });
        });

        $(document).on('click', '#btn-add-room', function (e) {

            e.preventDefault();

            var hostelId = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create')); ?>',
                type: 'get',
                data: {
                    hostel_id: hostelId,
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#add-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
//                if(response.status == 0)
//                {
//                    $('#add-room').modal('hide');
//                    swal('Thông báo', response.message, 'warning');
//                    return;
//                }
                    $('#add-room-content').html(response.data);
                    $('.datepicker').datepicker({
                        format: 'dd/mm/yyyy',
                        autoclose: true
                    });

                    $('#add-room-content').removeClass('ht-on-loading');

                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    

                    
                    
                    
                    

                    
                    
                    

                    
                    
                    

                }
            });


        });


        $(document).on('click', '.btn-voucher', function (e) {

            var room_id = $(this).attr('data-room');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-voucher')); ?>',
                type: 'get',
                data: {
                    room_id: room_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#voucher-content').removeClass('ht-on-loading').html(response.data);
                        $('.monthpicker').datepicker({
                            format: 'mm/yyyy',
                            autoclose: true,
                            viewMode: "months",
                            minViewMode: "months",
                        });

                    } else {
                        $('#voucher').modal('hide');
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });


        });

        $(document).on('change', '#month-voucher-all', function (e) {


        });
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

        
        

        

        $(document).on('click', '.btn-voucher-all', function (e) {

            var room_id = $(this).attr('data-room');
            // var month = $('#month-voucher-all').val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-voucher-all')); ?>',
                type: 'get',
                data: {
                    room_id: room_id,
                    // month: month
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#voucher-all-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#voucher-all-content').removeClass('ht-on-loading').html(response.data);

                        $('.monthpicker').datepicker({
                            format: 'mm/yyyy',
                            autoclose: true,
                            viewMode: "months",
                            minViewMode: "months",

                        }).on('changeDate', function (e) {

                            $.ajax({
                                url: '<?php echo e(url('admin2/room/create-voucher-all-edit')); ?>',
                                type: 'get',
                                data: {
                                    room_id: room_id,
                                    month: e.format()
                                },
                                dataType: 'json',
                                beforeSend: function () {
                                    $('#voucher-body-all').addClass('ht-on-loading');
                                },
                                success: function (response) {
                                    if (response.status == 1) {
                                        $('#voucher-body-all').removeClass('ht-on-loading').html(response.data);
                                    } else {
                                        $('#voucher-body-all').removeClass('ht-on-loading').html('');
                                        swal('Thông báo', response.message, 'warning');
                                    }
                                }
                            });
                        });
                    } else {
                        $('#voucher-all').modal('hide');
                        swal('Thông báo', response.message, 'warning');
                    }

                }
            });


        });

        $(document).on('click', '#btn-add-room-type', function (e) {

            var hostel_id = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-room-type')); ?>',
                type: 'get',
                data: {
                    hostel_id: hostel_id
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }

                    if (response.status == 1) {
                        $('#table-room-types').append(response.data);
                    }
                }
            });


        });

        $(document).on('click', '#btn-add-fee', function (e) {

            var hostel_id = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-fee')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    hostel_id: hostel_id
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#table-hostel-fees').append(response.data);
                    }

                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });


        });

        $(document).on('click', '.btn-ew', function (e) {
            var roomId = $(this).attr('data-room');
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-ew')); ?>' + '/' + roomId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#ew-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#ew-content').removeClass('ht-on-loading').html(response.data);
                    $('.monthpicker').datepicker({
                        format: 'mm/yyyy',
                        autoclose: true,
                        viewMode: "months",
                        minViewMode: "months",
                    });
                }
            });


        });

        $(document).on('click', '.btn-add-contract-reserve', function (e) {
            //      $('#add-contract-reserve').modal('hide');
            var roomId = $(this).attr('data-room');
            var reserve_id = $(this).attr('data-reserve');
            var bed_id = $(this).attr('data-bed');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-contract')); ?>',
                type: 'get',
                data: {
                    bed_id: bed_id,
                    room_id: roomId,
                    reserve_id: reserve_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#add-contract-reserve-content').addClass('ht-on-loading');
                },
                success: function (response) {

                    if (response.status == 1) {
                        // $('#add-contract-reserve').modal('show');
                        $('#add-contract-reserve-content').removeClass('ht-on-loading').html(response.data);
                        $('.datepicker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true,
                        });
                        var dateToday = new Date();
                        $('.monthpicker').datepicker({
                            format: 'mm/yyyy',
                            autoclose: true,
                            viewMode: "months",
                            minViewMode: "months",
                        });
                    } else if (response.status == 2) {
                        $('#add-contract-reserve').modal('hide');
                        swal('Thông báo', response.message, 'info');
                    } else {
                        $('#add-contract-reserve').modal('hide');
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });


        });

        $(document).on('click', '.btn-add-contract', function (e) {
            var roomId = $(this).attr('data-room');
            var bed_id = $(this).attr('data-bed');
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-contract')); ?>',
                type: 'get',
                data: {
                    bed_id: bed_id,
                    room_id: roomId
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#add-contract-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 1) {
                        $('#add-contract-content').removeClass('ht-on-loading').html(response.data);
                        $('.datepicker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true,
                        });
                        var dateToday = new Date();
                        $('.monthpicker').datepicker({
                            format: 'mm/yyyy',
                            autoclose: true,
                            viewMode: "months",
                            minViewMode: "months",
                        });

                        $('.select2').select2();

                        $('input[name ="phone"]').prop("readonly", false);
                        $('input[name ="name"]').prop("readonly", false);
                        $('input[name ="email"]').prop("readonly", false);
                        $('input[name ="id_number"]').prop("readonly", false);
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    } else {
                        $('#add-contract').modal('hide');
                        if (response.status == 0) {
                            swal('Thông báo', response.message, 'warning');
                        } else {
                            swal('Cảnh báo', response.message, 'info');
                        }

                    }
                }
            });


        });

        $(document).on('click', '#btn-save-contract', function (e) {
            e.preventDefault();
            $(this).addClass('disabled');
            var that = this;

            var formStatus = $('#form-add-contract').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'date_contract': "required",
                    'date_enable': {
                        required: true,
                    },
                    'start_date': {
                        required: true,
                    },
                    'end_date': {
                        required: true,
                    },
                    'months': {
                        required: true,
                        number: true
                    },
                    'room_price': {
                        required: true,
                    },
                    'deposit': {
                        required: true,
                    },
                    'name': {
                        required: true,
                    },
                    // 'id_number': {
                    //     required: true,
                    // },
                    'phone': {
                        required: true,
                        //  checkPhone: true,
                    },
                    'email': {
                        email: true
                    },
                    // 'date_join': {
                    //     required: true,
                    // },
                    'collect_to': {
                        required: {
                            collect_to: {required: "#is_collected:checked"}
                        }
                    },
                    'date_end_residence': {
                        required: function (el) {
                            return $(el).closest('form').find('#add-renter-residence-status').val() == '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>';
                        }
                    }

                },
                messages: {
                    'date_contract': "Không được bỏ trống ngày hợp đồng",
                    'date_enable': "Không được bỏ trống ngày hiệu lực",
                    'start_date': "Không được bỏ trống ngày thuê bắt đầu",
                    'end_date': "Không được bỏ trống ngày kết thúc thuê",
                    'end_date': {
                        required: "Ngày hết hạn không được nhỏ hơn ngày bắt đầu",
                    },
                    'months': {
                        required: "Không được bỏ trống hạn HĐ",
                        number: "Dữ liệu phải là số"
                    },
                    'room_price': "Không được bỏ trống giá phòng",

                    'deposit': "Không được bỏ trống tiền cọc",
                    'name': "Không được bỏ trống họ tên",
                    //'id_number': "Không được bỏ trống CMTND",
                    'phone': {
                        'required': "Không được bỏ trống SĐT",
                        // 'checkPhone': 'Số điện thoại phải đúng định dạng'
                    },
                    'email': {
                        email: "Email phải đúng định dạng"
                    },
                    // 'date_join': "Không được bỏ trống ngày vào phòng",
                    'collect_to': "Không được bỏ trống thu đến tháng",
                    'date_end_residence': "Không được bỏ hạn tạm trú"
                }
            }).form();

            if (formStatus) {
                var form = $('#form-add-contract')[0];
                console.log(form);
                var data = new FormData(form);
                $.ajax({
                    url: '<?php echo e(url('admin2/room/create-contract')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    contentType: false,
                    processData: false,

                    beforeSend: function () {
                        $('#add-contract-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#add-contract-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thành công', '', 'success');
                            $('button[data-block-name="' + blockGlobalName + '"]').click();
                            $('#add-contract').modal('hide');
                            $('#add-contract-reserve').modal('hide');

                        } else if (response.status == 2) {
                            swal('Thông báo', response.message, 'info');
                        } else {
                            swal('Thông báo', response.message, 'warning');
                            //$('#add-contract').modal('hide');
                        }

                        $(that).removeClass('disabled');

                    }
                });

            }
        });

        
        
        
        
        
        
        

        $(document).on('change', 'input[type=checkbox][name=is_collected]', function (e) {
            if ($(this).is(":checked")) {
                $('#to_month').show();
            } else {
                $('#to_month').hide();
                $('#collect_to-error').closest('.form-group').removeClass('has-error');
                $('#collect_to-error').remove();
            }
        });

        $(document).on('click', '#cf-end-contract', function (e) {

            var contractId = $(this).attr('data-contract');
            var is_return_deposit = 0;
            var is_return_money_info = 0;

            if ($('#return-deposit').is(":checked")) {
                is_return_deposit = 1;
            }

            if ($('#return-money-info').is(":checked")) {
                is_return_money_info = 1;
            }
            bootbox.confirm({
                message: "Bạn có chắc chắn xác nhận thanh toán và thanh lý hợp đồng này ?",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/end-contract')); ?>' + '/' + contractId,
                            type: 'post',
                            data: {
                                is_confirm: 1,
                                date_end_contract: $('#date-end-contract').val(),
                                is_return_deposit: is_return_deposit,
                                is_return_money_info: is_return_money_info,
                                amount_return_deposit: $('#amount_return_deposit').val()
                            },
                            beforeSend: function () {
                                $('#end-contract-money-content').addClass('ht-on-loading');
                            },
                            dataType: 'json',
                            success: function (response) {
                                $('#end-contract-money-content').removeClass('ht-on-loading');
                                if (response.status == 1) {
                                    swal('Thanh toán và thanh lý thành công', '', 'success');
                                    $('#end-contract-money').modal('hide');
                                    $('#detail-room').modal('hide');
                                    $('button[data-block-name="' + blockGlobalName + '"]').click();

                                    rating(contractId);
                                } else {
                                    swal('Thông báo', response.message, 'warning');
                                }
                            }
                        });
                    }
                }
            });
        });

        $(document).on('click', '#print-end-contract', function (e) {

            var contractId = $(this).attr('data-contract');
            var is_return_deposit = 0;
            var is_return_money_info = 0;
            var date_end_contract = $('#date-end-contract').val();

            if ($('#return-deposit').is(":checked")) {
                is_return_deposit = 1;
            }

            if ($('#return-money-info').is(":checked")) {
                is_return_money_info = 1;
            }

            var amount_return_deposit = $('#amount_return_deposit').val();
            var base_url_print = '<?php echo e(url('admin2/money/print-end-contract')); ?>' + '/' + contractId;
            var obj = {
                is_return_deposit: is_return_deposit,
                is_return_money_info: is_return_money_info,
                date_end_contract: date_end_contract,
                amount_return_deposit: amount_return_deposit
            };
            var url = base_url_print + '?' + $.param(obj);
            var win = window.open(url, '_blank');
            if (win) {
                //Browser has allowed it to be opened
                win.focus();
            } else {
                //Browser has blocked it
                alert('Please allow popups for this website');
            }


        });


        $(document).on('click', '.btn-number-people-room', function (e) {

            roomId = $(this).attr('data-room');

            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-room')); ?>' + '/' + roomId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#detail-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#detail-room-content').removeClass('ht-on-loading').html(response.data);
                    $.ajax({
                        url: '<?php echo e(url('admin2/room/renters')); ?>' + '/' + roomId,
                        type: 'get',
                        dataType: 'json',
                        beforeSend: function () {
                            $('#tab_1_2').addClass('ht-on-loading');
                        },
                        success: function (response) {
                            $('#tab_1_2').removeClass('ht-on-loading').html(response.data);
                        }
                    });
                    $("#tabs").find('li').removeClass('active');
                    $("#tabs").find('li').first().next().addClass('active');
                    $('.tab-content').find('.tab-pane').removeClass('active in');
                    $('.tab-content').find('.tab-pane').first().next().addClass('active in');
                }
            });


        });


        $(document).on('click', '.btn-delete-room-image', function (e) {

            e.preventDefault();

            var id = $(this).attr('data-id');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete-image')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                $('#room_images').html(response.data);
                            }
                        });
                    }
                }
            });

        });

        $(document).on('click', '.btn-detail-room', function (e) {

            roomId = $(this).attr('data-room');

            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-room')); ?>' + '/' + roomId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#detail-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#detail-room-content').removeClass('ht-on-loading').html(response.data);
                    $('.nav-tabs').tab();
                    $('#title-detail-room').text(response.name);
                    $.ajax({
                        url: '<?php echo e(url('admin2/room/info')); ?>' + '/' + roomId,
                        type: 'get',
                        dataType: 'json',
                        beforeSend: function () {
                            $('#tab_1_1').addClass('ht-on-loading');
                        },
                        success: function (response) {
                            $('#tab_1_1').removeClass('ht-on-loading').html(response.data);
                        }
                    })
                }
            });


        });

        $(document).on('click', '.btn-update-room', function (e) {

            roomId = $(this).attr('data-room');

            $.ajax({
                url: '<?php echo e(url('admin2/room/edit')); ?>' + '/' + roomId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#edit-room-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#edit-room-content').removeClass('ht-on-loading').html(response.data);
                    $('.datepicker').datepicker({
                        format: 'dd/mm/yyyy',
                        autoclose: true
                    });
                    $('.nav-tabs').tab();
                }
            });


        });

        $(document).on('click', '#btn-room-type-config', function (e) {

            var hostel_id = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/room-type')); ?>',
                type: 'get',
                data: {
                    hostel_id: hostel_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#room-type-config-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#room-type-config-content').removeClass('ht-on-loading').html(response.data);
                }
            });


        });

        $(document).on('click', '.btn-hostel-fee-quota', function (e) {
            e.preventDefault();

            var type = $(this).attr('data-type');
            var hostelId = $(this).attr('data-hostel');
            var feeId = $(this).attr('data-id');
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/quota')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    hostel_id: hostelId,
                    type: type,
                    fee_id: feeId
                },
                beforeSend: function () {
                    $('#hostel-fee-quota-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#hostel-fee-quota-content').removeClass('ht-on-loading').html(response.data);
                }
            });


        });

        $(document).on('click', '#btn-hostel-fee-config', function (e) {
            hostelId = $(this).attr('data-hostel');
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/fee')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    hostel_id: hostelId
                },
                beforeSend: function () {
                    $('#hostel-fee-config-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#hostel-fee-config-content').removeClass('ht-on-loading').html(response.data);
                }
            });


        });

        $(document).on('change', '#hostels', function (e) {
            e.preventDefault();

            var hostelId = $(this).val();

            $.ajax({
                url: '<?php echo e(url('admin2/hostel/detail-hostel-room')); ?>' + '/' + hostelId,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#hostel-detail').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#hostel-detail').removeClass('ht-on-loading').html(response.data);
                    $('#hostels-button').html(response.buttons);
                    $('#floor-rooms').find('button').first().click();

                    var chart = AmCharts.makeChart("pie-room", {
                        "hideCredits": true,
                        "type": "pie",
                        "theme": "dark",
                        "dataProvider": response.chart_room,
                        "colorField": "color",
                        "valueField": "value",
                        "titleField": "name",
                        "titles": [
                            {
                                "text": "Tỷ lệ đầy phòng",
                                "size": 15
                            }
                        ],
                        //"labelsEnabled": false,
                        autoMargins: false,
                        marginTop: 0,
                        marginBottom: 0,
                        marginLeft: 0,
                        marginRight: 0,
                        pullOutRadius: 0,
                        radius: 80
//                    "balloon": {
//                        "fixedPosition": true
//                    },
//                    "export": {
//                        "enabled": true
//                    }
                    });

                    var chart2 = AmCharts.makeChart("pie-payment", {
                        "hideCredits": true,
                        "type": "pie",
                        "theme": "dark",
                        "dataProvider": response.chart_payment,
                        "colorField": "color",
                        "valueField": "value",
                        "titleField": "name",
                        "titles": [
                            {
                                "text": "Tỷ lệ thanh toán",
                                "size": 15
                            }
                        ],
                        autoMargins: false,
                        //"labelsEnabled": false,
                        marginTop: 0,
                        marginBottom: 0,
                        marginLeft: 0,
                        marginRight: 0,
                        pullOutRadius: 0,
                        radius: 80
                        //    pullOutRadius: '12%',
//                    "balloon": {
//                        "fixedPosition": true
//                    },
//                    "export": {
//                        "enabled": true
//                    }
                    });
                }
            });

        });

        $(document).on('click', '#btn-save-hostel-fee-quota', function (e) {
            var data = $('#form-hostel-quota').serialize();

            $.ajax({
                url: '<?php echo e(url('admin2/hostel/save-quota')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        swal('Thành công', 'Dữ liệu đã được lưu lại', 'success');
                    }
                }
            });

        });


        $(document).on('click', '.btn-edit-payment', function (e) {
            e.preventDefault();
            var transaction_id = $(this).attr('data-payment');
            var that = this;

            $.ajax({
                url: '<?php echo e(url('admin2/room/get-edit-payment')); ?>',
                type: 'get',
                data: {
                    transaction_id: transaction_id
                },
                dataType: 'json',
                success: function (response) {
                    $(that).closest('td').prev().html(response.html);
                    $(that).closest('td').html(response.button);
                }
            });


        });


        $(document).on('click', '#btn-save-edit-renter', function (e) {
            e.preventDefault();

            var form = $('#form-edit-renter')[0];
            var data = new FormData(form);

            var formStatus = $('#form-edit-renter').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'name': "required",
                    //  'amenities[]': "required",
                    'phone': {
                        required: true,
                        //  number: true
                    },
                    // 'date_join': {
                    //     required: true,
                    // },
                    'residence_status': {
                        required: true,
                    },
                },
                messages: {
                    'name': "Không được bỏ trống tên",
                    'phone': "Không được bỏ trống SĐT",
                    'residence_status': "Không được bỏ trống khai báo tạm trú",
                    // 'amenities[]': "Không được bỏ trống tiện ích"
                }
            }).form();

            if (formStatus) {
                $.ajax({
                    url: '<?php echo e(url('admin2/renter/edit')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    contentType: false,
                    processData: false,

                    beforeSend: function () {
                        $('#edit-renter-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#edit-renter-content').removeClass('ht-on-loading');
                        if (response.status == 1) {
                            swal('Thành công', 'Dữ liệu đã được cập nhật', 'success');
                            table.ajax.reload();
                            $('#edit-renter').modal('hide');
                        }

                        if (response.status == 0) {
                            swal('Thông báo', response.message, 'info');
                            $('#edit-renter').modal('hide');
                        }

                    }
                });
            }
        });


        $(document).on('click', '#btn-add-bike', function (e) {
            e.preventDefault();
            var renter_id = $(this).attr('data-renter');
            var room_id = $(this).attr('data-room');

            $.ajax({
                url: '<?php echo e(url('admin2/room/get-add-bike')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#renter-bikes').append(response.data);
                }
            });


        });

        $(document).on('click', '#btn-add-bike-2', function (e) {
            e.preventDefault();
            var renter_id = $(this).attr('data-renter');
            var room_id = $(this).attr('data-room');

            $.ajax({
                url: '<?php echo e(url('admin2/room/get-add-bike')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#renter-bikes-2').append(response.data);
                }
            });


        });


        $(document).on('click', '.btn-delete-bike-js', function (e) {
            e.preventDefault();
            $(this).closest('.row').remove();
        });

        $(document).on('click', '.btn-delete-bike', function (e) {
            e.preventDefault();

            var id = $(this).attr('data-id');
            var that = this;

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete-bike')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                $(that).closest('tbody').html(response.data);
                            }
                        });
                    }
                }
            });
        });

        $(document).on('click', '.btn-delete-room', function (e) {
            e.preventDefault();

            var id = $(this).attr('data-room');
            var that = this;

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/delete')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                $('button[data-block-name="' + blockGlobalName + '"]').click();
                                $('button[data-block-name="' + blockGlobalName + '"]').html(response.button);
                            }
                        });
                    }
                }
            });
        });

        $(document).on('click', '.btn-save-edit-bike', function (e) {
            e.preventDefault();
            var id = $(this).attr('data-id');
            var name = $(this).closest('tr').find('td').first().next().find('input').val();
            var type = $(this).closest('tr').find('td').first().next().next().find('select').val();
            var bks = $(this).closest('tr').find('td').first().next().next().next().find('input').val();
            var that = this;

            $.ajax({
                url: '<?php echo e(url('admin2/room/edit-bike')); ?>',
                type: 'post',
                data: {
                    id: id,
                    name: name,
                    type: type,
                    bks: bks
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        swal('Thành công', '', 'success');
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                    $(that).closest('tr').html(response.data);
                }
            });


        });


        $(document).on('click', '.btn-save-edit-payment', function (e) {
            e.preventDefault();
            var transaction_id = $(this).attr('data-transaction');
            var amount = $(this).closest('td').prev().find('input').val();
            var that = this;

            $.ajax({
                url: '<?php echo e(url('admin2/room/edit-payment')); ?>',
                type: 'post',
                data: {
                    transaction_id: transaction_id,
                    amount: amount
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        swal('Thành công', '', 'success');
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                    $(that).closest('td').prev().html(response.html);
                    $(that).closest('td').html(response.button);
                }
            });


        });


        $(document).on('click', '.btn-edit-renter', function (e) {

            var renter_id = $(this).attr('data-renter');


            $.ajax({
                url: '<?php echo e(url('admin2/renter/edit')); ?>' + '/' + renter_id,
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#edit-renter-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#edit-renter-content').removeClass('ht-on-loading').html(response.data);
                    $('.select2').select2();
                    $('.datepicker').datepicker({
                        format: 'dd/mm/yyyy',
                        autoclose: true
                    });
                }
            });


        });

        $(document).on('click', '.btn-cancel-edit-payment', function (e) {
            e.preventDefault();
            var transaction_id = $(this).attr('data-transaction');
            var that = this;

            $.ajax({
                url: '<?php echo e(url('admin2/room/cancel-edit-payment')); ?>',
                type: 'get',
                data: {
                    transaction_id: transaction_id,
                },
                dataType: 'json',
                success: function (response) {
                    $(that).closest('td').prev().html(response.html);
                    $(that).closest('td').html(response.button);
                }
            });
        });

        $(document).on('change', '#add-room-type', function (e) {
            e.preventDefault();

            var type = $(this).val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-room-type')); ?>',
                type: 'get',
                data: {
                    type: type
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#add-room-content').addClass('ht-on-loading');
                },
                success: function (response) {

                    if (response.status == 1) {
                        $('#add-room-size').val(response.data.size);
                        $('#add-room-max-renters').val(response.data.max_renters);
                        $('#add-room-price').val(response.data.price);

                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }

                    $('#add-room-content').removeClass('ht-on-loading');
                }
            });
        });

        $(document).on('click', '.btn-save-payment', function (e) {
            e.preventDefault();

            var data = $(this).closest('form').serialize();

            $.ajax({
                url: '<?php echo e(url('admin2/room/spend')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#payment-items').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#payment-items').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        swal('Thành công', 'Thanh toán thành công', 'success');
                        $('#tabs').find('li.active > a').click();
                        $('#btn-filter-payment').click();
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                }
            });

        });

        $(document).on('click', '#btn-filter-payment', function (e) {
            e.preventDefault();

            var data = $('#form-payment-filter').serialize();

            $.ajax({
                url: '<?php echo e(url('admin2/room/filter-payment')); ?>',
                type: 'get',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#payment-items').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#payment-items').removeClass('ht-on-loading').html(response.data);
                    $('#payment-data').html(response.payment_data);
                }
            });

        });


        $(document).on('click', '.btn-extend-contract', function (e) {
            e.preventDefault();

            var contract_id = $(this).attr('data-contract');

            $.ajax({
                url: '<?php echo e(url('admin2/room/get-extend-contract')); ?>',
                type: 'get',
                data: {
                    contract_id: contract_id
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#extend-contract-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                    if (response.status == 1) {
                        $('#extend-contract-content').removeClass('ht-on-loading').html(response.data);

                        $('.datepicker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true,
                        });
                    }
                }
            });

        });

        $(document).on('click', '#btn-filter-contract', function (e) {
            e.preventDefault();

            var data = $('#form-contract-filter').serialize();

            $.ajax({
                url: '<?php echo e(url('admin2/room/filter-contract')); ?>',
                type: 'get',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#contract-items').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#contract-items').removeClass('ht-on-loading').html(response.data);
                }
            });

        });


        $(document).on('change', '#add-renter-residence-status', function (e) {
            var residence_status = $(this).val();
            if (residence_status !== '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>') {
                $('#add-renter-date-end-residence').hide();
            } else {
                $('#add-renter-date-end-residence').show();
            }
        });

        $(document).on('change', '#add-renter-residence-status-2', function (e) {
            var residence_status = $(this).val();
            if (residence_status !== '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>') {
                $('#add-renter-date-end-residence-2').hide();
            } else {
                $('#add-renter-date-end-residence-2').show();
            }
        });

        $(document).on('change', '#edit-renter-residence-status', function (e) {
            var residence_status = $(this).val();
            if (residence_status !== '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>') {
                $('#edit-renter-date-end-residence').hide();
            } else {
                $('#edit-renter-date-end-residence').show();
            }
        });

        $(document).on('change', '#edit-renter-residence-status', function (e) {
            var residence_status = $(this).val();
            if (residence_status !== '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>') {
                $('#edit-renter-date-end-residence').hide();
            } else {
                $('#edit-renter-date-end-residence').show();
            }
        });

        var hostelId_c = null;
        var floor_c = null;
        var blockName_c = null;

        $(document).on('change', '#is-empty-checkbox', function (e) {
            e.preventDefault();

            var is_empty = 'off';
            if ($(this).is(':checked')) {
                is_empty = 'on';
            }

            blockGlobalName = blockName_c;

            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-rooms')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    is_empty: is_empty,
                    hostel_id: hostelId_c,
                    block_name: blockName_c
                },
                // cache: false,
                beforeSend: function () {
                    $('#rooms').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#rooms').removeClass('ht-on-loading').html(response.data);
                }
            });
        });
        $(document).on('click', '.floor-detail', function (e) {
            e.preventDefault();

            var hostelId = $(this).attr('data-hostel');
            var floor = $(this).attr('data-floor');
            var blockName = $(this).attr('data-block-name');
            var is_empty = 'off';

            hostelId_c = hostelId;
            floor_c = floor;
            blockName_c = blockName;

            if ($('#is-empty-checkbox').is(':checked')) {
                is_empty = 'on';
            }

            blockGlobalName = blockName;

            $.ajax({
                url: '<?php echo e(url('admin2/room/detail-rooms')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    is_empty: is_empty,
                    hostel_id: hostelId_c,
                    block_name: blockName_c
                },
                // cache: false,
                beforeSend: function () {
                    $('#rooms').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#rooms').removeClass('ht-on-loading').html(response.data);
                }
            });

        });

        $(document).on('click', '#btn-save-room-type-config', function (e) {

            e.preventDefault();

            var formStatus = $('#form-add-room-type').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'room_type_name[]': "required",
                    'room_type_price[]': {
                        required: true
                    },
//                'room_type_long[]': {
//                    required: true,
//                    number: true
//                },
//                'room_type_width[]': {
//                    required: true,
//                    number: true
//                },
                    'room_type_max_people[]': {
                        required: true,
                        number: true
                    },
                    'room_type_size[]': {
                        required: true,
                        number: true,
                        min: 1,
                    }
                },
                messages: {
                    'room_type_name[]': "Không được bỏ trống tên",
                    'room_type_price[]': "Không được bỏ trống đơn giá",
                    'room_type_size[]': "Không được bỏ trống diện tích",
//                'room_type_long[]': "Không được bỏ trống chiều dài",
//                'room_type_width[]': "Không được bỏ trống chiều rộng",
                    'room_type_max_people[]': "Không được bỏ trống số người tối đa",
                }
            }).form();


            if (formStatus === true) {
                var data = $('#form-add-room-type').serialize();
                $.ajax({
                    url: '<?php echo e(url('admin2/room/create-room-type')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',

                    success: function (response) {
                        $('#table-room-types').html(response.data);
                        $('#room-type-config').modal('hide');
                        $('#hostels').trigger('change');
                    }
                });
            }

        });

        $(document).on('click', '#btn-save-hostel-fee-config', function (e) {

            e.preventDefault();

            var formStatus = $('#form-add-hostel-fee').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'fee_name[]': "required",
                    'fee_type[]': {
                        required: true,
                        number: true
                    },
                    'fee_unit[]': {
                        required: true,
                    },
                    'fee[]': {
                        required: true,
                    },
                },
                messages: {
                    'fee_name[]': "Không được bỏ trống tên",
                    'fee_type[]': "Không được bỏ trống loại phí",
                    'fee_unit[]': "Không được bỏ trống đơn vị",
                    'fee[]': "Không được bỏ trống đơn giá",
                }
            }).form();


            if (formStatus === true) {
                var data = $('#form-add-hostel-fee').serialize();
                $.ajax({
                    url: '<?php echo e(url('admin2/hostel/create-hostel-fee')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',

                    success: function (response) {
                        if (response.status == 1) {
                            $('#table-hostel-fees').html(response.data);
                            $('#hostel-fee-config').modal('hide');
                            swal('Thành công', '', 'success');
                        } else {
                            swal('Thông báo', response.message, 'warning');
                        }
                    }
                });
            }

        });

        $(document).on('click', '#btn-add-image-room', function (e) {
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-image-room')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#room_images').append(response.data);
                    $('.dropzone').dropzone({
                        url: '<?php echo e(url('admin2/room/upload-image')); ?>',
                        dictDefaultMessage: "",
                        dictMaxFilesExceeded: 'Bạn chỉ được tải lên 1 file',
                        init: function () {
                            this.on("success", function (file, response) {
                                var name = string_to_slug(file.name);
                                $('#room_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                            }).on("addedfile", function (e) {
                                var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                    t = this;
                                n.addEventListener("click", function (n) {
                                    n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                                }), e.previewElement.appendChild(n)
                            }).on("removedfile", function (file) {
                                var name = string_to_slug(file.name);
                                $('#' + name).remove();
                            })


                        },
                        acceptedFiles: 'image/*',
                        maxFiles: 1,
                        headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                    });
                }
            });

        });

        $(document).on('click', '#btn-add-amenity-room', function (e) {

            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-user-amenity')); ?>',
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    $('#user_amenities').append(response.data);
                }
            });
        });

        $(document).on('click', '#btn-add-renter', function (e) {
            roomId = $(this).attr('data-room');
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-renter')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    room_id: roomId
                },
                beforeSend: function () {
                    $('#add-renter-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-renter-content').removeClass('ht-on-loading').html(response.data);
                    var residence_status = $('#add-renter-residence-status').val();
                    if (residence_status !== '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>') {
                        $('#add-renter-date-end-residence').hide();
                    } else {
                        $('#add-renter-date-end-residence').show();
                    }

                    $('.datepicker').datepicker({
                        format: 'dd/mm/yyyy',
                        autoclose: true,
                    });

                    $('.select2').select2();
                }
            });
        });

        

        $(document).on('change', '.fee-type', function (e) {
            var dt = $(this).val();
            var uniid = $(this).attr('data-check-id');
            var hostel_id = $(this).attr('data-hostel');
            if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC); ?>' || dt == '<?php echo e(\App\Models\HostelFee::WATER); ?>') {
//            $(this).closest('td').next().next().next().html('<a data-target="#hostel-fee-quota" data-hostel="' + hostel_id + '" data-type="' + dt + '" data-toggle="modal" class="btn btn-sm red btn-hostel-fee-quota">Thiết lập</a>');
                $(this).closest('td').next().html('Biến động');
                if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Kwh')
                } else if (dt == '<?php echo e(\App\Models\HostelFee::WATER); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Khối')
                }

            } else if (dt == '<?php echo e(\App\Models\HostelFee::DYNAMIC); ?>' || dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC_DYNAMIC); ?>'
                || dt == '<?php echo e(\App\Models\HostelFee::WATER_DYNAMIC); ?>') {

                $(this).closest('td').next().next().next().html('Biến động');
                $(this).closest('td').next().html('Biến động');
                if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC_DYNAMIC); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Kwh')
                } else if (dt == '<?php echo e(\App\Models\HostelFee::WATER_DYNAMIC); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Khối')
                } else {
                    $(this).closest('td').next().next().html('Đồng/tháng')
                }

            } else {
                if (dt == '<?php echo e(\App\Models\HostelFee::VEHICLE); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Chiếc/Tháng')
                } else if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC_BY_PEOPLE); ?>' || dt == '<?php echo e(\App\Models\HostelFee::WATER_BY_PEOPLE); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Người')
                } else if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC_BY_CLOCK); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Kwh')
                } else if (dt == '<?php echo e(\App\Models\HostelFee::WATER_BY_CLOCK); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Khối')
                } else {
                    $(this).closest('td').next().next().html('Đồng/Tháng')
                }
                $(this).closest('td').next().next().next().html('');
                $(this).closest('td').next().html('<div class="form-group"><input class="form-control price-r" name="fee[' + uniid + ']"></div>');
            }

            var cnt = $('.price-r').length;


            if (cnt > 0) {

                $('.price-r').toArray().forEach(function (field) {
                    var cleave = new Cleave(field, {
                        numeral: true,
                        numeralThousandsGroupStyle: 'thousand',
                        numeralDecimalMark: ',',
                        delimiter: '.'
                    });
                });


            }
        });

        $(document).on('change', '.fee-type-edit', function (e) {
            var dt = $(this).val();
            var hostel_id = $(this).attr('data-hostel');
            if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC); ?>' || dt == '<?php echo e(\App\Models\HostelFee::WATER); ?>') {
                $(this).closest('td').next().next().next().html('<a data-target="#hostel-fee-quota" data-hostel="' + hostel_id + '" data-type="' + dt + '" data-toggle="modal" class="btn btn-sm red btn-hostel-fee-quota">Thiết lập</a>');
                if (dt == '<?php echo e(\App\Models\HostelFee::ELECTRIC); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Kwh')
                } else if (dt == '<?php echo e(\App\Models\HostelFee::WATER); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Khối')
                }

            } else {
                if (dt == '<?php echo e(\App\Models\HostelFee::VEHICLE); ?>') {
                    $(this).closest('td').next().next().html('Đồng/Chiếc/Tháng')
                } else {
                    $(this).closest('td').next().next().html('Đồng/Tháng')
                }
                var curVal = $(this).closest('td').next().find('input').val();
                $(this).closest('td').next().html('<div class="form-group"><input class="form-control price-r" name="fee_edit[]" value="' + curVal + '"></div>');
            }
        });

        $(document).on('blur', '#add_renter_code', function (e) {
            e.preventDefault();
            var phone = $(this).val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-renter-by-code')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    phone: phone,
                },
                beforeSend: function () {
                    $('#add-renter-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-renter-content').removeClass('ht-on-loading');
                    if (response.status == 1) {

                        $('#add-renter-content input[name="name"]').val(response.data.name);
                        $('#add-renter-content input[name="phone"]').val(response.data.phone);
                        $('#add-renter-content input[name="id_number"]').val(response.data.id_number);
                        $('#add-renter-content input[name="email"]').val(response.data.email);

                    }
                }
            });

        });

        $(document).on('blur', '#phone-contract', function (e) {
            e.preventDefault();
            var phone = $(this).val();
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-renter-by-code')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    phone: phone,
                },
                beforeSend: function () {
                    $('#add-contract-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-contract-content').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        $('#add-contract input[name="name"]').val(response.data.name);
                        $('#add-contract input[name="phone"]').val(response.data.phone);
                        $('#add-contract input[name="id_number"]').val(response.data.id_number);
                        $('#add-contract input[name="email"]').val(response.data.email);
                        $('.fileinput-new img').attr('src', response.data.image);

                        $('#add-contract input[name="address"]').val(response.data.address);
                        if (response.select_province != '') {
                            $('#province1').html(response.select_province);
                        }
                        if (response.select_district !== '') {
                            $('#district1').html(response.select_district);
                        }
                        if (response.select_ward !== '') {
                            $('#ward1').html(response.select_ward);
                        }
                    } else {
                        $('#add-contract input[name="name"]').val('');
                        $('#add-contract input[name="id_number"]').val('');
                        $('#add-contract input[name="email"]').val('');
                        $('.fileinput-new img').attr('src', '/frontend3/assets/img/placeholder.png');
                    }
                }
            });

        });

        $(document).on('click', '.btn-add-renter', function (e) {
            roomId = $(this).attr('data-room');
            type_rent = $(this).attr('data-type-rent');
            e.preventDefault();
            $.ajax({
                url: '<?php echo e(url('admin2/room/create-renter')); ?>',
                type: 'get',
                dataType: 'json',
                data: {
                    room_id: roomId,
                    type_rent: type_rent
                },
                beforeSend: function () {
                    $('#add-renter-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-renter-content').removeClass('ht-on-loading').html(response.data);
                    var residence_status = $('#add-renter-residence-status').val();
                    if (residence_status !== '<?php echo e(\App\Models\RenterRoom::RESIDENCE_LIMIT); ?>') {
                        $('#add-renter-date-end-residence').hide();
                    } else {
                        $('#add-renter-date-end-residence').show();
                    }
                    $('.datepicker').datepicker({
                        format: 'dd/mm/yyyy',
                        autoclose: true,
                    });

                    $('.select2').select2();
                }
            });
        });


        $(document).on('click', '#tabs a', function (e) {
            e.preventDefault();

            var url = $(this).attr("data-url");
            var href = this.hash;
            var pane = $(this);

            // ajax load from data-url
            if (href == '#tab_1_4') {

                var id_contract = $("#contract_data option:selected").val();
                roomId = $(this).attr('data-room');
                $.ajax({
                    url: '<?php echo e(url('admin2/room/payment-history')); ?>' + '/' + roomId,
                    data: {contract_id: id_contract},
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#tab_1_4').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#tab_1_4').removeClass('ht-on-loading').html(response.data);
                        $('.monthpicker').datepicker({
                            format: 'mm/yyyy',
                            autoclose: true,
                            viewMode: "months",
                            minViewMode: "months",
                        });
                    }
                })
            } else if (href == '#tab_1_5') {
                var id_contract = $("#payment_contract option:selected").val();
                roomId = $(this).attr('data-room');
                $.ajax({
                    url: '<?php echo e(url('admin2/room/contracts')); ?>' + '/' + roomId,
                    data: {contract_id: id_contract},
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#tab_1_5').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#tab_1_5').removeClass('ht-on-loading').html(response.data);
                        $('.monthpicker').datepicker({
                            format: 'mm/yyyy',
                            autoclose: true,
                            viewMode: "months",
                            minViewMode: "months",
                        });
                    }
                })
            } else if (href == '#tab_1_1') {
                $.ajax({
                    url: '<?php echo e(url('admin2/room/info')); ?>' + '/' + roomId,
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#tab_1_1').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#tab_1_1').removeClass('ht-on-loading').html(response.data);
                    }
                })
            } else if (href == '#tab_1_2') {
                $.ajax({
                    url: '<?php echo e(url('admin2/room/renters')); ?>' + '/' + roomId,
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#tab_1_2').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#tab_1_2').removeClass('ht-on-loading').html(response.data);
                    }
                })
            } else if (href == '#tab_1_7') {
                $.ajax({
                    url: '<?php echo e(url('admin2/room/items')); ?>' + '/' + roomId,
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#tab_1_7').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#tab_1_7').removeClass('ht-on-loading').html(response.data);
                    }
                })
            } else if (href == '#tab_1_6') {
                $.ajax({
                    url: '<?php echo e(url('admin2/room/breaks')); ?>' + '/' + roomId,
                    type: 'get',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#tab_1_6').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#tab_1_6').removeClass('ht-on-loading').html(response.data);
                    }
                })
            }
        });

        $(document).on('click', '.btn-cancel-paid', function (e) {
            e.preventDefault();

            $(this).parent().parent().parent().parent().remove();

        });


        $(".form-add-room-type").validate(
            {
                ignore: ".ignore",
                rules: {
                    'room_type_name[]': "required",
                },
                messages: {
                    // image: 'Vui lòng không bỏ trống hình ảnh'
                }
            }
        );


        $(document).on('click', '.btn-leave-room', function (e) {
            var that = this;
            var room_id = $(this).attr('data-room');
            var renter_id = $(this).attr('data-renter');
            var contract_id = $(this).attr('data-contract');
            if (contract_id == -1) {
                bootbox.confirm({
                    message: "Bạn có chắc chắn muốn khách thuê rời phòng ?",
                    buttons: {
                        confirm: {
                            label: 'Có',
                            className: 'btn-success'
                        },
                        cancel: {
                            label: 'Không',
                            className: 'btn-danger'
                        }
                    },


                    callback: function (result) {
                        if (result == true) {
                            leave_room(room_id, renter_id);
                        }
                    }
                });
            } else {
                var dialog = bootbox.dialog({
                    title: 'Chọn đại diện HĐ mới',
                    message: '<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>',
                    buttons: {
                        cancel: {
                            label: "Hủy",
                            className: 'btn-danger',
                            callback: function () {
                                console.log('Custom cancel clicked');
                            }
                        },
                        ok: {
                            label: "Chuyển",
                            className: 'btn-info',
                            callback: function () {
                                var data = $('#form-change-contract').serialize();
                                $.ajax({
                                    url: '<?php echo e(url('admin2/renter/change-contract')); ?>',
                                    type: 'post',
                                    data: data,
                                    dataType: 'json',
                                    success: function (response) {
                                        leave_room(room_id, renter_id);
                                    }
                                });
                            }
                        }
                    }
                });

                dialog.init(function () {
                    $.ajax({
                        url: '<?php echo e(url('admin2/renter/get-contract')); ?>',
                        type: 'get',
                        data: {
                            contract_id: contract_id,
                            room_id: room_id
                        },
                        dataType: 'json',
                        success: function (response) {
                            dialog.find('.bootbox-body').html(response.data);
                        }
                    });

                });
            }
        });

        function leave_room(room_id, renter_id) {
            $.ajax({
                url: '<?php echo e(url('admin2/room/leave')); ?>',
                type: 'post',
                data: {
                    room_id: room_id,
                    renter_id: renter_id
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        swal('Thành công', 'Người thuê đã rời phòng', 'success');
                        $('#tabs').find('li.active > a').click();
                        rating('', renter_id, room_id);
                    } else if (response.status == 3) {
                        swal('Thông báo', response.message, 'info');
                    } else if (response.status == 2) {
                        var contractId = response.contract_id;
                        $.ajax({
                            url: '<?php echo e(url('admin2/room/end-contract')); ?>' + '/' + contractId,
                            type: 'post',
                            dataType: 'json',
                            cache: false,
                            beforeSend: function () {
                                $('#contract-items').addClass('ht-on-loading');
                            },
                            success: function (response) {
                                $('#contract-items').removeClass('ht-on-loading');
                                if (response.status == 1) {
                                    swal('Thành công', 'Hợp đồng đã được thanh lý', 'success');
                                    $('#tabs').find('li.active > a').click();
                                    rating(contractId);

                                } else if (response.status == 2) {
                                    $('#end-contract-money').modal('show');
                                    $('#end-contract-money-content').html(response.data);
                                }
                            }
                        });

                    } else {
                        swal('Thông báo', response.message, 'warning');
                    }
                    $('button[data-block-name="' + blockGlobalName + '"]').click();
//                $(that).parent().parent().find('.col-md-12').first().next().html(response.data);
                }
            })
        }

        function rating(contractId, renterId, roomId) {
            renterId = typeof renterId !== 'undefined' ? renterId : '';
            contractId = typeof contractId !== 'undefined' ? contractId : '';
            roomId = typeof roomId !== 'undefined' ? roomId : '';
            $('#rating').modal('show');
            $.ajax({
                url: '<?php echo e(url('admin2/renter/rating')); ?>',
                type: 'get',
                data: {
                    contract_id: contractId,
                    renter_id: renterId,
                    room_id: roomId
                },
                dataType: 'json',
                beforeSend: function () {
                    $('#rating-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#rating-content').removeClass('ht-on-loading').html(response.data);
                }
            });
        }

        $(document).on('click', '.btn-paid', function (e) {
            var that = this;
            var money_info_id = $(this).attr('data-money-info');
            $.ajax({
                url: '<?php echo e(url('admin2/room/paid-form')); ?>',
                type: 'get',
                data: {
                    money_info_id: money_info_id
                },
                dataType: 'json',
                success: function (response) {

                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }

                    if (response.status == 1) {

                        $('#form-paid-' + money_info_id).html(response.data);
                        $('.datepicker').datepicker({
                            format: 'dd/mm/yyyy',
                            autoclose: true
                        });

                    }
//                $(that).parent().parent().find('.col-md-12').first().next().html(response.data);
                }
            })
        });

        $(document).on('click', '.btn-paid-full', function (e) {
            e.preventDefault();
            var that = this;
            var money_info_id = $(this).attr('data-money-info');
            $.ajax({
                url: '<?php echo e(url('admin2/room/get-remain')); ?>',
                type: 'get',
                data: {
                    money_info_id: money_info_id
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                    if (response.status == 1) {
                        $('#form-paid-' + money_info_id).find('.price-r').val(response.data.remain);
                    }
//                $(that).parent().parent().find('.col-md-12').first().next().html(response.data);
                }
            })
        });


        $(document).on('click', '.btn-detail-history', function (e) {
            e.preventDefault();
            var roomId = $(this).attr('data-room');
            var moneyInfoId = $(this).attr('data-money-info');
            $.ajax({
                url: '<?php echo e(url('admin2/room/paid-history')); ?>',
                data: {
                    room_id: roomId,
                    money_info_id: moneyInfoId
                },
                type: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $('#detail-history-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#detail-history-content').removeClass('ht-on-loading').html(response.data);
                }
            })
        });

        $(document).on('blur', '.room-type-long', function (e) {
            var long = $(this).val();
            var width = $(this).parent().parent().parent().find('.room-type-width').val();

            if (long == '') {
                long = 0;
            }

            if (width == '') {
                width = 0;
            }

            long = parseInt(long);
            width = parseInt(width);
            var size = long * width;
            $(this).parent().parent().parent().find('.room-type-size').val(size);


        });

        $(document).on('blur', '.room-type-width', function (e) {
            var width = $(this).val();
            var long = $(this).parent().parent().parent().find('.room-type-long').val();

            if (long == '') {
                long = 0;
            }

            if (width == '') {
                width = 0;
            }

            long = parseInt(long);
            width = parseInt(width);
            var size = long * width;
            $(this).parent().parent().parent().find('.room-type-size').val(size);


        });

        $(document).on('change', '#province1', function (e) {
            $.ajax({
                url: '<?php echo e(url('get-sub-location')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'province',
                },
                dataType: 'html',
                success: function (response) {
                    $('#district1').html(response);
                    $('#ward1').html('');
                    $('.select2').select2();

                }
            });
        });

        $(document).on('change', '#district1', function (e) {
            $.ajax({
                url: '<?php echo e(url('get-sub-location')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'district'
                },
                dataType: 'html',
                success: function (response) {
                    $('#ward1').html(response);
                    $('.select2').select2();
                }
            });
        });
        $(document).on('change', '#hostels_form', function () {
            var id = $(this).val();
            //var type = $(this).attr('data-type');
            $.ajax({
                url: '<?php echo e(url('get-sub-hostel')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'other'
                },
                dataType: 'html',
                success: function (response) {
                    $('#room_id').html(response);
                    $('#room_id').select2();
                }
            });
        });

        $(document).on('change', '#province2', function (e) {
            $.ajax({
                url: '<?php echo e(url('get-sub-location')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'province',
                },
                dataType: 'html',
                success: function (response) {
                    $('#district2').html(response);
                    $('#ward2').html('');
                    $('.select2').select2();

                }
            });
        });

        $(document).on('change', '#district2', function (e) {
            $.ajax({
                url: '<?php echo e(url('get-sub-location')); ?>',
                type: 'get',
                data: {
                    'id': $(this).val(),
                    'type': 'district'
                },
                dataType: 'html',
                success: function (response) {
                    $('#ward2').html(response);
                    $('.select2').select2();
                }
            });
        });

        function update_money_info(money_info_id) {
            var start_date = $('#start_date_money_info').val();
            var end_date = $('#end_date_money_info').val();
            var discount = $('#money-info-discount').val();
            var value_money_info = $('#value-money-info').val();

            $.ajax({
                url: '<?php echo e(url('admin2/room/cal-money-info')); ?>',
                data: {
                    start_date: start_date,
                    end_date: end_date,
                    money_info_id: money_info_id,
                    discount: discount,
                    value_money_info: value_money_info
                },
                type: 'post',
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        $('#money-info-amount').val(response.data);
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            })
        }

        $(document).on('blur', '#money-info-discount, #value-money-info', function () {
            update_money_info(g_money_info_id);
        });

        var g_money_info_id;
        $(document).on('click', '.update-money-info', function (e) {
            var money_info_id = $(this).attr('data-money-info');

            g_money_info_id = money_info_id;
            $.ajax({
                url: '<?php echo e(url('admin2/room/update-money-info')); ?>',
                data: {
                    money_info_id: money_info_id,
                },
                type: 'get',
                beforeSend: function (xhr) {

                    xhrthat = xhr;
                    $.ajax({
                        url: '<?php echo e(url('admin2/room/check-payment-status-money-info')); ?>',
                        data: {
                            money_info_id: money_info_id,
                        },
                        type: 'get',
                        dataType: 'json',
                        success: function (response) {
                            if (response.status == 0) {
                                swal('Thông báo', response.message, 'info');
                                xhrthat.abort();
                            } else {
                                // $('#update-money-info-content').addClass('ht-on-loading');
                                $('#update-money-info-modal').modal('show');
                            }
                        }
                    });
                },
                dataType: 'json',
                success: function (response) {
                    if (response.status == 1) {
                        $('#update-money-info-content').removeClass('ht-on-loading').html(response.data);
                        $('.datepicker').datepicker({
                            format: 'dd/mm/yyyy',
                            language: 'vi',
                            autoclose: true,
                        }).on('changeDate', function (e) {
                            update_money_info(money_info_id)
                            //   get_stat();
                        });
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            })
        });

        $(document).on('click', '#btn-save-money-info-update', function (e) {
            e.preventDefault();
            var data = $('#form-update-money-info').serialize();
            $.ajax({
                url: '<?php echo e(url('admin2/room/update-money-info-room')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#update-money-info-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#update-money-info-content').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        $('#update-money-info-modal').modal('hide');
                        swal('Thông báo', 'Dữ liệu đã được cập nhật', 'success');
                        $('#tabs').find('li.active > a').click();
                    } else {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        });

        $(document).on('click', '#btn-gen-invoice', function (e) {
            e.preventDefault();
            var contract_id = $(this).attr('data-contract');
            bootbox.confirm({
                message: "Bạn có chắc chắn muốn sinh hóa đơn cho tháng tiếp theo ?",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },
                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin2/contract/gen-next-invoice')); ?>',
                            data: {
                                contract_id: contract_id,
                            },
                            type: 'post',
                            dataType: 'json',
                            success: function (response) {
                                if (response.status == 1) {
                                    swal('Thành công', 'Hệ thống đã xử lý hóa đơn', 'success');
                                    $('#next-invoice-date').text(response.data);
                                } else {
                                    swal('Thông báo', response.message, 'info');
                                }
                            }
                        })
                    }
                }
            });
        });

        $('#btn-save-import-service').click(function (e) {
            e.preventDefault();

            var formStatus = $('#form-import-service').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'file': "required",
                },
                messages: {
                    'file': "Không được bỏ trống file",
                }
            }).form();

            if (formStatus) {
                let data = new FormData($('#form-import-service')[0]);
                $.ajax({
                    url: '<?php echo e(url('admin2/money/import-money-info-service')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    processData: false,
                    contentType: false,
                    beforeSend: function () {
                        $('#import-service-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#import-service-content').removeClass('ht-on-loading');
                        $('#import-service').modal('hide');
                        if (response.status == 1) {
                            $('#progress-action').modal('show');
                            $('#progress-action-content').html('<h4>Hệ thống đang tiến hành đọc file xử lý. Bạn có thể tắt popup này và tiếp tục thao tác</h4>');

                        } else if (response.status == 0) {
                            swal('Thông báo', response.message, 'warning');
                        } else if (response.status == 2) {
                            swal('Thông báo', response.message, 'info');
                        }

                    }
                });
            }
        });

        $('#btn-save-import-contract').click(function (e) {
            e.preventDefault();

            var formStatus = $('#form-import-contract').validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",

                highlight: function (e) {
                    $(e).closest(".form-group").addClass("has-error")
                },
                unhighlight: function (e) {
                    $(e).closest(".form-group").removeClass("has-error")
                },
                success: function (e) {
                    e.closest(".form-group").removeClass("has-error")
                },
                rules: {
                    'file': "required",
                },
                messages: {
                    'file': "Không được bỏ trống file",
                }
            }).form();

            if (formStatus) {
                let data = new FormData($('#form-import-contract')[0]);
                $.ajax({
                    url: '<?php echo e(url('admin2/contract/import-contract')); ?>',
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    processData: false,
                    contentType: false,
                    beforeSend: function () {
                        $('#import-contract-content').addClass('ht-on-loading');
                    },
                    success: function (response) {
                        $('#import-contract-content').removeClass('ht-on-loading');
                        $('#import-contract').modal('hide');
                        if (response.status == 1) {
                            //  swal('Thành công', response.message, 'success');
                            $('#progress-action').modal('show');
                            $('#progress-action-content').html('<h4>Hệ thống đang tiến hành đọc file xử lý. Bạn có thể tắt popup này và tiếp tục thao tác</h4>');
                            // setTimeout(function () {
                            //     location.reload();
                            // }, 2000);

                        } else if (response.status == 0) {
                            swal('Thông báo', response.message, 'warning');
                        } else if (response.status == 2) {
                            swal('Thông báo', response.message, 'info');
                        }

                    }
                });
            }
        });

    </script>
    <script src="<?php echo e(asset('/assets/js/plugins/Zen-input.js')); ?>" type="text/javascript"></script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin2', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>