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.

1012 lines
40 KiB

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="col-md-6">
  228. <label for="gisentry" class="form-label fw-bold">GIS Entry Type<span class="text-danger">*</span></label>
  229. <select id="gisentry" class="form-select" style="width: 100%;" required>
  230. </select>
  231. </div>
  232. <!-- div class="col-md-6">
  233. <label for="funeraladvance" class="form-label fw-bold">Sanctioned GIS Advance <span class="text-danger">*</span></label>
  234. <div class="dropdown">
  235. <input type="number" id="funeraladvance" class="form-control" >
  236. </div>
  237. </div> -->
  238. <div class="col-md-6">
  239. <label for="gisamount" class="form-label fw-bold">
  240. Sanctioned GIS Advance
  241. <span class="text-danger">*</span>
  242. </label>
  243. <div class="d-flex align-items-center">
  244. <div class="form-check" style="padding-right:10px;">
  245. <input type="radio" id="yes1" name="gisamount" class="form-check-input" value="yes">
  246. <label for="yes1" class="form-check-label">Yes</label>
  247. </div>
  248. <div class="form-check">
  249. <input type="radio" id="no1" name="gisamount" class="form-check-input" value="no">
  250. <label for="no1" class="form-check-label">No</label>
  251. </div>
  252. </div>
  253. <div class="dropdown" id="gisAmountInputContainer" style="display: none; margin-top: 10px;">
  254. <input type="number" id="gisAmountInput" name="gisamount_value" class="form-control"
  255. placeholder="Enter Sanctioned Gis Amount" min="1" oninput="validatePositiveNumber(this)">
  256. </div>
  257. </div>
  258. <div class="col-md-6">
  259. <label for="filesentdate" class="form-label fw-bold"> File Sent to GD Pension Section On<span class="text-danger">*</span></label>
  260. <div class="dropdown">
  261. <input type="text" id="filesentdate" class="form-control" readonly>
  262. </div>
  263. </div>
  264. <div class="col-md-12">
  265. <label for="remarks" class="form-label fw-bold">Comments/Remarks <span class="text-danger">*</span></label>
  266. <div class="dropdown">
  267. <textarea id="remarks" class="form-control" rows="4" placeholder="Enter your remarks here" required></textarea>
  268. </div>
  269. </div>
  270. </div>
  271. <div class="row mt-4 mt-20">
  272. <div class="col-12 d-flex justify-content-center">
  273. <button id="submitButton" class="btn btn-primary mt-2 mx-2">Mark as Forward to Pension</button>
  274. <button id="cancelButton" class="btn btn-secondary mt-2">Cancel</button>
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. <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;">
  284. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  285. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  286. <span class="sr-only">Loading...</span>
  287. </div>
  288. <!-- Add the 'Please wait' text below the spinner -->
  289. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  290. </div>
  291. </div>
  292. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  293. </div>
  294. </div>
  295. <div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
  296. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  297. <script src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
  298. <!-- Bootstrap 5 JS -->
  299. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  300. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  301. <script>
  302. document.addEventListener("DOMContentLoaded", function() {
  303. // Get today's date
  304. const today = new Date();
  305. // Format the date as DD-MM-YYYY for display
  306. const day = String(today.getDate()).padStart(2, '0');
  307. const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
  308. const year = today.getFullYear();
  309. // Combine into DD-MM-YYYY format for display
  310. const formattedDateDisplay = `${day}-${month}-${year}`;
  311. // Set the value of the input field to the current date (in DD-MM-YYYY format for display)
  312. document.getElementById("filesentdate").value = formattedDateDisplay;
  313. });
  314. function convertDateFormat(dateString) {
  315. if (!dateString) return '';
  316. let [day, month, year] = dateString.split('-');
  317. return `${year}-${month}-${day}`;
  318. }
  319. document.addEventListener("DOMContentLoaded", function () {
  320. let today = new Date().toISOString().split("T")[0]; // Get today's date in YYYY-MM-DD format
  321. let servicedeathInput = document.getElementById("servicedeath");
  322. // Set max attribute to disable future dates
  323. servicedeathInput.setAttribute("max", today);
  324. // Prevent manual future date entry
  325. servicedeathInput.addEventListener("change", function () {
  326. if (this.value > today) {
  327. Swal.fire({
  328. icon: 'warning',
  329. title: 'Invalid Date',
  330. text: 'Future dates are not allowed.',
  331. confirmButtonText: 'OK'
  332. });
  333. this.value = ""; // Clear the invalid input
  334. }
  335. });
  336. });
  337. console.log("before ajaxx....")
  338. $(document).ready(function () {
  339. $(document).ready(function () {
  340. $('#addNewbutton').on('click', function () {
  341. // Show the staff type container
  342. $('#staffTypeContainer').show();
  343. $('#employeeCard').hide();
  344. $('input[name="staffType"]').prop('checked', false);
  345. // Add change event listener to the radio buttons
  346. $('input[name="staffType"]').off('change').on('change', function () {
  347. const selectedType = $('input[name="staffType"]:checked').val();
  348. $('#staffTypeContainer').hide();
  349. if (selectedType === 'temporary') {
  350. // Show the employee card
  351. $('#employeeCard').show();
  352. // Pre-fill "GIS" in Employee No and enforce rules
  353. $('#employeeno')
  354. .val('GIS') // Pre-fill with "GIS"
  355. .prop('readonly', false) // Allow editing, but only after "GIS"
  356. .off('input keydown') // Remove existing event listeners
  357. .on('input', function () {
  358. const value = $(this).val();
  359. if (!value.startsWith('GIS')) {
  360. $(this).val('GIS');
  361. } else {
  362. const numericPart = value.slice(3).replace(/\D/g, ''); // Allow only digits after "GIS"
  363. $(this).val('GIS' + numericPart);
  364. }
  365. })
  366. .on('keydown', function (e) {
  367. const cursorPosition = this.selectionStart;
  368. if ((e.key === 'Backspace' || e.key === 'Delete') && cursorPosition <= 3) {
  369. e.preventDefault(); // Prevent removing "GIS"
  370. }
  371. });
  372. // Pre-fill and enable fields
  373. $('#employeename').val('').prop('readonly', false);
  374. $('#department').val($('#deptname').text().trim()).prop('readonly', true);
  375. $('#designation').val('').prop('readonly', false);
  376. $('#servicedeath').val('').prop('readonly', false);
  377. $('#deceased').val('').prop('readonly', false);
  378. //$('#funeraladvance').val('').prop('readonly', false);
  379. $('#filesentdate').prop('readonly', true);
  380. $('#remarks').val('').prop('readonly', false);
  381. } else if (selectedType === 'permanent') {
  382. // Hide the employee card and show a SweetAlert
  383. $('#employeeCard').hide();
  384. Swal.fire({
  385. icon: 'warning',
  386. title: 'ERP Required',
  387. text: 'Please create a number in ERP for permanent staff.',
  388. confirmButtonText: 'OK',
  389. customClass: {
  390. confirmButton: 'btn btn-primary'
  391. }
  392. });
  393. }
  394. });
  395. });
  396. $('#submitButton').off('click').on('click', function () {
  397. const gisPattern = /^GIS\d+$/;
  398. const employeeNo = $('#employeeno').val().trim();
  399. // Validate Employee No
  400. if (!gisPattern.test(employeeNo)) {
  401. Swal.fire({
  402. icon: 'warning',
  403. title: 'Validation Error',
  404. text: 'Employee No must start with "GIS" and be followed by one or more numbers.',
  405. confirmButtonText: 'OK'
  406. });
  407. console.warn('Validation failed: Employee No is invalid.');
  408. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to Pension'); // Re-enable button
  409. return; // Stop execution if validation fails
  410. }
  411. // Log and call save function
  412. console.log("Save button clicked. Triggering saveEntryDetails function.");
  413. saveEntryDetailsnew();
  414. });
  415. });
  416. // Handle Search button click
  417. $('#searchButton').on('click', function () {
  418. const empCode = $('#empCode').val().trim(); // Trim input to avoid accidental spaces
  419. console.log("empCode...",empCode);
  420. if (!empCode) {
  421. Swal.fire({
  422. icon: "warning",
  423. title: "Missing Employee Number",
  424. text: "Please enter an employee number to proceed.",
  425. confirmButtonText: "OK",
  426. customClass: {
  427. confirmButton: "btn btn-primary"
  428. }
  429. });
  430. console.log("No Employee Code provided. Aborting search.");
  431. return; // Stop further execution if empCode is not provided
  432. }
  433. // Show loader and hide other elements
  434. $('#pageLoader').show();
  435. $('#employeeCard').hide();
  436. $('#newemployeeCard').hide();
  437. $('#gisAmountInput').val('');
  438. $('input[name="gisamount"]').prop('checked', false);
  439. console.log("Checking if employee exists: ${empCode}");
  440. // Step 1: Check if employee exists in the database
  441. $.ajax({
  442. url: '/gcc/api/department/newentry/exists', // Endpoint to check existence
  443. type: 'GET',
  444. data: { empCode: empCode },
  445. success: function (existsResponse) {
  446. console.log("Exists API Response:", existsResponse);
  447. $('#pageLoader').hide();
  448. if (existsResponse && existsResponse.exists) {
  449. console.log("Employee Code ${empCode} exists in the database.");
  450. Swal.fire({
  451. icon: "warning",
  452. title: "Already Exists",
  453. text: "This employee number already exists.",
  454. confirmButtonText: "OK",
  455. customClass: {
  456. confirmButton: "btn btn-primary"
  457. }
  458. });
  459. return; // Exit the function if the employee exists
  460. }
  461. console.log(`Employee Code ${empCode} does not exist. Fetching details from the external API.`);
  462. // If employee does not exist, fetch details from the external API
  463. fetchEmployeeDetails(empCode);
  464. },
  465. error: function (xhr) {
  466. $('#pageLoader').hide();
  467. console.error("Error during existence check:", xhr.responseText);
  468. Swal.fire({
  469. icon: "error",
  470. title: "Error",
  471. text: "An error occurred while checking employee existence. Please try again.",
  472. confirmButtonText: "OK"
  473. });
  474. }
  475. });
  476. });
  477. // Function to fetch employee details from external API
  478. console.log("fetchEmployeeDetails.....")
  479. function fetchEmployeeDetails(empCode) {
  480. console.log("Fetching details for employee:");
  481. $('#pageLoader').show();
  482. $.ajax({
  483. url: '/gcc/api/department/newentry/employeedetails', // External API endpoint
  484. type: 'GET',
  485. data: { empCode: empCode },
  486. success: function (response) {
  487. console.log("Employee Details API Response:", response);
  488. $('#pageLoader').hide();
  489. if (response.list && response.list.length > 0) {
  490. const employeeDetails = response.list[0];
  491. console.log("Employee Details Retrieved:", employeeDetails);
  492. // Check if the employee code is null or not found
  493. const loggedInDeptId = $('#deptId').text().trim(); // Get deptId dynamically
  494. // Validate department ID
  495. if (employeeDetails.ID_DEPT !== loggedInDeptId) {
  496. Swal.fire({
  497. icon: "error",
  498. title: "Access Denied",
  499. text: "This employee does not belong to your department. Please try again with a valid employeecode.",
  500. confirmButtonText: "OK",
  501. customClass: {
  502. confirmButton: "btn btn-danger"
  503. }
  504. });
  505. return;
  506.                }
  507. // Populate the employee details
  508. console.log("Populating employee details in the UI.");
  509. $('#employeeno').val(employeeDetails.EMPLOYEE_CODE).prop('readonly', true);;
  510. $('#employeename').val(employeeDetails.EMPLOYEE_NAME).prop('readonly', true);
  511. $('#department').val(employeeDetails.DEPARTMENT).prop('readonly', true);
  512. $('#designation').val(employeeDetails.DESIGNATION).prop('readonly', true);
  513. $('#classes').val(employeeDetails.GROUP_TYPE);
  514. $('#retrirementdate').val(employeeDetails.RETIREMENT_DATE);
  515. $('#EmployeeCode').text(empCode);
  516. $('#employeeCard').show();
  517. // Attach event handler for saving details
  518. $('#submitButton').off('click').on('click', function () {
  519. console.log("Save button clicked. Triggering saveEntryDetails function.");
  520. saveEntryDetailsnew();
  521. });
  522. } else {
  523. console.warn("No employee data found in the external API response.");
  524. Swal.fire({
  525. icon: "warning",
  526. title: "No Data Found",
  527. text: "No details found for this employee number.",
  528. confirmButtonText: "OK",
  529. customClass: {
  530. confirmButton: "btn btn-primary"
  531. }
  532. });
  533. $('#newemployeeCard').show();
  534. }
  535. },
  536. error: function (xhr) {
  537. $('#pageLoader').hide();
  538. console.error("Error in Employee Details API:", xhr.responseText);
  539. Swal.fire({
  540. icon: "error",
  541. title: "Error",
  542. text: "An error occurred while fetching data. Please try again.",
  543. confirmButtonText: "OK"
  544. });
  545. }
  546. });
  547. }
  548. document.querySelectorAll('input[name="gisamount"]').forEach(radio => {
  549. radio.addEventListener('change', function () {
  550. const gisAmountInputContainer = document.getElementById('gisAmountInputContainer');
  551. if (this.value === 'yes') {
  552. gisAmountInputContainer.style.display = 'block'; // Show the input field
  553. } else {
  554. gisAmountInputContainer.style.display = 'none'; // Hide the input field
  555. document.getElementById('gisAmountInput').value = ''; // Clear the input field
  556. }
  557. });
  558. });
  559. //dropdown for gisentry type:
  560. $(document).ready(function () {
  561. function loadEntryTypes() {
  562. $.ajax({
  563. url: "/gcc/api/getGisEntryTypes",
  564. type: "GET",
  565. success: function (data) {
  566. var dropdown = $("#gisentry");
  567. dropdown.empty(); // Clear existing options
  568. dropdown.append('<option value="" selected>-- Select Option --</option>');
  569. // Loop through the API response and add options
  570. $.each(data, function (key, entry) {
  571. dropdown.append($('<option></option>').attr('value', entry.gis_entry).text(entry.gis_entry));
  572. //dropdown.append('<option value="' + item.id + '">' + item.gis_entry + '</option>');
  573. });
  574. },
  575. error: function () {
  576. console.log("Error loading dropdown data.");
  577. }
  578. });
  579. }
  580. // Call function on page load
  581. loadEntryTypes();
  582. });
  583. function saveEntryDetailsnew() {
  584. let selgisamount = $('input[name="gisamount"]:checked').val();
  585. let selgismamountval = null;
  586. if (selgisamount === 'yes') {
  587. selgismamountval = $('#gisAmountInput').val();
  588. if (!selgismamountval || selgismamountval <= 0) {
  589. Swal.fire({
  590. icon: 'warning',
  591. title: 'Validation Error',
  592. text: 'Please enter a valid Sanctioned Gis Amount',
  593. confirmButtonText: 'OK'
  594. });
  595. return ; // Stop further execution
  596. }
  597. }
  598. let entryDetails = {
  599. empNo: $('#employeeno').val(),
  600. empName: $('#employeename').val(),
  601. deptName: $('#department').val(),
  602. designation: $('#designation').val(),
  603. serviceDeath: $('#servicedeath').val(),
  604. dateToPension: convertDateFormat($('#filesentdate').val()?.trim()),
  605. deceased: $('#deceased').val(),
  606. gisentry: $('#gisentry').val(),
  607. //funeralAdvance: $('#funeraladvance').val(),
  608. gisAdvanceamount : selgismamountval,
  609. gisAdvance : selgisamount,
  610. remarks: $('#remarks').val(),
  611. deptId: $('#deptId').text().trim(),
  612. filemovedby: $('#userId').text().trim(),
  613. filecategory: $('#filecategory').text().trim()
  614. };
  615. console.log("Saving employee details:", entryDetails);
  616. if (!entryDetails.empName) {
  617. Swal.fire({
  618. icon: 'warning',
  619. title: 'Validation Error!',
  620. text: 'Employee Name is required.',
  621. confirmButtonText: 'OK'
  622. });
  623. return;
  624. }
  625. if (!entryDetails.designation) {
  626. Swal.fire({
  627. icon: 'warning',
  628. title: 'Validation Error!',
  629. text: 'Designation is required.',
  630. confirmButtonText: 'OK'
  631. });
  632. return;
  633. }
  634. if (!entryDetails.dateToPension) {
  635. Swal.fire({
  636. icon: 'warning',
  637. title: 'Validation Error!',
  638. text: 'Date to Pension is required.',
  639. confirmButtonText: 'OK'
  640. });
  641. return;
  642. }
  643. if (!entryDetails.serviceDeath) {
  644. Swal.fire({
  645. icon: 'warning',
  646. title: 'Validation Error!',
  647. text: 'Service Death Date is required.',
  648. confirmButtonText: 'OK'
  649. });
  650. return;
  651. }
  652. if (!entryDetails.deceased) {
  653. Swal.fire({
  654. icon: 'warning',
  655. title: 'Validation Error!',
  656. text: 'Relationship of Deceased is required.',
  657. confirmButtonText: 'OK'
  658. });
  659. return;
  660. }
  661. if (!entryDetails.gisentry) {
  662. Swal.fire({
  663. icon: 'warning',
  664. title: 'Validation Error!',
  665. text: 'Gis Entry Type is required.',
  666. confirmButtonText: 'OK'
  667. });
  668. return;
  669. }
  670. if (!entryDetails.gisAdvance) {
  671. Swal.fire({
  672. icon: 'warning',
  673. title: 'Validation Error!',
  674. text: 'Sanctional Gis Advance is required.',
  675. confirmButtonText: 'OK'
  676. });
  677. return;
  678. }
  679. if (!entryDetails.remarks) {
  680. Swal.fire({
  681. icon: 'warning',
  682. title: 'Validation Error!',
  683. text: 'Remarks are required.',
  684. confirmButtonText: 'OK'
  685. });
  686. return;
  687. }
  688. const employeeNo = entryDetails.empNo.trim();
  689. // Validate Employee No format
  690. /* const gisPattern = /^GIS\d+$/;
  691. if (!gisPattern.test(employeeNo)) {
  692. Swal.fire({
  693. icon: 'warning',
  694. title: 'Validation Error',
  695. text: 'Employee No must start with "GIS" and be followed by one or more numbers.',
  696. confirmButtonText: 'OK'
  697. });
  698. console.warn('Validation failed: Employee No is invalid.');
  699. $('#submitButton').prop('disabled', false).text('Mark as sent audit'); // Re-enable button
  700. return; // Stop further execution
  701. } */
  702. // Step 1: Check if the employee exists in the database
  703. $('#submitButton').prop('disabled', true).text('Checking...');
  704. $.ajax({
  705. url: '/gcc/api/department/newentry/exists',
  706. type: 'GET',
  707. data: { empCode: employeeNo },
  708. success: function (existsResponse) {
  709. console.log("Exists API Response:", existsResponse);
  710. $('#pageLoader').hide();
  711. if (existsResponse && existsResponse.exists) {
  712. console.log(`Employee Code ${employeeNo} already exists in the database.`);
  713. Swal.fire({
  714. icon: "warning",
  715. title: "Already Exists",
  716. text: "This employee number already exists in our database.",
  717. confirmButtonText: "OK",
  718. customClass: {
  719. confirmButton: "btn btn-primary"
  720. }
  721. });
  722. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to pension'); // Re-enable button
  723. return; // Exit the function if the employee exists
  724. }
  725. // If employee does not exist, proceed to save details
  726. console.log(`Employee Code ${employeeNo} does not exist. Proceeding to save details.`);
  727. $('#submitButton').prop('disabled', true).text('Processing...');
  728. $.ajax({
  729. url: '/gcc/api/department/newentry/saveEmployeeDetailsGis',
  730. type: 'POST',
  731. contentType: 'application/json',
  732. data: JSON.stringify(entryDetails),
  733. success: function (response) {
  734. console.log("Save API Response:", response);
  735. Swal.fire({
  736. icon: 'success',
  737. title: 'Success',
  738. text: response,
  739. allowOutsideClick: false,
  740. allowEscapeKey: false,
  741. allowEnterKey: false,
  742. confirmButtonText: 'OK'
  743. }).then((result) => {
  744. if (result.isConfirmed) {
  745. console.log("Save confirmed. Redirecting to GIS page.");
  746. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to Pension');
  747. window.location.href = "/gcc/department/newentry/gis";
  748. }
  749. });
  750. },
  751. error: function (xhr) {
  752. console.error("Error in Save API:", xhr.responseText);
  753. Swal.fire({
  754. icon: 'error',
  755. title: 'Error',
  756. text: 'Failed to save details. Please try again.',
  757. confirmButtonText: 'OK'
  758. });
  759. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to pension'); // Re-enable button
  760. }
  761. });
  762. },
  763. error: function (xhr) {
  764. console.error("Error during existence check:", xhr.responseText);
  765. Swal.fire({
  766. icon: "error",
  767. title: "Error",
  768. text: "An error occurred while checking employee existence. Please try again.",
  769. confirmButtonText: "OK"
  770. });
  771. $('#submitButton').prop('disabled', false).text('Mark as Forwarded to pension'); // Re-enable button
  772. }
  773. });
  774. }
  775. });
  776. // Trigger search on pressing Enter key
  777. $('#empCode').on('keydown', function (event) {
  778. if (event.key === 'Enter') {
  779. event.preventDefault(); // Prevent default form submission or page reload
  780. const empCode = $('#empCode').val(); // Get the value of empCode
  781. if (!empCode) {
  782. // Show Swal alert if the employee number is missing
  783. Swal.fire({
  784. icon: "warning", // Display a warning icon
  785. title: "Missing Employee Number",
  786. text: "Please enter an employee number to proceed.",
  787. confirmButtonText: "OK",
  788. customClass: {
  789. confirmButton: "btn btn-primary" // Optional styling for the button
  790. }
  791. });
  792. return; // Stop further execution
  793. }
  794. $('#searchButton').click(); // Trigger the click event of the search button
  795. }
  796. });
  797. // Handle close button click
  798. $('#cancelButton').click(function () {
  799. // Clear the input field value
  800. $('#empCode').val('');
  801. // Hide the card
  802. $('#employeeCard').hide();
  803. $('#staffTypeContainer').hide();
  804. });
  805. // Handle close button click
  806. $('#cancelButtonnew').click(function () {
  807. // Clear the input field value
  808. $('#empCode').val('');
  809. $('#newemployeeCard').hide();
  810. });
  811. function validatePositiveNumber(input) {
  812. if (input.value < 1) {
  813. input.value = "";
  814. }
  815. }
  816. $(document).ready(function () {
  817. // Restrict Employee Name to only alphabets
  818. $('#employeename').on('input', function () {
  819. let value = $(this).val();
  820. $(this).val(value.replace(/[^A-Za-z\s]/g, '')); // Allow only letters and spaces
  821. });
  822. $('#submitButton').on('click', function () {
  823. const employeeName = $('#employeename').val().trim();
  824. if (!/^[A-Za-z\s]+$/.test(employeeName)) {
  825. Swal.fire({
  826. icon: 'warning',
  827. title: 'Validation Error',
  828. text: 'Employee Name must contain only alphabets.',
  829. confirmButtonText: 'OK'
  830. });
  831. return;
  832. }
  833. });
  834. });
  835. </script>
  836. </body>
  837. </html>