HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/hrms-production/storage/framework/views/4c52ff2393fc371eb707ec1dd06ede294ff32f25.php
<div class="modal fade" id="addDepartment">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Add Department</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- Main content -->
                <form id="addDepartmentform">
                    <input type="hidden" name="_token" id="token_department" value="<?php echo e(csrf_token()); ?>">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group mb-2">
                                    <label class="mb-0" for="ActualWorkPlace">Actual Work Place<span class="text-danger">*</label>
                                    <select class="form-control form-control-sm select2" style="width: 100%;" aria-hidden="true" name="ActualWorkPlaceId" id="AWPIdDepartment" data-placeholder="Select Actual Work Place" required>
                                        <option selected="selected" disabled>Select Actual Work Place</option>
                                      </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group mb-2">
                                    <label class="mb-0" for="DepartmentName">Department Name<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control form-control-sm" id="DepartmentName" name="DepartmentName" required>
                                </div>
                            </div>
                        </div>
                        <hr />
                        <div class="row">
                            <div class="col-12">
                                <div class="d-flex align-items-center justify-content-center">
                                    <button type="button" class="btn btn-sm btn-outline-secondary mx-1"
                                        data-dismiss="modal" aria-label="Close">Cancel</button>
                                    <button type="submit" id="btn-save-new-department"
                                        class="btn btn-sm btn-outline-info mx-1">Save &amp; New</button>
                                    <button type="submit" id="btn-save-department"
                                        class="btn btn-sm btn-info mx-1">Save</button>
                                </div>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->


<div class="modal fade" id="updateDepartment">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Department <span id="DepartmentName" class="text-info"></span></h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- Main content -->
                <form id="updateDepartmentform">
                    <input type="hidden" name="_token" id="token_department_update" value="<?php echo e(csrf_token()); ?>">
                    <input type="hidden" id="DepartmentId" name="DepartmentId">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group mb-2">
                                    <label class="mb-0" for="name">Department Name<span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control form-control-sm" id="editDepartmentName"
                                        name="DepartmentName" onkeyup="checkDuplicateDepartment(this);" required>
                                    <span id='editCheckDepartment'></span>
                                </div>
                            </div>
                        </div>
                        <hr />
                        <div class="row">
                            <div class="col-12">
                                <div class="d-flex align-items-center justify-content-center">
                                    <button type="button" class="btn btn-sm btn-outline-secondary mx-1"
                                        data-dismiss="modal" aria-label="Close">Cancel</button>
                                    <button type="button" id="btn-update-department" name="Update" value="Update"
                                        class="btn btn-sm btn-info mx-1" disabled>Update</button>
                                </div>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->




<script>
    $(document).ready(function() {
        $.ajax({
          type: "GET",
          url: "<?php echo e(url('/actual-work-place-list')); ?>",
          dataType: "json",
          success: function(response) {
            var json = response.AWPList;
            $.each(json, function(i, awp) {
              $("#AWPIdDepartment, #AWPIdDepartmentEdit").append("<option value='" + awp.ActualWorkPlaceId + "'>" + awp.ActualWorkPlaceName + "</option>");
              $('#AWPIdDepartment, #AWPIdDepartmentEdit').trigger('change');
            });
          }
        });
    });
</script>


<script>
    function checkDuplicateDepartment(element, id){
        var id = id;
        var DepartmentName = $(element).val();
        if (DepartmentName == "") {
            $('span#CheckDepartment, #editCheckDepartment').css("display", "none");
        } else {
            $('span#CheckDepartment, #editCheckDepartment').css("display", "block");
        }
        //alert (Department);
        $.ajax({
            type: "GET",
            url: '<?php echo e(url("/")); ?>/check-department/',
            data: {DepartmentName:DepartmentName, id:id},
            dataType: "json",
            success: function(res) {
                if(res.exists){
                    $('span#CheckDepartment, span#editCheckDepartment').html('<span class="text-danger">Department name is already exist!</span>');
                    $('#btn-save-new-department, #btn-save-department, #btn-update-department').attr('disabled', true);
                } else {
                    $('span#CheckDepartment, span#editCheckDepartment').html('<span class="text-success">Department name is available!</span>');
                    $('#btn-save-new-department, #btn-save-department, #btn-update-department').attr('disabled', false);
                }
            },
            error: function (jqXHR, exception) {
            }
        });
    }
</script>


<script>
    var reload = 0;
    $(function () {
      $.validator.setDefaults({
        submitHandler: function () {
            saveDepartmentRecord();
        }
      });
      // Reload page after data save 
      $('#btn-save-department').click(function(){
        reload = 1;
      });

      // Validate Fields
      $('#addDepartmentform').validate({
        rules: {
            DepartmentName: {
            required: true,
            remote: {
                type: "POST",
                url:'<?php echo e(url("/")); ?>/check-duplicate-department',
                data: {
                    DepartmentName: function() {
                    return $( "#DepartmentName" ).val();
                },
                ActualWorkPlaceId: function() {
                    return $('#AWPIdDepartment').find(":selected").val();
                },
                '_token':$('meta[name="csrf-token"]').attr('content')
                }
            },
          },
        },
        messages: {
          DepartmentName: {
            required: "Please enter the department name",
            remote: "The department already exists in the selected place.",
          },
        },
        errorElement: 'span',
        errorPlacement: function (error, element) {
          error.addClass('invalid-feedback');
          element.closest('.form-group').append(error);
        },
        highlight: function (element, errorClass, validClass) {
          $(element).addClass('is-invalid');
        },
        unhighlight: function (element, errorClass, validClass) {
          $(element).removeClass('is-invalid');
        }
      });
    });
