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.

707 lines
25 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/modules/base/head :: head}">
  4. <title>Add Electrical Asset In Master</title>
  5. <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  6. <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
  7. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
  9. </head>
  10. <style>
  11. /* Remove background image from the container itself */
  12. .select2-container--default .select2-selection--multiple {
  13. padding-right: 30px;
  14. min-height: 38px;
  15. display: flex;
  16. flex-wrap: wrap;
  17. align-items: center;
  18. position: relative; /* important for the ::after */
  19. background-image: none;
  20. }
  21. /* Add the dropdown arrow via a pseudo-element */
  22. .select2-container--default .select2-selection--multiple::after {
  23. content: "";
  24. position: absolute;
  25. top: 50%;
  26. right: 8px;
  27. width: 14px;
  28. height: 14px;
  29. transform: translateY(-50%);
  30. background-image: url("data:image/svg+xml;utf8,<svg fill='gray' height='20' viewBox='0 0 24 24' width='20' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  31. background-repeat: no-repeat;
  32. background-size: contain;
  33. pointer-events: none;
  34. }
  35. /* Each selected tag */
  36. .select2-container--default .select2-selection--multiple .select2-selection__choice {
  37. display: flex;
  38. align-items: center;
  39. justify-content: space-between;
  40. padding: 5px 10px;
  41. margin: 4px 4px 0 0;
  42. background-color: #f5f5f5;
  43. border: 1px solid #ccc;
  44. border-radius: 4px;
  45. font-size: 13px;
  46. line-height: 1.4;
  47. max-width: 100%;
  48. white-space: nowrap;
  49. overflow: hidden;
  50. text-overflow: ellipsis;
  51. }
  52. /* The text inside the tag */
  53. .select2-container--default .select2-selection--multiple .select2-selection__choice__display {
  54. overflow: hidden;
  55. text-overflow: ellipsis;
  56. white-space: nowrap;
  57. flex: 1;
  58. margin-right: 8px;
  59. }
  60. /* The "X" close icon */
  61. .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  62. position: static;
  63. transform: none;
  64. color: #333;
  65. font-size: 14px;
  66. font-weight: bold;
  67. cursor: pointer;
  68. background: transparent;
  69. border: none;
  70. line-height: 1;
  71. }
  72. </style>
  73. <body>
  74. <div class="wrapper">
  75. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  76. <div class="page-wrap">
  77. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  78. <div class="card">
  79. <div class="main-content" style="background-color: white;">
  80. <div class="container">
  81. <!-- Card 2: Other Details -->
  82. <div class="col-md-12">
  83. <div style="padding: 0px;margin-top:-58px;margin-left: -233px;">
  84. <div class="card-header d-flex justify-content-between align-items-center">
  85. <b>List of Electrical Assets</b>
  86. <button type="button" class="btn btn-primary add-ebtn"> <i class="ik ik-plus"></i>Add Assets</button>
  87. </div>
  88. <div class="card-body" style="padding: 5px;">
  89. <table id="EAssetManageDatatable"
  90. class="table table-striped table-bordered table-hover dataTable" role="grid"
  91. style="width: 100%">
  92. <thead class="thead-dark">
  93. <tr>
  94. <th>S.NO</th>
  95. <th>ASSET TYPE</th>
  96. <th>MASTER QTY</th>
  97. <th>MAPPED QTY</th>
  98. <th>UNMAPPED QTY</th>
  99. <th>ACTION</th>
  100. </tr>
  101. </thead>
  102. <tbody>
  103. </tbody>
  104. </table>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. <div id="pageLoader"
  110. 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;">
  111. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  112. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  113. <span class="sr-only">Loading...</span>
  114. </div>
  115. <!-- Add the 'Please wait' text below the spinner -->
  116. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="modal fade" id="AddEAssetModal" tabindex="-1" role="dialog" aria-labelledby="AddEAssetModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  124. <div class="modal-dialog modal-lg" role="document">
  125. <div class="modal-content">
  126. <div class="modal-header">
  127. <h5 class="modal-title">
  128. Add Electrical Assets
  129. </h5>
  130. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  131. <span aria-hidden="true">&times;</span>
  132. </button>
  133. </div>
  134. <div class="modal-body">
  135. <div class="row">
  136. <div class="form-group col-6">
  137. <label>Select Asset <span style="color: red;">*</span></label>
  138. <select id="subAssetType" class="form-control" multiple></select>
  139. </div>
  140. </div>
  141. <div id="selectedAssetsContainer" class="mt-3"></div>
  142. <div class="row pb-2 mt-4" id="savingcontainer" style="display: none;">
  143. <div class="col-12 d-flex justify-content-center">
  144. <button type="button" class="btn btn-primary" id="savingEAsset">Save</button>
  145. </div>
  146. </div>
  147. </div>
  148. <div class="modal-footer">
  149. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. <div class="modal fade" id="EditEAssetModal" tabindex="-1" role="dialog" aria-labelledby="EditEAssetModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
  155. <div class="modal-dialog modal-lg" role="document">
  156. <div class="modal-content">
  157. <div class="modal-header">
  158. <h5 class="modal-title">
  159. <span id="Eeditassetname"></span> - Edit Electrical Asset
  160. </h5>
  161. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  162. <span aria-hidden="true">&times;</span>
  163. </button>
  164. </div>
  165. <div class="modal-body">
  166. <span id="Eeditid" style="display: none;"></span>
  167. <div class="row">
  168. <div class="form-group col-6">
  169. <label for="Emaster_qty">Master Quantity &nbsp;(&nbsp;Already in master&nbsp;<span id="AEmaster_qty" style="font-style: italic;font-weight: bold;"></span>&nbsp;)<span class="text-danger">*</span></label>
  170. <input type="text" class="form-control" id="Emaster_qty" name="Emaster_qty">
  171. </div>
  172. <div class="form-group col-6">
  173. <label for="Emapped_qty">Mapped Quantity</label>
  174. <input type="text" class="form-control" id="Emapped_qty" name="Emapped_qty" readonly>
  175. </div>
  176. <div class="form-group col-6">
  177. <label for="">Unmapped Quantity</label>
  178. <input type="text" class="form-control" id="Eunmapped_qty" name="Eunmapped_qty" readonly>
  179. </div>
  180. </div>
  181. <div class="row pb-2 mt-4">
  182. <div class="col-12 d-flex justify-content-center">
  183. <button type="button" class="btn btn-primary" id="UpdatingEAsset">Update</button>
  184. </div>
  185. </div>
  186. </div>
  187. <div class="modal-footer">
  188. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  194. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  195. <script type="text/javascript">
  196. console.log("hi electrical assets...");
  197. $(document).ready(function () {
  198. let ElectricalAsseturlParams = new URLSearchParams(window.location.search);
  199. let EAssetschoolId = ElectricalAsseturlParams.get("schoolId");
  200. loadEAsset(EAssetschoolId);
  201. // Only run after DOM and libraries are ready
  202. $('#subAssetType').on('select2:opening', function() {
  203. setTimeout(() => {
  204. $('.select2-search__field').prop('readonly', true); // disable typing
  205. }, 0);
  206. });
  207. if (!window.EassetEventsBound) {
  208. $(document).on('click', '.add-ebtn', function () {
  209. handleAddEAsset(EAssetschoolId);
  210. });
  211. $(document).on('click', '#savingEAsset', function () {
  212. handleSaveEAsset(EAssetschoolId);
  213. });
  214. $(document).on('click', '.edit-btne', handleEAssetEdit);
  215. $(document).on('click', '#UpdatingEAsset', handelEditEAsset);
  216. window.EassetEventsBound = true;
  217. }
  218. $('#subAssetType').on('change', function () {
  219. console.log("hi...");
  220. const selectedOptions = $(this).find('option:selected');
  221. const $container = $('#selectedAssetsContainer');
  222. $container.empty(); // Clear previous entries
  223. if (selectedOptions.length >= 1) {
  224. $('#savingcontainer').show();
  225. } else {
  226. $('#savingcontainer').hide();
  227. }
  228. let labelRow = '';
  229. let inputRow = '';
  230. let counter = 0;
  231. selectedOptions.each(function (index) {
  232. const assetName = $(this).text();
  233. const assetId = $(this).val();
  234. // Start new row every 3 items
  235. if (counter % 3 === 0) {
  236. if (labelRow || inputRow) {
  237. labelRow += '</div>';
  238. inputRow += '</div>';
  239. $container.append(labelRow);
  240. $container.append(inputRow);
  241. }
  242. labelRow = '<div class="row mb-1">';
  243. inputRow = '<div class="row mb-3">';
  244. }
  245. labelRow += `
  246. <div class="col-md-4">
  247. <label><b>${assetName}</b></label>
  248. </div>
  249. `;
  250. inputRow += `
  251. <div class="col-md-4">
  252. <input type="number" class="form-control" name="assetQuantity_${assetId}" placeholder="Enter Quantity" min="0">
  253. </div>
  254. `;
  255. counter++;
  256. });
  257. // Append remaining items
  258. if (labelRow || inputRow) {
  259. labelRow += '</div>';
  260. inputRow += '</div>';
  261. $container.append(labelRow);
  262. $container.append(inputRow);
  263. }
  264. });
  265. });
  266. function handleEAssetEdit(){
  267. console.log("Button clicked");
  268. let id = $(this).data('id');
  269. console.log("id=" + id);
  270. $.ajax({
  271. type: "GET",
  272. url: "/gcc/api/gccschool/schoolproperty/getAssetMasterById",
  273. data: { assetMasterId: id,asset_id:2 },
  274. success: function (response) {
  275. if (response.status === "Success" && response.data) {
  276. let data = response.data;
  277. // Populate modal fields
  278. $('#Eeditassetname').text(data.asset_name || '');
  279. //$('#Emaster_qty').val(data.master_qty || '');
  280. $('#Emapped_qty').val(data.mapped_qty || '');
  281. $('#Eunmapped_qty').val(data.unmapped_qty || '');
  282. $('#Eeditid').val(data.electrical_master_id);
  283. $('#AEmaster_qty').text(data.master_qty || '');
  284. // Show the modal
  285. $('#EditEAssetModal').modal('show');
  286. } else {
  287. Swal.fire('Error', 'Unable to fetch Electrical asset details.', 'error');
  288. }
  289. },
  290. error: function (xhr, status, error) {
  291. console.error('Error fetching Electrical asset:', error);
  292. Swal.fire('Error', 'Server error while fetching Electrical asset.', 'error');
  293. }
  294. });
  295. }
  296. function loadEAsset(schoolId) {
  297. //console.log("vvvvvvvvvv");
  298. var buttons = [
  299. {
  300. extend: 'pageLength',
  301. className: 'btn btn-warning'
  302. },
  303. {
  304. title: 'Data export',
  305. extend: 'copyHtml5',
  306. text: 'Copy',
  307. className: 'btn btn-secondary',
  308. id: 'copyBtn'
  309. },
  310. {
  311. extend: 'excelHtml5',
  312. text: 'Excel',
  313. className: 'btn btn-secondary',
  314. id: 'excelBtn',
  315. title: 'Electrical Asset List'
  316. },
  317. {
  318. extend: 'csvHtml5',
  319. text: 'CSV',
  320. className: 'btn btn-secondary',
  321. id: 'csvBtn',
  322. title: 'Electrical Asset List'
  323. },
  324. {
  325. extend: 'pdfHtml5',
  326. text: 'PDF',
  327. className: 'btn btn-secondary',
  328. id: 'pdfBtn',
  329. title: 'Electrical Asset List'
  330. },
  331. {
  332. extend: 'print',
  333. text: 'Print',
  334. className: 'btn btn-secondary',
  335. id: 'printBtn',
  336. title: 'Electrical Asset List',
  337. exportOptions: {
  338. columns: ':visible:not(.no-print)' // Exclude columns with class 'no-print' from print view
  339. }
  340. }
  341. ];
  342. $.get('/gcc/api/gccschool/schoolproperty/getAssetMaster', {school_id: schoolId,asset_id:2}, res => {
  343. if ($.fn.DataTable.isDataTable('#EAssetManageDatatable')) {
  344. $('#EAssetManageDatatable').DataTable().clear().destroy(true);
  345. }
  346. //console.log("hello");
  347. let tableData = [];
  348. if (res.status === "Success" && Array.isArray(res.data)) {
  349. //console.log("res.data="+res.data);
  350. tableData = res.data;
  351. }
  352. $('#EAssetManageDatatable').DataTable({
  353. data: tableData,
  354. columns: [
  355. {data: null, render: (d, t, r, m) => m.row + 1, className: 'text-center'},
  356. {data: 'asset_name',className: 'text-center'},
  357. {data: 'master_qty',className: 'text-center'},
  358. {
  359. data: 'mapped_qty',className: 'text-center',
  360. render: data => data != null ? data : '-'
  361. },
  362. {
  363. data: 'unmapped_qty',className: 'text-center',
  364. render: data => data != null ? data : '-'
  365. },
  366. {
  367. data: 'electrical_master_id',
  368. render: (data, t, row) => `
  369. <div class="text-center">
  370. <button class="btn btn-sm btn-success edit-btne" data-id="${row.electrical_master_id}" ><i class="ik ik-edit-2" style="font-size:medium;margin-left:5px;"></i></button>
  371. </div>`, className: 'text-center'
  372. }
  373. ],
  374. lengthMenu: [
  375. [50, 100, 200, 500, -1],
  376. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  377. ],
  378. dom: 'Bftip',
  379. //fixedColumns: {left: 0, right: 0},
  380. scrollY: '70vh',
  381. scrollX: true,
  382. autoWidth: true,
  383. paging: true,
  384. info: true,
  385. buttons: buttons,
  386. responsive: false,
  387. searching: true,
  388. select: false,
  389. processing: false,
  390. language: {
  391. emptyTable: '<span class="text-danger">No Details found</span>'
  392. }
  393. });
  394. });
  395. }
  396. function loadsubassets(schoolId) {
  397. $.ajax({
  398. url: '/gcc/api/gccschool/dropdown/getSplSubAssetType',
  399. type: 'GET',
  400. data: { school_id:schoolId,assetid: 2 },
  401. success: function (response) {
  402. const $court = $('#subAssetType');
  403. $court.empty();
  404. if (response.status === 'OK' && Array.isArray(response.data)) {
  405. response.data.forEach(item => {
  406. $court.append(`<option value="${item.sub_asset_id}">${item.asset_name}</option>`);
  407. });
  408. } else {
  409. $court.append('<option value="">No Data Found</option>');
  410. }
  411. if ($court.hasClass("select2-hidden-accessible")) {
  412. $court.select2('destroy');
  413. }
  414. $court.select2({
  415. placeholder: "Select Asset",
  416. width: '100%',
  417. minimumResultsForSearch: Infinity,
  418. closeOnSelect: false
  419. });
  420. },
  421. error: function () {
  422. const $court = $('#subAssetType');
  423. $court.empty().append('<option value="">Error loading data</option>');
  424. if ($court.hasClass("select2-hidden-accessible")) {
  425. $court.select2('destroy');
  426. }
  427. $court.select2({
  428. placeholder: "Select Asset",
  429. width: '100%',
  430. minimumResultsForSearch: Infinity,
  431. closeOnSelect: false
  432. });
  433. alert("Something went wrong while fetching asset sub types.");
  434. }
  435. });
  436. }
  437. function handleAddEAsset(schoolId) {
  438. $('#savingcontainer').hide();
  439. $('#subAssetType').empty();
  440. $('#selectedAssetsContainer').empty();
  441. loadsubassets(schoolId);
  442. // Then show the modal
  443. $('#AddEAssetModal').modal('show');
  444. }
  445. function handleSaveEAsset(EAssetschoolId) {
  446. $('#savingEAsset').prop('disabled', true).text('Saving...');
  447. const selectedAssets = $('#subAssetType').val(); // array of selected sub_asset_id
  448. const assetData = [];
  449. if (!selectedAssets || selectedAssets.length === 0) {
  450. $('#savingEAsset').prop('disabled', false).text('Save');
  451. Swal.fire({
  452. icon: 'warning',
  453. title: 'Missing Field',
  454. text: 'Please select at least one asset.',
  455. });
  456. return;
  457. }
  458. let hasError = false;
  459. let hasZero = false;
  460. let errorAssets = [];
  461. let zeroAssets = [];
  462. selectedAssets.forEach(function (subAssetId) {
  463. const quantityInput = $(`input[name="assetQuantity_${subAssetId}"]`);
  464. const quantity = quantityInput.val();
  465. const assetName = $(`#subAssetType option[value="${subAssetId}"]`).text(); // Get asset name
  466. if (!quantity || isNaN(quantity) || parseInt(quantity) < 0) {
  467. hasError = true;
  468. errorAssets.push(assetName);
  469. } else if (parseInt(quantity) === 0) {
  470. hasZero = true;
  471. zeroAssets.push(assetName);
  472. } else {
  473. assetData.push({
  474. sub_asset_id: subAssetId,
  475. master_qty: parseInt(quantity)
  476. });
  477. }
  478. });
  479. if (hasError) {
  480. $('#savingEAsset').prop('disabled', false).text('Save');
  481. Swal.fire({
  482. icon: 'warning',
  483. title: 'Validation Error',
  484. html: `Please enter a valid quantity for the following assets:<br><b>${errorAssets.join(', ')}</b>`,
  485. });
  486. return;
  487. }
  488. if (hasZero) {
  489. $('#savingEAsset').prop('disabled', false).text('Save');
  490. Swal.fire({
  491. icon: 'warning',
  492. title: 'Zero Quantity Error',
  493. html: `You have entered 0 for the following assets:<br><b>${zeroAssets.join(', ')}</b><br>Please remove them from the selection or enter a valid quantity.`,
  494. allowOutsideClick: false,
  495. allowEscapeKey: false,
  496. showConfirmButton: true
  497. });
  498. return;
  499. }
  500. const payload = {
  501. school_id: EAssetschoolId,
  502. asset_id: "2", // electrical asset
  503. data: assetData
  504. };
  505. console.log("Final Payload to Save:", payload);
  506. $.ajax({
  507. url: '/gcc/api/gccschool/schoolproperty/saveAssetMaster',
  508. type: 'POST',
  509. contentType: 'application/json',
  510. data: JSON.stringify(payload),
  511. success: function(response) {
  512. $('#savingEAsset').prop('disabled', false).text('Save');
  513. if (response.status === 'OK') {
  514. //Swal.fire('Success', response.message, 'success');
  515. //$('#AddEAssetModal').modal('hide');
  516. Swal.fire({
  517. allowOutsideClick: false,
  518. allowEscapeKey: false,
  519. allowEnterKey: false,
  520. icon: 'success',
  521. title: 'Success',
  522. text: response.message
  523. }).then(() => {
  524. location.reload();
  525. });
  526. } else {
  527. Swal.fire('Error', response.message, 'error');
  528. }
  529. },
  530. error: function() {
  531. $('#savingEAsset').prop('disabled', false).text('Save');
  532. Swal.fire('Error', 'Something went wrong while saving assets.', 'error');
  533. }
  534. });
  535. }
  536. function handelEditEAsset(){
  537. let emaster_qty = $('#Emaster_qty').val();
  538. let eassetMasterId = $('#Eeditid').val();
  539. console.log("emaster_qty"+emaster_qty);
  540. console.log("eassetMasterId"+eassetMasterId);
  541. if (!emaster_qty || isNaN(emaster_qty)) {
  542. Swal.fire({
  543. icon: 'warning',
  544. title: 'Invalid Quantity',
  545. text: 'Please enter a valid Master Quantity',
  546. });
  547. return;
  548. }
  549. if (!eassetMasterId || isNaN(eassetMasterId)) {
  550. Swal.fire({
  551. icon: 'warning',
  552. title: 'Missing ID',
  553. text: 'Electrical Asset ID is missing or invalid.',
  554. });
  555. return;
  556. }
  557. $.ajax({
  558. type: "POST",
  559. url: "/gcc/api/gccschool/schoolproperty/updateAssetMaster", // your endpoint
  560. data: {
  561. master_qty: parseInt(emaster_qty),
  562. assetMasterId: parseInt(eassetMasterId),
  563. asset_id:2
  564. },
  565. success: function (response) {
  566. if (response === "Success") {
  567. Swal.fire({
  568. allowOutsideClick: false,
  569. allowEscapeKey: false,
  570. allowEnterKey: false,
  571. icon: 'success',
  572. title: 'Asset Updated',
  573. text: 'Asset Updated successfully!'
  574. }).then(() => {
  575. location.reload();
  576. });
  577. } else {
  578. Swal.fire({
  579. icon: 'error',
  580. title: 'Error',
  581. text: 'Something went wrong while updating asset.'
  582. });
  583. }
  584. },
  585. error: function (xhr, status, error) {
  586. console.error('Error updating assets:', error);
  587. Swal.fire({
  588. icon: 'error',
  589. title: 'Request Failed',
  590. text: 'Unable to send request to the server.'
  591. });
  592. }
  593. });
  594. }
  595. </script>
  596. </body>
  597. </html>