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.

295 lines
9.5 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/head-counter :: head}">
  4. <title>Calculate Hall Amount</title>
  5. </head>
  6. <style>
  7. @media (min-width: 992px) {
  8. .col-lg-12 {
  9. flex: 0 0 auto;
  10. width: 92%;
  11. margin-left: 45px;
  12. }
  13. }
  14. </style>
  15. <body>
  16. <div id="page-container"
  17. class="sidebar-o sidebar-dark enable-page-overlay side-scroll page-header-fixed page-header-dark">
  18. <aside th:replace="~{fragments/aside-right :: aside}"></aside>
  19. <nav th:replace="~{fragments/nav-counter :: nav}"></nav>
  20. <header th:replace="~{fragments/header-counter :: header}"></header>
  21. <main id="main-container">
  22. <div class="content">
  23. <div class="block block-rounded">
  24. <div class="block-header block-header-default">
  25. <h3 class="block-title">Calculate Hall Amount</h3>
  26. </div>
  27. <div class="block-content p-0">
  28. <div class="p-sm-4 p-0">
  29. <div class="row justify-content-center">
  30. <div class="col-sm-4 col-lg-4 col-md-4">
  31. <label for="selecthall">Select Hall:</label>
  32. <select id="selecthall" class="form-control" name="hallId" required>
  33. <option value="">Select a hall</option>
  34. <!-- Dynamically populated options will be inserted here -->
  35. </select>
  36. </div>
  37. <br>
  38. <br>
  39. <div id="amountDetails" style="display:none; margin-top: 26px; width: 68%;">
  40. <table class="table table-bordered">
  41. <thead>
  42. <tr>
  43. <th scope="col">Description</th>
  44. <th scope="col">Amount</th>
  45. </tr>
  46. </thead>
  47. <tbody>
  48. <tr>
  49. <td>Full Day Amount</td>
  50. <td id="fullDayAmount"></td>
  51. </tr>
  52. <tr>
  53. <td>Half Day Amount</td>
  54. <td id="halfDayAmount"></td>
  55. </tr>
  56. <tr>
  57. <td>Deposit Amount</td>
  58. <td id="depositAmount"></td>
  59. </tr>
  60. <tr>
  61. <td>GST</td>
  62. <td id="gst"></td>
  63. </tr>
  64. </tbody>
  65. </table>
  66. <div class="row justify-content-center">
  67. <div class="col-sm-4 col-lg-4 col-md-4"> <label for="numDaysCount">Number of
  68. Days:</label>
  69. <select class="form-control" id="numDaysCount" name="days" required>
  70. <option value="select">select</option>
  71. <option value="1">1</option>
  72. <option value="2">2</option>
  73. <option value="3">3</option>
  74. <option value="4">4</option>
  75. <option value="5">5</option>
  76. <option value="6">6</option>
  77. <option value="7">7</option>
  78. </select>
  79. </div>
  80. <div class="col-sm-4 col-lg-4 col-md-4"> <label for="startPeriodDropdown">Start
  81. Period:</label>
  82. <select id="startPeriodDropdown" name="startingSlot" class="form-control"
  83. required>
  84. <option value="">select</option>
  85. <option value="1">Morning (6:00 AM)</option>
  86. <option value="2">Evening (2:00 PM)</option>
  87. </select>
  88. </div>
  89. <div class="col-sm-4 col-lg-4 col-md-4"> <label for="endPeriodDropdown">End
  90. Period:</label>
  91. <select id="endPeriodDropdown" name="endingSlot" class="form-control"
  92. required>
  93. <option value="">select</option>
  94. <option value="1">Morning (2:00 PM)</option>
  95. <option value="2">Evening (10:00 PM)</option>
  96. </select>
  97. </div>
  98. </div>
  99. <br>
  100. <div class="text-center">
  101. <button id="calculateButton" class="btn btn-primary">Calculate</button>
  102. </div>
  103. <div id="totalAmountDiv" class="text-center mt-3" style="display:none;">
  104. <h3>Total Amount: <span id="totalAmount"></span></h3>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </main>
  113. <footer th:replace="~{fragments/footer2 :: footer}"></footer>
  114. </div>
  115. <script th:replace="~{fragments/loginscript :: script}"></script>
  116. <script type="text/javascript">
  117. function getHallDetails(hallId, callback) {
  118. $.ajax({
  119. type: 'GET',
  120. url: '/communityhall/user/api/gethalldetails/' + hallId,
  121. success: function (response) {
  122. callback(response);
  123. },
  124. error: function (xhr, status, error) {
  125. console.error('Error fetching hall details:', error);
  126. }
  127. });
  128. }
  129. // Get hallId from URL parameters and fetch hall details
  130. const urlParams = new URLSearchParams(window.location.search);
  131. const hallId = urlParams.get('hallId');
  132. // console.log("Hall ID:", hallId);
  133. $(document).ready(function () {
  134. if (hallId != null) {
  135. getHallDetails(hallId, function (response) {
  136. $('#selecthall').val(hallId);
  137. $('#fullDayAmount').data('amount', response.fullDayRent);
  138. $('#halfDayAmount').data('amount', response.halfDayRent);
  139. $('#depositAmount').data('amount', response.depositAmount);
  140. $('#gst').data('rate', response.gst);
  141. });
  142. }
  143. });
  144. // Populate the dropdown options with the received hall names
  145. $(function () {
  146. $("#selecthall").select2();
  147. });
  148. $.ajax({
  149. type: 'GET',
  150. url: '/communityhall/user/api/gethallnames',
  151. success: function (response) {
  152. var selectHallDropdown = $('#selecthall');
  153. $.each(response, function (index, hall) {
  154. selectHallDropdown.append($('<option></option>').attr('value', hall.hallId).text(hall.hallName));
  155. if (hallId == hall.hallId) {
  156. selectHallDropdown.find('option[value="' + hall.hallId + '"]').prop('selected', true);
  157. }
  158. });
  159. },
  160. error: function (xhr, status, error) {
  161. console.error('Error fetching hall names:', error);
  162. }
  163. });
  164. // Event listener for the Select Hall dropdown change
  165. $('#selecthall').change(function () {
  166. var hallId = $(this).val();
  167. if (hallId) {
  168. getHallDetails(hallId, function (response) {
  169. $('#fullDayAmount').text(response.fullDayRent.toFixed(2));
  170. $('#halfDayAmount').text(response.halfDayRent.toFixed(2));
  171. $('#depositAmount').text(response.depositAmount.toFixed(2));
  172. $('#gst').text(response.gst.toFixed(2));
  173. // Show the required amount details once hall is selected
  174. $('#amountDetails').show();
  175. });
  176. } else {
  177. // Hide the amount details if no hall is selected
  178. $('#amountDetails').hide();
  179. }
  180. });
  181. function calculateAmount(numDays, startPeriod, endPeriod, fullDayAmount, halfDayAmount) {
  182. var amount = 0;
  183. // If there is only one day
  184. if (numDays === 1) {
  185. if (startPeriod === "1" && endPeriod === "2") {
  186. amount = fullDayAmount;
  187. } else if (startPeriod === "1" && endPeriod === "1") {
  188. amount = halfDayAmount;
  189. } else if (startPeriod === "2" && endPeriod === "2") {
  190. amount = halfDayAmount;
  191. }
  192. } else {
  193. // For multiple days
  194. if (startPeriod === "1" && endPeriod === "2") {
  195. amount = fullDayAmount * numDays;
  196. } else if (startPeriod === "1" && endPeriod === "1") {
  197. amount = fullDayAmount * (numDays - 1) + halfDayAmount;
  198. } else if (startPeriod === "2" && endPeriod === "2") {
  199. amount = fullDayAmount * (numDays - 1) + halfDayAmount;
  200. }
  201. else if (startPeriod === "2" && endPeriod === "1") {
  202. amount = fullDayAmount * (numDays - 2) + halfDayAmount * 2;
  203. }
  204. }
  205. return amount;
  206. }
  207. function calculateGST(amount, gstRate) {
  208. return (amount * gstRate) / 100;
  209. }
  210. function handlePeriodDropdowns(numDays, startPeriod) {
  211. if (numDays === 1 && startPeriod === "2") {
  212. $('#endPeriodDropdown').val("2");
  213. $('#endPeriodDropdown').prop('disabled', true);
  214. } else {
  215. $('#endPeriodDropdown').prop('disabled', false);
  216. }
  217. }
  218. $('#numDaysCount').change(function () {
  219. var numDays = parseInt($(this).val(), 10);
  220. var startPeriod = $('#startPeriodDropdown').val();
  221. handlePeriodDropdowns(numDays, startPeriod);
  222. });
  223. $('#startPeriodDropdown').change(function () {
  224. var numDays = parseInt($('#numDaysCount').val(), 10);
  225. var startPeriod = $(this).val();
  226. handlePeriodDropdowns(numDays, startPeriod);
  227. });
  228. $('#calculateButton').click(function () {
  229. var numDays = parseInt($('#numDaysCount').val(), 10);
  230. var startPeriod = $('#startPeriodDropdown').val();
  231. var endPeriod = $('#endPeriodDropdown').val();
  232. // Check if numDays is valid
  233. if (isNaN(numDays) || numDays < 1 || numDays > 7) {
  234. $('#numDaysCount')[0].setCustomValidity('Please select a valid number of days.');
  235. $('#numDaysCount')[0].reportValidity();
  236. return;
  237. } else {
  238. $('#numDaysCount')[0].setCustomValidity('');
  239. }
  240. // Check if startPeriod is selected
  241. if (!startPeriod) {
  242. $('#startPeriodDropdown')[0].setCustomValidity('Please select a start period.');
  243. $('#startPeriodDropdown')[0].reportValidity();
  244. return;
  245. } else {
  246. $('#startPeriodDropdown')[0].setCustomValidity('');
  247. }
  248. // Check if endPeriod is selected
  249. if (!endPeriod) {
  250. $('#endPeriodDropdown')[0].setCustomValidity('Please select an end period.');
  251. $('#endPeriodDropdown')[0].reportValidity();
  252. return;
  253. } else {
  254. $('#endPeriodDropdown')[0].setCustomValidity('');
  255. }
  256. var fullDayAmount = parseFloat($('#fullDayAmount').text());
  257. var halfDayAmount = parseFloat($('#halfDayAmount').text());
  258. var depositAmount = parseFloat($('#depositAmount').text());
  259. var gstRate = parseFloat($('#gst').text());
  260. var amount = calculateAmount(numDays, startPeriod, endPeriod, fullDayAmount, halfDayAmount);
  261. var gst = calculateGST(amount, gstRate);
  262. var totalAmount = amount + gst + depositAmount;
  263. $('#totalAmount').text(totalAmount.toFixed(2));
  264. // Show the total amount div
  265. $('#totalAmountDiv').show();
  266. });
  267. </script>
  268. </body>
  269. </html>