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.

883 lines
35 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  4. <style>
  5. .required{
  6. color: red;
  7. }
  8. #modalBody h4 {
  9. font-weight: bold;
  10. margin-top: 15px;
  11. margin-bottom: 10px;
  12. }
  13. #modalBody p {
  14. margin: 5px 0;
  15. }
  16. #modalBody hr {
  17. margin: 15px 0;
  18. }
  19. .comment {
  20. margin-bottom: 20px;
  21. }
  22. .comment p {
  23. margin: 0;
  24. }
  25. hr {
  26. border: 1px solid #ccc;
  27. margin-top: 20px;
  28. margin-bottom: 20px;
  29. }
  30. h5 {
  31. font-size: bold;
  32. }
  33. /* Limit the height of the dropdown menu and make it scrollable */
  34. .dropdown-menu {
  35. max-height: 200px; /* Adjust this value as needed */
  36. overflow-y: auto;
  37. }
  38. .col-4 {
  39. font-weight: bold;
  40. text-align: right;
  41. }
  42. .col-8 {
  43. padding-left: 20px;
  44. }
  45. .comment {
  46. padding: 10px 0;
  47. }
  48. .comment .text-muted {
  49. font-size: 0.9em;
  50. color: #6c757d;
  51. }
  52. .comment hr {
  53. border-top: 1px solid #ccc;
  54. }
  55. .comment .btn-link {
  56. font-size: 0.9em;
  57. text-decoration: underline;
  58. color: #007bff;
  59. }
  60. /* Make the modal body scrollable */
  61. #detailsModal .modal-body {
  62. max-height: 70vh; /* Limit the height to 70% of the viewport */
  63. overflow-y: auto; /* Enable vertical scrolling */
  64. }
  65. .card-box {
  66. border-radius: 20px;
  67. box-shadow: rgba(0, 0, 0, 0.5) 0px 3px 8px;
  68. }
  69. #followupCard {
  70. transition: transform 0.2s ease; /* Smooth scaling transition */
  71. cursor: pointer; /* Default cursor change */
  72. }
  73. #followupCard:hover {
  74. transform: scale(1.05); /* Slightly scale up on hover */
  75. cursor: pointer; /* Change cursor to hand symbol */
  76. }
  77. .card-block {
  78. padding: 20px;
  79. }
  80. .form-label {
  81. margin-bottom: 0.5rem;
  82. }
  83. input.form-control {
  84. padding: 10px;
  85. }
  86. .form-select {
  87. padding: 10px;
  88. height: 40px;
  89. }
  90. #employeeCard label{
  91. padding-top: 2%;
  92. }
  93. </style>
  94. <body>
  95. <!--[if lt IE 8]>
  96. <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>
  97. <![endif]-->
  98. <div class="wrapper">
  99. <!-- header top menu Start -->
  100. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  101. <!-- header top menu end -->
  102. <div class="page-wrap">
  103. <!--=============== Left Menu side Start ================-->
  104. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  105. <!--=============== Left side End ================-->
  106. <div class="main-content">
  107. <div class="container-fluid">
  108. <div class="page-header mb-2">
  109. <div class="row align-items-end">
  110. <div class="col-lg-8">
  111. <div class="page-header-title">
  112. <i class="fa fa-list-alt bg-blue"></i>
  113. <div class="d-inline">
  114. <h5>Department Entries</h5>
  115. <span>Family Pension</span>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="col-lg-4">
  120. <nav class="breadcrumb-container" aria-label="breadcrumb">
  121. <ol class="breadcrumb">
  122. <li class="breadcrumb-item"><a href="/gcc/index"><i class="ik ik-home"></i></a></li>
  123. <li class="breadcrumb-item" aria-current="page">Department Entries</li>
  124. <li class="breadcrumb-item" aria-current="page">NewEntry</li>
  125. <li class="breadcrumb-item active" aria-current="page">Family Pension</li>
  126. </ol>
  127. </nav>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="row mt-4" >
  132. <div class="col-md-12">
  133. <div class="card">
  134. <div class="card-block">
  135. <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>
  136. <h5 style="font-weight:bold;"><span th:text="${deptId}" id="deptId" style="display:none"></span> New Entry - Family Pension</h5>
  137. <span th:text="${userId}" id="userId" style="display:none"></span>
  138. <div class="row mb-4">
  139. <!-- Input Fields for Year Selection -->
  140. <!-- Start Year Dropdown as Button Dropdown -->
  141. <!-- Start Year Dropdown as Button Dropdown -->
  142. <div class="col-md-4" >
  143. <label for="empCode" class="form-label fw-bold">Search by Employee No <span class="text-danger">*</span></label>
  144. <div class="dropdown">
  145. <input type="number" id="empCode" class="form-control" pattern="^[A-Za-z0-9]+$" placeholder="Enter Employee No" required>
  146. <small id="employeenoHelp" class="form-text text-muted">Only numeric characters (numbers) are allowed.</small>
  147. </div>
  148. </div>
  149. <div class="col-md-4 mt-20" >
  150. <button id="searchButton" class="btn btn-primary mt-2" Style="height:38px;">Search</button>
  151. <!-- <button id="resetButton" class="btn btn-secondary mt-2">Reset</button> -->
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="row mb-4" id="employeeCard" style="display: none;">
  159. <div class="col-md-12">
  160. <div class="card">
  161. <div class="card-block">
  162. <h5 style="font-weight:bold;">New Entry - Family Pension - <span id="EmployeeCode"></span></h5>
  163. <hr>
  164. <div class="row">
  165. <!-- Employee No -->
  166. <div class="col-md-6">
  167. <label for="employeeno" class="form-label fw-bold">Employee No <span class="text-danger">*</span></label>
  168. <div class="dropdown">
  169. <input type="number" id="employeeno" class="form-control" readonly>
  170. </div>
  171. </div>
  172. <!-- Employee Name -->
  173. <div class="col-md-6">
  174. <label for="employeename" class="form-label fw-bold">Employee Name <span class="text-danger">*</span></label>
  175. <div class="dropdown">
  176. <input type="text" id="employeename" class="form-control" readonly>
  177. </div>
  178. </div>
  179. <div class="col-md-6">
  180. <label for="Department" class="form-label fw-bold">Department <span class="text-danger">*</span></label>
  181. <div class="dropdown">
  182. <input type="text" id="department" class="form-control" readonly>
  183. </div>
  184. </div>
  185. <div class="col-md-6">
  186. <label for="Designation" class="form-label fw-bold">Designation<span class="text-danger">*</span></label>
  187. <div class="dropdown">
  188. <input type="text" id="designation" class="form-control" readonly>
  189. </div>
  190. </div>
  191. <!-- pending duration-->
  192. <div class="col-md-6">
  193. <label for="pendingDuration" class="form-label fw-bold">
  194. Pending Duration
  195. <span class="text-danger">*</span>
  196. </label>
  197. <div class="d-flex align-items-center">
  198. <div class="form-check" style="padding-right:10px;">
  199. <input type="radio" id="yes" name="pendingDuration" value="yes"class="form-check-input">
  200. <label for="yes" class="form-check-label">Yes</label>
  201. </div>
  202. <div class="form-check">
  203. <input type="radio" id="no" name="pendingDuration" value="no"class="form-check-input">
  204. <label for="no" class="form-check-label">No</label>
  205. </div>
  206. </div>
  207. <div class="dropdown" id="pendingDurationInputContainer" style="display: none; margin-top: 10px;">
  208. <input type="text" id="pendingDurationInput" name="pendingDurationValue" class="form-control" placeholder="Enter details for pending duration">
  209. </div>
  210. </div>
  211. <div class="col-md-6">
  212. <label for="servicedeath" class="form-label fw-bold">While In Service Death <span class="text-danger">*</span></label>
  213. <div class="dropdown">
  214. <input type="date" id="servicedeath" class="form-control" onclick="this.showPicker()" >
  215. </div>
  216. </div>
  217. <div class="col-md-6">
  218. <label for="deceased" class="form-label fw-bold">Relationship of Deceased<span class="text-danger">*</span></label>
  219. <div class="dropdown">
  220. <input type="text" id="deceased" class="form-control" >
  221. </div>
  222. </div>
  223. <div class="col-md-6">
  224. <label for="sanctionedgis" class="form-label fw-bold">Sanctioned GIS<span class="text-danger">*</span></label>
  225. <div class="dropdown">
  226. <input type="number" id="sanctionedgis" class="form-control" min="1" oninput="validatePositiveNumber(this)">
  227. </div>
  228. </div>
  229. <div class="col-md-6">
  230. <label for="Audit File" class="form-label fw-bold">Date file sent to Audit<span class="text-danger">*</span></label>
  231. <div class="dropdown">
  232. <input type="text" id="filesentdate" class="form-control" readonly>
  233. </div>
  234. </div>
  235. <div class="col-md-12">
  236. <label for="Remarks" class="form-label fw-bold">Comments/Remarks <span class="text-danger">*</span></label>
  237. <div class="dropdown">
  238. <textarea id="remarks" class="form-control" rows="4" placeholder="Enter your remarks here" required></textarea>
  239. </div>
  240. </div>
  241. </div>
  242. <div class="row mt-4">
  243. <div class="col-12 d-flex justify-content-center">
  244. <button id="lfauditButton" class="btn btn-primary mt-2 mx-2">Mark as sent audit</button>
  245. <button id="cancelButton" class="btn btn-secondary mt-2">Cancel</button>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. </div>
  252. </div>
  253. </div>
  254. <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;">
  255. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  256. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  257. <span class="sr-only">Loading...</span>
  258. </div>
  259. <!-- Add the 'Please wait' text below the spinner -->
  260. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  261. </div>
  262. </div>
  263. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  264. </div>
  265. </div>
  266. <div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
  267. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  268. <script src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
  269. <!-- Bootstrap 5 JS -->
  270. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  271. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  272. <script>
  273. $(document).ready(function (){
  274. // Handle Search button click
  275. /* $('#searchButton').on('click', function () {
  276. const empCode = $('#empCode').val();
  277. console.log("empCode",empCode);
  278. if (empCode) {
  279. $('#pageLoader').show();
  280. document.getElementById("employeeCard").style.display = "block";
  281. }else{
  282. Swal.fire({
  283. icon: "warning", // Display a warning icon
  284. title: "Missing Employee Number",
  285. text: "Please enter an employee number to proceed.",
  286. confirmButtonText: "OK",
  287. customClass: {
  288. confirmButton: "btn btn-primary" // Optional styling for the button
  289. }
  290. });
  291. return;
  292. }
  293. // Format dates to dd-MM-yyyy
  294. //$('#pageLoader').show();
  295. $('#pageLoader').show();
  296. $('#employeeCard').hide();
  297. $('#newemployeeCard').hide();
  298. $('#servicedeath').val('');
  299. $('#sanctionedgis').val('');
  300. $('#deceased').val('');
  301. //$('#filesentdate').val('');
  302. $('#remarks').val('');
  303. // Call the API
  304. $.ajax({
  305. url: '/gcc/api/department/newentry/employeedetails', // Correct API URL
  306. type: 'GET',
  307. data: { empCode: empCode },
  308. success: function (response) {
  309. $('#pageLoader').hide();
  310. console.log("response:", response.list);
  311. if (response.list && response.list.length > 0) {
  312. // Clear existing data
  313. let employeeDetails = response.list[0];
  314. console.log("employeedetails",response);
  315. // Check if the employee code is null or not found
  316. const loggedInDeptId = $('#deptId').text().trim(); // Get logged-in deptId dynamically
  317. // Validate department ID
  318. if (employeeDetails.ID_DEPT !== loggedInDeptId) {
  319. Swal.fire({
  320. icon: "error",
  321. title: "Access Denied",
  322. text: "This employee does not belong to your department. Please try again with a valid employee code.",
  323. confirmButtonText: "OK",
  324. customClass: {
  325. confirmButton: "btn btn-danger"
  326. }
  327. });
  328. return; // Exit if the department does not match
  329. }
  330. $('#employeeno').val(employeeDetails.EMPLOYEE_CODE);
  331. $('#employeename').val(employeeDetails.EMPLOYEE_NAME);
  332. $('#department').val(employeeDetails.DEPARTMENT);
  333. $('#designation').val(employeeDetails.DESIGNATION);
  334. $('#classes').val(employeeDetails.GROUP_TYPE);
  335. $('#retrirementdate').val(employeeDetails.RETIREMENT_DATE);
  336. $('#EmployeeCode').text(empCode);
  337. //show the modal
  338. $('#employeeCard').show();
  339. } else {
  340. $('#pageLoader').hide();
  341. Swal.fire({
  342. icon: "warning", // Display a warning icon
  343. title: "No Data Found",
  344. text: "No details found for this employee number. Please create a new one to proceed.",
  345. confirmButtonText: "OK",
  346. customClass: {
  347. confirmButton: "btn btn-primary" // Optional styling for the button
  348. }
  349. });
  350. //document.getElementById("newemployeeCard").style.display = "block"; // Show the new employee card
  351. }
  352. },
  353. error: function () {
  354. $('#pageLoader').hide();
  355. Swal.fire({
  356. icon: "error",
  357. title: "Error",
  358. text: "An error occurred while fetching data. Please try again.",
  359. confirmButtonText: "OK",
  360. });
  361. }
  362. });
  363. }); */
  364. /* document.getElementById('lfauditButton').addEventListener('click', function () {
  365. // Trigger the save function when the button is clicked
  366. saveFamilyPensionDetails();
  367. }); */
  368. $('#searchButton').on('click', function () {
  369. const empCode = $('#empCode').val().trim();
  370. console.log("empCode:", empCode);
  371. if (!empCode) {
  372. Swal.fire({
  373. icon: "warning",
  374. title: "Missing Employee Number",
  375. text: "Please enter an employee number to proceed.",
  376. confirmButtonText: "OK",
  377. customClass: {
  378. confirmButton: "btn btn-primary"
  379. }
  380. });
  381. console.log("No Employee Code provided. Aborting search.");
  382. return;
  383. }
  384. // Show loader and hide any existing employee cards
  385. $('#pageLoader').show();
  386. $('#employeeCard').hide();
  387. $('#newemployeeCard').hide();
  388. // Clear any form fields that need resetting
  389. $('#servicedeath').val('');
  390. $('#sanctionedgis').val('');
  391. $('#deceased').val('');
  392. //$('#filesentdate').val('');
  393. $('#remarks').val('');
  394. // STEP 1: Check if the employee already exists in the database
  395. $.ajax({
  396. url: '/gcc/api/department/newentry/familypensionexists', // Endpoint to check existence
  397. type: 'GET',
  398. data: { empCode: empCode },
  399. success: function (existsResponse) {
  400. console.log("Exists API Response:", existsResponse);
  401. $('#pageLoader').hide(); // Hide loader after the first API response
  402. if (existsResponse && existsResponse.exists) {
  403. console.log(`Employee Code ${empCode} exists in the database.`);
  404. Swal.fire({
  405. icon: "warning",
  406. title: "Already Exists",
  407. text: "This employee number already exists.",
  408. confirmButtonText: "OK",
  409. customClass: {
  410. confirmButton: "btn btn-primary"
  411. }
  412. });
  413. return; // Exit if employee already exists
  414. }
  415. // STEP 2: Since the employee does not exist, fetch employee details
  416. $('#pageLoader').show(); // Show loader for the second API call
  417. $.ajax({
  418. url: '/gcc/api/department/newentry/employeedetails', // Correct API URL
  419. type: 'GET',
  420. data: { empCode: empCode },
  421. success: function (response) {
  422. $('#pageLoader').hide();
  423. console.log("Employee Details API Response:", response.list);
  424. if (response.list && response.list.length > 0) {
  425. // Extract employee details
  426. let employeeDetails = response.list[0];
  427. console.log("Employee Details:", employeeDetails);
  428. // Validate department ID
  429. const loggedInDeptId = $('#deptId').text().trim(); // Get logged-in deptId dynamically
  430. if (employeeDetails.ID_DEPT !== loggedInDeptId) {
  431. Swal.fire({
  432. icon: "error",
  433. title: "Access Denied",
  434. text: "This employee does not belong to your department. Please try again with a valid employee code.",
  435. confirmButtonText: "OK",
  436. customClass: {
  437. confirmButton: "btn btn-danger"
  438. }
  439. });
  440. return; // Exit if the department does not match
  441. }
  442. const currentDate = $('#filesentdate').val().trim();
  443. if(employeeDetails.RETIREMENT_DATE <= currentDate){
  444. Swal.fire({
  445. icon: "warning",
  446. title: "Not Applicable",
  447. text: "This employee not applicable for this familypension.",
  448. confirmButtonText: "OK",
  449. customClass: {
  450. confirmButton: "btn btn-primary"
  451. }
  452. });
  453. return;
  454. }
  455. // Populate the form fields with the employee details
  456. $('#employeeno').val(employeeDetails.EMPLOYEE_CODE);
  457. $('#employeename').val(employeeDetails.EMPLOYEE_NAME);
  458. $('#department').val(employeeDetails.DEPARTMENT);
  459. $('#designation').val(employeeDetails.DESIGNATION);
  460. $('#classes').val(employeeDetails.GROUP_TYPE);
  461. $('#retrirementdate').val(employeeDetails.RETIREMENT_DATE);
  462. $('#EmployeeCode').text(empCode);
  463. // Show the employee details card/modal
  464. $('#employeeCard').show();
  465. } else {
  466. $('#pageLoader').hide();
  467. Swal.fire({
  468. icon: "warning",
  469. title: "No Data Found",
  470. text: "No details found for this employee number.",
  471. confirmButtonText: "OK",
  472. customClass: {
  473. confirmButton: "btn btn-primary"
  474. }
  475. });
  476. // Optionally, show the new employee card:
  477. // document.getElementById("newemployeeCard").style.display = "block";
  478. }
  479. },
  480. error: function () {
  481. $('#pageLoader').hide();
  482. Swal.fire({
  483. icon: "error",
  484. title: "Error",
  485. text: "An error occurred while fetching data. Please try again.",
  486. confirmButtonText: "OK",
  487. });
  488. }
  489. });
  490. },
  491. error: function () {
  492. $('#pageLoader').hide();
  493. Swal.fire({
  494. icon: "error",
  495. title: "Error",
  496. text: "An error occurred while checking the employee. Please try again.",
  497. confirmButtonText: "OK",
  498. });
  499. }
  500. });
  501. });
  502. //$('#lfauditButton').one('click', saveFamilyPensionDetails);
  503. $('#lfauditButton').off('click').on('click', saveFamilyPensionDetails);
  504. })
  505. function validatePositiveNumber(input) {
  506. if (input.value < 1) {
  507. input.value = "";
  508. }
  509. }
  510. document.addEventListener("DOMContentLoaded", function() {
  511. // Get today's date
  512. const today = new Date();
  513. // Format the date as DD-MM-YYYY for display
  514. const day = String(today.getDate()).padStart(2, '0');
  515. const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
  516. const year = today.getFullYear();
  517. // Combine into DD-MM-YYYY format for display
  518. const formattedDateDisplay = `${day}-${month}-${year}`;
  519. // Set the value of the input field to the current date (in DD-MM-YYYY format for display)
  520. document.getElementById("filesentdate").value = formattedDateDisplay;
  521. });
  522. function convertDateFormat(dateString) {
  523. if (!dateString) return '';
  524. let [day, month, year] = dateString.split('-');
  525. return `${year}-${month}-${day}`;
  526. }
  527. // Trigger search on pressing Enter key
  528. $('#empCode').on('keydown', function (event) {
  529. if (event.key === 'Enter') {
  530. event.preventDefault(); // Prevent default form submission or page reload
  531. const empCode = $('#empCode').val(); // Get the value of empCode
  532. if (!empCode) {
  533. // Show Swal alert if the employee number is missing
  534. Swal.fire({
  535. icon: "warning", // Display a warning icon
  536. title: "Missing Employee Number",
  537. text: "Please enter an employee number to proceed.",
  538. confirmButtonText: "OK",
  539. customClass: {
  540. confirmButton: "btn btn-primary" // Optional styling for the button
  541. }
  542. });
  543. return; // Stop further execution
  544. }
  545. $('#searchButton').click(); // Trigger the click event of the search button
  546. }
  547. });
  548. // Handle close button click
  549. $('#cancelButton').click(function () {
  550. // Clear the input field value
  551. $('#empCode').val('');
  552. // Hide the card
  553. $('#employeeCard').hide();
  554. });
  555. // Handle close button click
  556. $('#cancelButtonnew').click(function () {
  557. // Clear the input field value
  558. $('#empCode').val('');
  559. $('#newemployeeCard').hide();
  560. });
  561. function saveFamilyPensionDetails() {
  562. let pendingDuration= $('input[name="pendingDuration"]:checked').val();
  563. let pendingDurationReason=null;
  564. if (pendingDuration === 'yes' ) {
  565. pendingDurationReason = $('#pendingDurationInput').val(); // Retrieve the amount if available, else null
  566. if (!pendingDurationReason) {
  567. Swal.fire({
  568. icon: 'warning',
  569. title: 'Validation Error',
  570. text: 'Please Enter Pending Duration',
  571. confirmButtonText: 'OK'
  572. });
  573. return; // Stop further execution if validation fails
  574. }
  575. }
  576. let entryDetails = {
  577. empNo: $('#employeeno').val(),
  578. empName: $('#employeename').val(),
  579. deptName: $('#department').val(),
  580. designation: $('#designation').val(),
  581. serviceDeath: $('#servicedeath').val(),
  582. sanctionedgis: $('#sanctionedgis').val(),
  583. deceased: $('#deceased').val(),
  584. dateToAudit: convertDateFormat($('#filesentdate').val()?.trim()),
  585. remarks: $('#remarks').val(),
  586. pendingDuration: pendingDuration,
  587. reasonPending: pendingDurationReason,
  588. deptId:$('#deptId').text().trim(),
  589. filemovedby:$('#userId').text().trim(),
  590. filecategory:$('#filecategory').text().trim()
  591. };
  592. console.log("entrydetails..",entryDetails);
  593. if(!entryDetails.pendingDuration) {
  594. Swal.fire({
  595. icon: 'warning',
  596. title: 'Validation Error!',
  597. text: 'Pending Duration is required.',
  598. confirmButtonText: 'OK'
  599. });
  600. return;
  601. }
  602. if (!entryDetails.serviceDeath) {
  603. Swal.fire({
  604. icon: 'warning',
  605. title: 'Validation Error!',
  606. text: 'Service Death is required.',
  607. confirmButtonText: 'OK'
  608. });
  609. return;
  610. }
  611. if (!entryDetails.sanctionedgis) {
  612. Swal.fire({
  613. icon: 'warning',
  614. title: 'Validation Error!',
  615. text: 'Sanctioned GIS is required.',
  616. confirmButtonText: 'OK'
  617. });
  618. return;
  619. }
  620. if (!entryDetails.deceased) {
  621. Swal.fire({
  622. icon: 'warning',
  623. title: 'Validation Error!',
  624. text: 'Deceased is required.',
  625. confirmButtonText: 'OK'
  626. });
  627. return;
  628. }
  629. if (!entryDetails.remarks) {
  630. Swal.fire({
  631. icon: 'warning',
  632. title: 'Validation Error!',
  633. text: 'Remarks are required.',
  634. confirmButtonText: 'OK'
  635. });
  636. return;
  637. }
  638. // Collect missing fields
  639. /* let missingFields = [];
  640. if (!entryDetails.sanctionedgis) missingFields.push("Sanctioned GIS");
  641. if (!entryDetails.serviceDeath) missingFields.push("Service Death");
  642. if (!entryDetails.deceased) missingFields.push("Deceased");
  643. if (!entryDetails.remarks) missingFields.push("Remarks");
  644. if (!entryDetails.dateToAudit) missingFields.push("Date to Audit");
  645. // Show warning if any fields are missing
  646. if (missingFields.length > 0) {
  647. Swal.fire({
  648. icon: 'warning',
  649. title: 'Validation Error!',
  650. html: `<strong style="display:block; text-align:center; font-size:18px;">Please fill the following mandatory fields:</strong>
  651. <ul style="color:red; text-align:center; list-style:none; padding:0;">
  652. ${missingFields.map(field => `<li>${field}</li>`).join('')}
  653. </ul>`,
  654. confirmButtonText: 'OK'
  655. });
  656. return;
  657. } */
  658. $('#lfauditButton').prop('disabled', true).text('Processing...');
  659. $.ajax({
  660. url: '/gcc/api/department/newentry/saveFamilyPensionDetails',
  661. type: 'POST',
  662. contentType: 'application/json',
  663. data: JSON.stringify(entryDetails),
  664. success: function (response) {
  665. $('#lfauditButton').prop('disabled', false).text('Mark as sent audit');
  666. Swal.fire({
  667. icon: 'success',
  668. title: 'Success',
  669. text: response,
  670. allowOutsideClick: false,
  671. allowEscapeKey: false,
  672. allowEnterKey: false,
  673. confirmButtonText: 'OK'
  674. }).then((result) => {
  675. if (result.isConfirmed) {
  676. $('#lfauditButton').prop('disabled', false).text('Mark as sent audit');
  677. window.location.href = "/gcc/department/newentry/familypension";
  678. console.log("Continue clicked");
  679. }
  680. });
  681. },
  682. error: function (xhr, status, error) {
  683. $('#lfauditButton').prop('disabled', false).text('Mark as sent audit');
  684. Swal.fire({
  685. icon: 'error',
  686. title: 'Error',
  687. text: 'Failed to save details. Please try again.',
  688. confirmButtonText: 'OK'
  689. });
  690. console.error('Error:', xhr.responseText);
  691. }
  692. });
  693. }
  694. document.querySelectorAll('input[name="pendingDuration"]').forEach(radio => {
  695. radio.addEventListener('change', function () {
  696. const pendingDurationInputContainer = document.getElementById('pendingDurationInputContainer');
  697. if (this.value === 'yes') {
  698. pendingDurationInputContainer.style.display = 'block'; // Show the input field
  699. } else {
  700. pendingDurationInputContainer.style.display = 'none'; // Hide the input field
  701. document.getElementById('pendingDurationInput').value = ''; // Clear the input field
  702. }
  703. });
  704. });
  705. //service death date field
  706. document.addEventListener("DOMContentLoaded", function () {
  707. let today = new Date().toISOString().split("T")[0]; // Get today's date in YYYY-MM-DD format
  708. let servicedeathInput = document.getElementById("servicedeath");
  709. // Set max attribute to disable future dates
  710. servicedeathInput.setAttribute("max", today);
  711. // Prevent manual future date entry
  712. servicedeathInput.addEventListener("change", function () {
  713. if (this.value > today) {
  714. Swal.fire({
  715. icon: 'warning',
  716. title: 'Invalid Date',
  717. text: 'Future dates are not allowed.',
  718. confirmButtonText: 'OK'
  719. });
  720. this.value = ""; // Clear the invalid input
  721. }
  722. });
  723. });
  724. </script>
  725. </body>
  726. </html>