You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

884 lines
35 KiB

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{fragments/modules/base/head :: head}"></head>
<style>
.required{
color: red;
}
#modalBody h4 {
font-weight: bold;
margin-top: 15px;
margin-bottom: 10px;
}
#modalBody p {
margin: 5px 0;
}
#modalBody hr {
margin: 15px 0;
}
.comment {
margin-bottom: 20px;
}
.comment p {
margin: 0;
}
hr {
border: 1px solid #ccc;
margin-top: 20px;
margin-bottom: 20px;
}
h5 {
font-size: bold;
}
/* Limit the height of the dropdown menu and make it scrollable */
.dropdown-menu {
max-height: 200px; /* Adjust this value as needed */
overflow-y: auto;
}
.col-4 {
font-weight: bold;
text-align: right;
}
.col-8 {
padding-left: 20px;
}
.comment {
padding: 10px 0;
}
.comment .text-muted {
font-size: 0.9em;
color: #6c757d;
}
.comment hr {
border-top: 1px solid #ccc;
}
.comment .btn-link {
font-size: 0.9em;
text-decoration: underline;
color: #007bff;
}
/* Make the modal body scrollable */
#detailsModal .modal-body {
max-height: 70vh; /* Limit the height to 70% of the viewport */
overflow-y: auto; /* Enable vertical scrolling */
}
.card-box {
border-radius: 20px;
box-shadow: rgba(0, 0, 0, 0.5) 0px 3px 8px;
}
#followupCard {
transition: transform 0.2s ease; /* Smooth scaling transition */
cursor: pointer; /* Default cursor change */
}
#followupCard:hover {
transform: scale(1.05); /* Slightly scale up on hover */
cursor: pointer; /* Change cursor to hand symbol */
}
.card-block {
padding: 20px;
}
.form-label {
margin-bottom: 0.5rem;
}
input.form-control {
padding: 10px;
}
.form-select {
padding: 10px;
height: 40px;
}
#employeeCard label{
padding-top: 2%;
}
</style>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="wrapper">
<!-- header top menu Start -->
<header th:replace="~{fragments/modules/base/header :: header}"></header>
<!-- header top menu end -->
<div class="page-wrap">
<!--=============== Left Menu side Start ================-->
<div th:replace="~{fragments/modules/base/menu :: menu}"></div>
<!--=============== Left side End ================-->
<div class="main-content">
<div class="container-fluid">
<div class="page-header mb-2">
<div class="row align-items-end">
<div class="col-lg-8">
<div class="page-header-title">
<i class="fa fa-list-alt bg-blue"></i>
<div class="d-inline">
<h5>Department Entries</h5>
<span>Family Pension</span>
</div>
</div>
</div>
<div class="col-lg-4">
<nav class="breadcrumb-container" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/gcc/index"><i class="ik ik-home"></i></a></li>
<li class="breadcrumb-item" aria-current="page">Department Entries</li>
<li class="breadcrumb-item" aria-current="page">NewEntry</li>
<li class="breadcrumb-item active" aria-current="page">Family Pension</li>
</ol>
</nav>
</div>
</div>
</div>
<div class="row mt-4" >
<div class="col-md-12">
<div class="card">
<div class="card-block">
<h5 style="font-weight:bold;"> <span th:text="${deptname}" id="deptname"></span>&nbsp;Department</h5><span th:text="${filecategory}" id="filecategory" style="display:none"></span>
<h5 style="font-weight:bold;"><span th:text="${deptId}" id="deptId" style="display:none"></span> New Entry - Family Pension</h5>
<span th:text="${userId}" id="userId" style="display:none"></span>
<div class="row mb-4">
<!-- Input Fields for Year Selection -->
<!-- Start Year Dropdown as Button Dropdown -->
<!-- Start Year Dropdown as Button Dropdown -->
<div class="col-md-4" >
<label for="empCode" class="form-label fw-bold">Search by Employee No <span class="text-danger">*</span></label>
<div class="dropdown">
<input type="number" id="empCode" class="form-control" pattern="^[A-Za-z0-9]+$" placeholder="Enter Employee No" required>
<small id="employeenoHelp" class="form-text text-muted">Only numeric characters (numbers) are allowed.</small>
</div>
</div>
<div class="col-md-4 mt-20" >
<button id="searchButton" class="btn btn-primary mt-2" Style="height:38px;">Search</button>
<!-- <button id="resetButton" class="btn btn-secondary mt-2">Reset</button> -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mb-4" id="employeeCard" style="display: none;">
<div class="col-md-12">
<div class="card">
<div class="card-block">
<h5 style="font-weight:bold;">New Entry - Family Pension - <span id="EmployeeCode"></span></h5>
<hr>
<div class="row">
<!-- Employee No -->
<div class="col-md-6">
<label for="employeeno" class="form-label fw-bold">Employee No <span class="text-danger">*</span></label>
<div class="dropdown">
<input type="number" id="employeeno" class="form-control" readonly>
</div>
</div>
<!-- Employee Name -->
<div class="col-md-6">
<label for="employeename" class="form-label fw-bold">Employee Name <span class="text-danger">*</span></label>
<div class="dropdown">
<input type="text" id="employeename" class="form-control" readonly>
</div>
</div>
<div class="col-md-6">
<label for="Department" class="form-label fw-bold">Department <span class="text-danger">*</span></label>
<div class="dropdown">
<input type="text" id="department" class="form-control" readonly>
</div>
</div>
<div class="col-md-6">
<label for="Designation" class="form-label fw-bold">Designation<span class="text-danger">*</span></label>
<div class="dropdown">
<input type="text" id="designation" class="form-control" readonly>
</div>
</div>
<!-- pending duration-->
<div class="col-md-6">
<label for="pendingDuration" class="form-label fw-bold">
Pending Duration
<span class="text-danger">*</span>
</label>
<div class="d-flex align-items-center">
<div class="form-check" style="padding-right:10px;">
<input type="radio" id="yes" name="pendingDuration" value="yes"class="form-check-input">
<label for="yes" class="form-check-label">Yes</label>
</div>
<div class="form-check">
<input type="radio" id="no" name="pendingDuration" value="no"class="form-check-input">
<label for="no" class="form-check-label">No</label>
</div>
</div>
<div class="dropdown" id="pendingDurationInputContainer" style="display: none; margin-top: 10px;">
<input type="text" id="pendingDurationInput" name="pendingDurationValue" class="form-control" placeholder="Enter details for pending duration">
</div>
</div>
<div class="col-md-6">
<label for="servicedeath" class="form-label fw-bold">While In Service Death <span class="text-danger">*</span></label>
<div class="dropdown">
<input type="date" id="servicedeath" class="form-control" onclick="this.showPicker()" >
</div>
</div>
<div class="col-md-6">
<label for="deceased" class="form-label fw-bold">Relationship of Deceased<span class="text-danger">*</span></label>
<div class="dropdown">
<input type="text" id="deceased" class="form-control" >
</div>
</div>
<div class="col-md-6">
<label for="sanctionedgis" class="form-label fw-bold">Sanctioned GIS<span class="text-danger">*</span></label>
<div class="dropdown">
<input type="number" id="sanctionedgis" class="form-control" min="1" oninput="validatePositiveNumber(this)">
</div>
</div>
<div class="col-md-6">
<label for="Audit File" class="form-label fw-bold">Date file sent to Audit<span class="text-danger">*</span></label>
<div class="dropdown">
<input type="text" id="filesentdate" class="form-control" readonly>
</div>
</div>
<div class="col-md-12">
<label for="Remarks" class="form-label fw-bold">Comments/Remarks <span class="text-danger">*</span></label>
<div class="dropdown">
<textarea id="remarks" class="form-control" rows="4" placeholder="Enter your remarks here" required></textarea>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-12 d-flex justify-content-center">
<button id="lfauditButton" class="btn btn-primary mt-2 mx-2">Mark as sent audit</button>
<button id="cancelButton" class="btn btn-secondary mt-2">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="pageLoader" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.8); z-index: 9999; text-align: center;">
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
<span class="sr-only">Loading...</span>
</div>
<!-- Add the 'Please wait' text below the spinner -->
<p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
</div>
</div>
<footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
</div>
</div>
<div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
<script th:replace="~{fragments/modules/base/script :: script}"></script>
<script src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Bootstrap 5 JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
$(document).ready(function (){
// Handle Search button click
/* $('#searchButton').on('click', function () {
const empCode = $('#empCode').val();
console.log("empCode",empCode);
if (empCode) {
$('#pageLoader').show();
document.getElementById("employeeCard").style.display = "block";
}else{
Swal.fire({
icon: "warning", // Display a warning icon
title: "Missing Employee Number",
text: "Please enter an employee number to proceed.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary" // Optional styling for the button
}
});
return;
}
// Format dates to dd-MM-yyyy
//$('#pageLoader').show();
$('#pageLoader').show();
$('#employeeCard').hide();
$('#newemployeeCard').hide();
$('#servicedeath').val('');
$('#sanctionedgis').val('');
$('#deceased').val('');
//$('#filesentdate').val('');
$('#remarks').val('');
// Call the API
$.ajax({
url: '/gcc/api/department/newentry/employeedetails', // Correct API URL
type: 'GET',
data: { empCode: empCode },
success: function (response) {
$('#pageLoader').hide();
console.log("response:", response.list);
if (response.list && response.list.length > 0) {
// Clear existing data
let employeeDetails = response.list[0];
console.log("employeedetails",response);
// Check if the employee code is null or not found
const loggedInDeptId = $('#deptId').text().trim(); // Get logged-in deptId dynamically
// Validate department ID
if (employeeDetails.ID_DEPT !== loggedInDeptId) {
Swal.fire({
icon: "error",
title: "Access Denied",
text: "This employee does not belong to your department. Please try again with a valid employee code.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-danger"
}
});
return; // Exit if the department does not match
}
$('#employeeno').val(employeeDetails.EMPLOYEE_CODE);
$('#employeename').val(employeeDetails.EMPLOYEE_NAME);
$('#department').val(employeeDetails.DEPARTMENT);
$('#designation').val(employeeDetails.DESIGNATION);
$('#classes').val(employeeDetails.GROUP_TYPE);
$('#retrirementdate').val(employeeDetails.RETIREMENT_DATE);
$('#EmployeeCode').text(empCode);
//show the modal
$('#employeeCard').show();
} else {
$('#pageLoader').hide();
Swal.fire({
icon: "warning", // Display a warning icon
title: "No Data Found",
text: "No details found for this employee number. Please create a new one to proceed.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary" // Optional styling for the button
}
});
//document.getElementById("newemployeeCard").style.display = "block"; // Show the new employee card
}
},
error: function () {
$('#pageLoader').hide();
Swal.fire({
icon: "error",
title: "Error",
text: "An error occurred while fetching data. Please try again.",
confirmButtonText: "OK",
});
}
});
}); */
/* document.getElementById('lfauditButton').addEventListener('click', function () {
// Trigger the save function when the button is clicked
saveFamilyPensionDetails();
}); */
$('#searchButton').on('click', function () {
const empCode = $('#empCode').val().trim();
console.log("empCode:", empCode);
if (!empCode) {
Swal.fire({
icon: "warning",
title: "Missing Employee Number",
text: "Please enter an employee number to proceed.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary"
}
});
console.log("No Employee Code provided. Aborting search.");
return;
}
// Show loader and hide any existing employee cards
$('#pageLoader').show();
$('#employeeCard').hide();
$('#newemployeeCard').hide();
// Clear any form fields that need resetting
$('#servicedeath').val('');
$('#sanctionedgis').val('');
$('#deceased').val('');
//$('#filesentdate').val('');
$('#remarks').val('');
// STEP 1: Check if the employee already exists in the database
$.ajax({
url: '/gcc/api/department/newentry/familypensionexists', // Endpoint to check existence
type: 'GET',
data: { empCode: empCode },
success: function (existsResponse) {
console.log("Exists API Response:", existsResponse);
$('#pageLoader').hide(); // Hide loader after the first API response
if (existsResponse && existsResponse.exists) {
console.log(`Employee Code ${empCode} exists in the database.`);
Swal.fire({
icon: "warning",
title: "Already Exists",
text: "This employee number already exists.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary"
}
});
return; // Exit if employee already exists
}
// STEP 2: Since the employee does not exist, fetch employee details
$('#pageLoader').show(); // Show loader for the second API call
$.ajax({
url: '/gcc/api/department/newentry/employeedetails', // Correct API URL
type: 'GET',
data: { empCode: empCode },
success: function (response) {
$('#pageLoader').hide();
console.log("Employee Details API Response:", response.list);
if (response.list && response.list.length > 0) {
// Extract employee details
let employeeDetails = response.list[0];
console.log("Employee Details:", employeeDetails);
// Validate department ID
const loggedInDeptId = $('#deptId').text().trim(); // Get logged-in deptId dynamically
if (employeeDetails.ID_DEPT !== loggedInDeptId) {
Swal.fire({
icon: "error",
title: "Access Denied",
text: "This employee does not belong to your department. Please try again with a valid employee code.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-danger"
}
});
return; // Exit if the department does not match
}
const currentDate = $('#filesentdate').val().trim();
if(employeeDetails.RETIREMENT_DATE <= currentDate){
Swal.fire({
icon: "warning",
title: "Not Applicable",
text: "This employee not applicable for this familypension.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary"
}
});
return;
}
// Populate the form fields with the employee details
$('#employeeno').val(employeeDetails.EMPLOYEE_CODE);
$('#employeename').val(employeeDetails.EMPLOYEE_NAME);
$('#department').val(employeeDetails.DEPARTMENT);
$('#designation').val(employeeDetails.DESIGNATION);
$('#classes').val(employeeDetails.GROUP_TYPE);
$('#retrirementdate').val(employeeDetails.RETIREMENT_DATE);
$('#EmployeeCode').text(empCode);
// Show the employee details card/modal
$('#employeeCard').show();
} else {
$('#pageLoader').hide();
Swal.fire({
icon: "warning",
title: "No Data Found",
text: "No details found for this employee number.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary"
}
});
// Optionally, show the new employee card:
// document.getElementById("newemployeeCard").style.display = "block";
}
},
error: function () {
$('#pageLoader').hide();
Swal.fire({
icon: "error",
title: "Error",
text: "An error occurred while fetching data. Please try again.",
confirmButtonText: "OK",
});
}
});
},
error: function () {
$('#pageLoader').hide();
Swal.fire({
icon: "error",
title: "Error",
text: "An error occurred while checking the employee. Please try again.",
confirmButtonText: "OK",
});
}
});
});
//$('#lfauditButton').one('click', saveFamilyPensionDetails);
$('#lfauditButton').off('click').on('click', saveFamilyPensionDetails);
})
function validatePositiveNumber(input) {
if (input.value < 1) {
input.value = "";
}
}
document.addEventListener("DOMContentLoaded", function() {
// Get today's date
const today = new Date();
// Format the date as DD-MM-YYYY for display
const day = String(today.getDate()).padStart(2, '0');
const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
const year = today.getFullYear();
// Combine into DD-MM-YYYY format for display
const formattedDateDisplay = `${day}-${month}-${year}`;
// Set the value of the input field to the current date (in DD-MM-YYYY format for display)
document.getElementById("filesentdate").value = formattedDateDisplay;
});
function convertDateFormat(dateString) {
if (!dateString) return '';
let [day, month, year] = dateString.split('-');
return `${year}-${month}-${day}`;
}
// Trigger search on pressing Enter key
$('#empCode').on('keydown', function (event) {
if (event.key === 'Enter') {
event.preventDefault(); // Prevent default form submission or page reload
const empCode = $('#empCode').val(); // Get the value of empCode
if (!empCode) {
// Show Swal alert if the employee number is missing
Swal.fire({
icon: "warning", // Display a warning icon
title: "Missing Employee Number",
text: "Please enter an employee number to proceed.",
confirmButtonText: "OK",
customClass: {
confirmButton: "btn btn-primary" // Optional styling for the button
}
});
return; // Stop further execution
}
$('#searchButton').click(); // Trigger the click event of the search button
}
});
// Handle close button click
$('#cancelButton').click(function () {
// Clear the input field value
$('#empCode').val('');
// Hide the card
$('#employeeCard').hide();
});
// Handle close button click
$('#cancelButtonnew').click(function () {
// Clear the input field value
$('#empCode').val('');
$('#newemployeeCard').hide();
});
function saveFamilyPensionDetails() {
let pendingDuration= $('input[name="pendingDuration"]:checked').val();
let pendingDurationReason=null;
if (pendingDuration === 'yes' ) {
pendingDurationReason = $('#pendingDurationInput').val(); // Retrieve the amount if available, else null
if (!pendingDurationReason) {
Swal.fire({
icon: 'warning',
title: 'Validation Error',
text: 'Please Enter Pending Duration',
confirmButtonText: 'OK'
});
return; // Stop further execution if validation fails
}
}
let entryDetails = {
empNo: $('#employeeno').val(),
empName: $('#employeename').val(),
deptName: $('#department').val(),
designation: $('#designation').val(),
serviceDeath: $('#servicedeath').val(),
sanctionedgis: $('#sanctionedgis').val(),
deceased: $('#deceased').val(),
dateToAudit: convertDateFormat($('#filesentdate').val()?.trim()),
remarks: $('#remarks').val(),
pendingDuration: pendingDuration,
reasonPending: pendingDurationReason,
deptId:$('#deptId').text().trim(),
filemovedby:$('#userId').text().trim(),
filecategory:$('#filecategory').text().trim()
};
console.log("entrydetails..",entryDetails);
if(!entryDetails.pendingDuration) {
Swal.fire({
icon: 'warning',
title: 'Validation Error!',
text: 'Pending Duration is required.',
confirmButtonText: 'OK'
});
return;
}
if (!entryDetails.serviceDeath) {
Swal.fire({
icon: 'warning',
title: 'Validation Error!',
text: 'Service Death is required.',
confirmButtonText: 'OK'
});
return;
}
if (!entryDetails.sanctionedgis) {
Swal.fire({
icon: 'warning',
title: 'Validation Error!',
text: 'Sanctioned GIS is required.',
confirmButtonText: 'OK'
});
return;
}
if (!entryDetails.deceased) {
Swal.fire({
icon: 'warning',
title: 'Validation Error!',
text: 'Deceased is required.',
confirmButtonText: 'OK'
});
return;
}
if (!entryDetails.remarks) {
Swal.fire({
icon: 'warning',
title: 'Validation Error!',
text: 'Remarks are required.',
confirmButtonText: 'OK'
});
return;
}
// Collect missing fields
/* let missingFields = [];
if (!entryDetails.sanctionedgis) missingFields.push("Sanctioned GIS");
if (!entryDetails.serviceDeath) missingFields.push("Service Death");
if (!entryDetails.deceased) missingFields.push("Deceased");
if (!entryDetails.remarks) missingFields.push("Remarks");
if (!entryDetails.dateToAudit) missingFields.push("Date to Audit");
// Show warning if any fields are missing
if (missingFields.length > 0) {
Swal.fire({
icon: 'warning',
title: 'Validation Error!',
html: `<strong style="display:block; text-align:center; font-size:18px;">Please fill the following mandatory fields:</strong>
<ul style="color:red; text-align:center; list-style:none; padding:0;">
${missingFields.map(field => `<li>${field}</li>`).join('')}
</ul>`,
confirmButtonText: 'OK'
});
return;
} */
$('#lfauditButton').prop('disabled', true).text('Processing...');
$.ajax({
url: '/gcc/api/department/newentry/saveFamilyPensionDetails',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(entryDetails),
success: function (response) {
$('#lfauditButton').prop('disabled', false).text('Mark as sent audit');
Swal.fire({
icon: 'success',
title: 'Success',
text: response,
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
confirmButtonText: 'OK'
}).then((result) => {
if (result.isConfirmed) {
$('#lfauditButton').prop('disabled', false).text('Mark as sent audit');
window.location.href = "/gcc/department/newentry/familypension";
console.log("Continue clicked");
}
});
},
error: function (xhr, status, error) {
$('#lfauditButton').prop('disabled', false).text('Mark as sent audit');
Swal.fire({
icon: 'error',
title: 'Error',
text: 'Failed to save details. Please try again.',
confirmButtonText: 'OK'
});
console.error('Error:', xhr.responseText);
}
});
}
document.querySelectorAll('input[name="pendingDuration"]').forEach(radio => {
radio.addEventListener('change', function () {
const pendingDurationInputContainer = document.getElementById('pendingDurationInputContainer');
if (this.value === 'yes') {
pendingDurationInputContainer.style.display = 'block'; // Show the input field
} else {
pendingDurationInputContainer.style.display = 'none'; // Hide the input field
document.getElementById('pendingDurationInput').value = ''; // Clear the input field
}
});
});
//service death date field
document.addEventListener("DOMContentLoaded", function () {
let today = new Date().toISOString().split("T")[0]; // Get today's date in YYYY-MM-DD format
let servicedeathInput = document.getElementById("servicedeath");
// Set max attribute to disable future dates
servicedeathInput.setAttribute("max", today);
// Prevent manual future date entry
servicedeathInput.addEventListener("change", function () {
if (this.value > today) {
Swal.fire({
icon: 'warning',
title: 'Invalid Date',
text: 'Future dates are not allowed.',
confirmButtonText: 'OK'
});
this.value = ""; // Clear the invalid input
}
});
});
</script>
</body>
</html>