

<?php $__env->startSection('content'); ?>

<div class="card-header"><span><a href="<?php echo e(route('dashboard')); ?>"><?php echo e(__('Dashboard')); ?></a></span> >
    <span><?php echo e(__('Employee Data')); ?></span></div>
<div class="card-body dashboard-card">
   
    

    <!------- Filter data by Datewise----->
    <div class="row search-form mt-4">
        <div class="col-md-8">

            

        </div>
        <!------- Export data in table----->
        <div class="col-md-4">
            <div class="row">
                <div class="col-lg-4 col-md-4 col-12"></div>
                <div class="col-lg-4 col-md-4 col-12"></div>
                <div class="col-lg-4 col-md-4 col-12">
                    <a class="btn" href="#" data-toggle="modal" data-target="#importModal">Import</a>
                </div>
                
            </div>
        </div>
    </div>

    <!------- Data table----->
    <div class="row mt-4">
        <div class="col-12 table-responsive">
            <table class="table table-bordered datatable">
                <thead>
                    <tr>
                        <th class="text-center" width="2%">Sl.No</th>
                        <th width="5%">UniqueID</th>
                        <th width="24%">Name</th>
                        <th width="14%">Phone</th>
                        <th width="13%">Q-ID</th>
                        <th width="17%">Email</th>
                        <th width="16%">Created At</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>

<!---- Import modal --->
<div class="modal" id="importModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Import employee data</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="importForm" name="importForm" class="form-horizontal" enctype="multipart/form-data" action="<?php echo e(route('importdata.import')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="form-group">
                        <label>Select file for uploading</label>
                        <input type="file" name="file" id="file" class="form-control" accept=".xlsx, .xls, .csv" required />
                    </div>
                    <div class="alert alert-danger mt-2 error_import_file" style="display: none">Please enter
                        correct data</div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary" id="uploadBtn">Upload File</button>
                </div>
            </form>
        </div>
    </div>
</div>

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

<?php $__env->startSection('scripts'); ?>
<script type="text/javascript">
    var _token = $('meta[name="csrf-token"]').attr('content');
    var s_message = "<?php echo e(session('success')); ?>";
    var e_message = "<?php echo e(session('error')); ?>";

    $(function () {

        var from_date = $('#from_date').val();
        var to_date = $('#to_date').val();

        var table = $('.datatable').DataTable({
            processing: true,
            serverSide: true,

            ajax: {
                "url": "<?php echo e(route('employee_data.post')); ?>",
                "dataType": "json",
                method: "POST",
                data: {
                    from_date: $('#from_date').val(),
                    to_date: $('#to_date').val(),
                    _token: _token
                },
            },
            columns: [{
                    data: 'DT_RowIndex',
                    name: 'DT_RowIndex',
                    orderable: false,
                    searchable: false
                },
                {
                    data: 'unique_id',
                    name: 'unique_id'
                },
                {
                    data: 'name',
                    name: 'name'
                },
                {
                    data: 'phone',
                    name: 'phone'
                },
                {
                    data: 'q_id',
                    name: 'q_id'
                },
                {
                    data: 'email',
                    name: 'email'
                },
               
                {
                    data: 'created_date',
                    name: 'created_date'
                },
                // {
                //     data: 'action',
                //     name: 'action',
                //     orderable: false,
                //     searchable: false
                // },
            ],
            'columnDefs': [
                    {
                        "targets": 0, 
                        "className": "text-center"
                }
            ]
        });

        // //Show success message
        // if (s_message)
        //     Swal.fire({
        //         text: s_message,
        //         type: 'success',
        //         confirmButtonText: 'Ok',
        //         confirmButtonColor: "rgb(174,46,184)"

        //     });
        // if (e_message)
        //     Swal.fire({
        //         text: e_message,
        //         type: 'error',
        //         confirmButtonText: 'Ok',
        //         confirmButtonColor: "rgb(174,46,184)"

        //     });



            // Import data modal submit

        $('#importForm').submit(function(e) {

            e.preventDefault();
            $('#uploadBtn').html('Uploading..');

            let formData = new FormData(this);

            $.ajax({
                type: "POST",
                url: "<?php echo e(route('employee_data.import')); ?>",
                data:formData,
                contentType: false,
                processData:false,
                success: function (data) {
                    if (data.status == "success") {
                        $('#importForm').trigger("reset");
                        $('#uploadBtn').html('Upload file');
                        $(".error_import_file").hide();

                        $('#importModal').modal('hide');
                        Swal.fire({
                            text: data.message,
                            type: 'success',
                            confirmButtonText: 'Ok',
                            confirmButtonColor: "#F4C202"

                        }).then((result) => {
                        // Reload the Page
                        location.reload();
                        });
                    } else {

                        $(".error_import_file").text(data.message);
                        $(".error_import_file").show();
                        $('#uploadBtn').html('Upload file');
                    }

                },
                error: function (data) {
                    // console.log('Error:', data);
                    $('#uploadBtn').html('Upload file');
                }
            });
        });
        // Refresh date range
        $( ".refresh_btn" ).on( "click", function() {
            
            $('#from_date').val("");
            $('#to_date').val("");
           
        });
        
    });


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

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\abu-raffledraw\resources\views/import_employee_data.blade.php ENDPATH**/ ?>