Browse Source

added logic for monthly and fix error for half day and full day logic

master
AJITHKUMAR12 6 months ago
parent
commit
ee4653652d
  1. 173
      src/main/java/com/gcc/coworkspace/service/BookingService.java
  2. 5
      src/main/resources/application.properties
  3. 12
      src/main/resources/templates/user/book-Conferance.html
  4. 12
      src/main/resources/templates/user/book-reading.html
  5. 15
      src/main/resources/templates/user/book-workdesk.html
  6. 20
      src/main/resources/templates/user/razor-pay.html

173
src/main/java/com/gcc/coworkspace/service/BookingService.java

@ -214,7 +214,8 @@ public class BookingService {
System.out.println("noOfPerson: " + noOfPerson);
System.out.println("slotId: " + slotId);
Map<String, Object> getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId);
Map<String, Object> getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId);
Map<String, Object> capacity = getCapacity(scid, cid);
int capsint = Integer.parseInt(capacity.get("limits").toString());
@ -288,6 +289,7 @@ public class BookingService {
return availableSeats;
}
public Map<String, Object> getCapacity(int sId, int catId) {
System.out.println("sid" + sId);
System.out.println("catId" + catId);
@ -303,8 +305,175 @@ public class BookingService {
}
}
public Map<String, Object> getCalendarBySlotId(int bid, int cid, LocalDate Bdate, int slotId) {
System.out.println("Bdate: " + Bdate);
// ✅ Detect monthly slot
boolean isMonthly = (cid == 2 && slotId == 9) ||
(cid == 6 && slotId == 62) ||
(cid == 16 && slotId == 111);
// ================= DESKSPACE GROUP =================
if (cid == 2 || cid == 6 || cid == 16) {
String slotCondition = "";
boolean hasDynamicSlot = true;
/*if (cid == 2) {
slotCondition = "slotId IN (?,8,9)";
} else if (cid == 6) {
slotCondition = "slotId IN (?,61,62)";
} else if (cid == 16) {
slotCondition = "slotId IN (?,110,111)";
}*/
if (cid == 2) {
if (slotId == 8 || slotId == 9) {
// ✅ FULL DAY → include ALL
slotCondition = "slotId IN (6,7,8,9)";
hasDynamicSlot = false;
} else {
// ✅ NORMAL
slotCondition = "slotId IN (?,8,9)";
}
} else if (cid == 6) {
if (slotId == 61 || slotId == 62) {
slotCondition = "slotId IN (59,60,61,62)";
hasDynamicSlot = false;
} else {
slotCondition = "slotId IN (?,61,62)";
}
} else if (cid == 16) {
if (slotId == 110 || slotId == 111) {
slotCondition = "slotId IN (108,109,110,111)";
hasDynamicSlot = false;
} else {
slotCondition = "slotId IN (?,110,111)";
}
}
// ================= MONTHLY =================
/* if (isMonthly) {
int maxBooked = 0;
for (int i = 0; i < 30; i++) {
LocalDate date = Bdate.plusDays(i);
String sql = "SELECT COALESCE(SUM(bcount),0) AS filed " +
"FROM calendar " +
"WHERE bdate = ? AND cid = ? AND bid = ? " +
"AND " + slotCondition;
Map<String, Object> row;
// ✅ FIX HERE
if (hasDynamicSlot) {
row = jdbcTemplate.queryForMap(sql, date, cid, bid, slotId);
} else {
row = jdbcTemplate.queryForMap(sql, date, cid, bid);
}
System.out.println("Slot condition: " + slotCondition);
System.out.println("SQL: " + sql);
System.out.println(
"Params → date: " + date + ", cid: " + cid + ", bid: " + bid + ", slotId: " + slotId);
int booked = Integer.parseInt(row.get("filed").toString());
System.out.println("Date: " + date + " → booked: " + booked);
System.out.println("booked"+booked);
if (booked > maxBooked) {
maxBooked = booked;
}
}
return Collections.singletonMap("filed", maxBooked);
}*/
if (isMonthly) {
LocalDate endDate = Bdate.plusDays(29); // 30 days range
String sql = "SELECT bdate, COALESCE(SUM(bcount), 0) AS filed " +
"FROM calendar " +
"WHERE bdate BETWEEN ? AND ? " +
"AND cid = ? AND bid = ? " +
"AND " + slotCondition + " " +
"GROUP BY bdate ORDER BY bdate";
System.out.println("SQL: " + sql);
System.out.println("Params → startDate: " + Bdate +
", endDate: " + endDate +
", cid: " + cid +
", bid: " + bid +
(hasDynamicSlot ? ", slotId: " + slotId : ""));
List<Map<String, Object>> rows;
// ✅ Handle dynamic slot
if (hasDynamicSlot) {
rows = jdbcTemplate.queryForList(sql, Bdate, endDate, cid, bid, slotId);
} else {
rows = jdbcTemplate.queryForList(sql, Bdate, endDate, cid, bid);
}
int maxBooked = 0;
for (Map<String, Object> row : rows) {
int booked = Integer.parseInt(row.get("filed").toString());
System.out.println("Date: " + row.get("bdate") + " → booked: " + booked);
if (booked > maxBooked) {
maxBooked = booked;
}
}
return Collections.singletonMap("filed", maxBooked);
}
// ================= NORMAL (DAILY) =================
else {
String sql = "SELECT COALESCE(SUM(bcount),0) AS filed " +
"FROM calendar " +
"WHERE bdate = ? AND cid = ? AND bid = ? " +
"AND " + slotCondition;
System.out.println("slotCondition"+slotCondition);
System.out.println("SQL: " + sql);
System.out.println(
"Params → Bdate: " + Bdate + ", cid: " + cid + ", bid: " + bid + ", slotId: " + slotId);
if (hasDynamicSlot) {
return jdbcTemplate.queryForMap(sql, Bdate, cid, bid, slotId);
} else {
return jdbcTemplate.queryForMap(sql, Bdate, cid, bid);
}
}
}
// ================= DEFAULT =================
else {
String sql = "SELECT COALESCE(SUM(bcount),0) AS filed " +
"FROM calendar " +
"WHERE bdate = ? AND cid = ? AND bid = ? AND slotId = ?";
return jdbcTemplate.queryForMap(sql, Bdate, cid, bid, slotId);
}
}
public Map<String, Object> getCalendarBySlotId(int bid, int cid, LocalDate Bdate, int slotId) {
public Map<String, Object> getCalendarBySlotId1(int bid, int cid, LocalDate Bdate, int slotId) {
System.out.println("Bdate: " + Bdate);
String sql = "";
if (cid == 2 || cid == 6 || cid == 16) {

5
src/main/resources/application.properties

@ -9,3 +9,8 @@ google.place.id=ChIJG8YjaABlUjoRAyFklVuYvk4
complaintfile_directory=complaintfile_uploads
caretakerfileuploads_directory=caretakercomplaintfile_uploads
# \u2705 Allow long-running report requests (3 minutes)
spring.mvc.async.request-timeout=180000
server.connection-timeout=180000

12
src/main/resources/templates/user/book-Conferance.html

@ -608,6 +608,16 @@
</div>
</div>
</div>
<div id="pageLoader"
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;">
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
<span class="sr-only">Loading...</span>
</div>
<!-- Add the 'Please wait' text below the spinner -->
<p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
</div>
</div>
<script th:replace="~{fragments/user-script :: script}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@ -987,6 +997,7 @@ if (msg.includes("Slot Full")) {
$('.adultcount').text(noOfPeople);
$('.slot').text(selectedSlot);
$(".noOfPeoplecount").text(noOfPeople);
$('#pageLoader').show();
$.ajax({
url: '/muthalvarpadaippagam/book/api/saveInTemp',
@ -1004,6 +1015,7 @@ if (msg.includes("Slot Full")) {
},
success: function (response) {
if (response) {
$('#pageLoader').hide();
let tempId = response.tempBookId;
$(".amount").text(response.amount);
let finalAmount = response.amount;

12
src/main/resources/templates/user/book-reading.html

@ -547,6 +547,16 @@
</div>
</div>
</div>
<div id="pageLoader"
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;">
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
<span class="sr-only">Loading...</span>
</div>
<!-- Add the 'Please wait' text below the spinner -->
<p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
</div>
</div>
<script th:replace="~{fragments/user-script :: script}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@ -912,6 +922,7 @@ if (msg.includes("Slot Full")) {
$('.adultcount').text(noOfPeople);
$('.slot').text(selectedSlot);
$(".noOfPeoplecount").text(noOfPeople);
$('#pageLoader').show();
$.ajax({
@ -931,6 +942,7 @@ if (msg.includes("Slot Full")) {
success: function (response) {
console.log(response);
if (response) {
$('#pageLoader').hide();
let tempId = response.tempBookId;
$(".amount").text(response.amount);
let finalAmount = response.amount;

15
src/main/resources/templates/user/book-workdesk.html

@ -648,6 +648,16 @@
</div>
</div>
</div>
<div id="pageLoader"
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;">
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
<span class="sr-only">Loading...</span>
</div>
<!-- Add the 'Please wait' text below the spinner -->
<p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
</div>
</div>
<script th:replace="~{fragments/user-script :: script}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@ -833,7 +843,8 @@ function selectTimeSlot(element) {
let slotId = element.value;
let bid = $('#buildingId').val();
let cid = $('#categoryId').val();
let scid = $('#subId').val();
//let scid = $('#subId').val();
let scid =document.querySelector('input[name="booking_type"]:checked').value;
let bDate = $('#selectDate').val();
let noOfPerson = $('#numSeats').val();
@ -1098,6 +1109,7 @@ if (msg.includes("Slot Full")) {
$('.adultcount').text(noOfPeople);
$('.slot').text(selectedSlot);
$(".noOfPeoplecount").text(noOfPeople);
$('#pageLoader').show();
$.ajax({
@ -1117,6 +1129,7 @@ if (msg.includes("Slot Full")) {
success: function (response) {
//console.log("Akg Response:"+response);
if (response) {
$('#pageLoader').hide();
let tempId = response.tempBookId;
$(".amount").text(response.amount);
let finalAmount = response.amount;

20
src/main/resources/templates/user/razor-pay.html

@ -1,5 +1,15 @@
<html>
<header>
<div id="pageLoader"
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;">
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
<span class="sr-only">Loading...</span>
</div>
<!-- Add the 'Please wait' text below the spinner -->
<p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
</div>
</div>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
@ -7,6 +17,7 @@
<script type="text/javascript">
const paymentStart = (id) => {
console.log("payment started :-" + id);
$('#pageLoader').show();
$.ajax({
url: '/muthalvarpadaippagam/book/api/create_order',
data: { id: id },
@ -14,13 +25,14 @@
dataType: 'json',
success: function (response) {
$('#ackModal').modal('hide');
$('#pageLoader').hide();
let amt = response.amount;
console.log("FIRST:==>");
console.log(response);
if (response.status == "created") {
let options = {
// "key": "[[${keyId}]]",
"key": "rzp_test_tDkHFEqWXmuEi8", // Enter the Key ID generated from the Dashboard
"key": "[[${keyId}]]",
//"key": "rzp_test_tDkHFEqWXmuEi8", // Enter the Key ID generated from the Dashboard
"amount": response.amount, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
"currency": "INR",
"name": "Greater Chennai Corporation",
@ -45,6 +57,9 @@
}).then((result) => {
if (result.isConfirmed) {
$('#pageLoader').show();
updatePaymentInServer(
response.razorpay_payment_id,
@ -99,6 +114,7 @@
dataType: 'json',
success: function (response) {
console.log("update payment in server");
$('#pageLoader').hide();
//alert(response);
if (response != "error") {
window.location.href = "/muthalvarpadaippagam/bookingQRCode?booking_id=" + response;

Loading…
Cancel
Save