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.

1026 lines
41 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="">
  3. <html xmlns:th="http://www.thymeleaf.org">
  4. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  5. <style>
  6. .required{
  7. color: red;
  8. }
  9. #modalBody h4 {
  10. font-weight: bold;
  11. margin-top: 15px;
  12. margin-bottom: 10px;
  13. }
  14. #modalBody p {
  15. margin: 5px 0;
  16. }
  17. #modalBody hr {
  18. margin: 15px 0;
  19. }
  20. .comment {
  21. margin-bottom: 20px;
  22. }
  23. .comment p {
  24. margin: 0;
  25. }
  26. hr {
  27. border: 1px solid #ccc;
  28. margin-top: 20px;
  29. margin-bottom: 20px;
  30. }
  31. h5 {
  32. font-size: bold;
  33. }
  34. /* Limit the height of the dropdown menu and make it scrollable */
  35. .dropdown-menu {
  36. max-height: 200px; /* Adjust this value as needed */
  37. overflow-y: auto;
  38. }
  39. .col-4 {
  40. font-weight: bold;
  41. text-align: right;
  42. }
  43. .col-8 {
  44. padding-left: 20px;
  45. }
  46. .comment {
  47. padding: 10px 0;
  48. }
  49. .comment .text-muted {
  50. font-size: 0.9em;
  51. color: #6c757d;
  52. }
  53. .comment hr {
  54. border-top: 1px solid #ccc;
  55. }
  56. .comment .btn-link {
  57. font-size: 0.9em;
  58. text-decoration: underline;
  59. color: #007bff;
  60. }
  61. /* Make the modal body scrollable */
  62. #detailsModal .modal-body {
  63. max-height: 70vh; /* Limit the height to 70% of the viewport */
  64. overflow-y: auto; /* Enable vertical scrolling */
  65. }
  66. .card-box {
  67. border-radius: 20px;
  68. box-shadow: rgba(0, 0, 0, 0.5) 0px 3px 8px;
  69. }
  70. #followupCard {
  71. transition: transform 0.2s ease; /* Smooth scaling transition */
  72. cursor: pointer; /* Default cursor change */
  73. }
  74. #followupCard:hover {
  75. transform: scale(1.05); /* Slightly scale up on hover */
  76. cursor: pointer; /* Change cursor to hand symbol */
  77. }
  78. .card-block {
  79. padding: 20px;
  80. }
  81. .form-label {
  82. margin-bottom: 0.5rem;
  83. }
  84. input.form-control {
  85. padding: 10px;
  86. }
  87. .form-select {
  88. padding: 10px;
  89. height: 40px;
  90. }
  91. </style>
  92. <body>
  93. <!--[if lt IE 8]>
  94. <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>
  95. <![endif]-->
  96. <div class="wrapper">
  97. <!-- header top menu Start -->
  98. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  99. <!-- header top menu end -->
  100. <div class="page-wrap">
  101. <!--=============== Left Menu side Start ================-->
  102. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  103. <!--=============== Left side End ================-->
  104. <div class="main-content">
  105. <div class="container-fluid">
  106. <div class="page-header mb-2">
  107. <div class="row align-items-end">
  108. <div class="col-lg-8">
  109. <div class="page-header-title">
  110. <i class="fa fa-list-alt bg-blue"></i>
  111. <div class="d-inline">
  112. <h5>Department Entries</h5>
  113. <span>GIS</span>
  114. </div>
  115. </div>
  116. </div>
  117. <div class="col-lg-4">
  118. <nav class="breadcrumb-container" aria-label="breadcrumb">
  119. <ol class="breadcrumb">
  120. <li class="breadcrumb-item"><a href="/gcc/index"><i class="ik ik-home"></i></a></li>
  121. <li class="breadcrumb-item" aria-current="page">Department Entries</li>
  122. <li class="breadcrumb-item" aria-current="page">NewEntry</li>
  123. <li class="breadcrumb-item active" aria-current="page">GIS</li>
  124. </ol>
  125. </nav>
  126. </div>
  127. </div>
  128. </div>
  129. <div class="row mt-4" >
  130. <div class="col-md-12">
  131. <div class="card">
  132. <div class="card-block">
  133. <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>
  134. <div id="headingContainer">
  135. <h5 style="font-weight: bold;">
  136. <span th:text="${deptId}" id="deptId" style="display: none"></span>
  137. New Entry - GIS
  138. </h5>
  139. </div>
  140. <span th:text="${userId}" id="userId" style="display:none"></span>
  141. <div class="row mb-4">
  142. <!-- Input Fields for Year Selection -->
  143. <!-- Start Year Dropdown as Button Dropdown -->
  144. <!-- Start Year Dropdown as Button Dropdown -->
  145. <div class="col-md-4" >
  146. <label for="empCode" class="form-label fw-bold">Search by Employee No <span class="text-danger">*</span></label>
  147. <div class="dropdown">
  148. <input type="number" id="empCode" class="form-control" pattern="^[A-Za-z0-9]+$" placeholder="Enter Employee No" required>
  149. <small id="employeenoHelp" class="form-text text-muted">Only numeric characters (numbers) are allowed.</small>
  150. </div>
  151. </div>
  152. <div class="col-md-4 mt-20">
  153. <button id="searchButton" class="btn btn-primary mt-2" Style="height:38px;">Search</button>
  154. <!-- <button id="resetButton" class="btn btn-secondary mt-2">Reset</button> -->
  155. </div>
  156. </div>
  157. <div>
  158. <button id="addNewbutton" class="btn btn-success mt-2"
  159. Style="height: 38px;">Create New</button>
  160. </div>
  161. <div id="staffTypeContainer"
  162. style="display: none; margin-top: 10px;">
  163. <label style="font-weight: bold; margin-bottom: 5px;">Select
  164. Staff Type:</label>
  165. <div style="display: flex; align-items: center; gap: 40px;">
  166. <div>
  167. <input type="radio" id="temporaryStaff" name="staffType" value="temporary">
  168. <label for="temporaryStaff">Temporary Staff</label>
  169. </div>
  170. <div>
  171. <input type="radio" id="permanentStaff" name="staffType" value="permanent">
  172. <label for="permanentStaff">Permanent Staff</label>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. <div class="row mb-4" id="employeeCard" style="display: none;">
  181. <div class="col-md-12">
  182. <div class="card">
  183. <div class="card-block">
  184. <h5 style="font-weight:bold;">New Entry - GIS </h5>
  185. <hr>
  186. <div class="row">
  187. <!-- Employee No -->
  188. <div class="col-md-6">
  189. <label for="employeeno" class="form-label fw-bold">Employee No <span class="text-danger">*</span></label>
  190. <div class="dropdown">
  191. <input type="text" id="employeeno" class="form-control" readonly>
  192. </div>
  193. </div>
  194. <!-- Employee Name -->
  195. <div class="col-md-6">
  196. <label for="employeename" class="form-label fw-bold">Employee Name <span class="text-danger">*</span></label>
  197. <div class="dropdown">
  198. <input type="text" id="employeename" class="form-control" readonly>
  199. </div>
  200. </div>
  201. <div class="col-md-6">
  202. <label for="Department" class="form-label fw-bold">Department <span class="text-danger">*</span></label>
  203. <div class="dropdown">
  204. <input type="text" id="department" class="form-control" readonly>
  205. </div>
  206. </div>
  207. <div class="col-md-6">
  208. <label for="Designation" class="form-label fw-bold">Designation<span class="text-danger">*</span></label>
  209. <div class="dropdown">
  210. <input type="text" id="designation" class="form-control" readonly>
  211. </div>
  212. </div>
  213. <div class="col-md-6">
  214. <label for="servicedeath" class="form-label fw-bold">
  215. While In Service Death <span class="text-danger">*</span>
  216. </label>
  217. <div class="dropdown">
  218. <input type="date" id="servicedeath" class="form-control" onclick="this.showPicker()" max="">
  219. </div>
  220. </div>
  221. <div class="col-md-6">
  222. <label for="deceased" class="form-label fw-bold">Relationship of Deceased<span class="text-danger">*</span></label>
  223. <div class="dropdown">
  224. <input type="text" id="deceased" class="form-control" >
  225. </div>
  226. </div>
  227. <div class="row col-md-12" id="tempcontainer" style="display: none;">
  228. <div class="col-md-6">
  229. <label for="gisentry" class="form-label fw-bold">GIS Entry Type<span class="text-danger">*</span></label>
  230. <select id="gisentry" class="form-select" style="width: 100%;" required>
  231. </select>
  232. </div>
  233. <!-- div class="col-md-6">
  234. <label for="funeraladvance" class="form-label fw-bold">Sanctioned GIS Advance <span class="text-danger">*</span></label>
  235. <div class="dropdown">
  236. <input type="number" id="funeraladvance" class="form-control" >
  237. </div>
  238. </div> -->
  239. <div class="col-md-6">
  240. <label for="gisamount" class="form-label fw-bold">
  241. Sanctioned GIS Advance
  242. <span class="text-danger">*</span>
  243. </label>
  244. <div class="d-flex align-items-center">
  245. <div class="form-check" style="padding-right:10px;">
  246. <input type="radio" id="yes1" name="gisamount" class="form-check-input" value="yes">
  247. <label for="yes1" class="form-check-label">Yes</label>
  248. </div>
  249. <div class="form-check">
  250. <input type="radio" id="no1" name="gisamount" class="form-check-input" value="no">
  251. <label for="no1" class="form-check-label">No</label>
  252. </div>
  253. </div>
  254. <div class="dropdown" id="gisAmountInputContainer" style="display: none; margin-top: 10px;">
  255. <input type="number" id="gisAmountInput" name="gisamount_value" class="form-control"
  256. placeholder="Enter Sanctioned Gis Amount" min="1" oninput="validatePositiveNumber(this)">
  257. </div>
  258. </div>
  259. </div>
  260. <div class="col-md-6">
  261. <label for="filesentdate" class="form-label fw-bold"> File Sent to GD Pension Section On<span class="text-danger">*</span></label>
  262. <div class="dropdown">
  263. <input type="text" id="filesentdate" class="form-control" readonly>
  264. </div>
  265. </div>
  266. <div class="col-md-12">
  267. <label for="remarks" class="form-label fw-bold">Comments/Remarks <span class="text-danger">*</span></label>
  268. <div class="dropdown">
  269. <textarea id="remarks" class="form-control" rows="4" placeholder="Enter your remarks here" required></textarea>
  270. </div>
  271. </div>
  272. </div>
  273. <div class="row mt-4 mt-20">
  274. <div class="col-12 d-flex justify-content-center">
  275. <button id="submitButton" class="btn btn-primary mt-2 mx-2">Mark as Forward to Pension</button>
  276. <button id="cancelButton" class="btn btn-secondary mt-2">Cancel</button>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. <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;">
  286. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  287. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  288. <span class="sr-only">Loading...</span>
  289. </div>
  290. <!-- Add the 'Please wait' text below the spinner -->
  291. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  292. </div>
  293. </div>
  294. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  295. </div>
  296. </div>
  297. <div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
  298. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  299. <script src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
  300. <!-- Bootstrap 5 JS -->
  301. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  302. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  303. <script>
  304. document.addEventListener("DOMContentLoaded", function() {
  305. // Get today's date
  306. const today = new Date();
  307. // Format the date as DD-MM-YYYY for display
  308. const day = String(today.getDate()).padStart(2, '0');
  309. const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
  310. const year = today.getFullYear();
  311. // Combine into DD-MM-YYYY format for display
  312. const formattedDateDisplay = `${day}-${month}-${year}`;
  313. // Set the value of the input field to the current date (in DD-MM-YYYY format for display)
  314. document.getElementById("filesentdate").value = formattedDateDisplay;
  315. });
  316. function convertDateFormat(dateString) {
  317. if (!dateString) return '';
  318. let [day, month, year] = dateString.split('-');
  319. return `${year}-${month}-${day}`;
  320. }
  321. document.addEventListener("DOMContentLoaded", function () {
  322. let today = new Date().toISOString().split("T")[0]; // Get today's date in YYYY-MM-DD format
  323. let servicedeathInput = document.getElementById("servicedeath");
  324. // Set max attribute to disable future dates
  325. servicedeathInput.setAttribute("max", today);
  326. // Prevent manual future date entry
  327. servicedeathInput.addEventListener("change", function () {
  328. if (this.value > today) {
  329. Swal.fire({
  330. icon: 'warning',
  331. title: 'Invalid Date',
  332. text: 'Future dates are not allowed.',
  333. confirmButtonText: 'OK'
  334. });
  335. this.value = ""; // Clear the invalid input
  336. }
  337. });
  338. });
  339. console.log("before ajaxx....")
  340. $(document).ready(function () {
  341. $(document).ready(function () {
  342. $('#addNewbutton').on('click', function () {
  343. $('#empCode').val('');
  344. // Show the staff type container
  345. $('#staffTypeContainer').show();
  346. $('#employeeCard').hide();
  347. $('input[name="staffType"]').prop('checked', false);
  348. // Add change event listener to the radio buttons
  349. $('input[name="staffType"]').off('change').on('change', function () {
  350. const selectedType = $('input[name="staffType"]:checked').val();
  351. $('#staffTypeContainer').hide();
  352. if (selectedType === 'temporary') {
  353. // Show the employee card
  354. $('#employeeCard').show();
  355. $('#tempcontainer').hide();
  356. // Pre-fill "GIS" in Employee No and enforce rules
  357. $('#employeeno')
  358. .val('GIS') // Pre-fill with "GIS"
  359. .prop('readonly', false) // Allow editing, but only after "GIS"
  360. .off('input keydown') // Remove existing event listeners
  361. .on('input', function () {
  362. const value = $(this).val();
  363. if (!value.startsWith('GIS')) {
  364. $(this).val('GIS');
  365. } else {
  366. const numericPart = value.slice(3).replace(/\D/g, ''); // Allow only digits after "GIS"
  367. $(this).val('GIS' + numericPart);
  368. }
  369. })
  370. .on('keydown', function (e) {
  371. const cursorPosition = this.selectionStart;
  372. if ((e.key === 'Backspace' || e.key === 'Delete') && cursorPosition <= 3) {
  373. e.preventDefault(); // Prevent removing "GIS"
  374. }
  375. });
  376. // Pre-fill and enable fields
  377. $('#employeename').val('').prop('readonly', false);
  378. $('#department').val($('#deptname').text().trim()).prop('readonly', true);
  379. $('#designation').val('').prop('readonly', false);
  380. $('#servicedeath').val('').prop('readonly', false);
  381. $('#deceased').val('').prop('readonly', false);
  382. //$('#funeraladvance').val('').prop('readonly', false);
  383. $('#filesentdate').prop('readonly', true);
  384. $('#remarks').val('').prop('readonly', false);
  385. } else if (selectedType === 'permanent') {
  386. // Hide the employee card and show a SweetAlert
  387. $('#employeeCard').hide();
  388. Swal.fire({
  389. icon: 'warning',
  390. title: 'ERP Required',
  391. text: 'Please create a number in ERP for permanent staff.',
  392. confirmButtonText: 'OK',
  393. customClass: {
  394. confirmButton: 'btn btn-primary'
  395. }
  396. });
  397. }
  398. });
  399. });
  400. $('#submitButton').off('click').on('click', function () {
  401. const gisPattern = /^GIS\d+$/;
  402. const employeeNo = $('#employeeno').val().trim();
  403. // Validate Employee No
  404. if (!gisPattern.test(employeeNo)) {
  405. Swal.fire({
  406. icon: 'warning',
  407. title: 'Validation Error',
  408. text: 'Employee No must start with "GIS" and be followed by one or more numbers.',
  409. confirmButtonText: 'OK'
  410. });
  411. console.warn('Validation failed: Employee No is invalid.');
  412. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to Pension'); // Re-enable button
  413. return; // Stop execution if validation fails
  414. }
  415. // Log and call save function
  416. console.log("Save button clicked. Triggering saveEntryDetails function.");
  417. saveEntryDetailsnew();
  418. });
  419. });
  420. // Handle Search button click
  421. $('#searchButton').on('click', function () {
  422. const empCode = $('#empCode').val().trim(); // Trim input to avoid accidental spaces
  423. console.log("empCode...",empCode);
  424. if (!empCode) {
  425. Swal.fire({
  426. icon: "warning",
  427. title: "Missing Employee Number",
  428. text: "Please enter an employee number to proceed.",
  429. confirmButtonText: "OK",
  430. customClass: {
  431. confirmButton: "btn btn-primary"
  432. }
  433. });
  434. console.log("No Employee Code provided. Aborting search.");
  435. return; // Stop further execution if empCode is not provided
  436. }
  437. // Show loader and hide other elements
  438. $('#pageLoader').show();
  439. $('#employeeCard').hide();
  440. $('#newemployeeCard').hide();
  441. $('#gisAmountInput').val('');
  442. $('#tempcontainer').show();
  443. $('input[name="gisamount"]').prop('checked', false);
  444. console.log("Checking if employee exists: ${empCode}");
  445. // Step 1: Check if employee exists in the database
  446. $.ajax({
  447. url: '/gcc/api/department/newentry/exists', // Endpoint to check existence
  448. type: 'GET',
  449. data: { empCode: empCode },
  450. success: function (existsResponse) {
  451. console.log("Exists API Response:", existsResponse);
  452. $('#pageLoader').hide();
  453. if (existsResponse && existsResponse.exists) {
  454. console.log("Employee Code ${empCode} exists in the database.");
  455. Swal.fire({
  456. icon: "warning",
  457. title: "Already Exists",
  458. text: "This employee number already exists.",
  459. confirmButtonText: "OK",
  460. customClass: {
  461. confirmButton: "btn btn-primary"
  462. }
  463. });
  464. return; // Exit the function if the employee exists
  465. }
  466. console.log(`Employee Code ${empCode} does not exist. Fetching details from the external API.`);
  467. // If employee does not exist, fetch details from the external API
  468. fetchEmployeeDetails(empCode);
  469. },
  470. error: function (xhr) {
  471. $('#pageLoader').hide();
  472. console.error("Error during existence check:", xhr.responseText);
  473. Swal.fire({
  474. icon: "error",
  475. title: "Error",
  476. text: "An error occurred while checking employee existence. Please try again.",
  477. confirmButtonText: "OK"
  478. });
  479. }
  480. });
  481. });
  482. // Function to fetch employee details from external API
  483. console.log("fetchEmployeeDetails.....")
  484. function fetchEmployeeDetails(empCode) {
  485. console.log("Fetching details for employee:");
  486. $('#pageLoader').show();
  487. $.ajax({
  488. url: '/gcc/api/department/newentry/employeedetails', // External API endpoint
  489. type: 'GET',
  490. data: { empCode: empCode },
  491. success: function (response) {
  492. console.log("Employee Details API Response:", response);
  493. $('#pageLoader').hide();
  494. if (response.list && response.list.length > 0) {
  495. const employeeDetails = response.list[0];
  496. console.log("Employee Details Retrieved:", employeeDetails);
  497. // Check if the employee code is null or not found
  498. const loggedInDeptId = $('#deptId').text().trim(); // Get deptId dynamically
  499. // Validate department ID
  500. if (employeeDetails.ID_DEPT !== loggedInDeptId) {
  501. Swal.fire({
  502. icon: "error",
  503. title: "Access Denied",
  504. text: "This employee does not belong to your department. Please try again with a valid employeecode.",
  505. confirmButtonText: "OK",
  506. customClass: {
  507. confirmButton: "btn btn-danger"
  508. }
  509. });
  510. return;
  511.                }
  512. // Populate the employee details
  513. console.log("Populating employee details in the UI.");
  514. $('#employeeno').val(employeeDetails.EMPLOYEE_CODE).prop('readonly', true);;
  515. $('#employeename').val(employeeDetails.EMPLOYEE_NAME).prop('readonly', true);
  516. $('#department').val(employeeDetails.DEPARTMENT).prop('readonly', true);
  517. $('#designation').val(employeeDetails.DESIGNATION).prop('readonly', true);
  518. $('#classes').val(employeeDetails.GROUP_TYPE);
  519. $('#retrirementdate').val(employeeDetails.RETIREMENT_DATE);
  520. $('#EmployeeCode').text(empCode);
  521. $('#employeeCard').show();
  522. // Attach event handler for saving details
  523. $('#submitButton').off('click').on('click', function () {
  524. console.log("Save button clicked. Triggering saveEntryDetails function.");
  525. saveEntryDetailsnew();
  526. });
  527. } else {
  528. console.warn("No employee data found in the external API response.");
  529. Swal.fire({
  530. icon: "warning",
  531. title: "No Data Found",
  532. text: "No details found for this employee number.",
  533. confirmButtonText: "OK",
  534. customClass: {
  535. confirmButton: "btn btn-primary"
  536. }
  537. });
  538. $('#newemployeeCard').show();
  539. }
  540. },
  541. error: function (xhr) {
  542. $('#pageLoader').hide();
  543. console.error("Error in Employee Details API:", xhr.responseText);
  544. Swal.fire({
  545. icon: "error",
  546. title: "Error",
  547. text: "An error occurred while fetching data. Please try again.",
  548. confirmButtonText: "OK"
  549. });
  550. }
  551. });
  552. }
  553. document.querySelectorAll('input[name="gisamount"]').forEach(radio => {
  554. radio.addEventListener('change', function () {
  555. const gisAmountInputContainer = document.getElementById('gisAmountInputContainer');
  556. if (this.value === 'yes') {
  557. gisAmountInputContainer.style.display = 'block'; // Show the input field
  558. } else {
  559. gisAmountInputContainer.style.display = 'none'; // Hide the input field
  560. document.getElementById('gisAmountInput').value = ''; // Clear the input field
  561. }
  562. });
  563. });
  564. //dropdown for gisentry type:
  565. $(document).ready(function () {
  566. function loadEntryTypes() {
  567. $.ajax({
  568. url: "/gcc/api/getGisEntryTypes",
  569. type: "GET",
  570. success: function (data) {
  571. var dropdown = $("#gisentry");
  572. dropdown.empty(); // Clear existing options
  573. dropdown.append('<option value="" selected>-- Select Option --</option>');
  574. // Loop through the API response and add options
  575. $.each(data, function (key, entry) {
  576. dropdown.append($('<option></option>').attr('value', entry.gis_entry).text(entry.gis_entry));
  577. //dropdown.append('<option value="' + item.id + '">' + item.gis_entry + '</option>');
  578. });
  579. },
  580. error: function () {
  581. console.log("Error loading dropdown data.");
  582. }
  583. });
  584. }
  585. // Call function on page load
  586. loadEntryTypes();
  587. });
  588. function saveEntryDetailsnew() {
  589. const selectedstaffType = $('input[name="staffType"]:checked').val();
  590. console.log("selectedstaffType====="+selectedstaffType);
  591. let selgisamount = $('input[name="gisamount"]:checked').val();
  592. let selgismamountval = null;
  593. if (selgisamount === 'yes') {
  594. selgismamountval = $('#gisAmountInput').val();
  595. if (!selgismamountval || selgismamountval <= 0) {
  596. Swal.fire({
  597. icon: 'warning',
  598. title: 'Validation Error',
  599. text: 'Please enter a valid Sanctioned Gis Amount',
  600. confirmButtonText: 'OK'
  601. });
  602. return ; // Stop further execution
  603. }
  604. }
  605. let entryDetails = {
  606. empNo: $('#employeeno').val(),
  607. empName: $('#employeename').val(),
  608. deptName: $('#department').val(),
  609. designation: $('#designation').val(),
  610. serviceDeath: $('#servicedeath').val(),
  611. dateToPension: convertDateFormat($('#filesentdate').val()?.trim()),
  612. deceased: $('#deceased').val(),
  613. gisentry: $('#gisentry').val() || null,
  614. gisAdvanceamount : selgismamountval || null,
  615. gisAdvance : selgisamount || null,
  616. remarks: $('#remarks').val(),
  617. deptId: $('#deptId').text().trim(),
  618. filemovedby: $('#userId').text().trim(),
  619. filecategory: $('#filecategory').text().trim()
  620. };
  621. console.log("Saving employee details:", entryDetails);
  622. if (!entryDetails.empName) {
  623. Swal.fire({
  624. icon: 'warning',
  625. title: 'Validation Error!',
  626. text: 'Employee Name is required.',
  627. confirmButtonText: 'OK'
  628. });
  629. return;
  630. }
  631. if (!entryDetails.designation) {
  632. Swal.fire({
  633. icon: 'warning',
  634. title: 'Validation Error!',
  635. text: 'Designation is required.',
  636. confirmButtonText: 'OK'
  637. });
  638. return;
  639. }
  640. if (!entryDetails.dateToPension) {
  641. Swal.fire({
  642. icon: 'warning',
  643. title: 'Validation Error!',
  644. text: 'Date to Pension is required.',
  645. confirmButtonText: 'OK'
  646. });
  647. return;
  648. }
  649. if (!entryDetails.serviceDeath) {
  650. Swal.fire({
  651. icon: 'warning',
  652. title: 'Validation Error!',
  653. text: 'Service Death Date is required.',
  654. confirmButtonText: 'OK'
  655. });
  656. return;
  657. }
  658. if (!entryDetails.deceased) {
  659. Swal.fire({
  660. icon: 'warning',
  661. title: 'Validation Error!',
  662. text: 'Relationship of Deceased is required.',
  663. confirmButtonText: 'OK'
  664. });
  665. return;
  666. }
  667. if (selectedstaffType !== 'temporary'){
  668. if (!entryDetails.gisentry || entryDetails.gisentry.trim() === '') {
  669. Swal.fire({
  670. icon: 'warning',
  671. title: 'Validation Error!',
  672. text: 'Gis Entry Type is required.',
  673. confirmButtonText: 'OK'
  674. });
  675. return;
  676. }
  677. if (!entryDetails.gisAdvance || entryDetails.gisAdvance.trim() === '') {
  678. Swal.fire({
  679. icon: 'warning',
  680. title: 'Validation Error!',
  681. text: 'Sanctional Gis Advance is required.',
  682. confirmButtonText: 'OK'
  683. });
  684. return;
  685. }
  686. }
  687. if (!entryDetails.remarks) {
  688. Swal.fire({
  689. icon: 'warning',
  690. title: 'Validation Error!',
  691. text: 'Remarks are required.',
  692. confirmButtonText: 'OK'
  693. });
  694. return;
  695. }
  696. const employeeNo = entryDetails.empNo.trim();
  697. // Validate Employee No format
  698. /* const gisPattern = /^GIS\d+$/;
  699. if (!gisPattern.test(employeeNo)) {
  700. Swal.fire({
  701. icon: 'warning',
  702. title: 'Validation Error',
  703. text: 'Employee No must start with "GIS" and be followed by one or more numbers.',
  704. confirmButtonText: 'OK'
  705. });
  706. console.warn('Validation failed: Employee No is invalid.');
  707. $('#submitButton').prop('disabled', false).text('Mark as sent audit'); // Re-enable button
  708. return; // Stop further execution
  709. } */
  710. // Step 1: Check if the employee exists in the database
  711. $('#submitButton').prop('disabled', true).text('Checking...');
  712. $.ajax({
  713. url: '/gcc/api/department/newentry/exists',
  714. type: 'GET',
  715. data: { empCode: employeeNo },
  716. success: function (existsResponse) {
  717. console.log("Exists API Response:", existsResponse);
  718. $('#pageLoader').hide();
  719. if (existsResponse && existsResponse.exists) {
  720. console.log(`Employee Code ${employeeNo} already exists in the database.`);
  721. Swal.fire({
  722. icon: "warning",
  723. title: "Already Exists",
  724. text: "This employee number already exists in our database.",
  725. confirmButtonText: "OK",
  726. customClass: {
  727. confirmButton: "btn btn-primary"
  728. }
  729. });
  730. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to pension'); // Re-enable button
  731. return; // Exit the function if the employee exists
  732. }
  733. // If employee does not exist, proceed to save details
  734. console.log(`Employee Code ${employeeNo} does not exist. Proceeding to save details.`);
  735. $('#submitButton').prop('disabled', true).text('Processing...');
  736. $.ajax({
  737. url: '/gcc/api/department/newentry/saveEmployeeDetailsGis',
  738. type: 'POST',
  739. contentType: 'application/json',
  740. data: JSON.stringify(entryDetails),
  741. success: function (response) {
  742. console.log("Save API Response:", response);
  743. Swal.fire({
  744. icon: 'success',
  745. title: 'Success',
  746. text: response,
  747. allowOutsideClick: false,
  748. allowEscapeKey: false,
  749. allowEnterKey: false,
  750. confirmButtonText: 'OK'
  751. }).then((result) => {
  752. if (result.isConfirmed) {
  753. console.log("Save confirmed. Redirecting to GIS page.");
  754. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to Pension');
  755. window.location.href = "/gcc/department/newentry/gis";
  756. }
  757. });
  758. },
  759. error: function (xhr) {
  760. console.error("Error in Save API:", xhr.responseText);
  761. Swal.fire({
  762. icon: 'error',
  763. title: 'Error',
  764. text: 'Failed to save details. Please try again.',
  765. confirmButtonText: 'OK'
  766. });
  767. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to pension'); // Re-enable button
  768. }
  769. });
  770. },
  771. error: function (xhr) {
  772. console.error("Error during existence check:", xhr.responseText);
  773. Swal.fire({
  774. icon: "error",
  775. title: "Error",
  776. text: "An error occurred while checking employee existence. Please try again.",
  777. confirmButtonText: "OK"
  778. });
  779. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to pension'); // Re-enable button
  780. }
  781. });
  782. }
  783. });
  784. // Trigger search on pressing Enter key
  785. $('#empCode').on('keydown', function (event) {
  786. if (event.key === 'Enter') {
  787. event.preventDefault(); // Prevent default form submission or page reload
  788. const empCode = $('#empCode').val(); // Get the value of empCode
  789. if (!empCode) {
  790. // Show Swal alert if the employee number is missing
  791. Swal.fire({
  792. icon: "warning", // Display a warning icon
  793. title: "Missing Employee Number",
  794. text: "Please enter an employee number to proceed.",
  795. confirmButtonText: "OK",
  796. customClass: {
  797. confirmButton: "btn btn-primary" // Optional styling for the button
  798. }
  799. });
  800. return; // Stop further execution
  801. }
  802. $('#searchButton').click(); // Trigger the click event of the search button
  803. }
  804. });
  805. // Handle close button click
  806. $('#cancelButton').click(function () {
  807. // Clear the input field value
  808. $('#empCode').val('');
  809. // Hide the card
  810. $('#employeeCard').hide();
  811. $('#staffTypeContainer').hide();
  812. });
  813. // Handle close button click
  814. $('#cancelButtonnew').click(function () {
  815. // Clear the input field value
  816. $('#empCode').val('');
  817. $('#newemployeeCard').hide();
  818. });
  819. function validatePositiveNumber(input) {
  820. if (input.value < 1) {
  821. input.value = "";
  822. }
  823. }
  824. $(document).ready(function () {
  825. // Restrict Employee Name to only alphabets
  826. $('#employeename').on('input', function () {
  827. let value = $(this).val();
  828. $(this).val(value.replace(/[^A-Za-z\s]/g, '')); // Allow only letters and spaces
  829. });
  830. $('#submitButton').on('click', function () {
  831. const employeeName = $('#employeename').val().trim();
  832. if (!/^[A-Za-z\s]+$/.test(employeeName)) {
  833. Swal.fire({
  834. icon: 'warning',
  835. title: 'Validation Error',
  836. text: 'Employee Name must contain only alphabets.',
  837. confirmButtonText: 'OK'
  838. });
  839. return;
  840. }
  841. });
  842. });
  843. </script>
  844. </body>
  845. </html>