

<?php $__env->startSection('styles'); ?>

    <link href="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-editable/bootstrap-editable/css/bootstrap-editable.css"
          rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-editable/inputs-ext/address/address.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>

        .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;
        }

        tfoot input {
            font-weight: normal !important;
        }

        tfoot select {
            font-weight: normal !important;
        }

        .dataTables_filter {
            display: none;
        }

        #orders-table_length {
            display: none;
        }

        .ws-nr {
            width: 100% !important;
        }

        /*.alert-danger .btn-danger {*/
        /*float: right;*/
        /*}*/

        /*.alert-danger span {*/
        /*line-height: 34px;*/
        /*}*/

        /*.alert-danger > div:after {*/
        /*clear: both;*/
        /*content: '';*/
        /*display: table;*/
        /*}*/
    </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">
        Danh sách tài sản
    </h1>


    <div class="row">


        <?php if(auth('backend')->user()->can('add-item')): ?>
        <div class="col-md-12">

            <a href="#add-item-excel" class="btn green-meadow pull-right" id="btn-add-item-excel" data-toggle="modal">Thêm
                từ excel</a>
            <a href="#add-item" data-toggle="modal" class="btn btn-success" id="btn-add-item"
               style="float: right; margin-right: 5px">Thêm tài sản</a>

        </div>
        <?php endif; ?>

        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover" id="orders-table">
                <thead>
                <tr style="background-color: #5376B9; color: white">
                    <th>STT</th>
                    <th>Tên</th>
                    <th>Mã tài sản</th>
                    <th>Mã tham chiếu</th>
                    <th>Giá</th>
                    <th>Tình trạng</th>
                    <th style="width: 10%;">Thao tác</th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th style="width: 10%;"></th>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12" id="detail">
        </div>
    </div>

    <div class="modal fade bs-modal-lg" id="add-item" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close2" data-dismiss="modal" aria-hidden="true"><span
                                aria-hidden="true" style="
    color: white;
">×</span></button>
                    <h4 class="modal-title">Thêm tài sản</h4>
                </div>
                <div class="modal-body" id="add-item-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-item">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>



    <div class="modal fade bs-modal-lg" id="add-item-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 tài sản từ file excel</h4>
                </div>
                <div class="modal-body" id="add-item-excel-content">
                    <form novalidate="novalidate" class="simple_form import" enctype="multipart/form-data"
                          action="/admin2/item/import-excel" accept-charset="UTF-8" data-remote="true" method="post">
                        <?php echo csrf_field(); ?>

                        <ul class="errors"></ul>
                        <div class="row">
                            <div class="col-md-6">
                                <div style="float: right"><a class="btn btn-circle yellow"
                                                             href="https://itro.vn/Sample_Import_Warehouse.xlsx" download=""><i
                                                class="fa fa-download" aria-hidden="true"></i> Tải tệp mẫu</a></div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="fileinput fileinput-new" data-provides="fileinput"><span
                                                class="btn btn-circle green btn-file"> <span class="fileinput-new"><i
                                                        class="fa fa-upload"
                                                        aria-hidden="true"></i> Chọn tệp </span> <span
                                                    class="fileinput-exists"><i class="fa fa-upload"
                                                                                aria-hidden="true"></i> Thay đổi </span> <input
                                                    type="file" name="file"> </span> <span
                                                class="fileinput-filename"> </span> &nbsp; <a href="javascript:;"
                                                                                              class="close fileinput-exists"
                                                                                              data-dismiss="fileinput"> </a>
                                    </div>
                                </div>
                            </div>
                            <input type="hidden" name="hostel_id" id="add-room-excel-hostel" value="5065"></div>
                    </form>

                </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-item-excel">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<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/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 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>
    $.validator.addMethod("greaterThan",
        function (value, element, param) {
            var $otherElement = $(param);
            return parseInt(value, 10) >= parseInt($otherElement.val(), 10);
        }
    );
</script>


<?php $__env->stopPush(); ?>


<?php $__env->startPush('scripts'); ?>















