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.

775 lines
34 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr" xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/modules/base/head :: head}">
  4. <meta charset="UTF-8" />
  5. <title>Staff Strength Management</title>
  6. <style>
  7. body {
  8. background-color: #f8f9fa;
  9. }
  10. .header {
  11. font-size: 22px;
  12. font-weight: bold;
  13. margin-bottom: 20px;
  14. }
  15. .table {
  16. border: 1px solid #dee2e6;
  17. }
  18. .table th,
  19. .table td {
  20. border: 1px solid #dee2e6;
  21. padding: 10px;
  22. }
  23. .section-title {
  24. font-size: 18px;
  25. font-weight: bold;
  26. margin-top: 20px;
  27. border-bottom: 2px solid #007bff;
  28. padding-bottom: 5px;
  29. }
  30. .form-group {
  31. margin-top: 15px;
  32. }
  33. .radio-group {
  34. display: flex;
  35. gap: 20px;
  36. margin-top: 10px;
  37. }
  38. /* Optional: styling update button gap */
  39. .btn-gap {
  40. margin-left: 1rem;
  41. }
  42. </style>
  43. <!-- jQuery -->
  44. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  45. <!-- Bootstrap CSS (you may already have it from your fragments) -->
  46. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" />
  47. <!-- Bootstrap JS Bundle -->
  48. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  49. </head>
  50. <body>
  51. <div class="container mt-4">
  52. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  53. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  54. <div class="card p-3">
  55. <div id="staffReadOnlyView" class="container mt-4" style="display: none; "></div>
  56. <!-- Update Button for Staff (if record exists) -->
  57. <div class="text-center mt-3" id="updateStaffContainer" style="display: none;">
  58. <button type="button" class="btn btn-primary" id="updateStaffBtn">Update</button>
  59. </div>
  60. <!-- Container for Editable Staff Form -->
  61. <div id="staffFormContainer">
  62. <form id="staffStrengthForm" novalidate>
  63. <!-- SG Teachers -->
  64. <div class="col-md-12">
  65. <div class="card" style="background-color: lightgrey; padding: 20px;">
  66. <div class="card-header">
  67. <b>1. SG Teachers *</b>
  68. </div>
  69. <div class="row mt-3">
  70. <div class="col-md-3">
  71. <label>No of Regu Teachers</label>
  72. <input type="number" class="form-control" name="sgRegTeacher" id="sgRegTeacher" placeholder="Enter Value" required />
  73. </div>
  74. <div class="col-md-3">
  75. <label>No of Smc Teachers</label>
  76. <input type="number" class="form-control" name="sgTempTeacher" id="sgTempTeacher" placeholder="Enter Value" required />
  77. </div>
  78. <div class="col-md-3">
  79. <label>No of Part-time Teachers</label>
  80. <input type="number" class="form-control" name="sgPtTeacher" id="sgPtTeacher" placeholder="Enter Value" required />
  81. </div>
  82. <div class="col-md-3">
  83. <label>No of NGO Teachers</label>
  84. <input type="number" class="form-control" name="sgNgoTeacher" id="sgNgoTeacher" placeholder="Enter Value" required />
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. <!-- BT Teachers -->
  90. <div class="col-md-12">
  91. <div class="card" style="background-color: aliceblue; padding: 20px; ">
  92. <div class="card-header">
  93. <b>2. BT Teachers *</b>
  94. </div>
  95. <div class="row mt-3">
  96. <div class="col-md-3">
  97. <label>No of Regu Teachers</label>
  98. <input type="number" class="form-control" name="btRegTeacher" id="btRegTeacher" placeholder="Enter Value" required />
  99. </div>
  100. <div class="col-md-3">
  101. <label>No of Smc Teachers</label>
  102. <input type="number" class="form-control" name="btTempTeacher" id="btTempTeacher" placeholder="Enter Value" required />
  103. </div>
  104. <div class="col-md-3">
  105. <label>No of Part-time Teachers</label>
  106. <input type="number" class="form-control" name="btPtTeacher" id="btPtTeacher" placeholder="Enter Value" required />
  107. </div>
  108. <div class="col-md-3">
  109. <label>No of NGO Teachers</label>
  110. <input type="number" class="form-control" name="btNgoTeacher" id="btNgoTeacher" placeholder="Enter Value" required />
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <!-- PG Teachers -->
  116. <div class="col-md-12">
  117. <div class="card" style="background-color: cornsilk; padding: 20px;">
  118. <div class="card-header">
  119. <b>3. PG Teachers *</b>
  120. </div>
  121. <div class="row mt-3">
  122. <div class="col-md-3">
  123. <label>No of Regu Teachers</label>
  124. <input type="number" class="form-control" name="pgRegTeacher" id="pgRegTeacher" placeholder="Enter Value" required />
  125. </div>
  126. <div class="col-md-3">
  127. <label>No of Smc Teachers</label>
  128. <input type="number" class="form-control" name="pgTempTeacher" id="pgTempTeacher" placeholder="Enter Value" required />
  129. </div>
  130. <div class="col-md-3">
  131. <label>No of Part-time Teachers</label>
  132. <input type="number" class="form-control" name="pgPtTeacher" id="pgPtTeacher" placeholder="Enter Value" required />
  133. </div>
  134. <div class="col-md-3">
  135. <label>No of NGO Teachers</label>
  136. <input type="number" class="form-control" name="pgNgoTeacher" id="pgNgoTeacher" placeholder="Enter Value" required />
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. <div class="col-md-12">
  142. <div class="card mt-3" style="background-color: lavender; padding: 20px;">
  143. <div class="card-header">
  144. <b>4. PET Teachers*</b>
  145. </div>
  146. <div class="row mt-3">
  147. <div class="col-md-3">
  148. <label>No of Regu Teachers</label>
  149. <input type="number" class="form-control" name="petRegTeacher" id="petRegTeacher" placeholder="Enter Value" required />
  150. </div>
  151. <div class="col-md-3">
  152. <label>No of Smc Teachers</label>
  153. <input type="number" class="form-control" name="petTempTeacher" id="petTempTeacher" placeholder="Enter Value" required />
  154. </div>
  155. <div class="col-md-3">
  156. <label>No of Grade 1 Teachers</label>
  157. <input type="number" class="form-control" name="petGrade1Teacher" id="petGrade1Teacher" placeholder="Enter Value" required />
  158. </div>
  159. <div class="col-md-3">
  160. <label>No of Grade 2 Teachers</label>
  161. <input type="number" class="form-control" name="petGrade2Teacher" id="petGrade2Teacher" placeholder="Enter Value" required />
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <div class="col-md-12">
  167. <div class="card mt-3" style="background-color: honeydew; padding: 20px; ">
  168. <div class="card-header">
  169. <b>5. kG Teachers*</b>
  170. </div>
  171. <div class="row mt-3">
  172. <div class="col-md-3">
  173. <label>No of Regu Teachers</label>
  174. <input type="number" class="form-control" name="kgRegTeacher" id="kgRegTeacher" placeholder="Enter Value" required />
  175. </div>
  176. <div class="col-md-3">
  177. <label>No of Smc Teachers</label>
  178. <input type="number" class="form-control" name="kgTempTeacher" id="kgTempTeacher" placeholder="Enter Value" required />
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. <!-- Other Details -->
  184. <div class="col-md-12">
  185. <div class="card" style="padding: 20px; background-color: #f8f9fa; margin-top: 10px;">
  186. <div class="card-header">
  187. <b>Other Details *</b>
  188. </div>
  189. <div class="row mt-3">
  190. <!-- <div class="col-md-3">
  191. <label>No of KG Teachers</label>
  192. <input type="number" class="form-control" name="kgTeacher" id="kgTeacher" placeholder="Enter Value" required />
  193. </div>
  194. <div class="col-md-3">
  195. <label>No of PT Teachers</label>
  196. <input type="number" class="form-control" name="petTeacher" id="petTeacher" placeholder="Enter Value" required />
  197. </div>-->
  198. <div class="col-md-3">
  199. <label>Total No of OA</label>
  200. <input type="number" class="form-control" name="totOa" id="totOa" placeholder="Enter Value" required />
  201. </div>
  202. <div class="col-md-3">
  203. <label>KG Ayah</label>
  204. <input type="number" class="form-control" name="kgAyah" id="kgAyah" placeholder="Enter Value" required />
  205. </div>
  206. <div class="col-md-3 mt-3">
  207. <label>Computer Assistance</label>
  208. <input type="number" class="form-control" name="compAss" id="compAss" placeholder="Enter Value" required />
  209. </div>
  210. <div class="col-md-3 mt-3">
  211. <label>Watchman</label>
  212. <input type="number" class="form-control" name="watchmen" id="watchmen" placeholder="Enter Value" required />
  213. </div>
  214. <div class="col-md-3 mt-3">
  215. <label>Scavengers</label>
  216. <input type="number" class="form-control" name="scavengers" id="scavengers" placeholder="Enter Value" required />
  217. </div>
  218. <div class="col-md-3 mt-3">
  219. <label>Sweeper</label>
  220. <input type="number" class="form-control" name="maintenanceWork" id="maintenanceWork" placeholder="Enter Value" required />
  221. </div>
  222. </div>
  223. <div class="card-footer text-center mt-3">
  224. <button type="submit" class="btn btn-primary" id="requestSubmitBtn">
  225. <i class="ik ik-save"></i> Submit
  226. </button>
  227. <button type="reset" class="btn btn-secondary ml-2" id="resetButton">
  228. <i class="ik ik-refresh-cw"></i> Reset
  229. </button>
  230. </div>
  231. </div>
  232. </div>
  233. </form>
  234. </div>
  235. <!-- End of Staff Form -->
  236. <!-- Page Loader -->
  237. <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;">
  238. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  239. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  240. <span class="sr-only">Loading...</span>
  241. </div>
  242. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  243. </div>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. <!-- Staff Update Modal -->
  250. <div class="modal fade" id="staffUpdateModal" tabindex="-1">
  251. <div class="modal-dialog modal-xl">
  252. <div class="modal-content">
  253. <div class="modal-header">
  254. <h5 class="modal-title">Update Staff Strength</h5>
  255. <button type="button" class="close" data-bs-dismiss="modal"
  256. aria-label="Close"><span aria-hidden="true">&times;</span></button>
  257. </div>
  258. <div class="modal-body">
  259. <div class="row g-3">
  260. <!-- SG Section -->
  261. <div class="col-md-3"><label>SG - Regu Teachers *</label><input type="number" id="modal_sgRegTeacher" class="form-control" /></div>
  262. <div class="col-md-3"><label>SG - Smc Teachers *</label><input type="number" id="modal_sgTempTeacher" class="form-control" /></div>
  263. <div class="col-md-3"><label>SG - Part-time Teachers *</label><input type="number" id="modal_sgPtTeacher" class="form-control" /></div>
  264. <div class="col-md-3"><label>SG - NGO Teachers *</label><input type="number" id="modal_sgNgoTeacher" class="form-control" /></div>
  265. <!-- BT Section -->
  266. <div class="col-md-3"><label>BT - Regu Teachers *</label><input type="number" id="modal_btRegTeacher" class="form-control" /></div>
  267. <div class="col-md-3"><label>BT - Smc Teachers *</label><input type="number" id="modal_btTempTeacher" class="form-control" /></div>
  268. <div class="col-md-3"><label>BT - Part-time Teachers *</label><input type="number" id="modal_btPtTeacher" class="form-control" /></div>
  269. <div class="col-md-3"><label>BT - NGO Teachers *</label><input type="number" id="modal_btNgoTeacher" class="form-control" /></div>
  270. <!-- PG Section -->
  271. <div class="col-md-3"><label>PG - Regu Teachers *</label><input type="number" id="modal_pgRegTeacher" class="form-control" /></div>
  272. <div class="col-md-3"><label>PG - Smc Teachers *</label><input type="number" id="modal_pgTempTeacher" class="form-control" /></div>
  273. <div class="col-md-3"><label>PG - Part-time Teachers *</label><input type="number" id="modal_pgPtTeacher" class="form-control" /></div>
  274. <div class="col-md-3"><label>PG - NGO Teachers *</label><input type="number" id="modal_pgNgoTeacher" class="form-control" /></div>
  275. <!-- PET Section -->
  276. <div class="col-md-3"><label>PET - Regu Teachers *</label><input type="number" id="modal_petRegTeacher" class="form-control" /></div>
  277. <div class="col-md-3"><label>PET - Smc Teachers *</label><input type="number" id="modal_petTempTeacher" class="form-control" /></div>
  278. <div class="col-md-3"><label>PET - Grade 1 Teachers *</label><input type="number" id="modal_petg1Teacher" class="form-control" /></div>
  279. <div class="col-md-3"><label>PET - Grade 2 Teachers *</label><input type="number" id="modal_petg2Teacher" class="form-control" /></div>
  280. <!-- kg Section -->
  281. <div class="col-md-3"><label>KG - Regu Teachers *</label><input type="number" id="modal_kgRegTeacher" class="form-control" /></div>
  282. <div class="col-md-3"><label>KG - Smc Teachers *</label><input type="number" id="modal_kgTempTeacher" class="form-control" /></div>
  283. <!-- Other Section -->
  284. <!-- <div class="col-md-3"><label>KG Teachers *</label><input id="modal_kgTeacher" class="form-control" /></div>
  285. <div class="col-md-3"><label>PT Teachers *</label><input id="modal_petTeacher" class="form-control" /></div>-->
  286. <div class="col-md-3"><label>Total OA *</label><input type="number" id="modal_totOa" class="form-control" /></div>
  287. <div class="col-md-3"><label>KG Ayah *</label><input type="number" id="modal_kgAyah" class="form-control" /></div>
  288. <div class="col-md-3"><label>Computer Assistance *</label><input type="number" id="modal_compAss" class="form-control" /></div>
  289. <div class="col-md-3"><label>Watchmen *</label><input type="number" id="modal_watchmen" class="form-control" /></div>
  290. <div class="col-md-3"><label>Scavengers *</label><input type="number" id="modal_scavengers" class="form-control" /></div>
  291. <div class="col-md-3"><label>Sweeper *</label><input type="number" id="modal_maintenanceWork" class="form-control" /></div>
  292. </div>
  293. </div>
  294. <div class="modal-footer">
  295. <button class="btn btn-primary" id="saveStaffModalUpdate">Save Changes</button>
  296. </div>
  297. </div>
  298. </div>
  299. </div>
  300. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  301. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  302. <!-- Scripts -->
  303. <script>
  304. $(document).ready(function () {
  305. const urlParams = new URLSearchParams(window.location.search);
  306. const schoolId = urlParams.get("schoolId");
  307. // Allow only whole positive numbers in number fields
  308. document.querySelectorAll('input[type="number"]').forEach(function (input) {
  309. input.addEventListener("input", function () {
  310. this.value = this.value.replace(/[^0-9]/g, "");
  311. if (parseInt(this.value) < 0) {
  312. this.value = "";
  313. }
  314. });
  315. });
  316. // Fetch staff data against schoolId
  317. $.ajax({
  318. url: '/gcc/api/gccschool/buildingasset/getStaffStrengthBySchoolId',
  319. type: 'GET',
  320. data: { schoolId },
  321. success: function (response) {
  322. console.log(response);
  323. if (response.status === 'OK' && response.staffStrength.length > 0) {
  324. const data = response.staffStrength[0];
  325. // Build a read-only table with fetched staff data
  326. const tableHtml = `
  327. <h6 class="text-left mb-3"><b>Staff Strength Details</b></h6>
  328. <hr>
  329. <!-- SG Teachers -->
  330. <h6><b>1. SG Teachers *</b></h6>
  331. <table class="table">
  332. <tbody>
  333. <tr><td>No of Regu Teachers</td><td>${data.sg_reg_teacher || 0}</td></tr>
  334. <tr><td>No of Smc Teachers</td><td>${data.sg_temp_teacher || 0}</td></tr>
  335. <tr><td>No of Part-time Teachers</td><td>${data.sg_pt_teacher || 0}</td></tr>
  336. <tr><td>No of NGO Teachers</td><td>${data.sg_ngo_teacher || 0}</td></tr>
  337. </tbody>
  338. </table>
  339. <!-- BT Teachers -->
  340. <h6><b>2. BT Teachers *</b></h6>
  341. <table class="table">
  342. <tbody>
  343. <tr><td>No of Regu Teachers</td><td>${data.bt_reg_teacher || 0}</td></tr>
  344. <tr><td>No of Smc Teachers</td><td>${data.bt_temp_teacher || 0}</td></tr>
  345. <tr><td>No of Part-time Teachers</td><td>${data.bt_pt_teacher || 0}</td></tr>
  346. <tr><td>No of NGO Teachers</td><td>${data.bt_ngo_teacher || 0}</td></tr>
  347. </tbody>
  348. </table>
  349. <!-- PG Teachers -->
  350. <h6><b>3. PG Teachers *</b></h6>
  351. <table class="table">
  352. <tbody>
  353. <tr><td>No of Regu Teachers</td><td>${data.pg_reg_teacher || 0}</td></tr>
  354. <tr><td>No of Smc Teachers</td><td>${data.pg_temp_teacher || 0}</td></tr>
  355. <tr><td>No of Part-time Teachers</td><td>${data.pg_pt_teacher || 0}</td></tr>
  356. <tr><td>No of NGO Teachers</td><td>${data.pg_ngo_teacher || 0}</td></tr>
  357. </tbody>
  358. </table>
  359. <!-- PG Teachers -->
  360. <h6><b>4. PET Teachers *</b></h6>
  361. <table class="table">
  362. <tbody>
  363. <tr><td>No of Regu Teachers</td><td>${data.pet_reg_teacher || 0}</td></tr>
  364. <tr><td>No of Smc Teachers</td><td>${data.pet_temp_teacher || 0}</td></tr>
  365. <tr><td>No of Grade 1 Teachers</td><td>${data.pet_grade1_teacher || 0}</td></tr>
  366. <tr><td>No of Grade 2 Teachers</td><td>${data.pet_grade2_teacher || 0}</td></tr>
  367. </tbody>
  368. </table>
  369. <!-- PG Teachers -->
  370. <h6><b>5. kG Teachers *</b></h6>
  371. <table class="table">
  372. <tbody>
  373. <tr><td>No of Regu Teachers</td><td>${data.kg_reg_teacher || 0}</td></tr>
  374. <tr><td>No of Smc Teachers</td><td>${data.kg_temp_teacher || 0}</td></tr>
  375. </tbody>
  376. </table>
  377. <!-- Other Details -->
  378. <h6><b>6. Other Details *</b></h6>
  379. <table class="table">
  380. <tbody>
  381. <tr><td>Total OA</td><td>${data.tot_oa || 0}</td></tr>
  382. <tr><td>KG Ayah</td><td>${data.kg_ayah || 0}</td></tr>
  383. <tr><td>Computer Assistance</td><td>${data.comp_ass || 0}</td></tr>
  384. <tr><td>Watchmen</td><td>${data.watchmen || 0}</td></tr>
  385. <tr><td>Scavengers</td><td>${data.scavengers || 0}</td></tr>
  386. <tr><td>Sweeper</td><td>${data.maintenance_work || 0}</td></tr>
  387. </tbody>
  388. </table>
  389. `;
  390. // Populate read-only view and hide staff form
  391. $('#staffReadOnlyView').html(tableHtml).show();
  392. $('#staffFormContainer').hide();
  393. $('#updateStaffContainer').show();
  394. // Bind Update button click event to open the modal with prefilled values
  395. $('#updateStaffBtn').click(() => {
  396. $('#modal_sgRegTeacher').val(data.sg_reg_teacher);
  397. $('#modal_sgTempTeacher').val(data.sg_temp_teacher);
  398. $('#modal_sgPtTeacher').val(data.sg_pt_teacher);
  399. $('#modal_sgNgoTeacher').val(data.sg_ngo_teacher);
  400. $('#modal_btRegTeacher').val(data.bt_reg_teacher);
  401. $('#modal_btTempTeacher').val(data.bt_temp_teacher);
  402. $('#modal_btPtTeacher').val(data.bt_pt_teacher);
  403. $('#modal_btNgoTeacher').val(data.bt_ngo_teacher);
  404. $('#modal_pgRegTeacher').val(data.pg_reg_teacher);
  405. $('#modal_pgTempTeacher').val(data.pg_temp_teacher);
  406. $('#modal_pgPtTeacher').val(data.pg_pt_teacher);
  407. $('#modal_pgNgoTeacher').val(data.pg_ngo_teacher);
  408. $('#modal_petRegTeacher').val(data.pet_reg_teacher);
  409. $('#modal_petTempTeacher').val(data.pet_temp_teacher);
  410. $('#modal_petg1Teacher').val(data.pet_grade1_teacher);
  411. $('#modal_petg2Teacher').val(data.pet_grade2_teacher);
  412. $('#modal_kgRegTeacher').val(data.kg_reg_teacher);
  413. $('#modal_kgTempTeacher').val(data.kg_temp_teacher);
  414. $('#modal_totOa').val(data.tot_oa);
  415. $('#modal_kgAyah').val(data.kg_ayah);
  416. $('#modal_compAss').val(data.comp_ass);
  417. $('#modal_watchmen').val(data.watchmen);
  418. $('#modal_scavengers').val(data.scavengers);
  419. $('#modal_maintenanceWork').val(data.maintenance_work);
  420. $('#staffUpdateModal').modal('show');
  421. });
  422. } else {
  423. // No staff data found – show form for entry
  424. $('#staffReadOnlyView').hide();
  425. $('#staffFormContainer').show();
  426. $('#updateStaffContainer').hide();
  427. }
  428. }
  429. });
  430. // Staff Form submission event
  431. $("#staffStrengthForm").submit(function (event) {
  432. event.preventDefault();
  433. console.log("Submit button clicked for Staff");
  434. console.log("SchoolId:", schoolId);
  435. // Validation: Check required fields
  436. /* const requiredFields = {
  437. 'sgRegTeacher': 'SG - Regular Teachers',
  438. 'sgTempTeacher': 'SG - Temp Teachers',
  439. 'sgPtTeacher': 'SG - Part-time Teachers',
  440. 'sgNgoTeacher': 'SG - NGO Teachers',
  441. 'btRegTeacher': 'BT - Regular Teachers',
  442. 'btTempTeacher': 'BT - Temp Teachers',
  443. 'btPtTeacher': 'BT - Part-time Teachers',
  444. 'btNgoTeacher': 'BT - NGO Teachers',
  445. 'pgRegTeacher': 'PG - Regular Teachers',
  446. 'pgTempTeacher': 'PG - Temp Teachers',
  447. 'pgPtTeacher': 'PG - Part-time Teachers',
  448. 'pgNgoTeacher': 'PG - NGO Teachers',
  449. 'kgTeacher': 'KG Teachers',
  450. 'petTeacher': 'PT Teachers',
  451. 'totOa': 'Total OA',
  452. 'kgAyah': 'KG Ayah',
  453. 'compAss': 'Computer Assistance',
  454. 'watchmen': 'Watchman',
  455. 'scavengers': 'Scavengers',
  456. 'maintenanceWork': 'Maintenance Works'
  457. };*/
  458. const requiredFields = {
  459. sgRegTeacher: 'SG - Regular Teachers',
  460. sgTempTeacher: 'SG - Smc Teachers',
  461. sgPtTeacher: 'SG - Part-time Teachers',
  462. sgNgoTeacher: 'SG - NGO Teachers',
  463. btRegTeacher: 'BT - Regular Teachers',
  464. btTempTeacher: 'BT - Smc Teachers',
  465. btPtTeacher: 'BT - Part-time Teachers',
  466. btNgoTeacher: 'BT - NGO Teachers',
  467. pgRegTeacher: 'PG - Regular Teachers',
  468. pgTempTeacher: 'PG - Smc Teachers',
  469. pgPtTeacher: 'PG - Part-time Teachers',
  470. pgNgoTeacher: 'PG - NGO Teachers',
  471. petRegTeacher: 'PET - Regular Teachers',
  472. petTempTeacher: 'PET - Smc Teachers',
  473. petGrade1Teacher: 'PET - Grade 1 Teachers',
  474. petGrade2Teacher: 'PET - Grade 2 Teachers',
  475. kgRegTeacher: 'KG - Regular Teachers',
  476. kgTempTeacher: 'KG - Smc Teachers',
  477. totOa: 'Total OA',
  478. kgAyah: 'KG Ayah',
  479. compAss: 'Computer Assistance',
  480. watchmen: 'Watchman',
  481. scavengers: 'Scavengers',
  482. maintenanceWork: 'Sweeper'
  483. };
  484. for (let fieldId in requiredFields) {
  485. const value = $(`#${fieldId}`).val();
  486. if (value === null || value.trim() === "" || isNaN(Number(value)) || parseInt(value) < 0) {
  487. Swal.fire({
  488. icon: 'warning',
  489. title: 'Missing or Invalid Input',
  490. text: `Please enter a valid number for "${requiredFields[fieldId]}"`,
  491. allowOutsideClick: false,
  492. allowEscapeKey: false,
  493. allowEnterKey: false,
  494. showConfirmButton: true
  495. });
  496. return;
  497. }
  498. }
  499. // Show loader before submitting
  500. $('#pageLoader').show();
  501. // Prepare form data
  502. var formData = new FormData(document.getElementById("staffStrengthForm"));
  503. formData.append("schoolId", schoolId);
  504. // Debug log (optional)
  505. const debugObj = {};
  506. formData.forEach((value, key) => {
  507. debugObj[key] = value;
  508. });
  509. console.log("Form Data Collected:", debugObj);
  510. // Submit via AJAX
  511. $.ajax({
  512. type: "POST",
  513. url: "/gcc/api/gccschool/schoolproperty/saveStaffStrength",
  514. data: formData,
  515. processData: false,
  516. contentType: false,
  517. success: function (response) {
  518. $("#pageLoader").hide();
  519. console.log("Data Submitted Successfully:", response);
  520. Swal.fire({
  521. icon: "success",
  522. title: "Data Saved!",
  523. text: "Staff strength details saved successfully!",
  524. confirmButtonColor: "#3085d6",
  525. allowOutsideClick: false,
  526. allowEscapeKey: false,
  527. allowEnterKey: false,
  528. showConfirmButton: true
  529. }).then(() => {
  530. $("#staffStrengthForm")[0].reset();
  531. // Optionally, reload page to refresh view
  532. location.reload();
  533. });
  534. },
  535. error: function (xhr, status, error) {
  536. $("#pageLoader").hide();
  537. console.error("Submission Error:", xhr.responseText);
  538. Swal.fire({
  539. icon: "error",
  540. title: "Error!",
  541. text: "Something went wrong. Please try again.",
  542. allowOutsideClick: false,
  543. allowEscapeKey: false,
  544. allowEnterKey: false,
  545. confirmButtonColor: "#d33"
  546. });
  547. }
  548. });
  549. });
  550. function resetStaffFields() {
  551. console.log("Reset button clicked");
  552. $('#staffStrengthForm input[type="number"]').val('');
  553. }
  554. $(document).on('click', '#resetButton', function (event) {
  555. event.preventDefault();
  556. resetStaffFields();
  557. });
  558. // Reset Button click event
  559. /* $("#resetButton").click(function () {
  560. Swal.fire({
  561. title: "Are you sure?",
  562. text: "This will reset all form fields!",
  563. icon: "warning",
  564. showCancelButton: true,
  565. confirmButtonColor: "#3085d6",
  566. cancelButtonColor: "#d33",
  567. confirmButtonText: "Yes, reset!"
  568. }).then((result) => {
  569. if (result.isConfirmed) {
  570. $("input[type='number']").val("");
  571. Swal.fire("Reset!", "Form has been cleared.", "success");
  572. }
  573. });
  574. });*/
  575. // Handle Save from Staff Update Modal
  576. $("#saveStaffModalUpdate").on('click', function () {
  577. const modalRequiredFields = {
  578. modal_sgRegTeacher: 'SG - Regular Teachers',
  579. modal_sgTempTeacher: 'SG - Smc Teachers',
  580. modal_sgPtTeacher: 'SG - Part-time Teachers',
  581. modal_sgNgoTeacher: 'SG - NGO Teachers',
  582. modal_btRegTeacher: 'BT - Regular Teachers',
  583. modal_btTempTeacher: 'BT - Smc Teachers',
  584. modal_btPtTeacher: 'BT - Part-time Teachers',
  585. modal_btNgoTeacher: 'BT - NGO Teachers',
  586. modal_pgRegTeacher: 'PG - Regular Teachers',
  587. modal_pgTempTeacher: 'PG - Smc Teachers',
  588. modal_pgPtTeacher: 'PG - Part-time Teachers',
  589. modal_pgNgoTeacher: 'PG - NGO Teachers',
  590. modal_petRegTeacher: 'PET - Regular Teachers',
  591. modal_petTempTeacher: 'PET - Smc Teachers',
  592. modal_petg1Teacher: 'PET - Grade 1 Teachers',
  593. modal_petg2Teacher: 'PET - Grade 2 Teachers',
  594. modal_kgRegTeacher: 'KG - Regular Teachers',
  595. modal_kgTempTeacher: 'KG - Smc Teachers',
  596. modal_totOa: 'Total OA',
  597. modal_kgAyah: 'KG Ayah',
  598. modal_compAss: 'Computer Assistance',
  599. modal_watchmen: 'Watchmen',
  600. modal_scavengers: 'Scavengers',
  601. modal_maintenanceWork: 'Sweeper'
  602. };
  603. for (let fieldId in modalRequiredFields) {
  604. const value = $(`#${fieldId}`).val();
  605. if (value === null || value.trim() === "" || isNaN(Number(value)) || parseInt(value) < 0) {
  606. Swal.fire({
  607. icon: 'warning',
  608. title: 'Missing or Invalid Input',
  609. text: `Please enter a valid number for "${modalRequiredFields[fieldId]}"`,
  610. allowOutsideClick: false,
  611. allowEscapeKey: false,
  612. allowEnterKey: false,
  613. showConfirmButton: true
  614. });
  615. return false; // Prevent further execution if validation fails
  616. }
  617. }
  618. const updatedData = {
  619. sgRegTeacher: $('#modal_sgRegTeacher').val(),
  620. sgTempTeacher: $('#modal_sgTempTeacher').val(),
  621. sgPtTeacher: $('#modal_sgPtTeacher').val(),
  622. sgNgoTeacher: $('#modal_sgNgoTeacher').val(),
  623. btRegTeacher: $('#modal_btRegTeacher').val(),
  624. btTempTeacher: $('#modal_btTempTeacher').val(),
  625. btPtTeacher: $('#modal_btPtTeacher').val(),
  626. btNgoTeacher: $('#modal_btNgoTeacher').val(),
  627. pgRegTeacher: $('#modal_pgRegTeacher').val(),
  628. pgTempTeacher: $('#modal_pgTempTeacher').val(),
  629. pgPtTeacher: $('#modal_pgPtTeacher').val(),
  630. pgNgoTeacher: $('#modal_pgNgoTeacher').val(),
  631. petRegTeacher: $('#modal_petRegTeacher').val(),
  632. petTempTeacher: $('#modal_petTempTeacher').val(),
  633. petGrade1Teacher: $('#modal_petg1Teacher').val(),
  634. petGrade2Teacher: $('#modal_petg2Teacher').val(),
  635. kgRegTeacher: $('#modal_kgRegTeacher').val(),
  636. kgTempTeacher: $('#modal_kgTempTeacher').val(),
  637. totOa: $('#modal_totOa').val(),
  638. kgAyah: $('#modal_kgAyah').val(),
  639. compAss: $('#modal_compAss').val(),
  640. watchmen: $('#modal_watchmen').val(),
  641. scavengers: $('#modal_scavengers').val(),
  642. maintenanceWork: $('#modal_maintenanceWork').val(),
  643. school_id: schoolId // IMPORTANT: use same name as @RequestParam
  644. };
  645. $('#pageLoader').show();
  646. $.ajax({
  647. url: '/gcc/api/gccschool/schoolproperty/updateStaffDetails',
  648. type: 'POST',
  649. contentType: 'application/x-www-form-urlencoded',
  650. data: $.param(updatedData),
  651. success: function (res) {
  652. $('#pageLoader').hide();
  653. $('#staffUpdateModal').modal('hide');
  654. // Swal.fire('Updated!', res, 'success').then(() => location.reload());
  655. Swal.fire({
  656. title: 'Updated!',
  657. text: 'Staff strength details updated successfully!',
  658. icon: 'success',
  659. allowOutsideClick: false,
  660. allowEscapeKey: false,
  661. allowEnterKey: false,
  662. showConfirmButton: true
  663. }).then(() => location.reload());
  664. },
  665. error: function (err) {
  666. $('#pageLoader').hide();
  667. Swal.fire({
  668. title: 'Error',
  669. text: err.responseText,
  670. icon: 'error',
  671. allowOutsideClick: false,
  672. allowEscapeKey: false,
  673. allowEnterKey: false,
  674. showConfirmButton: true
  675. });
  676. //Swal.fire('Error', err.responseText, 'error');
  677. }
  678. });
  679. });
  680. });
  681. </script>
  682. </body>
  683. </html>