<?php $__env->startSection('content_header'); ?>
    <?php echo notifyCss(); ?>
    <?php echo notifyJs(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card card-primary">
                    <div class="card-header">
                        <h3 class="card-title">Department</h3>
                    </div>
                    <?php echo $__env->make('notify::messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                    <!-- /.card-header -->
                    <div class="card-body">
                        <ul class="nav nav-tabs">
                            <li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#organisation_form"><b>Add Department</b></a></li>
                            <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#listorgdata"><b>View Department</b></a></li>
                        </ul>
                        <div class="tab-content">
                            <div id="organisation_form" class="tab-pane fade active show">
                                <!-- form start -->
                                <form id="userregform" class="form-horizontal" action="<?php echo e(URL::to('/department_post')); ?>" method="post" onsubmit="return validation();" autocomplete="off" enctype="multipart/form-data">
                                    <?php echo e(csrf_field()); ?>

                                    <div class="card-body">
                                        <div class="col-6">
                                            <div class="form-group row">
                                                <label for="exampleInputEmail1">Organisation</label>
                                                <select name="organisation_id" id="organisation_id" class="form-control" required>
                                                    <option value="">Select Organisation</option>
                                                    <?php $__currentLoopData = $organisations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $organisation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($organisation->id); ?>"><?php echo e($organisation->organisation_name); ?></option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </div>
                                            <div class="form-group row">
                                                <label for="exampleInputEmail1">Department Name</label>
                                                <input type="text" class="form-control" id="department_name" name="department_name" placeholder="Enter Department Name" required>
                                            </div>
                                            <div class="form-group row">
                                                <label for="exampleInputEmail1">Remarks</label>
                                                <input type="text" class="form-control" id="remarks" name="remarks" placeholder="Enter Remarks">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.card-body -->

                                    <div class="card-footer">
                                      <button type="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                            <div id="listorgdata" class="tab-pane fade" style="padding: 10px;">
                                <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                                    <thead>
                                        <tr>
                                          <th>Slno</th>
                                          <th>Organisation Name</th>
                                          <th>Department Name</th>
                                          <th>Remarks</th>
                                          <th>Actions</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">

        $(document).ready(function () 
        {
            $('#dept_details').DataTable({
                "buttons" : ['excelHtml5', 'excel', 'pdf', 'print', 'reset', 'reload'],
                "processing": true,
                "serverSide": true,
                "ajax":{

                         "url": "<?php echo e(url('get_department_details')); ?>",
                         "dataType": "json",
                         "type": "POST",
                         "data":{ _token: "<?php echo e(csrf_token()); ?>"}
                       },
                "columns": [
                    { "data": "DT_RowIndex" },
                    { "data": "organisation_name" },
                    { "data": "department_name" },
                    { "data": "remarks" },
                    { "data": "action" }
                ], 
                "order": [[1, 'asc']]
            });      
        });
        function confirmDeleteDepartment(dept_id) 
        {
            var x = confirm("Are you sure you want to delete?");
            if (x)
            {
                var csrf = "<?php echo e(csrf_token()); ?>";
                $.ajax({
                    type: "POST",
                    url: "<?php echo e(url('delete_department')); ?>",
                    dataType : 'json',
                    data: {_token: csrf, dept_id: dept_id},
                    success: function( msg ) {
                      if(msg)
                        alert("Department has been deleted");
                      else
                        alert("Sections are assigned to Selected Department.");
                      location.reload();
                    }
                });  
            }
            else
            {
              return false;
            }
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('adminlte::page', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/kmportal/resources/views/Admin/Settings/department.blade.php ENDPATH**/ ?>