<script>


    var table;

    //    $(document).on('click', '#btn-add-item', function () {
    //
    //    });

    $(document).on('click', '#btn-save-item-excel', function () {
       // alert('123');
        $('.simple_form').submit();
    });

    $(document).on('click', '#btn-add-item', function () {
        $.ajax({
            url: '<?php echo e(url('admin2/warehouse/create-item')); ?>',
            type: 'get',
            dataType: 'json',
            beforeSend: function () {
                $('#add-item-content').addClass('ht-on-loading');
            },
            success: function (response) {

                $('#add-item-content').removeClass('ht-on-loading').html(response.data);
                $('.select2').select2();
            }
        });

    });

    $(document).on('click', '#gen', function () {
        $.ajax({
            url: '<?php echo e(url('admin2/warehouse/create-item-number')); ?>',
            type: 'get',
            data: {
                numbers: $('#number').val()
            },
            dataType: 'json',
            success: function (response) {
                $('#numbers').html(response.data);
            }
        });

    });

    $(document).on('click', '#btn-save-item', function (e) {
        e.preventDefault();
        var data = $('#form-add-item').serialize();

        var formStatus = $('#form-add-item').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",
                'min': 1,
            },
            messages: {
                'name': "Không được bỏ trống tên",
                'number': {
                    min: "Số lượng tối thiểu là 1"
                }
                // 'amenities[]': "Không được bỏ trống tiện ích"
            }
        }).form();

        if (formStatus) {

            $.ajax({
                url: '<?php echo e(url('admin2/warehouse/create-item')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#add-item-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-item-content').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        $('#add-item').modal('hide');
                        table.ajax.reload(null, false);
                        swal('Thành công', 'Dữ liệu đã được thêm thành công', 'success');
                    } 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');
                    }
                }
            });
        }
    });


    $(function () {

        $('#orders-table tfoot th').each(function (index) {
            if (index != 0 && index != 3) {
                $(this).html('<input type="text" class="form-control" />');
            }
        });
        table = $('#orders-table').DataTable({
            "bDestroy": true,
            processing: true,
            searching: true,
            "aaSorting": [],
            serverSide: true,
            ajax: {
                url: '<?php echo url('admin2/warehouse/item.data'); ?>',
            },
            columns: [

                {data: 'DT_Row_Index', name: 'DT_Row_Index', orderable: false, searchable: false},
                {data: 'name', name: 'name'},
                {data: 'code', name: 'code'},
                {data: 'reference', name: 'reference'},
                {data: 'price', name:'price'},
                {data: 'status', name: 'status'},
                {data: 'action', name: 'action', 'orderable': false, searchable: false},
            ],
        });


        table.columns().every(function (index) {
            if (index !== 0) {
                var that = this;
                $('input', this.footer()).on('keyup change', function () {
                    if (that.search() !== this.value) {
                        that
                            .search(this.value)
                            .draw();
                    }
                });
            }
        });

    });

    $(document).on('click', '.btn_edit_item', function () {
        $(this).parents('tr').find('.name_input').css('display','block');
        $(this).parents('tr').find('.reference_input').css('display','block');
        $(this).parents('tr').find('.price_input').css('display','block');
        $(this).parents('tr').find('.status_input').css('display','block');

        $(this).parents('tr').find('.name_text').css('display','none');
        $(this).parents('tr').find('.reference_text').css('display','none');
        $(this).parents('tr').find('.price_text').css('display','none');
        $(this).parents('tr').find('.status_text').css('display','none');
        $(this).parents('tr').find('.btn_save_item').css('display','block');
        $(this).parents('tr').find('.btn_cancel_item').css('display','block');
        $(this).css('display','none');
    })

    $(document).on('click', '.btn_cancel_item', function () {
        $(this).parents('tr').find('.name_input').css('display','none');
        $(this).parents('tr').find('.reference_input').css('display','none');
        $(this).parents('tr').find('.price_input').css('display','none');
        $(this).parents('tr').find('.status_input').css('display','none');

        $(this).parents('tr').find('.name_text').css('display','block');
        $(this).parents('tr').find('.reference_text').css('display','block');
        $(this).parents('tr').find('.price_text').css('display','block');
        $(this).parents('tr').find('.status_text').css('display','block');
        $(this).parents('tr').find('.btn_save_item').css('display','none');
        $(this).parents('tr').find('.btn_edit_item').css('display','block');
        $(this).css('display','none');
    })

    $(document).on('click', '.btn_save_item', function () {
        var id = $(this).attr('data-id');
        var name = $(this).parents('tr').find('.name_input').val();
        var reference = $(this).parents('tr').find('.reference_input').val();
        var price = $(this).parents('tr').find('.price_input').val();
        var status = $(this).parents('tr').find('.status_input').val();
        $.ajax({
            url: '<?php echo e(url('admin2/warehouse/edit-item')); ?>',
            type: 'post',
            data:{id: id, name: name, reference: reference, price:price, status:status},
            dataType: 'json',
            success: function (response) {
                swal('Thông báo', response.message, 'success');
                table.ajax.reload(null, false);
            }
        });

    })

    $(document).on('click', '.btn_delete_item', function () {
        var id = $(this).attr('data-id');
        $.confirm({
            title: 'Cảnh báo!',
            content: 'Dữ liệu sẽ bị xóa khi thực hiện thao tác',
            type: 'orange',
            typeAnimated: true,
            buttons: {
                OK: {
                    text: 'Đồng ý',
                    btnClass: 'btn-orange',
                    action: function(){
                        $.ajax({
                            url: '<?php echo e(url('admin2/warehouse/delete-item')); ?>',
                            type: 'post',
                            data:{id: id,},
                            dataType: 'json',
                            success: function (response) {
                                swal('Thông báo', response.message, 'success');
                                table.ajax.reload(null, false);
                            }
                        });
                    }
                },
                close: {
                    text: 'Đóng',
                    action: function () {

                    }
                }
            }
        });

    })


</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin2', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>