Victoria Hall Booking for Events
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.

423 lines
13 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/head-admin :: head}"></head>
  4. <meta charset="ISO-8859-1">
  5. </head>
  6. <body>
  7. <style>
  8. .small-input {
  9. width: 150px;
  10. /* Adjust the width as needed */
  11. }
  12. .small-table th,
  13. .small-table td {
  14. font-size: 14px;
  15. /* Adjust font size as needed */
  16. }
  17. /* Reduce padding for table cells */
  18. .small-table td,
  19. .small-table th {
  20. padding: 5px;
  21. /* Adjust padding as needed */
  22. }
  23. </style>
  24. <body>
  25. <!-- Page Container -->
  26. <div id="page-container"
  27. class="sidebar-o sidebar-dark enable-page-overlay side-scroll page-header-fixed page-header-dark">
  28. <!-- Side Overlay aside (right)-->
  29. <aside th:replace="~{fragments/aside-right :: aside}"></aside>
  30. <!-- END Side Overlay (right)-->
  31. <!-- Sidebar Nav-->
  32. <nav th:replace="~{fragments/nav-admin :: nav}"></nav>
  33. <!-- END Sidebar -->
  34. <!-- Header -->
  35. <header th:replace="~{fragments/header-admin :: header}"></header>
  36. <!-- END Header -->
  37. <!-- Main Container -->
  38. <main id="main-container">
  39. <div class="content">
  40. <div class="block block-rounded">
  41. <div class="block-header block-header-default">
  42. <h3 class="block-title"> Discount Range</h3>
  43. <div class="block-options">
  44. <button type="button" class="btn-block-option" id="addButton" onclick="adddiscount()"><i
  45. class="far fa-plus-square"></i> Add New Discount</button>
  46. </div>
  47. </div>
  48. <!-- Page Content -->
  49. <div class="content">
  50. <div class="block block-rounded">
  51. <div class="block-content p-0">
  52. <div class="p-sm-4 p-0">
  53. <div class="table-responsive">
  54. <table id="discountrangetable"
  55. class="table table-bordered table-striped table-vcenter js-dataTable-responsive">
  56. <thead class="thead-light">
  57. <tr class="table-bordered">
  58. <th class="text-center no-sort">S.No</th>
  59. <th class="text-center" width="20%">UserType</th>
  60. <th class="text-center">DiscountRange</th>
  61. <th class="text-center"> Cdate</th>
  62. <th class="text-center">UpdatedBy</th>
  63. <th class="text-center">Action</th>
  64. </tr>
  65. </thead>
  66. <tbody>
  67. <tr th:each="discountRange, rowStat : ${discountRanges}">
  68. <td class="text-center" th:text="${rowStat.index + 1}"></td>
  69. <td class="text-center" th:text="${discountRange.usertype}">
  70. </td>
  71. <td class="text-center"
  72. th:text="${discountRange.discountRange}"></td>
  73. <td class="text-center" th:text="${discountRange.cDate}"></td>
  74. <td class="text-center" th:text="${discountRange.updtedBy}">
  75. </td>
  76. <td class="text-center">
  77. <a href="javascript:void(0);"
  78. th:onclick="'openEditModal(' + ${discountRange.id} + ');'"
  79. data-bs-toggle="tooltip" data-bs-animation="true"
  80. data-bs-placement="top" title="Edit">
  81. <i class="far fa-pen-to-square" style="font-size: 18px;"></i>
  82. </a>&nbsp;&nbsp;
  83. <a href="javascript:void(0);"
  84. th:onclick="return callDelete( [[${discountRange.id}]] );"
  85. data-bs-toggle="tooltip" data-bs-animation="true"
  86. data-bs-placement="top" title="Delete"><i
  87. class="far fa-trash-can"
  88. style="font-size: 18px;"></i></a>
  89. </a>
  90. </td>
  91. </tr>
  92. </tbody>
  93. </table>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. <!-- new Discount -->
  100. <div class="modal fade" id="saveModal" tabindex="-1" role="dialog"
  101. aria-labelledby="saveModalLabel" aria-hidden="true">
  102. <div class="modal-dialog" role="document">
  103. <div class="modal-content">
  104. <div class="modal-header">
  105. <h5 class="modal-title" id="saveModalLabel">Save Discount Range</h5>
  106. <button type="button" class="btn-block-option" data-bs-dismiss="modal">
  107. <i class="fa fa-fw fa-times"></i>
  108. </button>
  109. </div>
  110. <div class="modal-body">
  111. <form id="saveForm">
  112. <div class="form-group">
  113. <label for="userType">User Type</label>
  114. <select class="form-control" id="userType" name="userType" required>
  115. <option value="">Select</option>
  116. <option value="PUBLIC">PUBLIC</option>
  117. <option value="PENSIONER">PENSIONER</option>
  118. <option value="COUNCILLOR">COUNCILLOR</option>
  119. <option value="GCC_EMPLOYEE">GCC EMPLOYEE</option>
  120. </select>
  121. </div>
  122. <div class="form-group">
  123. <label for="editDiscountRange">Discount Range in Percentage</label>
  124. <input type="text" class="form-control" id="discountRange"
  125. name="discountRange" placeholder="Discount Range in %" required>
  126. </div>
  127. </form>
  128. </div>
  129. <div class="modal-footer">
  130. <button type="button" class="btn btn-secondary"
  131. data-bs-dismiss="modal">Close</button>
  132. <button type="button" class="btn btn-primary" id="savediscounts">Save</button>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. <!-- Edit Form -->
  138. <div class="modal fade" id="editModal" tabindex="-1" role="dialog"
  139. aria-labelledby="editModalLabel" aria-hidden="true">
  140. <div class="modal-dialog" role="document">
  141. <div class="modal-content">
  142. <div class="modal-header">
  143. <h5 class="modal-title" id="editModalLabel">Edit Discount Range</h5>
  144. <button type="button" class="btn-block-option" data-bs-dismiss="modal">
  145. <i class="fa fa-fw fa-times"></i>
  146. </button>
  147. </div>
  148. <div class="modal-body">
  149. <form id="editForm">
  150. <input type="hidden" id="editId">
  151. <div class="form-group">
  152. <label for="editUsertype">User Type</label>
  153. <input type="text" class="form-control" id="editUsertype" readonly>
  154. </div>
  155. <div class="form-group">
  156. <label for="editDiscountRange">Discount Range in Percentage</label>
  157. <input type="text" class="form-control" id="editDiscountRange"
  158. placeholder="Discount Range in %" required>
  159. </div>
  160. <div class="form-group">
  161. <label for="editCDate">Creation Date</label>
  162. <input type="date" class="form-control" id="editCDate" readonly>
  163. </div>
  164. <div class="form-group">
  165. <label for="editUpdatedBy">Updated By</label>
  166. <input type="text" class="form-control" id="editUpdatedBy" readonly>
  167. </div>
  168. </form>
  169. </div>
  170. <div class="modal-footer">
  171. <button type="button" class="btn btn-secondary"
  172. data-bs-dismiss="modal">Close</button>
  173. <button type="button" class="btn btn-primary" id="saveChanges">Save
  174. changes</button>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. </main>
  180. <div th:replace="~{fragments/resetpassword :: div}"></div>
  181. <footer th:replace="~{fragments/footer2 :: footer}"></footer>
  182. <script th:replace="~{fragments/loginscript :: script}"></script>
  183. <script>
  184. $(document).ready(
  185. function () {
  186. var buttons = [{
  187. extend: 'pageLength',
  188. className: 'btn btn-primary'
  189. }, {
  190. title: 'Data export',
  191. extend: 'copyHtml5',
  192. text: 'Copy',
  193. className: 'btn btn-primary',
  194. id: 'copyBtn'
  195. }, {
  196. extend: 'excelHtml5',
  197. text: 'Excel',
  198. className: 'btn btn-primary',
  199. id: 'excelBtn'
  200. }, {
  201. extend: 'csvHtml5',
  202. text: 'CSV',
  203. className: 'btn btn-primary',
  204. id: 'csvBtn'
  205. }, {
  206. extend: 'pdfHtml5',
  207. text: 'PDF',
  208. className: 'btn btn-primary',
  209. id: 'pdfBtn'
  210. },
  211. ];
  212. $('#discountrangetable').DataTable(
  213. {
  214. dom: 'Bftip',
  215. columnDefs: [{
  216. targets: 'no-sort',
  217. orderable: false
  218. }],
  219. lengthMenu: [
  220. [50, 100, 200, 500, -1],
  221. ['50 rows', '100 rows', '200 rows',
  222. '500 rows', 'Show all']],
  223. scrollY: '50vh',
  224. fixedColumns: {
  225. left: 1,
  226. right: 1
  227. },
  228. buttons: [buttons],
  229. responsive: true,
  230. searching: true, // Enable search
  231. select: false,
  232. processing: false,
  233. });
  234. // Link the search input to DataTable
  235. $('#searchInput').on('keyup', function () {
  236. dataTable.search(this.value).draw();
  237. });
  238. });
  239. function openEditModal(id) {
  240. $.ajax({
  241. type: "GET",
  242. url: '/victoriahallbooking/admin/api/getDiscountDetails',
  243. data: {
  244. 'id': id
  245. },
  246. success: function (response) {
  247. $('#editId').val(response.id);
  248. $('#editUsertype').val(response.usertype);
  249. $('#editDiscountRange').val(response.discountRange);
  250. $('#editCDate').val(response.cDate);
  251. $('#editUpdatedBy').val(response.updtedBy);
  252. $('#editModal').modal('show');
  253. }
  254. });
  255. }
  256. function adddiscount() {
  257. $('#saveModal').modal('show');
  258. }
  259. $('#savediscounts').click(function () {
  260. var userType = $('#userType').val();
  261. var discountRange = $('#discountRange').val();
  262. //console.log('User Type:', userType);
  263. //console.log('Discount Range:', discountRange);
  264. if(!userType){
  265. Swal.fire({
  266. icon: 'warning',
  267. title: 'No User Type Selected',
  268. text: 'Please select an usertype to update.',
  269. });
  270. return;
  271. }
  272. $.ajax({
  273. type: "POST",
  274. url: "/victoriahallbooking/admin/api/savediscountrange",
  275. data: {
  276. userType: userType,
  277. discountRange: discountRange,
  278. },
  279. success: function (data) {
  280. if (data === 'waiting') {
  281. Swal.fire(
  282. 'EXISTED!',
  283. 'User type already exists. Update or Delete the usertype',
  284. 'info'
  285. ).then(() => {
  286. location.reload();
  287. });
  288. } else if (data === 'success') {
  289. Swal.fire(
  290. 'Saved!',
  291. 'Details saved successfully.',
  292. 'success'
  293. ).then(() => {
  294. location.reload();
  295. });
  296. }
  297. },
  298. error: function (xhr, status, error) {
  299. Swal.fire(
  300. 'Error!',
  301. 'Failed to update the discount range.',
  302. 'error'
  303. );
  304. }
  305. });
  306. });
  307. $('#saveChanges').click(function () {
  308. var id = $('#editId').val();
  309. var discountRange = $('#editDiscountRange').val();
  310. // Log the data to the console for debugging
  311. $.ajax({
  312. type: "PUT",
  313. url: "/victoriahallbooking/admin/api/updateById/" + id,
  314. data: {
  315. 'id': id,
  316. 'discountRange': discountRange,
  317. },
  318. success: function (data) {
  319. Swal.fire(
  320. 'Updated!',
  321. 'Discount range ' + id + ' has been updated.',
  322. 'success'
  323. ).then(() => {
  324. location.reload();
  325. });
  326. },
  327. error: function (xhr, status, error) {
  328. console.error('Error occurred during the PUT request:', xhr.responseText);
  329. Swal.fire(
  330. 'Error!',
  331. 'Failed to update the discount range ' + id + ': ' + xhr.responseText,
  332. 'error'
  333. );
  334. }
  335. });
  336. });
  337. function callDelete(id) {
  338. Swal.fire({
  339. title: 'Are you sure you want to delete this?',
  340. text: "You won't be able to revert this!",
  341. icon: 'warning',
  342. showCancelButton: true,
  343. confirmButtonColor: '#3085d6',
  344. cancelButtonColor: '#d33',
  345. confirmButtonText: 'Yes, delete it!'
  346. }).then(function (result) {
  347. if (result.isConfirmed) {
  348. $.ajax({
  349. type: "DELETE",
  350. url: "/victoriahallbooking/admin/api/deleteById/" + id,
  351. success: function (data) {
  352. Swal.fire(
  353. 'Deleted!',
  354. 'Entry ' + id + ' has been deleted.',
  355. 'success'
  356. ).then(() => {
  357. location.reload();
  358. });
  359. },
  360. error: function (xhr, status, error) {
  361. Swal.fire(
  362. 'Error!',
  363. 'Failed to delete entry ' + id + ': ' + xhr.responseText,
  364. 'error'
  365. );
  366. }
  367. });
  368. }
  369. });
  370. }
  371. document.addEventListener('DOMContentLoaded', function () {
  372. function clearModalFields(modalId) {
  373. const modal = document.getElementById(modalId);
  374. if (modal) {
  375. // Clear text inputs and select elements
  376. modal.querySelectorAll('input[type="text"], input[type="date"], select').forEach(input => {
  377. if (input.tagName === 'SELECT') {
  378. input.selectedIndex = 0; // Reset to default option
  379. } else {
  380. input.value = ''; // Clear text inputs
  381. }
  382. });
  383. }
  384. }
  385. // Clear fields when the saveModal is hidden
  386. document.getElementById('saveModal').addEventListener('hidden.bs.modal', function () {
  387. clearModalFields('saveModal');
  388. });
  389. });
  390. </script>
  391. </body>
  392. </html>