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.

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