This portal only for GCC Officers. Based on there roles and Group ID they can view there module`s Like PGR, QR Public Asset Feedback, Makkalai Thedi Mayor,etc...
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.

1573 lines
64 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <html xmlns:th="http://www.thymeleaf.org">
  4. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  5. <style>
  6. #RoomAssetViewModal .modal-body {
  7. max-height: 500px;
  8. overflow-y: auto;
  9. }
  10. #RoomAssetEditModal .modal-body {
  11. max-height: 500px;
  12. overflow-y: auto;
  13. }
  14. #AddAssetModal .modal-body {
  15. max-height: 500px;
  16. overflow-y: auto;
  17. }
  18. </style>
  19. <body>
  20. <div class="wrapper">
  21. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  22. <div class="page-wrap">
  23. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  24. <div class="card">
  25. <div class="main-content" style="background-color: white;">
  26. <div class="container">
  27. <!-- Card 2: Other Details -->
  28. <div class="col-md-12">
  29. <div style="margin-top:-58px;margin-left: -233px;">
  30. <div class="card-header"><b>Room List</b></div>
  31. <div class="card-body">
  32. <table id="RoomAssetDatatable"
  33. class="table table-striped table-bordered table-hover dataTable" role="grid"
  34. style="width: 100%">
  35. <thead class="thead-dark">
  36. <tr>
  37. <th>S.NO</th>
  38. <th>Room Name</th>
  39. <th>Building Name</th>
  40. <th>Floor</th>
  41. <th>Room Type</th>
  42. <th>Action</th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. </tbody>
  47. </table>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. <div id="pageLoader"
  53. 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;">
  54. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  55. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  56. <span class="sr-only">Loading...</span>
  57. </div>
  58. <!-- Add the 'Please wait' text below the spinner -->
  59. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- Modal -->
  67. <div class="modal fade" id="RoomAssetViewModal" tabindex="-1" role="dialog" aria-labelledby="RoomAssetViewLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  68. <div class="modal-dialog modal-lg" role="document">
  69. <div class="modal-content">
  70. <div class="modal-header">
  71. <h5 class="modal-title">
  72. <span id="roomTitleView"></span> - Room Assets
  73. </h5>
  74. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  75. <span aria-hidden="true">&times;</span>
  76. </button>
  77. </div>
  78. <div class="modal-body">
  79. <span id="VroomId" style="display: none;"></span>
  80. <div class="row pb-2">
  81. <div class="col-md-6"><strong>Room Name:</strong><span id="roomNameView"></span></div>
  82. <div class="col-md-6"><strong>Room Type:</strong><span id="roomTypeView"></span></div>
  83. </div>
  84. <div class="row pb-2">
  85. <div class="col-md-6"><strong>Building Name:</strong><span id="buildingNameView"></span></div>
  86. <div class="col-md-6"><strong>Floor:</strong><span id="floorView"></span></div>
  87. </div>
  88. <!-- Tabs navigation -->
  89. <ul class="nav nav-tabs mt-3" id="assetTabs" role="tablist">
  90. <li class="nav-item">
  91. <a class="nav-link active" id="view-itasset-tab" data-bs-toggle="tab" href="#view-itasset" role="tab">IT Assets</a>
  92. </li>
  93. <li class="nav-item">
  94. <a class="nav-link" id="view-furniture-tab" data-bs-toggle="tab" href="#view-furniture" role="tab">Furniture Assets</a>
  95. </li>
  96. <li class="nav-item">
  97. <a class="nav-link" id="view-electrical-tab" data-bs-toggle="tab" href="#view-electrical" role="tab">Electrical Assets</a>
  98. </li>
  99. </ul>
  100. <div class="tab-content p-3 border border-top-0" id="assetTabsContent">
  101. <div class="tab-pane fade show active" id="view-itasset" role="tabpanel" aria-labelledby="view-itasset-tab">
  102. <div id="viewItAssetContainer">Loading IT Assets...</div>
  103. </div>
  104. <div class="tab-pane fade" id="view-furniture" role="tabpanel" aria-labelledby="view-furniture-tab">
  105. <div id="viewFurnitureAssetContainer">Loading Furniture Assets...</div>
  106. </div>
  107. <div class="tab-pane fade" id="view-electrical" role="tabpanel" aria-labelledby="view-electrical-tab">
  108. <div id="viewElectricalAssetContainer">Loading Electrical Assets...</div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="modal-footer">
  113. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. <div class="modal fade" id="RoomAssetEditModal" tabindex="-1" role="dialog" aria-labelledby="RoomAssetEditLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  119. <div class="modal-dialog modal-lg" role="document">
  120. <div class="modal-content">
  121. <div class="modal-header">
  122. <h5 class="modal-title">
  123. <span id="roomTitleEdit"></span> - Edit Room Assets
  124. </h5>
  125. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  126. <span aria-hidden="true">&times;</span>
  127. </button>
  128. </div>
  129. <div class="modal-body">
  130. <span id="Eschool_id" style="display: none;"></span>
  131. <span id="Ebuilding_id" style="display: none;"></span>
  132. <span id="Efloors_id" style="display: none;"></span>
  133. <span id="EroomId" style="display: none;"></span>
  134. <div class="row pb-2">
  135. <div class="col-md-6"><strong>Room Name:</strong><span id="roomNameEdit"></span></div>
  136. <div class="col-md-6"><strong>Room Type:</strong><span id="roomTypeEdit"></span></div>
  137. </div>
  138. <div class="row pb-2">
  139. <div class="col-md-6"><strong>Building Name:</strong><span id="buildingNameEdit"></span></div>
  140. <div class="col-md-6"><strong>Floor:</strong><span id="floorEdit"></span></div>
  141. </div>
  142. <!-- Tabs navigation -->
  143. <ul class="nav nav-tabs mt-3" id="assetTabsEdit" role="tablist">
  144. <li class="nav-item" role="presentation">
  145. <a class="nav-link active" id="edit-itasset-tab" data-bs-toggle="tab" href="#edit-itasset" role="tab">IT Assets</a>
  146. </li>
  147. <li class="nav-item" role="presentation">
  148. <a class="nav-link" id="edit-furniture-tab" data-bs-toggle="tab" href="#edit-furniture" role="tab">Furniture Assets</a>
  149. </li>
  150. <li class="nav-item" role="presentation">
  151. <a class="nav-link" id="edit-electrical-tab" data-bs-toggle="tab" href="#edit-electrical" role="tab">Electrical Assets</a>
  152. </li>
  153. </ul>
  154. <!-- Tabs content -->
  155. <div class="tab-content p-3 border border-top-0" id="assetTabsContentEdit">
  156. <div class="tab-pane fade show active" id="edit-itasset" role="tabpanel" aria-labelledby="edit-itasset-tab">
  157. <div class="col-md-12" id="editItAssetContainer"></div>
  158. </div>
  159. <div class="tab-pane fade " id="edit-furniture" role="tabpanel" aria-labelledby="edit-furniture-tab">
  160. <div class="col-md-12" id="editFurnitureAssetContainer"></div>
  161. </div>
  162. <div class="tab-pane fade" id="edit-electrical" role="tabpanel" aria-labelledby="edit-electrical-tab">
  163. <div class="col-md-12" id="editElectricalAssetContainer"></div>
  164. </div>
  165. </div>
  166. <div class="row pb-2 mt-4">
  167. <div class="col-12 d-flex justify-content-center">
  168. <button type="button" class="btn btn-primary" id="addAssetMapping">Add Asset Mapping</button>
  169. </div>
  170. </div>
  171. </div>
  172. <div class="modal-footer">
  173. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. <div class="modal fade" id="AddAssetModal" tabindex="-1" role="dialog" aria-labelledby="AddAssetModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  179. <div class="modal-dialog modal-lg" role="document">
  180. <div class="modal-content">
  181. <div class="modal-header">
  182. <h5 class="modal-title">
  183. <span id="roomTitleAdd"></span> Room - Add Assets Mapping
  184. </h5>
  185. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  186. <span aria-hidden="true">&times;</span>
  187. </button>
  188. </div>
  189. <div class="modal-body">
  190. <span id="Sschool_id" style="display: none;"></span>
  191. <span id="Sbuilding_id" style="display: none;"></span>
  192. <span id="Sfloors_id" style="display: none;"></span>
  193. <span id="SroomId" style="display: none;"></span>
  194. <div class="row">
  195. <div class="form-group col-6">
  196. <label for="assetType">Asset Type</label>
  197. <select id="assetType" class="form-control">
  198. <option value="">Select Asset Type</option>
  199. </select>
  200. </div>
  201. <div class="form-group col-6" style="display: none;" id="subAssetTypeContainer">
  202. <label for="subAssetType">Sub Asset Type</label>
  203. <select id="subAssetType" class="form-control">
  204. <option value="">Select Sub Asset Type</option>
  205. </select>
  206. </div>
  207. </div>
  208. <div class="row">
  209. <div class="col-12">
  210. <div id="AddingAssetContainer1" style="display: none;">
  211. </div>
  212. <div id="AddingAssetContainer2" style="display: none;">
  213. </div>
  214. </div>
  215. </div>
  216. <div class="row pb-2 mt-4" style="display: none;" id="savingAssetContainer1">
  217. <div class="col-12 d-flex justify-content-center">
  218. <button type="button" class="btn btn-primary" id="savingItAssetButton">Save</button>
  219. </div>
  220. </div>
  221. <div class="row pb-2 mt-4" style="display: none;" id="savingAssetContainer2">
  222. <div class="col-12 d-flex justify-content-center">
  223. <button type="button" class="btn btn-primary" id="savingotherAssetButton">Save</button>
  224. </div>
  225. </div>
  226. </div>
  227. <div class="modal-footer">
  228. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  229. </div>
  230. </div>
  231. </div>
  232. </div>
  233. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  234. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  235. <script type="text/javascript">
  236. console.log("hi..Room asset");
  237. $(document).ready(function () {
  238. // Extract schoolId from URL
  239. let RoomAsseturlParams = new URLSearchParams(window.location.search);
  240. let RoomAssetschoolId = RoomAsseturlParams.get("schoolId");
  241. //let globalRoomId = null;
  242. let currentAssetTypeEdit = ''; // stores 'furnitureasset' or 'electricalasset'
  243. let currentTargetContainerEdit = ''; // stores container ID
  244. loadSavedBuildingRm(RoomAssetschoolId);
  245. /* $(document).off('click', '.view-btn').on('click', '.view-btn', handleView);
  246. $(document).off('click', '.edit-btn').on('click', '.edit-btn', handleEdit);
  247. $(document).off('click', '.del-btn').on('click', '.del-btn', handleDelete);
  248. $(document).off('click', '#addAssetMapping').on('click', '#addAssetMapping', addAssetMapping); */
  249. if (!window.assetMappingEventsBound) {
  250. $(document).on('click', '.view-btn', handleView);
  251. $(document).on('click', '.edit-btn', handleEdit);
  252. $(document).on('click', '.del-btn', handleDelete);
  253. $(document).on('click', '#addAssetMapping', addAssetMapping);
  254. $(document).on('click', '#savingItAssetButton', saveItAsset);
  255. $(document).on('click', '#savingotherAssetButton', saveOtherAsset);
  256. $(document).on('change', '#assetType', function () {
  257. const isassetTypeText = $('#assetType option:selected').text().trim();
  258. if(isassetTypeText==='Select Asset Type'){
  259. $('#AddingAssetContainer1').show().html('');
  260. $('#AddingAssetContainer2').show().html('');
  261. $('#subAssetTypeContainer').hide();
  262. return;
  263. }
  264. $('#subAssetTypeContainer').show();
  265. const assetId = $(this).val();
  266. $('#subAssetType').empty().append('<option value="">Select Sub Asset Type</option>');
  267. if (assetId) {
  268. $.ajax({
  269. url: '/gcc/api/gccschool/dropdown/getSubAssetType',
  270. type: 'GET',
  271. data: { assetid: assetId },
  272. success: function (response) {
  273. if (response.status === 'OK') {
  274. response.data.forEach(item => {
  275. $('#subAssetType').append(`<option value="${item.sub_asset_id}">${item.asset_name}</option>`);
  276. });
  277. if (response.status === 'Failed') {
  278. $('#subAssetType').empty().append('<option value="">No Data Found</option>');
  279. }
  280. }
  281. },
  282. error: function (xhr, status, error) {
  283. console.error("Error fetching sub asset types:", status, error);
  284. $('#subAssetType').empty().append('<option value="">Error loading data</option>');
  285. alert("Something went wrong while fetching sub asset types.");
  286. }
  287. });
  288. }
  289. });
  290. $(document).on('change', '#subAssetType', function () {
  291. const selectedOption = $(this).find('option:selected');
  292. const assetName = selectedOption.text().trim(); // Get the text (name)
  293. const subAssetId = $(this).val(); // In case you need ID too
  294. console.log("assetName="+assetName);
  295. // Get school ID from the span
  296. const schoolId = $('#Eschool_id').text().trim();
  297. console.log("schoolId="+schoolId);
  298. const assetTypeText = $('#assetType option:selected').text().trim();
  299. console.log("assetTypeText="+assetTypeText);
  300. if(assetTypeText==='Select Asset Type'|| subAssetId ==''){
  301. $('#AddingAssetContainer1').show().html('');
  302. $('#AddingAssetContainer2').show().html('');
  303. }
  304. if (subAssetId && assetName) {
  305. // Show the container
  306. // $('#AddingAssetContainer1').show().html('<p>Loading...</p>');
  307. $('#AddingAssetContainer1, #AddingAssetContainer2').hide();
  308. $('#savingAssetContainer1, #savingAssetContainer2').hide();
  309. if (assetTypeText === 'IT Asset') {
  310. // IT Asset section
  311. $('#AddingAssetContainer1').show().html('<p>Loading...</p>');
  312. //$('#savingAssetContainer1').show();
  313. $.ajax({
  314. url: '/gcc/api/gccschool/buildingasset/getSchoolAsset',
  315. type: 'GET',
  316. data: {
  317. school_id: schoolId,
  318. type: assetName
  319. },
  320. success: function (response) {
  321. if (response.status === 'Success') {
  322. if (response.data.length === 0) {
  323. $('#AddingAssetContainer1').html('<p class="text-muted">No assets found.</p>');
  324. $('#savingAssetContainer1').hide();
  325. return;
  326. }
  327. const dataAdding=response.data;
  328. const tableHtml3 = `
  329. <table id="AddAssetDatatable" class="table table-bordered table-striped table-hover" style="width:100%;">
  330. <thead class="thead-dark">
  331. <tr>
  332. <th>Select</th>
  333. <th>S.No</th>
  334. <th>Asset Code</th>
  335. <th>Name</th>
  336. <th>Source</th>
  337. <th>Serial Number</th>
  338. </tr>
  339. </thead>
  340. <tbody></tbody>
  341. </table>
  342. `;
  343. $('#AddingAssetContainer1').html(tableHtml3);
  344. // Destroy existing instance if exists
  345. if ($.fn.DataTable.isDataTable('#AddAssetDatatable')) {
  346. $('#AddAssetDatatable').DataTable().clear().destroy(true);
  347. }
  348. // Prepare DataTable buttons (same format as your existing function)
  349. const buttons = [
  350. {
  351. extend: 'pageLength',
  352. className: 'btn btn-warning'
  353. },
  354. {
  355. title: 'IT Asset List',
  356. extend: 'copyHtml5',
  357. text: 'Copy',
  358. className: 'btn btn-secondary'
  359. },
  360. {
  361. extend: 'excelHtml5',
  362. text: 'Excel',
  363. className: 'btn btn-secondary',
  364. title: 'IT Asset List'
  365. },
  366. {
  367. extend: 'csvHtml5',
  368. text: 'CSV',
  369. className: 'btn btn-secondary',
  370. title: 'IT Asset List'
  371. },
  372. {
  373. extend: 'pdfHtml5',
  374. text: 'PDF',
  375. className: 'btn btn-secondary',
  376. title: 'IT Asset List'
  377. },
  378. {
  379. extend: 'print',
  380. text: 'Print',
  381. className: 'btn btn-secondary',
  382. title: 'IT Asset List',
  383. exportOptions: {
  384. columns: ':visible'
  385. }
  386. }
  387. ];
  388. // Initialize DataTable
  389. $('#AddAssetDatatable').DataTable({
  390. data: dataAdding,
  391. columns: [
  392. {
  393. data: 'it_details_id',
  394. render: function (data, type, row, meta) {
  395. return `<input type="checkbox" class="asset-checkbox" value="${data}">`;
  396. },
  397. orderable: false,
  398. searchable: false, className: 'text-center'
  399. },
  400. { data: null, render: (d, t, r, m) => m.row + 1 , className: 'text-center'},
  401. { data: 'asset_name' , className: 'text-center'},
  402. { data: 'hardware_type' , className: 'text-center'},
  403. { data: 'source_of_asset' , className: 'text-center'},
  404. { data: 'serial_no' , className: 'text-center'}
  405. ],
  406. lengthMenu: [
  407. [25, 50, 100, -1],
  408. ['25 rows', '50 rows', '100 rows', 'Show all']
  409. ],
  410. dom: 'Bfrtip',
  411. buttons: buttons,
  412. scrollX: true,
  413. scrollY: '300px',
  414. autoWidth: true,
  415. paging: true,
  416. info: true,
  417. responsive: true,
  418. language: {
  419. emptyTable: '<span class="text-danger">No IT assets found</span>'
  420. }
  421. });
  422. $('#savingAssetContainer1').show();
  423. } else {
  424. $('#AddingAssetContainer1').html('<p>No data found.</p>');
  425. }
  426. },
  427. error: function (xhr, status, error) {
  428. console.error("Error fetching assets by type:", status, error);
  429. $('#AddingAssetContainer1').html('<p>Error loading data.</p>');
  430. alert("Something went wrong while fetching assets.");
  431. }
  432. });
  433. }
  434. else if (assetTypeText === 'Electrical Asset' || assetTypeText === 'Furniture Asset') {
  435. // Show input section for Electrical/Furniture
  436. $('#AddingAssetContainer2').show().html(`
  437. <div class="form-group col-6">
  438. <label for="addAssetQuantity">Enter Quantity for ${assetName}</label>
  439. <input type="number" id="addAssetQuantity" class="form-control" placeholder="Enter quantity">
  440. </div>
  441. `);
  442. $('#savingAssetContainer2').show();
  443. }
  444. }
  445. else {
  446. $('#AddingAssetContainer1, #AddingAssetContainer2').hide();
  447. $('#savingAssetContainer1, #savingAssetContainer2').hide();
  448. }
  449. });
  450. /*$(document).on('click', '#updateAssetType', function () {
  451. let assetDataArray = [];
  452. let emptyAssetName = null;
  453. let validationFailed = false;
  454. $(currentTargetContainerEdit).find('.col-md-6').each(function () {
  455. let mapId = $(this).data('map-id');
  456. let assetName = $(this).data('assetname');
  457. let originalQty = parseInt($(this).data('original-qty'), 10);
  458. let assetQtyStr = $(this).find('input').val().trim();
  459. if (assetQtyStr === "") {
  460. emptyAssetName = assetName;
  461. Swal.fire({
  462. icon: 'warning',
  463. title: 'Missing Quantity',
  464. text: Please enter quantity for: ${emptyAssetName}
  465. });
  466. validationFailed = true;
  467. return false; // Break out of each loop
  468. }
  469. let assetQty = parseInt(assetQtyStr, 10);
  470. let flag = '0';
  471. if (assetQty > originalQty) {
  472. flag = '+1';
  473. } else if (assetQty < originalQty) {
  474. flag = '-1';
  475. }
  476. console.log(flag);
  477. if (mapId && !isNaN(assetQty)) {
  478. assetDataArray.push({
  479. assetType: currentAssetTypeEdit,
  480. id: mapId,
  481. qty: assetQty,
  482. flag: flag,
  483. originalQty:originalQty
  484. });
  485. }
  486. });
  487. if (validationFailed) {
  488. return;
  489. }
  490. console.log(assetDataArray); // Inspect before sending
  491. // Send to server
  492. $.ajax({
  493. url: '/gcc/api/gccschool/buildingasset/updateassets',
  494. type: 'POST',
  495. contentType: 'application/json',
  496. data: JSON.stringify(assetDataArray),
  497. success: function (response) {
  498. if (response === "Sucess") {
  499. Swal.fire({
  500. icon: 'success',
  501. title: 'Updated!',
  502. text: 'Asset quantities updated successfully.',
  503. confirmButtonColor: '#3085d6'
  504. }).then((result) => {
  505. if (result.isConfirmed) {
  506. location.reload(); // ✅ Page will reload after OK
  507. }
  508. });
  509. } else {
  510. Swal.fire({
  511. icon: 'error',
  512. title: 'Update Failed',
  513. text: 'Something went wrong while updating the assets. Please try again.',
  514. confirmButtonColor: '#d33'
  515. });
  516. }
  517. },
  518. error: function (xhr, status, error) {
  519. console.error('Error saving assets:', error);
  520. Swal.fire({
  521. icon: 'error',
  522. title: 'Server Error',
  523. text: 'Unable to reach the server or an internal error occurred.',
  524. confirmButtonColor: '#d33'
  525. });
  526. }
  527. });
  528. });*/
  529. $(document).on('click', '#updateAssetType', function () {
  530. let assetDataArray = [];
  531. let emptyAssetName = null;
  532. //console.log("lets see");
  533. $(currentTargetContainerEdit).find('.col-md-6').each(function () {
  534. console.log("sgsg")
  535. console.log(this);
  536. let mapId = $(this).data('map-id');
  537. let assetName = $(this).data('assetname');
  538. let assetQtyStr = $(this).find('input').val().trim();
  539. let assetQty = parseInt(assetQtyStr, 10);
  540. let originalQty = parseInt($(this).data('original-qty'), 10);
  541. let subAssetId = $(this).data('sub_asset_id'); // Make sure this attribute exists
  542. let schoolId = $(this).data('schoolid'); // Make sure this attribute exists
  543. console.log("subsetid")
  544. console.log(subAssetId);
  545. console.log("schoolid");
  546. console.log(schoolId);
  547. if (assetQty === "") {
  548. emptyAssetName = assetName;
  549. if (emptyAssetName) {
  550. Swal.fire({
  551. icon: 'warning',
  552. title: 'Missing Quantity',
  553. text: 'Please enter quantity for: ${emptyAssetName}'
  554. });
  555. return;
  556. }
  557. }
  558. let flag = '0';
  559. if (assetQty > originalQty) {
  560. flag = '+1';
  561. } else if (assetQty < originalQty) {
  562. flag = '-1';
  563. }
  564. console.log(flag);
  565. if (mapId && assetQty) {
  566. assetDataArray.push({
  567. assetType: currentAssetTypeEdit, // from outer scope
  568. id: mapId, // either furniture_map_id or electrical_map_id
  569. qty: assetQty,
  570. flag: flag,
  571. originalQty:originalQty,
  572. subid: subAssetId, // new field
  573. schid: schoolId // new field
  574. });
  575. }
  576. });
  577. console.log(assetDataArray); // Inspect before sending
  578. // Send to server
  579. $.ajax({
  580. url: '/gcc/api/gccschool/buildingasset/updateassets',
  581. type: 'POST',
  582. contentType: 'application/json',
  583. data: JSON.stringify(assetDataArray),
  584. success: function (response) {
  585. //console.log("Response:", response);
  586. /* if (response === "Sucess") {
  587. Swal.fire({
  588. icon: 'success',
  589. title: 'Updated!',
  590. text: 'Asset quantities updated successfully.',
  591. confirmButtonColor: '#3085d6'
  592. });
  593. }*/
  594. if (response === "Sucess") {
  595. Swal.fire({
  596. icon: 'success',
  597. title: 'Updated!',
  598. text: 'Asset quantities updated successfully.',
  599. confirmButtonColor: '#3085d6'
  600. }).then((result) => {
  601. if (result.isConfirmed) {
  602. location.reload(); // ✅ Page will reload after OK
  603. }
  604. });
  605. }
  606. else if (response === 'Add Sufficient Master Quantity') {
  607. Swal.fire({
  608. icon: 'info',
  609. title: 'Out of Range',
  610. text: response, // Show the response text
  611. allowOutsideClick: false,
  612. allowEscapeKey: false,
  613. allowEnterKey: false,
  614. showConfirmButton: true
  615. });
  616. }
  617. else {
  618. Swal.fire({
  619. icon: 'error',
  620. title: 'Update Failed',
  621. text: 'Something went wrong while updating the assets. Please try again.',
  622. confirmButtonColor: '#d33'
  623. });
  624. }
  625. },
  626. error: function (xhr, status, error) {
  627. console.error('Error saving assets:', error);
  628. Swal.fire({
  629. icon: 'error',
  630. title: 'Server Error',
  631. text: 'Unable to reach the server or an internal error occurred.',
  632. confirmButtonColor: '#d33'
  633. });
  634. }
  635. });
  636. });
  637. window.assetMappingEventsBound = true;
  638. }
  639. function loadSavedBuildingRm(RoomAssetschoolId) {
  640. var buttons = [
  641. {
  642. extend: 'pageLength',
  643. className: 'btn btn-warning'
  644. },
  645. {
  646. title: 'Data export',
  647. extend: 'copyHtml5',
  648. text: 'Copy',
  649. className: 'btn btn-secondary',
  650. id: 'copyBtn'
  651. },
  652. {
  653. extend: 'excelHtml5',
  654. text: 'Excel',
  655. className: 'btn btn-secondary',
  656. id: 'excelBtn',
  657. title: 'Petition List'
  658. },
  659. {
  660. extend: 'csvHtml5',
  661. text: 'CSV',
  662. className: 'btn btn-secondary',
  663. id: 'csvBtn',
  664. title: 'Petition List'
  665. },
  666. {
  667. extend: 'pdfHtml5',
  668. text: 'PDF',
  669. className: 'btn btn-secondary',
  670. id: 'pdfBtn',
  671. title: 'Petition List'
  672. },
  673. {
  674. extend: 'print',
  675. text: 'Print',
  676. className: 'btn btn-secondary',
  677. id: 'printBtn',
  678. title: 'Petition List',
  679. exportOptions: {
  680. columns: ':visible:not(.no-print)' // Exclude columns with class 'no-print' from print view
  681. }
  682. }
  683. ];
  684. $.get('/gcc/api/gccschool/buildingasset/getRoomDetails', {school_id: RoomAssetschoolId}, res => {
  685. if ($.fn.DataTable.isDataTable('#RoomAssetDatatable')) {
  686. $('#RoomAssetDatatable').DataTable().clear().destroy(true);
  687. }
  688. let tableData = [];
  689. if (res.status === "OK" && Array.isArray(res.data)) {
  690. tableData = res.data;
  691. }
  692. $('#RoomAssetDatatable').DataTable({
  693. data: tableData,
  694. columns: [
  695. {data: null, render: (d, t, r, m) => m.row + 1},
  696. {data: 'room_name'},
  697. {data: 'building_name'},
  698. {data: 'floor'},
  699. {data: 'room_type'},
  700. {
  701. data: 'building_id',
  702. render: (data, t, row) => `
  703. <div class="text-center">
  704. <button class="btn btn-sm btn-primary view-btn" data-building_name="${row.building_name}" data-floor="${row.floor}" data-room_type="${row.room_type}" data-room-id="${row.room_id}" data-room-name="${row.room_name}"><i class="ik ik-eye" style="font-size:medium;margin-left:5px;"></i></button>
  705. <button class="btn btn-sm btn-success edit-btn" data-building_name="${row.building_name}" data-floor="${row.floor}" data-room_type="${row.room_type}" data-room-id="${row.room_id}" data-room-name="${row.room_name}" data-building_id="${row.building_id}" data-floors_id="${row.floors_id}" data-school_id="${row.school_id}"><i class="ik ik-edit-2" style="font-size:medium;margin-left:5px;"></i></button>
  706. </div>`
  707. }
  708. ],
  709. lengthMenu: [
  710. [50, 100, 200, 500, -1],
  711. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  712. ],
  713. dom: 'Bftip',
  714. //fixedColumns: {left: 0, right: 0},
  715. scrollY: '60vh',
  716. scrollX: true,
  717. autoWidth: true,
  718. paging: true,
  719. info: true,
  720. buttons: buttons,
  721. responsive: false,
  722. searching: true,
  723. select: false,
  724. processing: false,
  725. language: {
  726. emptyTable: '<span class="text-danger">No Details found</span>'
  727. }
  728. });
  729. });
  730. }
  731. function handleView() {
  732. let roomName = $(this).data('room-name');
  733. let roomId = $(this).data('room-id');
  734. let buildingName= $(this).data('building_name');
  735. let Floor= $(this).data('floor');
  736. let roomType= $(this).data('room_type');
  737. //globalRoomId = roomId;
  738. // Update modal title
  739. $('#roomTitleView').text(roomName);
  740. $('#roomNameView').text(roomName);
  741. $('#buildingNameView').text(buildingName);
  742. $('#floorView').text(Floor);
  743. $('#roomTypeView').text(roomType);
  744. $('#VroomId').text(roomId);
  745. let roomIdV=$('#VroomId').text().trim();
  746. $('#RoomAssetViewModal').modal('show');
  747. $('#view-itasset-tab').tab('show');
  748. // Clear previous content before loading new one
  749. $('#viewItAssetContainer, #viewFurnitureAssetContainer, #viewElectricalAssetContainer').html('');
  750. // Load default (IT Assets)
  751. loadAssetTab('itasset',roomIdV);
  752. }
  753. // Tab click event to fetch data based on clicked tab
  754. /* $('#assetTabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  755. const assetType = $(e.target).attr('href').substring(1); // e.g. 'furniture'
  756. loadAssetTab(assetType);
  757. }); */
  758. $('#assetTabs a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
  759. const tabIdToAssetTypeMap = {
  760. 'view-itasset': 'itasset',
  761. 'view-furniture': 'furnitureasset',
  762. 'view-electrical': 'electricalasset'
  763. };
  764. const tabId = $(e.target).attr('href').substring(1); // e.g. 'view-furniture'
  765. const assetType = tabIdToAssetTypeMap[tabId];
  766. if (assetType) {
  767. //console.log("assetType="+assetType);
  768. let roomIdV=$('#VroomId').text().trim();
  769. loadAssetTab(assetType,roomIdV);
  770. }
  771. });
  772. $('#assetTabsEdit a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
  773. const tabIdToAssetTypeEditMap = {
  774. 'edit-itasset': 'itasset',
  775. 'edit-furniture': 'furnitureasset',
  776. 'edit-electrical': 'electricalasset'
  777. };
  778. const EdittabId = $(e.target).attr('href').substring(1); // e.g. 'view-furniture'
  779. const EditassetType = tabIdToAssetTypeEditMap[EdittabId];
  780. if (EditassetType) {
  781. //console.log("EditassetType="+EditassetType);
  782. let roomIdE = $('#EroomId').text().trim();
  783. loadEditAssetTab(EditassetType,roomIdE);
  784. }
  785. });
  786. // Tab click event to fetch data based on clicked tab
  787. /* $('#assetTabsEdit a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  788. const editassetType = $(e.target).attr('href').substring(1); // e.g. 'furniture'
  789. loadEditAssetTab(editassetType);
  790. }); */
  791. // Reusable function for AJAX loading of asset tab content
  792. function loadAssetTab(assetType,roomIdV) {
  793. const assetMap = {
  794. itasset: '#viewItAssetContainer',
  795. furnitureasset: '#viewFurnitureAssetContainer',
  796. electricalasset: '#viewElectricalAssetContainer'
  797. };
  798. const targetContainer = assetMap[assetType];
  799. $(targetContainer).html('<p>Loading...</p>');
  800. $.get('/gcc/api/gccschool/buildingasset/getItAssetMapping', { room_id: roomIdV, assetType: assetType }, res => {
  801. //console.log("===");
  802. if (res.Status === "OK") {
  803. //console.log(res.data);
  804. const data = res.data;
  805. if (data.length === 0) {
  806. $(targetContainer).html('<p class="text-muted">No assets found.</p>');
  807. return;
  808. }
  809. if (assetType === 'itasset') {
  810. // Clear and re-insert the table structure dynamically
  811. const tableHtml = `
  812. <table id="ItAssetDatatable" class="table table-bordered table-striped table-hover" style="width:100%;">
  813. <thead class="thead-dark">
  814. <tr>
  815. <th>S.No</th>
  816. <th>Asset Code</th>
  817. <th>Name</th>
  818. <th>Source</th>
  819. <th>Serial Number</th>
  820. </tr>
  821. </thead>
  822. <tbody></tbody>
  823. </table>
  824. `;
  825. $(targetContainer).html(tableHtml);
  826. // Destroy existing instance if exists
  827. if ($.fn.DataTable.isDataTable('#ItAssetDatatable')) {
  828. $('#ItAssetDatatable').DataTable().clear().destroy(true);
  829. }
  830. // Prepare DataTable buttons (same format as your existing function)
  831. const buttons = [
  832. {
  833. extend: 'pageLength',
  834. className: 'btn btn-warning'
  835. },
  836. {
  837. title: 'IT Asset List',
  838. extend: 'copyHtml5',
  839. text: 'Copy',
  840. className: 'btn btn-secondary'
  841. },
  842. {
  843. extend: 'excelHtml5',
  844. text: 'Excel',
  845. className: 'btn btn-secondary',
  846. title: 'IT Asset List'
  847. },
  848. {
  849. extend: 'csvHtml5',
  850. text: 'CSV',
  851. className: 'btn btn-secondary',
  852. title: 'IT Asset List'
  853. },
  854. {
  855. extend: 'pdfHtml5',
  856. text: 'PDF',
  857. className: 'btn btn-secondary',
  858. title: 'IT Asset List'
  859. },
  860. {
  861. extend: 'print',
  862. text: 'Print',
  863. className: 'btn btn-secondary',
  864. title: 'IT Asset List',
  865. exportOptions: {
  866. columns: ':visible'
  867. }
  868. }
  869. ];
  870. // Initialize DataTable
  871. $('#ItAssetDatatable').DataTable({
  872. data: data,
  873. columns: [
  874. { data: null, render: (d, t, r, m) => m.row + 1 },
  875. { data: 'asset_name' },
  876. { data: 'hardware_type' },
  877. { data: 'source_of_asset' },
  878. { data: 'serial_no' }
  879. ],
  880. lengthMenu: [
  881. [25, 50, 100, -1],
  882. ['25 rows', '50 rows', '100 rows', 'Show all']
  883. ],
  884. dom: 'Bfrtip',
  885. buttons: buttons,
  886. scrollX: true,
  887. scrollY: '300px',
  888. autoWidth: true,
  889. paging: true,
  890. info: true,
  891. responsive: true,
  892. language: {
  893. emptyTable: '<span class="text-danger">No IT assets found</span>'
  894. }
  895. });
  896. }
  897. else if (assetType === 'furnitureasset'|| assetType === 'electricalasset') {
  898. // Render furniture/electrical: only show assetname and asset_qty
  899. let html = data.map(item => {
  900. return `
  901. <div class="row p-2 mb-2">
  902. <div class="col-md-6">
  903. <strong>${item.assetname}:</strong>
  904. <input value="${item.asset_qty}" class="form-control" readonly>
  905. </div>
  906. </div>
  907. `;
  908. }).join('');
  909. $(targetContainer).html(html);
  910. }
  911. else{
  912. $(targetContainer).html('<p class="text-danger">No asset data.</p>');
  913. }
  914. } else {
  915. $(targetContainer).html('<p class="text-danger">Error fetching asset data.</p>');
  916. }
  917. });
  918. }
  919. function handleEdit() {
  920. let roomName = $(this).data('room-name');
  921. let roomId = $(this).data('room-id');
  922. let buildingName= $(this).data('building_name');
  923. let Floor= $(this).data('floor');
  924. let roomType= $(this).data('room_type');
  925. let Ebuilding_id= $(this).data('building_id');
  926. let Efloors_id= $(this).data('floors_id');
  927. let Eschool_id= $(this).data('school_id');
  928. let EroomId = $(this).data('room-id');
  929. //console.log("Ebuilding_id="+Ebuilding_id);
  930. //console.log("Efloors_id="+Efloors_id);
  931. //console.log("Eschool_id="+Eschool_id);
  932. //console.log("EroomId="+EroomId);
  933. //globalRoomId = roomId;
  934. //console.log("globalRoomId="+globalRoomId);
  935. $('#roomTitleEdit').text(roomName);
  936. $('#roomNameEdit').text(roomName);
  937. $('#buildingNameEdit').text(buildingName);
  938. $('#floorEdit').text(Floor);
  939. $('#roomTypeEdit').text(roomType);
  940. $('#Eschool_id').text(Eschool_id);
  941. $('#Ebuilding_id').text(Ebuilding_id);
  942. $('#Efloors_id').text(Efloors_id);
  943. $('#EroomId').text(EroomId);
  944. $('#RoomAssetEditModal').modal('show');
  945. $('#edit-itasset-tab').tab('show');
  946. // Load default (IT Assets)
  947. loadEditAssetTab('itasset',EroomId);
  948. }
  949. function loadEditAssetTab(EditassetType,EroomId){
  950. const assetMapEdit = {
  951. itasset: '#editItAssetContainer',
  952. furnitureasset: '#editFurnitureAssetContainer',
  953. electricalasset: '#editElectricalAssetContainer'
  954. };
  955. currentAssetTypeEdit = EditassetType;
  956. currentTargetContainerEdit = assetMapEdit[EditassetType]; // save globally
  957. const targetContainerEdit = assetMapEdit[EditassetType];
  958. $(targetContainerEdit).html('<p>Loading...</p>');
  959. $.get('/gcc/api/gccschool/buildingasset/getItAssetMapping', { room_id: EroomId, assetType: EditassetType }, result => {
  960. if (result.Status === "OK") {
  961. console.log(result.data);
  962. const data2 = result.data;
  963. console.log(data2);
  964. if (data2.length === 0) {
  965. $(targetContainerEdit).html('<p class="text-muted">No assets found.</p>');
  966. return;
  967. }
  968. if (EditassetType === 'itasset') {
  969. // Clear and re-insert the table structure dynamically
  970. const tableHtml2 = `
  971. <table id="ItAssetDatatable2" class="table table-bordered table-striped table-hover" style="width:100%;">
  972. <thead class="thead-dark">
  973. <tr>
  974. <th class="text-center">S.No</th>
  975. <th class="text-center">Asset Code</th>
  976. <th class="text-center">Name</th>
  977. <th class="text-center">Source</th>
  978. <th class="text-center">Serial Number</th>
  979. <th class="text-center">Action</th>
  980. </tr>
  981. </thead>
  982. <tbody></tbody>
  983. </table>
  984. `;
  985. $(targetContainerEdit).html(tableHtml2);
  986. // Destroy existing instance if exists
  987. if ($.fn.DataTable.isDataTable('#ItAssetDatatable2')) {
  988. $('#ItAssetDatatable2').DataTable().clear().destroy(true);
  989. }
  990. // Prepare DataTable buttons (same format as your existing function)
  991. const Ebuttons = [
  992. {
  993. extend: 'pageLength',
  994. className: 'btn btn-warning'
  995. },
  996. {
  997. title: 'IT Asset List',
  998. extend: 'copyHtml5',
  999. text: 'Copy',
  1000. className: 'btn btn-secondary'
  1001. },
  1002. {
  1003. extend: 'excelHtml5',
  1004. text: 'Excel',
  1005. className: 'btn btn-secondary',
  1006. title: 'IT Asset List'
  1007. },
  1008. {
  1009. extend: 'csvHtml5',
  1010. text: 'CSV',
  1011. className: 'btn btn-secondary',
  1012. title: 'IT Asset List'
  1013. },
  1014. {
  1015. extend: 'pdfHtml5',
  1016. text: 'PDF',
  1017. className: 'btn btn-secondary',
  1018. title: 'IT Asset List'
  1019. },
  1020. {
  1021. extend: 'print',
  1022. text: 'Print',
  1023. className: 'btn btn-secondary',
  1024. title: 'IT Asset List',
  1025. exportOptions: {
  1026. columns: ':visible'
  1027. }
  1028. }
  1029. ];
  1030. // Initialize DataTable
  1031. $('#ItAssetDatatable2').DataTable({
  1032. data: data2,
  1033. columns: [
  1034. { data: null, render: (d, t, r, m) => m.row + 1 , className: 'text-center'},
  1035. { data: 'asset_name', className: 'text-center' },
  1036. { data: 'hardware_type' , className: 'text-center'},
  1037. { data: 'source_of_asset' , className: 'text-center' },
  1038. { data: 'serial_no' , className: 'text-center'},
  1039. {
  1040. data: 'it_map_id',
  1041. render: (data, t, row) => `
  1042. <div class="text-center">
  1043. <button class="btn btn-sm btn-primary del-btn" data-deleteid="${row.it_map_id}">
  1044. <i class="ik ik-trash-2"></i>Delete
  1045. </button>
  1046. </div>`
  1047. }
  1048. ],
  1049. lengthMenu: [
  1050. [25, 50, 100, -1],
  1051. ['25 rows', '50 rows', '100 rows', 'Show all']
  1052. ],
  1053. dom: 'Bfrtip',
  1054. buttons: Ebuttons,
  1055. scrollX: true,
  1056. scrollY: '30vh',
  1057. autoWidth: true,
  1058. paging: true,
  1059. info: true,
  1060. responsive: true,
  1061. language: {
  1062. emptyTable: '<span class="text-danger">No IT assets found</span>'
  1063. }
  1064. });
  1065. }
  1066. else if (EditassetType === 'furnitureasset'|| EditassetType === 'electricalasset') {
  1067. // Start the row container
  1068. let html = `<div class="row p-2 mb-2">`;
  1069. // Add each asset as a col inside that row
  1070. html += data2.map(item => {
  1071. const mapId = EditassetType === 'furnitureasset' ? item.furniture_map_id : item.electrical_map_id;
  1072. console.log("item");
  1073. console.log(item);
  1074. return `
  1075. <div class="col-md-6" data-map-id="${mapId}" data-assetname="${item.assetname}" data-original-qty="${item.asset_qty}"
  1076. data-Schoolid="${item.school_id}" data-sub_asset_id="${item.sub_asset_id}">
  1077. <strong>${item.assetname}:</strong>
  1078. <input value="${item.asset_qty}" class="form-control">
  1079. </div>
  1080. `;
  1081. }).join('');
  1082. // Close the row
  1083. html += `</div>`;
  1084. // Add the update button outside the row
  1085. html += `
  1086. <div class="col-12 d-flex justify-content-center">
  1087. <button type="button" class="btn btn-info" id="updateAssetType">Update</button>
  1088. </div>
  1089. `;
  1090. $(targetContainerEdit).html(html);
  1091. }
  1092. else{
  1093. $(targetContainerEdit).html('<p class="text-danger">No asset data.</p>');
  1094. }
  1095. } else {
  1096. $(targetContainerEdit).html('<p class="text-danger">Error fetching asset data.</p>');
  1097. }
  1098. });
  1099. }
  1100. function handleDelete() {
  1101. //let deleteId = $(this).data('deleteId');
  1102. let deleteId = $(this).attr('data-deleteid');
  1103. const row = $(this).closest('tr');
  1104. //console.log("deleteId = " + deleteId);
  1105. // You can now make an AJAX call to delete or show confirmation
  1106. $.ajax({
  1107. url: '/gcc/api/gccschool/buildingasset/deleteAssetMapping',
  1108. type: 'POST',
  1109. data:{it_map_id: deleteId,is_delete:1},
  1110. success: function (response) {
  1111. if (response.status === 'Sucess') {
  1112. Swal.fire({
  1113. icon: 'success',
  1114. title: 'Success',
  1115. text: response.data,
  1116. allowOutsideClick: false,
  1117. allowEscapeKey: false,
  1118. allowEnterKey: false,
  1119. confirmButtonText: 'OK'
  1120. }).then((result) => {
  1121. if (result.isConfirmed) {
  1122. //console.log("Continue clicked");
  1123. const Rtable = $('#ItAssetDatatable2').DataTable();
  1124. // Remove the row
  1125. Rtable.row(row).remove();
  1126. // Reorder S.No column
  1127. Rtable.rows().every(function (index) {
  1128. const row = this.node();
  1129. $(row).find('td:first-child').text(index + 1); // Update S.No
  1130. });
  1131. // Redraw the table
  1132. Rtable.draw(false);
  1133. }
  1134. });
  1135. }
  1136. else {
  1137. }
  1138. },
  1139. error: function (xhr, status, error) {
  1140. console.error("Error deleting asset:", status, error);
  1141. alert("Something went wrong while deleting asset.");
  1142. }
  1143. });
  1144. }
  1145. function addAssetMapping(){
  1146. // Get values from hidden spans
  1147. let AschoolId = $('#Eschool_id').text().trim();
  1148. let AbuildingId = $('#Ebuilding_id').text().trim();
  1149. let AfloorId = $('#Efloors_id').text().trim();
  1150. let AroomId = $('#EroomId').text().trim();
  1151. /* console.log("School ID:", AschoolId);
  1152. console.log("Building ID:", AbuildingId);
  1153. console.log("Floor ID:", AfloorId);
  1154. console.log("Room ID:", AroomId); */
  1155. let AddroomName = $('#roomTitleEdit').text();
  1156. $('#roomTitleAdd').text(AddroomName);
  1157. $('#RoomAssetEditModal').modal('hide');
  1158. $('#subAssetTypeContainer').hide();
  1159. $('#Sschool_id').text(AschoolId);
  1160. $('#Sbuilding_id').text(AbuildingId);
  1161. $('#Sfloors_id').text(AfloorId);
  1162. $('#SroomId').text(AroomId);
  1163. $('#AddAssetModal').modal('show');
  1164. $('#AddingAssetContainer1').hide();
  1165. $('#AddingAssetContainer2').hide();
  1166. $('#savingAssetContainer1').hide();
  1167. $('#savingAssetContainer2').hide();
  1168. // Clear previous dropdowns
  1169. $('#assetType').empty().append('<option value="">Select Asset Type</option>');
  1170. $('#subAssetType').empty().append('<option value="">Select Sub Asset Type</option>');
  1171. // Load Asset Types via AJAX
  1172. $.ajax({
  1173. url: '/gcc/api/gccschool/dropdown/getAssetType',
  1174. type: 'GET',
  1175. success: function (response) {
  1176. if (response.status === 'OK') {
  1177. response.data.forEach(item => {
  1178. $('#assetType').append(`<option value="${item.asset_master_id}">${item.asset_type}</option>`);
  1179. });
  1180. }
  1181. if (response.status === 'Failed') {
  1182. $('#assetType').empty().append('<option value="">No Data Found</option>');
  1183. }
  1184. },
  1185. error: function (xhr, status, error) {
  1186. console.error("Error fetching asset types:", status, error);
  1187. $('#assetType').empty().append('<option value="">Error loading data</option>');
  1188. alert("Something went wrong while fetching asset types.");
  1189. }
  1190. });
  1191. }
  1192. function saveItAsset(){
  1193. let schoolId1 = $('#Sschool_id').text().trim();
  1194. let buildingId1 = $('#Sbuilding_id').text().trim();
  1195. let floorId1 = $('#Sfloors_id').text().trim();
  1196. let roomId1 = $('#SroomId').text().trim();
  1197. let selectedAssets = [];
  1198. $('.asset-checkbox:checked').each(function () {
  1199. let itDetailsId = $(this).val();
  1200. selectedAssets.push({
  1201. it_details_id: itDetailsId,
  1202. school_id: schoolId1,
  1203. building_id: buildingId1,
  1204. floor_id: floorId1,
  1205. room_id: roomId1
  1206. });
  1207. });
  1208. if (selectedAssets.length === 0) {
  1209. Swal.fire("Please select at least one asset.");
  1210. return;
  1211. }
  1212. console.log("Submitting these assets:", selectedAssets);
  1213. $.ajax({
  1214. url: '/gcc/api/gccschool/buildingasset/mapAssets',
  1215. type: 'POST',
  1216. contentType: 'application/json',
  1217. data: JSON.stringify(selectedAssets),
  1218. success: function (response) {
  1219. if(response ==='Success'){
  1220. Swal.fire({
  1221. allowOutsideClick: false,
  1222. allowEscapeKey: false,
  1223. allowEnterKey: false,
  1224. icon: 'success',
  1225. title: 'Success!',
  1226. text: 'IT Assets have been mapped successfully.'
  1227. }).then(() => {
  1228. location.reload();
  1229. });
  1230. //Swal.fire("Success!", "IT Assets have been mapped successfully.", "success");
  1231. //$('#AddAssetModal').modal('hide');
  1232. }
  1233. else if (response==='Error'){
  1234. Swal.fire("Error", "Error in saving asset Mapping", "error");
  1235. }
  1236. else{
  1237. Swal.fire("Error", "Something went wrong!", "error");
  1238. }
  1239. // Optionally reload or refresh the page/table here
  1240. },
  1241. error: function (xhr, status, error) {
  1242. console.error("Save error:", status, error);
  1243. Swal.fire("Error!", "Something went wrong while saving.", "error");
  1244. }
  1245. });
  1246. }
  1247. function saveOtherAsset(){
  1248. let schoolId2 = $('#Sschool_id').text().trim();
  1249. let buildingId2 = $('#Sbuilding_id').text().trim();
  1250. let floorId2 = $('#Sfloors_id').text().trim();
  1251. let roomId2 = $('#SroomId').text().trim();
  1252. let assetTypeText = $('#assetType option:selected').text().trim();
  1253. let savingAssetType=null;
  1254. if(assetTypeText==='Furniture Asset'){
  1255. savingAssetType='furnitureasset'
  1256. }
  1257. if(assetTypeText==='Electrical Asset'){
  1258. savingAssetType='electricalasset'
  1259. }
  1260. let subAssetTypeId = $('#subAssetType').val();
  1261. let addAssetQuantity = $('#addAssetQuantity').val()?.trim();
  1262. if (!subAssetTypeId || !schoolId2 || !buildingId2 || !floorId2 || !roomId2 || !savingAssetType) {
  1263. //Swal.fire("Error", "Please make sure all fields are filled correctly.", "error");
  1264. Swal.fire({
  1265. icon: 'error',
  1266. title: 'Error',
  1267. text: 'Please make sure all fields are filled correctly.',
  1268. allowOutsideClick: false,
  1269. allowEscapeKey: false,
  1270. allowEnterKey: false,
  1271. showConfirmButton: true
  1272. });
  1273. return;
  1274. }
  1275. if(!addAssetQuantity){
  1276. Swal.fire({
  1277. icon: 'info',
  1278. title: 'Info',
  1279. text: 'Enter quantity',
  1280. allowOutsideClick: false,
  1281. allowEscapeKey: false,
  1282. allowEnterKey: false,
  1283. showConfirmButton: true
  1284. });
  1285. return;
  1286. }
  1287. $.ajax({
  1288. url: '/gcc/api/gccschool/buildingasset/addFurAsset',
  1289. type: 'POST',
  1290. data: {
  1291. sub_asset_id: subAssetTypeId,
  1292. asset_qty: addAssetQuantity,
  1293. room_id: roomId2,
  1294. building_id: buildingId2,
  1295. floor_id: floorId2,
  1296. school_id: schoolId2,
  1297. assetType: savingAssetType
  1298. },
  1299. success: function (response) {
  1300. if (response === 'Sucess') {
  1301. Swal.fire({
  1302. allowOutsideClick: false,
  1303. allowEscapeKey: false,
  1304. allowEnterKey: false,
  1305. icon: 'success',
  1306. title: 'Success!',
  1307. text: 'Assets have been mapped successfully.'
  1308. }).then(() => {
  1309. location.reload();
  1310. $('#addAssetQuantity').val('');
  1311. $('#assetType').val('');
  1312. $('#subAssetTypeContainer').hide();
  1313. $('#subAssetType').empty().append('<option value="">Select Sub Asset Type</option>');
  1314. $('#AddingAssetContainer2, #savingAssetContainer2').hide();
  1315. $('#AddingAssetContainer1, #savingAssetContainer1').hide();
  1316. // $('#AddAssetModal').hide();
  1317. });
  1318. } /*else {
  1319. Swal.fire("Error", "Failed to add asset.", "error");
  1320. }*/
  1321. else if (response === 'Add Sufficient Quantity') {
  1322. Swal.fire({
  1323. icon: 'info',
  1324. title: 'InSufficient Quantity',
  1325. text: response, // Show the response text
  1326. allowOutsideClick: false,
  1327. allowEscapeKey: false,
  1328. allowEnterKey: false,
  1329. showConfirmButton: true
  1330. });
  1331. } else {
  1332. Swal.fire("Error", "Failed to add asset.", "error");
  1333. }
  1334. },
  1335. error: function (xhr, status, error) {
  1336. console.error("Error while mapping asset:", status, error);
  1337. Swal.fire("Error", "Something went wrong. Please try again.", "error");
  1338. }
  1339. });
  1340. }
  1341. });
  1342. </script>
  1343. </body>
  1344. </html>