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.

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