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.

807 lines
33 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #employeeCard label{
  92. padding-top: 2%;
  93. }
  94. </style>
  95. <body>
  96. <!--[if lt IE 8]>
  97. <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>
  98. <![endif]-->
  99. <div class="wrapper">
  100. <!-- header top menu Start -->
  101. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  102. <!-- header top menu end -->
  103. <div class="page-wrap">
  104. <!--=============== Left Menu side Start ================-->
  105. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  106. <!--=============== Left side End ================-->
  107. <div class="main-content">
  108. <div class="container-fluid">
  109. <div class="page-header mb-2">
  110. <div class="row align-items-end">
  111. <div class="col-lg-8">
  112. <div class="page-header-title">
  113. <i class="fa fa-list-alt bg-blue"></i>
  114. <div class="d-inline">
  115. <h5>Department Entries</h5>
  116. <span>Pendency</span>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="col-lg-4">
  121. <nav class="breadcrumb-container" aria-label="breadcrumb">
  122. <ol class="breadcrumb">
  123. <li class="breadcrumb-item"><a href="/gcc/index"><i class="ik ik-home"></i></a></li>
  124. <li class="breadcrumb-item" aria-current="page">Department Entries</li>
  125. <li class="breadcrumb-item" aria-current="page">NewEntry</li>
  126. <li class="breadcrumb-item active" aria-current="page">Pendency</li>
  127. </ol>
  128. </nav>
  129. </div>
  130. </div>
  131. </div>
  132. <div class="row mt-4" >
  133. <div class="col-md-12">
  134. <div class="card">
  135. <div class="card-block">
  136. <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>
  137. <h5 style="font-weight:bold;"><span th:text="${deptId}" id="deptId" style="display:none"></span> New Entry - Pendency</h5>
  138. <span th:text="${userId}" id="userId" style="display:none"></span>
  139. <div class="row mb-4">
  140. <div class="col-md-4" >
  141. <label for="empCode" class="form-label fw-bold">Search by Employee No <span class="text-danger">*</span></label>
  142. <div class="dropdown">
  143. <input type="number" id="empCode" class="form-control" pattern="^[A-Za-z0-9]+$" placeholder="Enter Employee No" required>
  144. <small id="employeenoHelp" class="form-text text-muted">Only numeric characters (numbers) are allowed.</small>
  145. </div>
  146. </div>
  147. <div class="col-md-4 mt-20">
  148. <button id="searchButton" class="btn btn-primary mt-2" Style="height:38px;">Search</button>
  149. <!-- <button id="resetButton" class="btn btn-secondary mt-2">Reset</button> -->
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. <div class="row mb-4" id="employeeCard" style="display: none;">
  157. <div class="col-md-12">
  158. <div class="card">
  159. <div class="card-block">
  160. <h5 style="font-weight:bold;">New Entry - Pendency - <span id="EmployeeCode"></span></h5>
  161. <hr>
  162. <div class="row">
  163. <!-- Employee No -->
  164. <div class="col-md-6">
  165. <label for="employeeno" class="form-label fw-bold">Employee No <span class="text-danger">*</span></label>
  166. <div class="dropdown">
  167. <input type="number" id="employeeno" class="form-control" readonly>
  168. </div>
  169. </div>
  170. <!-- Employee Name -->
  171. <div class="col-md-6">
  172. <label for="employeename" class="form-label fw-bold">Employee Name <span class="text-danger">*</span></label>
  173. <div class="dropdown">
  174. <input type="text" id="employeename" class="form-control" readonly>
  175. </div>
  176. </div>
  177. <div class="col-md-6">
  178. <label for="Department" class="form-label fw-bold">Department <span class="text-danger">*</span></label>
  179. <div class="dropdown">
  180. <input type="text" id="department" class="form-control" readonly>
  181. </div>
  182. </div>
  183. <div class="col-md-6">
  184. <label for="Designation" class="form-label fw-bold">Designation<span class="text-danger">*</span></label>
  185. <div class="dropdown">
  186. <input type="text" id="designation" class="form-control" readonly>
  187. </div>
  188. </div>
  189. <div class="col-md-6">
  190. <label for="classes" class="form-label fw-bold">Class<span class="text-danger">*</span></label>
  191. <div class="dropdown" >
  192. <input type="text" id="classes" class="form-control" readonly>
  193. </div>
  194. </div>
  195. <div class="col-sm-6">
  196. <label for="retirementdate" class="form-label fw-bold">Retirement Date <span class="text-danger">*</span></label>
  197. <input type="date" id="retirementdate" class="form-control" readonly>
  198. </div>
  199. <div class="col-md-6">
  200. <label for="retirement" class="form-label fw-bold">Type Of Retirement<span class="text-danger">*</span></label>
  201. <select id="retirement" class="form-select" style="width: 100%;height: 40px;" required>
  202. </select>
  203. </div>
  204. <!-- pending duration-->
  205. <div class="col-md-6">
  206. <label for="pendingDuration" class="form-label fw-bold">
  207. Pending Duration
  208. <span class="text-danger">*</span>
  209. </label>
  210. <div class="d-flex align-items-center">
  211. <div class="form-check" style="padding-right:10px;">
  212. <input type="radio" id="yes" name="pendingDuration" value="yes"class="form-check-input">
  213. <label for="yes" class="form-check-label">Yes</label>
  214. </div>
  215. <div class="form-check">
  216. <input type="radio" id="no" name="pendingDuration" value="no"class="form-check-input">
  217. <label for="no" class="form-check-label">No</label>
  218. </div>
  219. </div>
  220. <div id="clickyesdiv" style="display: none; margin-top: 10px;">
  221. <label for="clickyes" class="form-label">Please specify:<span class="text-danger">*</span></label>
  222. <input type="text" id="Clickyes" class="form-control" placeholder="Enter reason">
  223. </div>
  224. </div>
  225. </div>
  226. <div class="row">
  227. <div class="col-md-6">
  228. <label for="Audit File" class="form-label fw-bold">Date file sent to Audit<span class="text-danger">*</span></label>
  229. <div class="dropdown">
  230. <input type="text" id="filesentdate" class="form-control" readonly>
  231. </div>
  232. </div>
  233. <div class="col-md-12">
  234. <label for="remarks" class="form-label fw-bold">Comments/Remarks <span class="text-danger">*</span></label>
  235. <div class="dropdown">
  236. <textarea id="remarks" class="form-control" rows="4" placeholder="Enter your remarks here" required></textarea>
  237. </div>
  238. </div>
  239. </div>
  240. <div class="row mt-4">
  241. <div class="col-12 d-flex justify-content-center">
  242. <button id="lfauditButton" class="btn btn-primary mt-2 mx-2">Mark as sent Audit</button>
  243. <button id="cancelButton" class="btn btn-secondary mt-2">Cancel</button>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. </div>
  252. <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;">
  253. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  254. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  255. <span class="sr-only">Loading...</span>
  256. </div>
  257. <!-- Add the 'Please wait' text below the spinner -->
  258. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  259. </div>
  260. </div>
  261. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  262. </div>
  263. </div>
  264. <div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
  265. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  266. <script src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
  267. <!-- Bootstrap 5 JS -->
  268. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  269. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  270. <script>
  271. $(document).ready(function (){
  272. $('#searchButton').on('click', function () {
  273. const empCode = $('#empCode').val().trim(); // Trim any extra spaces
  274. console.log("empCode:", empCode);
  275. // If empCode is missing, show a warning and abort.
  276. if (!empCode) {
  277. Swal.fire({
  278. icon: "warning",
  279. title: "Missing Employee Number",
  280. text: "Please enter an employee number to proceed.",
  281. confirmButtonText: "OK",
  282. customClass: {
  283. confirmButton: "btn btn-primary"
  284. }
  285. });
  286. console.log("No Employee Code provided. Aborting search.");
  287. return;
  288. }
  289. // Show loader and hide any previously displayed cards
  290. $('#pageLoader').show();
  291. $('#employeeCard').hide();
  292. $('#newemployeeCard').hide();
  293. // Clear/reset form fields
  294. $('#typeofcategory').val('');
  295. $('#retirement').val('');
  296. $('#pendingDurationInput').val('');
  297. $('#remarks').val('');
  298. $('input[name="pendingDuration"]').prop('checked', false);
  299. // STEP 1: Check if the employee already exists in the database.
  300. $.ajax({
  301. url: '/gcc/api/department/newentry/prexists', // Endpoint to check existence
  302. type: 'GET',
  303. data: { empCode: empCode },
  304. success: function (existsResponse) {
  305. console.log("Exists API Response:", existsResponse);
  306. $('#pageLoader').hide();
  307. // If the employee exists, show a warning and stop processing.
  308. if (existsResponse && existsResponse.exists) {
  309. Swal.fire({
  310. icon: "warning",
  311. title: "Already Exists",
  312. text: "This employee number already exists.",
  313. confirmButtonText: "OK",
  314. customClass: {
  315. confirmButton: "btn btn-primary"
  316. }
  317. });
  318. return;
  319. }
  320. // STEP 2: If the employee does not exist, fetch employee details.
  321. $('#pageLoader').show(); // Show loader for the second API call
  322. $.ajax({
  323. url: '/gcc/api/department/newentry/employeedetails', // Correct API URL for employee details
  324. type: 'GET',
  325. data: { empCode: empCode },
  326. success: function (response) {
  327. $('#pageLoader').hide();
  328. console.log("Employee Details API Response:", response.list);
  329. if (response.list && response.list.length > 0) {
  330. // Retrieve the first (and presumably only) employee details record.
  331. let employeeDetails = response.list[0];
  332. console.log("Employee Details:", employeeDetails);
  333. // Optional: Validate department ID if needed.
  334. const loggedInDeptId = $('#deptId').text().trim();
  335. const currentDate = $('#filesentdate').val().trim();
  336. const retirementDateStr = employeeDetails.RETIREMENT_DATE.trim();
  337. // Convert input date from "dd-MM-yyyy" to "yyyy-MM-dd"
  338. function parseInputDate(dateStr) {
  339. let parts = dateStr.split('-'); // Assuming input is "dd-MM-yyyy"
  340. if (parts.length === 3) {
  341. return new Date(parts[2], parts[1] - 1, parts[0]); // Convert to "YYYY, MM-1, DD"
  342. }
  343. return null;
  344. }
  345. // Convert RETIREMENT_DATE from "YYYY-MM-DD" to Date object
  346. const retirementDate = new Date(retirementDateStr);
  347. const currentDateObj = parseInputDate(currentDate);
  348. if (!retirementDate || !currentDateObj) {
  349. console.error("Invalid date format", retirementDate, currentDateObj);
  350. return;
  351. }
  352. // Compare retirement date with current date
  353. if (retirementDate >= currentDateObj) {
  354. Swal.fire({
  355. icon: "warning",
  356. title: "Not Applicable",
  357. text: "This employee is not applicable for this pendency.",
  358. confirmButtonText: "OK",
  359. customClass: {
  360. confirmButton: "btn btn-primary"
  361. }
  362. });
  363. return;
  364. }
  365. // If the returned data is invalid, show a warning.
  366. if (!employeeDetails || !employeeDetails.EMPLOYEE_CODE) {
  367. Swal.fire({
  368. icon: "warning",
  369. title: "No Data Found",
  370. text: "No details found for this employee number.",
  371. confirmButtonText: "OK",
  372. customClass: {
  373. confirmButton: "btn btn-primary"
  374. }
  375. });
  376. return;
  377. }
  378. if (employeeDetails.ID_DEPT !== loggedInDeptId) {
  379. Swal.fire({
  380. icon: "error",
  381. title: "Access Denied",
  382. text: "This employee does not belong to your department. Please try again with a valid employee code.",
  383. confirmButtonText: "OK",
  384. customClass: {
  385. confirmButton: "btn btn-danger"
  386. }
  387. });
  388. return;
  389. }
  390. // Function to handle radio button state based on retirement date
  391. function handlePendingDurationState() {
  392. const currentDate = new Date().toISOString().split('T')[0]; // Get today's date in YYYY-MM-DD format
  393. const retirementDate = employeeDetails.RETIREMENT_DATE; // Assuming this comes in YYYY-MM-DD format
  394. const yesRadio = document.getElementById("yes");
  395. const noRadio = document.getElementById("no");
  396. const inputFieldDiv = document.getElementById('clickyesdiv');
  397. if (retirementDate <= currentDate) {
  398. // If retirement date is less than or equal to current date, disable 'Yes' option
  399. yesRadio.checked = true;
  400. inputFieldDiv.style.display = 'block';
  401. noRadio.disabled = true; // Default to 'No'
  402. } else {
  403. // If retirement date is greater than current date, disable 'No' option
  404. noRadio.checked = true;
  405. yesRadio.disabled = true; // Default to 'Yes'
  406. }
  407. }
  408. // Call the function after fetching `employeeDetails`
  409. handlePendingDurationState();
  410. // Populate the form fields with the fetched employee details.
  411. $('#employeeno').val(employeeDetails.EMPLOYEE_CODE);
  412. $('#employeename').val(employeeDetails.EMPLOYEE_NAME);
  413. $('#department').val(employeeDetails.DEPARTMENT);
  414. $('#designation').val(employeeDetails.DESIGNATION);
  415. $('#classes').val(employeeDetails.GROUP_TYPE);
  416. $('#retirementdate').val(employeeDetails.RETIREMENT_DATE);
  417. $('#EmployeeCode').text(empCode);
  418. // Finally, display the employee card/modal.
  419. $('#employeeCard').show();
  420. } else {
  421. $('#pageLoader').hide();
  422. Swal.fire({
  423. icon: "warning",
  424. title: "No Data Found",
  425. text: "No details found for this employee number.",
  426. confirmButtonText: "OK",
  427. customClass: {
  428. confirmButton: "btn btn-primary"
  429. }
  430. });
  431. }
  432. },
  433. error: function () {
  434. $('#pageLoader').hide();
  435. Swal.fire({
  436. icon: "error",
  437. title: "Error",
  438. text: "An error occurred while fetching data. Please try again.",
  439. confirmButtonText: "OK"
  440. });
  441. }
  442. });
  443. },
  444. error: function () {
  445. $('#pageLoader').hide();
  446. Swal.fire({
  447. icon: "error",
  448. title: "Error",
  449. text: "An error occurred while checking the employee. Please try again.",
  450. confirmButtonText: "OK"
  451. });
  452. }
  453. });
  454. });
  455. /* document.getElementById('lfauditButton').addEventListener('click', function () {
  456. // Trigger the save function when the button is clicked
  457. saveEntryDetails();
  458. }); */
  459. //$('#lfauditButton').one('click', saveEntryDetails);
  460. $('#lfauditButton').off('click').on('click', saveEntryDetails);
  461. })
  462. // Handle close button click
  463. $('#cancelButton').click(function () {
  464. // Clear the input field value
  465. $('#empCode').val('');
  466. // Hide the card
  467. $('#employeeCard').hide();
  468. });
  469. // Handle close button click
  470. $('#cancelButtonnew').click(function () {
  471. // Clear the input field value
  472. $('#empCode').val('');
  473. // Hide the card
  474. $('#newemployeeCard').hide();
  475. });
  476. // Trigger search on pressing Enter key
  477. $('#empCode').on('keydown', function (event) {
  478. if (event.key === 'Enter') {
  479. event.preventDefault(); // Prevent default form submission or page reload
  480. const empCode = $('#empCode').val(); // Get the value of empCode
  481. if (!empCode) {
  482. // Show Swal alert if the employee number is missing
  483. Swal.fire({
  484. icon: "warning", // Display a warning icon
  485. title: "Missing Employee Number",
  486. text: "Please enter an employee number to proceed.",
  487. confirmButtonText: "OK",
  488. customClass: {
  489. confirmButton: "btn btn-primary" // Optional styling for the button
  490. }
  491. });
  492. return; // Stop further execution
  493. }
  494. $('#searchButton').click(); // Trigger the click event of the search button
  495. }
  496. });
  497. $(document).ready(function () {
  498. function loadRetirementTypes() {
  499. $.ajax({
  500. url: "/gcc/api/getRetrimentTypes",
  501. type: "GET",
  502. success: function (data) {
  503. var dropdown = $("#retirement");
  504. dropdown.empty();
  505. dropdown.append('<option value="" selected>-- Select Option --</option>');
  506. $.each(data, function (key, entry) {
  507. if (entry.retriment_type !== "Provisional") { // Exclude "Provisional"
  508. dropdown.append($('<option></option>').attr('value', entry.retriment_type).text(entry.retriment_type));
  509. }
  510. });
  511. },
  512. error: function () {
  513. console.log("Error loading dropdown data.");
  514. }
  515. });
  516. }
  517. // Call function on page load
  518. loadRetirementTypes();
  519. });
  520. document.addEventListener("DOMContentLoaded", function() {
  521. // Get today's date
  522. const today = new Date();
  523. // Format the date as DD-MM-YYYY for display
  524. const day = String(today.getDate()).padStart(2, '0');
  525. const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
  526. const year = today.getFullYear();
  527. // Combine into DD-MM-YYYY format for display
  528. const formattedDateDisplay = `${day}-${month}-${year}`;
  529. // Set the value of the input field to the current date (in DD-MM-YYYY format for display)
  530. document.getElementById("filesentdate").value = formattedDateDisplay;
  531. });
  532. function convertDateFormat(dateString) {
  533. if (!dateString) return '';
  534. let [day, month, year] = dateString.split('-');
  535. return `${year}-${month}-${day}`;
  536. }
  537. function saveEntryDetails() {
  538. let selectedPendingDurationValue = $('input[name="pendingDuration"]:checked').val();
  539. let selectedReasonValue = $('#reason').val();
  540. // Check for "Yes" in Pending Duration
  541. if (selectedPendingDurationValue === 'yes') {
  542. selectedReasonPending = $('#Clickyes').val()?.trim() || null;
  543. if (!selectedReasonPending) {
  544. Swal.fire({
  545. icon: 'warning',
  546. title: 'Validation Error',
  547. text: 'Please specify the reason for selecting "Yes" for Pending Duration.',
  548. confirmButtonText: 'OK'
  549. });
  550. return;
  551. }
  552. }
  553. //pendencyCategory:$('#typeofcategory').val(),
  554. let entryDetails = {
  555. empNo: $('#employeeno').val(),
  556. empName: $('#employeename').val(),
  557. deptName: $('#department').val(),
  558. designation: $('#designation').val(),
  559. retirementclass: $('#classes').val(),
  560. typeOfRetirement: $('#retirement').val(),
  561. retirementDate:$('#retirementdate').val(),
  562. pendingDuration: selectedPendingDurationValue,
  563. reasonPending: selectedReasonPending || null,
  564. dateToAudit: convertDateFormat($('#filesentdate').val()?.trim()),
  565. remarks: $('#remarks').val(),
  566. deptId:$('#deptId').text().trim(),
  567. filemovedby:$('#userId').text().trim(),
  568. filecategory:$('#filecategory').text().trim()
  569. };
  570. console.log("entrydetails..",entryDetails);
  571. if (!entryDetails.pendingDuration) {
  572. Swal.fire({
  573. icon: 'warning',
  574. title: 'Validation Error!',
  575. text: 'Pending Duration.',
  576. confirmButtonText: 'OK'
  577. });
  578. return;
  579. }
  580. if (!entryDetails.typeOfRetirement) {
  581. Swal.fire({
  582. icon: 'warning',
  583. title: 'Validation Error!',
  584. text: 'Type of Retirement.',
  585. confirmButtonText: 'OK'
  586. });
  587. return;
  588. }
  589. if (!entryDetails.remarks) {
  590. Swal.fire({
  591. icon: 'warning',
  592. title: 'Validation Error!',
  593. text: 'Remarks are required.',
  594. confirmButtonText: 'OK'
  595. });
  596. return;
  597. }
  598. $('#lfauditButton').prop('disabled', true).text('Processing...');
  599. $.ajax({
  600. url: '/gcc/api/department/newentry/savePendecnyDetails',
  601. type: 'POST',
  602. contentType: 'application/json',
  603. data: JSON.stringify(entryDetails),
  604. success: function (response) {
  605. $('#lfauditButton').prop('disabled', false).text('Mark as sent Audit');
  606. Swal.fire({
  607. icon: 'success',
  608. title: 'Success',
  609. text: response,
  610. allowOutsideClick: false,
  611. allowEscapeKey: false,
  612. allowEnterKey: false,
  613. confirmButtonText: 'OK'
  614. }).then((result) => {
  615. if (result.isConfirmed) {
  616. $('#lfauditButton').prop('disabled', false).text('Mark as sent Audit');
  617. window.location.href = "/gcc/department/newentry/pendency";
  618. console.log("Continue clicked");
  619. }
  620. });
  621. },
  622. error: function (xhr, status, error) {
  623. $('#lfauditButton').prop('disabled', false).text('Mark as sent Audit');
  624. Swal.fire({
  625. icon: 'error',
  626. title: 'Error',
  627. text: 'Failed to save details. Please try again.',
  628. confirmButtonText: 'OK'
  629. });
  630. console.error('Error:', xhr.responseText);
  631. }
  632. });
  633. }
  634. function handleCategoryChange() {
  635. const categoryDropdown = document.getElementById('typeofcategory');
  636. const retirementDetailsContainer = document.getElementById('retirementDetailsContainer');
  637. // Show or hide the retirement details dropdown based on the selection
  638. if (categoryDropdown.value === 'Retirement') {
  639. retirementDetailsContainer.style.display = 'block'; // Show retirement dropdown
  640. } else {
  641. retirementDetailsContainer.style.display = 'none'; // Hide retirement dropdown
  642. }
  643. }
  644. document.querySelectorAll('input[name="pendingDuration"]').forEach(radio => {
  645. radio.addEventListener('change', function () {
  646. const pendingDurationInputContainer = document.getElementById('pendingDurationInputContainer');
  647. if (this.value === 'yes') {
  648. pendingDurationInputContainer.style.display = 'block'; // Show the input field
  649. } else {
  650. pendingDurationInputContainer.style.display = 'none'; // Hide the input field
  651. document.getElementById('pendingDurationInput').value = ''; // Clear the input field
  652. }
  653. });
  654. });
  655. </script>
  656. </body>
  657. </html>