<?php $__env->startSection('styles'); ?>
    <style>
        td {
            text-align: center;
            vertical-align: middle !important;
        }

        th {
            text-align: center;
            vertical-align: middle !important;
        }
    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <?php if(session()->has('error')): ?>
        <div class="alert alert-danger"><?php echo e(session()->get('error')); ?></div>
    <?php endif; ?>
    <?php if(session()->has('success')): ?>
        <div class="alert alert-success"><?php echo e(session()->get('success')); ?></div>
    <?php endif; ?>
    <?php if(session()->has('success_coupon')): ?>
        <?php echo session()->get('success_coupon'); ?>

    <?php endif; ?>
    <?php if(count($errors) > 0): ?>
        <div class="alert alert-danger">
            <ul>
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
    <?php endif; ?>
    <h1 class="page-title">
        Báo cáo tình hình sử dụng điện nước

    </h1>
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-4">
                    <input class="form-control monthpicker" id="month"
                           value="<?php echo e(Carbon\Carbon::now()->format('m/Y')); ?>">
                </div>
                <div class="col-md-4">
                    <select class="form-control" id="hostel_id">
                        <?php $__currentLoopData = $hostels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $hostel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($hostel->id); ?>"><?php echo e($hostel->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-4">
                    <button href="#" id="btn-export" class="btn btn-sm green-meadow"><i class="fa fa-file-excel-o"></i>
                        Xuất excel
                    </button>
                </div>
            </div>
        </div>
        <div class="col-md-12" id="detail" style="margin-top: 15px">

        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>

        function get_data() {
            $.ajax({
                url: '<?php echo e(url('admin2/report/ew-2-by-month')); ?>',
                type: 'get',
                data: {
                    month: $('#month').val(),
                    hostel_id: $('#hostel_id').val()
                },
                beforeSend: function () {
                    $('#detail').addClass('ht-on-loading');
                },
                dataType: 'json',
                success: function (response) {
                    $('#detail').removeClass('ht-on-loading').html(response.data);
                }
            });
        }

        $(document).ready(function () {
            get_data();
        });

        $('#btn-export').click(function () {
            var url = '<?php echo e(url('admin2/report/ew-2-by-month')); ?>' + '?month=' + $('#month').val() + '&is_export=1&hostel_id='+$('#hostel_id').val();
            console.log(url);
            window.location.href = url;
        });

        $('.monthpicker').datepicker({
            format: 'mm/yyyy',
            autoclose: true,
            viewMode: "months",
            minViewMode: "months",
        }).on('changeDate', function () {
            get_data();
        });

        $('#hostel_id').change(function() {
            get_data();
        });
    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin2', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>