</script>


<script>
    function saveDepartmentRecord() {
        event.preventDefault();
        $.ajax({
            type: "post",
            url: "<?php echo e(url('store-department')); ?>",
            dataType: "json",
            data: $('form#addDepartmentform').serialize(),
            success: function(response) {
                const Toast = Swal.mixin({
                      toast: true,
                      position: 'top-end',
                      showConfirmButton: false,
                      timer: 2000,
                      timerProgressBar: true,
                      didOpen: (toast) => {
                        toast.addEventListener('mouseenter', Swal.stopTimer)
                        toast.addEventListener('mouseleave', Swal.resumeTimer)
                      }
                    })
                    Toast.fire({
                      icon: 'success',
                      title: 'Department added successfully!'
                    });
                $('form#addDepartmentform').each(function() {
                    this.reset();
                    $('#AWPIdDepartment').val(null).trigger('change');
                });
                
                if(reload)
                {
                    location.reload();
                }
            },
            error: function(response) {
                const Toast = Swal.mixin({
                      toast: true,
                      position: 'top-end',
                      showConfirmButton: false,
                      timer: 3000,
                      timerProgressBar: true,
                      didOpen: (toast) => {
                        toast.addEventListener('mouseenter', Swal.stopTimer)
                        toast.addEventListener('mouseleave', Swal.resumeTimer)
                      }
                    })
                    Toast.fire({
                      icon: 'error',
                      title: 'Sorry, Something went wrong!'
                    })
            }
        });
    }
</script>

<script>
    // Activate
    function activateDepartment(DepartmentId) {
        var DepartmentId = DepartmentId;
        Swal.fire({
            title: 'Activate Department?',
            text: "Are you sure you want to activate Department!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, activate it!'
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    type: "get",
                    url: "<?php echo e(url('/')); ?>/change-status-department/" + DepartmentId,
                    success: function(response) {
                        Swal.fire({
                            icon: 'success',
                            title: 'Department has been activated!',
                            showConfirmButton: false,
                            timer: 1500
                        }).then(function() {
                            location.reload();
                        });
                    }
                });
            }
        });
    }
    // Deactivate
    function deactivateDepartment(DepartmentId) {
        var DepartmentId = DepartmentId;
        Swal.fire({
            title: 'De-activate Department?',
            text: "Are you sure you want to De-activate Department!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, De-activate it!'
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    type: "get",
                    url: "<?php echo e(url('/')); ?>/change-status-department/" + DepartmentId,
                    success: function(response) {
                        Swal.fire({
                            icon: 'success',
                            title: 'Department has been De-activated!',
                            showConfirmButton: false,
                            timer: 1500
                        }).then(function() {
                            location.reload();
                        });
                    }
                });
            }
        });
    }
</script>

<script>
    function editDepartment(DepartmentId)
  {
      var DepartmentId = DepartmentId;
      $('#updateDepartment').modal('show');
      $.ajax({
          type: "GET",
          url: "<?php echo e(url('/')); ?>/edit-department/" +DepartmentId,
          success: function (response) {
              $('#editDepartmentName').val(response.Department.DepartmentName);
              $('#DepartmentId').val(DepartmentId);
              $('span#DepartmentName').html('#' +response.Department.DepartmentName);
          }
      });
  }
</script>


<script>
    $("#btn-update-department").click(function (event) {
    event.preventDefault();
    var Name = $("#editDepartmentName").val();
    if (Name == "") {
        Swal.fire({
            icon: "warning",
            title: "Name is required!",
            showConfirmButton: false,
            timer: 2000,
        });
    } else {
        $.ajax({
            type: "post",
            url: "<?php echo e(url('update-department')); ?>",
            dataType: "json",
            data: $("form#updateDepartmentform").serialize(),
            success: function (response) {
                Swal.fire({
                    icon: "success",
                    title: "Department has been updated!",
                    showConfirmButton: false,
                    timer: 2000,
                }).then(function () {
                    location.reload();
                });
            },
            error: function (response) {
                Swal.fire({
                    icon: "error",
                    title: "Sorry, Some thing went wrong!",
                    showConfirmButton: false,
                    timer: 2000,
                });
            },
        });
    }
    });

</script>


<script>
    //Delete Department
    function deleteDepartment(DepartmentId) {
    var DepartmentId = DepartmentId;
    $.ajax({
        type: "GET",
        url: "<?php echo e(url('/')); ?>/check-employee-department/" + DepartmentId,
        success: function (response) {
            if (response.exists) {
                Swal.fire({
                    icon: "warning",
                    title: "Can't be deleted!",
                    text: "This Department is associated with empolyee(s)!",
                    showConfirmButton: true,
                });
            } else {
                Swal.fire({
                    title: "Delete Department?",
                    text: "Are you sure you want to delete this Department?",
                    icon: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    cancelButtonColor: "#d33",
                    confirmButtonText: "Yes, delete it!",
                }).then((result) => {
                    if (result.isConfirmed) {
                        $.ajax({
                            type: "get",
                            url:
                                "<?php echo e(url('/')); ?>/delete-department/" +
                                DepartmentId,
                            success: function (response) {
                                Swal.fire({
                                    icon: "success",
                                    title: "Department has been deleted!",
                                    showConfirmButton: false,
                                    timer: 1500,
                                }).then(function () {
                                    location.reload();
                                });
                            },
                        });
                    }
                });
            }
        },
    });
    }

</script><?php /**PATH /var/www/html/hrms-production/resources/views/components/department-modal.blade.php ENDPATH**/ ?>