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.

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