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.

830 lines
28 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. </style>
  7. <body>
  8. <div class="wrapper">
  9. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  10. <div class="page-wrap">
  11. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  12. <div class="card">
  13. <div class="main-content" style="background-color: white;">
  14. <div class="container">
  15. <!-- Card 2: Other Details -->
  16. <div class="col-md-12">
  17. <div style="padding: 0px;margin-top:-58px;margin-left: -233px;">
  18. <div class="card-header d-flex justify-content-between align-items-center">
  19. <b>List of IT Assets</b>
  20. <button type="button" class="btn btn-primary add-btn"> <i class="ik ik-plus"></i>Add Assets</button>
  21. </div>
  22. <div class="card-body" style="padding: 5px;">
  23. <table id="AssetManageDatatable"
  24. class="table table-striped table-bordered table-hover dataTable" role="grid"
  25. style="width: 100%">
  26. <thead class="thead-dark">
  27. <tr>
  28. <th>S.NO</th>
  29. <th>ASSET CODE</th>
  30. <th>NAME</th>
  31. <th>SOURCE</th>
  32. <th>SERIAL NUMBER</th>
  33. <th>RECEIVED DATE</th>
  34. <th>RECEIVED BY</th>
  35. <th>VENDOR DETAILS</th>
  36. <th>INVOICE NUMBER</th>
  37. <th>ACTION</th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. </tbody>
  42. </table>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <div id="pageLoader"
  48. 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;">
  49. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  50. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  51. <span class="sr-only">Loading...</span>
  52. </div>
  53. <!-- Add the 'Please wait' text below the spinner -->
  54. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="modal fade" id="AddAssetModal2" tabindex="-1" role="dialog" aria-labelledby="AddAssetModal2Label" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  62. <div class="modal-dialog modal-lg" role="document">
  63. <div class="modal-content">
  64. <div class="modal-header">
  65. <h5 class="modal-title">
  66. Add Assets
  67. </h5>
  68. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  69. <span aria-hidden="true">&times;</span>
  70. </button>
  71. </div>
  72. <div class="modal-body">
  73. <span id="school_udise" style="display: none;"></span>
  74. <div class="row">
  75. <!-- <div class="form-group col-6">
  76. <label for="assetCode">Asset Code<span class="text-danger">*</span></label>
  77. <input type="text" class="form-control" id="assetCode" name="assetCode">
  78. </div>-->
  79. <div class="form-group col-6">
  80. <label for="assetName">Name <span class="text-danger">*</span></label>
  81. <select class="form-control" id="assetName" name="assetName" required>
  82. <option value="">-- Select Sub Asset Type --</option>
  83. </select>
  84. </div>
  85. <div class="form-group col-6">
  86. <label for="assetSource">Source<span class="text-danger">*</span></label>
  87. <input type="text" class="form-control" id="assetSource" name="assetSource">
  88. </div>
  89. <div class="form-group col-6">
  90. <label for="serialNumber">Serial Number<span class="text-danger">*</span></label>
  91. <input type="text" class="form-control" id="serialNumber" name="serialNumber">
  92. </div>
  93. <div class="form-group col-6">
  94. <label for="vendorDetail">Vendor Detail<span class="text-danger">*</span></label>
  95. <input type="text" class="form-control" id="vendorDetail" name="vendorDetail">
  96. </div>
  97. <div class="form-group col-6">
  98. <label for="invoiceNumber">Invoice Number</label>
  99. <input type="text" class="form-control" id="invoiceNumber" name="invoiceNumber">
  100. </div>
  101. </div>
  102. <div class="row pb-2 mt-4">
  103. <div class="col-12 d-flex justify-content-center">
  104. <button type="button" class="btn btn-primary" id="savingAsset">Save</button>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="modal-footer">
  109. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. <div class="modal fade" id="EditAssetModal2" tabindex="-1" role="dialog" aria-labelledby="EditAssetModal2Label" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  115. <div class="modal-dialog modal-lg" role="document">
  116. <div class="modal-content">
  117. <div class="modal-header">
  118. <h5 class="modal-title">
  119. Edit Assets
  120. </h5>
  121. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  122. <span aria-hidden="true">&times;</span>
  123. </button>
  124. </div>
  125. <div class="modal-body">
  126. <span id="editid" style="display: none;"></span>
  127. <div class="row">
  128. <div class="form-group col-6">
  129. <label for="editassetCode">Asset Code<span class="text-danger">*</span></label>
  130. <input type="text" class="form-control" id="editassetCode" name="editassetCode">
  131. </div>
  132. <div class="form-group col-6">
  133. <label for="editassetName">Name<span class="text-danger">*</span></label>
  134. <input type="text" class="form-control" id="editassetName" name="editassetName">
  135. </div>
  136. <div class="form-group col-6">
  137. <label for="editassetSource">Source<span class="text-danger">*</span></label>
  138. <input type="text" class="form-control" id="editassetSource" name="editassetSource">
  139. </div>
  140. <div class="form-group col-6">
  141. <label for="editserialNumber">Serial Number<span class="text-danger">*</span></label>
  142. <input type="text" class="form-control" id="editserialNumber" name="editserialNumber">
  143. </div>
  144. <div class="form-group col-6">
  145. <label for="editvendorDetail">Vendor Detail<span class="text-danger">*</span></label>
  146. <input type="text" class="form-control" id="editvendorDetail" name="vendorDetail">
  147. </div>
  148. <div class="form-group col-6">
  149. <label for="editinvoiceNumber">Invoice Number</label>
  150. <input type="text" class="form-control" id="editinvoiceNumber" name="editinvoiceNumber">
  151. </div>
  152. </div>
  153. <div class="row pb-2 mt-4">
  154. <div class="col-12 d-flex justify-content-center">
  155. <button type="button" class="btn btn-primary" id="UpdatingAsset">Update</button>
  156. </div>
  157. </div>
  158. </div>
  159. <div class="modal-footer">
  160. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  166. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  167. <script type="text/javascript">
  168. console.log("hi..asset Management");
  169. $(document).ready(function () {
  170. let AssetManageurlParams = new URLSearchParams(window.location.search);
  171. let AssetManageschoolId = AssetManageurlParams.get("schoolId");
  172. loadSavedBuildingAm(AssetManageschoolId);
  173. if (!window.assetManagementEventsBound) {
  174. $(document).on('click', '.edit-btn1', handleManageEdit);
  175. //$(document).on('click', '.add-btn', handleAddAsset);
  176. $(document).on('click', '.add-btn', function () {
  177. handleAddAsset(AssetManageschoolId);
  178. });
  179. //$(document).on('click', '#savingAsset', handleSavingAsset);
  180. // Pass school ID to the handler
  181. $(document).on('click', '#savingAsset', function () {
  182. handleSavingAsset(AssetManageschoolId);
  183. });
  184. $(document).on('click', '#UpdatingAsset', handelEditAsset);
  185. window.assetManagementEventsBound = true;
  186. }
  187. });
  188. $(document).on('input', '#assetSource, #vendorDetail', function () {
  189. this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, ''); // Allow only alphanumeric + space
  190. });
  191. $(document).on('input', '#serialNumber, #invoiceNumber', function () {
  192. this.value = this.value.replace(/[^a-zA-Z0-9/]/g, ''); // Allow only alphanumeric + "/"
  193. });
  194. function loadSavedBuildingAm(AssetManageschoolId) {
  195. //console.log("hi");
  196. var buttons = [
  197. {
  198. extend: 'pageLength',
  199. className: 'btn btn-warning'
  200. },
  201. {
  202. title: 'Data export',
  203. extend: 'copyHtml5',
  204. text: 'Copy',
  205. className: 'btn btn-secondary',
  206. id: 'copyBtn'
  207. },
  208. {
  209. extend: 'excelHtml5',
  210. text: 'Excel',
  211. className: 'btn btn-secondary',
  212. id: 'excelBtn',
  213. title: 'Asset List'
  214. },
  215. {
  216. extend: 'csvHtml5',
  217. text: 'CSV',
  218. className: 'btn btn-secondary',
  219. id: 'csvBtn',
  220. title: 'Asset List'
  221. },
  222. {
  223. extend: 'pdfHtml5',
  224. text: 'PDF',
  225. className: 'btn btn-secondary',
  226. id: 'pdfBtn',
  227. title: 'Asset List'
  228. },
  229. {
  230. extend: 'print',
  231. text: 'Print',
  232. className: 'btn btn-secondary',
  233. id: 'printBtn',
  234. title: 'Asset List',
  235. exportOptions: {
  236. columns: ':visible:not(.no-print)' // Exclude columns with class 'no-print' from print view
  237. }
  238. }
  239. ];
  240. $.get('/gcc/api/gccschool/buildingasset/getAssetManagement', {school_id: AssetManageschoolId}, res => {
  241. if ($.fn.DataTable.isDataTable('#AssetManageDatatable')) {
  242. $('#AssetManageDatatable').DataTable().clear().destroy(true);
  243. }
  244. //console.log("hello");
  245. let tableData = [];
  246. if (res.status === "Sucess" && Array.isArray(res.data)) {
  247. //console.log("res.data="+res.data);
  248. tableData = res.data;
  249. }
  250. $('#AssetManageDatatable').DataTable({
  251. data: tableData,
  252. columns: [
  253. {data: null, render: (d, t, r, m) => m.row + 1, className: 'text-center'},
  254. {data: 'asset_name'},
  255. {data: 'hardware_type'},
  256. {data: 'source_of_asset'},
  257. {data: 'serial_no'},
  258. {data: 'date_received'},
  259. {data: 'asset_category'},
  260. {data: 'vendor_name'},
  261. {data: 'invoice_num'},
  262. {
  263. data: 'it_details_id',
  264. render: (data, t, row) => `
  265. <div class="text-center">
  266. <button class="btn btn-sm btn-success edit-btn1" data-id="${row.it_details_id}" ><i class="ik ik-edit-2" style="font-size:medium;margin-left:5px;"></i></button>
  267. </div>`, className: 'text-center'
  268. }
  269. ],
  270. lengthMenu: [
  271. [50, 100, 200, 500, -1],
  272. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  273. ],
  274. dom: 'Bftip',
  275. //fixedColumns: {left: 0, right: 0},
  276. scrollY: '70vh',
  277. scrollX: true,
  278. autoWidth: true,
  279. paging: true,
  280. info: true,
  281. buttons: buttons,
  282. responsive: false,
  283. searching: true,
  284. select: false,
  285. processing: false,
  286. language: {
  287. emptyTable: '<span class="text-danger">No Details found</span>'
  288. }
  289. });
  290. });
  291. }
  292. // Load sub asset types on modal open or page load
  293. // Load sub asset types on modal open or page load
  294. $.ajax({
  295. url: '/gcc/api/gccschool/dropdown/getSubAssetType',
  296. type: 'GET',
  297. data: { assetid: 1 }, // or dynamic ID later
  298. success: function (res) {
  299. console.log("Sub Asset API Response:", res);
  300. if (res.status === "OK" && Array.isArray(res.data)) {
  301. $('#assetName').empty().append('<option value="">-- Select Sub Asset Type --</option>');
  302. res.data.forEach(function (item) {
  303. $('#assetName').append(
  304. $('<option>', {
  305. value: item.code,
  306. text: item.asset_name
  307. })
  308. );
  309. });
  310. } else {
  311. $('#assetName').empty().append('<option value="">No Sub Asset Types Found</option>');
  312. }
  313. },
  314. error: function (xhr, status, error) {
  315. console.error("Failed to load sub asset types:", error);
  316. $('#assetName').empty().append('<option value="">Error Loading</option>');
  317. }
  318. });
  319. /*
  320. function handleAddAsset() {
  321. // Get DataTable instance
  322. let Atable = $('#AssetManageDatatable').DataTable();
  323. // Get data from the first row
  324. let firstRowData = Atable.row(0).data();
  325. if (firstRowData && firstRowData.udise) {
  326. let udise = firstRowData.udise;
  327. console.log("UDISE from first row:", udise);
  328. $('#school_udise').text(udise);
  329. $('#assetCode').val('');
  330. $('#assetName').val('');
  331. $('#assetSource').val('');
  332. $('#serialNumber').val('');
  333. $('#vendorDetail').val('');
  334. $('#invoiceNumber').val('');
  335. $('#AddAssetModal2').modal('show');
  336. // You can now use `udise` however you want here
  337. } else {
  338. console.log("No data or UDISE not found in the first row.");
  339. }
  340. }
  341. */
  342. function handleAddAsset(schid) {
  343. $('#AddAssetModal2').modal('show');
  344. $.ajax({
  345. type: 'GET',
  346. url: '/gcc/api/gccschool/schoolproperty/getSchoolDetails',
  347. data: {schoolId: schid},
  348. success: function (data) {
  349. console.log(data);
  350. $('#school_udise').text(data.udise);
  351. },
  352. error: function (xhr) {
  353. console.log("Failed to get udise for school: " + xhr.responseJSON?.message);
  354. }
  355. });
  356. $('#assetCode').val('');
  357. $('#assetName').val('');
  358. $('#assetSource').val('');
  359. $('#serialNumber').val('');
  360. $('#vendorDetail').val('');
  361. $('#invoiceNumber').val('');
  362. }
  363. function handleSavingAsset(assetManageschoolId){
  364. let school_udise = $('#school_udise').text().trim();
  365. // let assetCode = $('#assetCode').val().trim();
  366. //let subAssetId = $('#assetName').val();
  367. //let subAssetId = $('#assetName').val(); // This gives selected value = sub_asset_id
  368. let assetSource = $('#assetSource').val().trim();
  369. let serialNumber = $('#serialNumber').val().trim();
  370. let vendorDetail = $('#vendorDetail').val().trim();
  371. let invoiceNumber = $('#invoiceNumber').val().trim();
  372. //let assetCode = $('#assetName option:selected').text().trim();
  373. let assetCode = $('#assetName').val(); // Get selected value
  374. let assetName = $('#assetName option:selected').text().trim(); // Get selected text
  375. // Console log to verify
  376. console.log("UDISE:", school_udise);
  377. console.log("Asset Code:", assetCode);
  378. console.log("Asset Name:", assetName);
  379. //console.log("Asset Name:", assetName);
  380. console.log("Source:", assetSource);
  381. console.log("Serial Number:", serialNumber);
  382. console.log("Vendor Detail:", vendorDetail);
  383. console.log("Invoice Number:", invoiceNumber);
  384. console.log("assetManageschoolId="+assetManageschoolId);
  385. //console.log("Asset Name:", assetName);
  386. //console.log("Code:", code);
  387. // Validation
  388. /* if (assetCode === '') {
  389. Swal.fire({
  390. icon: 'warning',
  391. title: 'Missing Field',
  392. text: 'Please enter Asset Code',
  393. allowOutsideClick: false,
  394. allowEscapeKey: false,
  395. allowEnterKey: false,
  396. showConfirmButton: true
  397. });
  398. return;
  399. }*/
  400. if (assetCode === '' || assetName === '') {
  401. Swal.fire({
  402. icon: 'warning',
  403. title: 'Missing Field',
  404. text: 'Please Select Name',
  405. allowOutsideClick: false,
  406. allowEscapeKey: false,
  407. allowEnterKey: false,
  408. showConfirmButton: true
  409. });
  410. return;
  411. }
  412. if (assetSource === '') {
  413. Swal.fire({
  414. icon: 'warning',
  415. title: 'Missing Field',
  416. text: 'Please enter Source',
  417. allowOutsideClick: false,
  418. allowEscapeKey: false,
  419. allowEnterKey: false,
  420. showConfirmButton: true
  421. });
  422. return;
  423. }
  424. if (serialNumber === '') {
  425. Swal.fire({
  426. icon: 'warning',
  427. title: 'Missing Field',
  428. text: 'Please enter Serial Number',
  429. allowOutsideClick: false,
  430. allowEscapeKey: false,
  431. allowEnterKey: false,
  432. showConfirmButton: true
  433. });
  434. return;
  435. }
  436. if (vendorDetail === '') {
  437. Swal.fire({
  438. icon: 'warning',
  439. title: 'Missing Field',
  440. text: 'Please enter Vendor Detail',
  441. allowOutsideClick: false,
  442. allowEscapeKey: false,
  443. allowEnterKey: false,
  444. showConfirmButton: true
  445. });
  446. return;
  447. }
  448. console.log(assetManageschoolId);
  449. /*if (invoiceNumber === '') {
  450. Swal.fire({
  451. icon: 'warning',
  452. title: 'Missing Field',
  453. text: 'Please enter Invoice Number',
  454. allowOutsideClick: false,
  455. allowEscapeKey: false,
  456. allowEnterKey: false,
  457. showConfirmButton: true
  458. });
  459. return;
  460. }*/
  461. /* if (assetCode === '') {
  462. Swal.fire('Missing Field', 'Please enter Asset Code', 'warning');
  463. return;
  464. }
  465. if (assetName === '') {
  466. Swal.fire('Missing Field', 'Please enter Name', 'warning');
  467. return;
  468. }
  469. if (assetSource === '') {
  470. Swal.fire('Missing Field', 'Please enter Source', 'warning');
  471. return;
  472. }
  473. if (serialNumber === '') {
  474. Swal.fire('Missing Field', 'Please enter Serial Number', 'warning');
  475. return;
  476. }
  477. if (vendorDetail === '') {
  478. Swal.fire('Missing Field', 'Please enter Vendor Detail', 'warning');
  479. return;
  480. }
  481. if (invoiceNumber === '') {
  482. Swal.fire('Missing Field', 'Please enter Invoice Number', 'warning');
  483. return;
  484. }*/
  485. // AJAX POST
  486. $.ajax({
  487. type: "POST",
  488. url: "/gcc/api/gccschool/buildingasset/addAsset", // your endpoint
  489. data: {
  490. // assetCode: code,
  491. // sub_asset_id: subAssetId,
  492. name:assetName,
  493. code:assetCode,
  494. source: assetSource,
  495. serialNum: serialNumber,
  496. vendorDetail: vendorDetail,
  497. invoice_num: invoiceNumber,
  498. udise: school_udise,
  499. is_online: 0,
  500. school_id: assetManageschoolId
  501. },
  502. success: function (response) {
  503. if (response === "Sucess") {
  504. Swal.fire({
  505. allowOutsideClick: false,
  506. allowEscapeKey: false,
  507. allowEnterKey: false,
  508. icon: 'success',
  509. title: 'Asset Added',
  510. text: 'Asset added successfully!'
  511. }).then(() => {
  512. /* loadSavedBuildingAm(assetManageschoolId);
  513. $('#AddAssetModal2').modal('hide'); */
  514. location.reload();
  515. });
  516. } else {
  517. Swal.fire({
  518. icon: 'error',
  519. title: 'Error',
  520. text: 'Something went wrong while saving asset.'
  521. });
  522. }
  523. },
  524. error: function (xhr, status, error) {
  525. console.error('Error saving assets:', error);
  526. Swal.fire({
  527. icon: 'error',
  528. title: 'Request Failed',
  529. text: 'Unable to send request to the server.'
  530. });
  531. }
  532. });
  533. }
  534. function handleManageEdit(){
  535. console.log("Button clicked");
  536. let id = $(this).data('id');
  537. console.log("id=" + id);
  538. $.ajax({
  539. type: "GET",
  540. url: "/gcc/api/gccschool/buildingasset/getAssets",
  541. data: { it_details_id: id },
  542. success: function (response) {
  543. if (response.status === "Success" && response.data) {
  544. let data = response.data;
  545. // Populate modal fields
  546. $('#editassetCode').val(data.asset_name || '');
  547. $('#editassetName').val(data.hardware_type || '');
  548. $('#editassetSource').val(data.source_of_asset || '');
  549. $('#editserialNumber').val(data.serial_no || '');
  550. $('#editvendorDetail').val(data.vendor_name || '');
  551. $('#editinvoiceNumber').val(data.invoice_num || '');
  552. $('#editid').val(data.it_details_id);
  553. // Show the modal
  554. $('#EditAssetModal2').modal('show');
  555. } else {
  556. Swal.fire('Error', 'Unable to fetch asset details.', 'error');
  557. }
  558. },
  559. error: function (xhr, status, error) {
  560. console.error('Error fetching asset:', error);
  561. Swal.fire('Error', 'Server error while fetching asset.', 'error');
  562. }
  563. });
  564. }
  565. function handelEditAsset(){
  566. let editassetCode = $('#editassetCode').val().trim();
  567. let editassetName = $('#editassetName').val().trim();
  568. let editassetSource = $('#editassetSource').val().trim();
  569. let editserialNumber = $('#editserialNumber').val().trim();
  570. let editvendorDetail = $('#editvendorDetail').val().trim();
  571. let editinvoiceNumber = $('#editinvoiceNumber').val().trim();
  572. let editid= $('#editid').val().trim();
  573. // Validation
  574. /* if (editassetCode === '') {
  575. Swal.fire('Missing Field', 'Please enter Asset Code', 'warning');
  576. return;
  577. }
  578. if (editassetName === '') {
  579. Swal.fire('Missing Field', 'Please enter Name', 'warning');
  580. return;
  581. }
  582. if (editassetSource === '') {
  583. Swal.fire('Missing Field', 'Please enter Source', 'warning');
  584. return;
  585. }
  586. if (editserialNumber === '') {
  587. Swal.fire('Missing Field', 'Please enter Serial Number', 'warning');
  588. return;
  589. }
  590. if (editvendorDetail === '') {
  591. Swal.fire('Missing Field', 'Please enter Vendor Detail', 'warning');
  592. return;
  593. }
  594. if (editinvoiceNumber === '') {
  595. Swal.fire('Missing Field', 'Please enter Invoice Number', 'warning');
  596. return;
  597. }*/
  598. if (editassetCode === '') {
  599. Swal.fire({
  600. icon: 'warning',
  601. title: 'Missing Field',
  602. text: 'Please enter Asset Code',
  603. allowOutsideClick: false,
  604. allowEscapeKey: false,
  605. allowEnterKey: false,
  606. showConfirmButton: true
  607. });
  608. return;
  609. }
  610. if (editassetName === '') {
  611. Swal.fire({
  612. icon: 'warning',
  613. title: 'Missing Field',
  614. text: 'Please enter Name',
  615. allowOutsideClick: false,
  616. allowEscapeKey: false,
  617. allowEnterKey: false,
  618. showConfirmButton: true
  619. });
  620. return;
  621. }
  622. if (editassetSource === '') {
  623. Swal.fire({
  624. icon: 'warning',
  625. title: 'Missing Field',
  626. text: 'Please enter Source',
  627. allowOutsideClick: false,
  628. allowEscapeKey: false,
  629. allowEnterKey: false,
  630. showConfirmButton: true
  631. });
  632. return;
  633. }
  634. if (editserialNumber === '') {
  635. Swal.fire({
  636. icon: 'warning',
  637. title: 'Missing Field',
  638. text: 'Please enter Serial Number',
  639. allowOutsideClick: false,
  640. allowEscapeKey: false,
  641. allowEnterKey: false,
  642. showConfirmButton: true
  643. });
  644. return;
  645. }
  646. if (editvendorDetail === '') {
  647. Swal.fire({
  648. icon: 'warning',
  649. title: 'Missing Field',
  650. text: 'Please enter Vendor Detail',
  651. allowOutsideClick: false,
  652. allowEscapeKey: false,
  653. allowEnterKey: false,
  654. showConfirmButton: true
  655. });
  656. return;
  657. }
  658. /* if (editinvoiceNumber === '') {
  659. Swal.fire({
  660. icon: 'warning',
  661. title: 'Missing Field',
  662. text: 'Please enter Invoice Number',
  663. allowOutsideClick: false,
  664. allowEscapeKey: false,
  665. allowEnterKey: false,
  666. showConfirmButton: true
  667. });
  668. return;
  669. }*/
  670. $.ajax({
  671. type: "POST",
  672. url: "/gcc/api/gccschool/buildingasset/editAsset", // your endpoint
  673. data: {
  674. assetCode: editassetCode,
  675. name: editassetName,
  676. source: editassetSource,
  677. serialNum: editserialNumber,
  678. vendorDetail: editvendorDetail,
  679. invoice_num: editinvoiceNumber,
  680. it_details_id: editid
  681. },
  682. success: function (response) {
  683. if (response === "Success") {
  684. Swal.fire({
  685. allowOutsideClick: false,
  686. allowEscapeKey: false,
  687. allowEnterKey: false,
  688. icon: 'success',
  689. title: 'Asset Updated',
  690. text: 'Asset Updated successfully!'
  691. }).then(() => {
  692. location.reload();
  693. });
  694. } else {
  695. Swal.fire({
  696. icon: 'error',
  697. title: 'Error',
  698. text: 'Something went wrong while updating asset.'
  699. });
  700. }
  701. },
  702. error: function (xhr, status, error) {
  703. console.error('Error updating assets:', error);
  704. Swal.fire({
  705. icon: 'error',
  706. title: 'Request Failed',
  707. text: 'Unable to send request to the server.'
  708. });
  709. }
  710. });
  711. }
  712. </script>
  713. </body>
  714. </html>