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.

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