diff --git a/jwtToken.txt b/jwtToken.txt index 02e78fb3..4f50d0f6 100644 --- a/jwtToken.txt +++ b/jwtToken.txt @@ -1 +1 @@ -eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyVHlwZSI6ImFkbWluIiwiaGFsbElkIjoxLCJtb2JpbGVOdW1iZXIiOjg2Njc4ODE2NjEsImVtcGxveWVlSWQiOiIxIiwiem9uZSI6IjAwIiwiZXhwIjoxNzM0NjgwMzQ3fQ.aBXIv2Is-2-OkORh9aiJEGY1YO3QRJ_P4Pr7YzSiTWeoGyR_2Zk-JtHJjBR8QBNBF0pKSQpXbhY6uvBSiAGXYQ \ No newline at end of file +eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyVHlwZSI6ImFkbWluIiwiaGFsbElkIjoxLCJtb2JpbGVOdW1iZXIiOjgzNDQ5NzkyOTIsImVtcGxveWVlSWQiOiIxIiwiem9uZSI6IjAwIiwiZXhwIjoxNzYyODYwNzk0fQ.ltHuRFZWZqHUvUki5jbMcGTDbU2JyOWU5cgMFbVrp_8KMag9HVtHQ9iSFGUyIMUe_T08b58_BG9ZtrtM8rHo9Q \ No newline at end of file diff --git a/src/main/java/com/gcc/communityHall/controller/Admincontroller.java b/src/main/java/com/gcc/communityHall/controller/Admincontroller.java index 7a49e6d5..355ae670 100644 --- a/src/main/java/com/gcc/communityHall/controller/Admincontroller.java +++ b/src/main/java/com/gcc/communityHall/controller/Admincontroller.java @@ -263,8 +263,12 @@ public class Admincontroller { List cancelledbookings = bookingDetailsRepository.findAllSettlementCancelledList(); List rejectedbookings = bookingDetailsRepository.findAllSettlementRejectedList(); model.addAttribute("settlementlist", settlement); + //AKI + List settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPending(); + model.addAttribute("settlementIntiated", settlementIntiated); model.addAttribute("cancelledbookings", cancelledbookings); model.addAttribute("rejectedbookings", rejectedbookings); + System.out.println("Settlement List: " + settlement); return "admin/settlement-list"; } else { session.invalidate(); @@ -665,6 +669,15 @@ public class Admincontroller { String counterWiseBookingJson = new ObjectMapper().writeValueAsString(counterWiseBookingList); model.addAttribute("counterWiseBookingList", counterWiseBookingJson); } + //ak + if ("11".equals(request)) { + // Fetch Settlement Initiated Report details + List settlementInitiatedList = bookingService.getSettlementInitiatedReport(fromDate, toDate); + System.out.println("settlementInitatedList"+ settlementInitiatedList); + + // Add the list to the model + model.addAttribute("settlementInitiatedList", settlementInitiatedList); +} model.addAttribute("filterby", filterby); model.addAttribute("users", userList); @@ -687,6 +700,8 @@ public class Admincontroller { model.addAttribute("division1", division); model.addAttribute("hall1", hallid); model.addAttribute("adminname", adminname); + System.out.println("request" + request); + return "admin/reports"; } else { diff --git a/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java b/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java index eeb9a12f..29ff230c 100644 --- a/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java +++ b/src/main/java/com/gcc/communityHall/controller/HeadquartersController.java @@ -536,10 +536,14 @@ public class HeadquartersController { model.addAttribute("title", "settlement Pending"); String zone = (String) session.getAttribute("zone"); model.addAttribute("zone", zone); + //ak + List settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPending(); List settlement = bookingDetailsRepository.findAllSettlementPending(); List cancelledbookings = bookingDetailsRepository.findAllSettlementCancelledList(); List rejectedbookings = bookingDetailsRepository.findAllSettlementRejectedList(); model.addAttribute("settlementlist", settlement); + //AK + model.addAttribute("settlementIntiated", settlementIntiated); model.addAttribute("cancelledbookings", cancelledbookings); model.addAttribute("rejectedbookings", rejectedbookings); return "headquarters/settlement-list"; diff --git a/src/main/java/com/gcc/communityHall/controller/OfficerAPIController.java b/src/main/java/com/gcc/communityHall/controller/OfficerAPIController.java index 73f459b6..337eefff 100644 --- a/src/main/java/com/gcc/communityHall/controller/OfficerAPIController.java +++ b/src/main/java/com/gcc/communityHall/controller/OfficerAPIController.java @@ -3,8 +3,10 @@ package com.gcc.communityHall.controller; import java.io.FileOutputStream; import java.net.InetAddress; import java.net.UnknownHostException; +import java.time.Instant; import java.time.LocalDate; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -36,12 +38,14 @@ import com.gcc.communityHall.paymentService.entity.TransactionResponse; import com.gcc.communityHall.entity.BookingHistory; import com.gcc.communityHall.entity.CounterRefundList; import com.gcc.communityHall.entity.Settlement; +import com.gcc.communityHall.entity.SettlementHistory; import com.gcc.communityHall.entity.Users; import com.gcc.communityHall.repository.ApplicationLogsRepository; import com.gcc.communityHall.repository.BookingCalendarRepository; import com.gcc.communityHall.repository.BookingDetailsRepository; import com.gcc.communityHall.repository.BookingHistoryRepository; import com.gcc.communityHall.repository.CounterRefundListRepository; +import com.gcc.communityHall.repository.SettlementHistoryRepository; import com.gcc.communityHall.repository.SettlementRepository; import com.gcc.communityHall.repository.UsersRepository; import com.gcc.communityHall.service.BookingService; @@ -71,6 +75,9 @@ import lombok.AllArgsConstructor; @AllArgsConstructor @Validated public class OfficerAPIController { + //ak// ak + @Autowired + private SettlementHistoryRepository settlementHistoryRepository; @Autowired private UserService userService; @@ -150,6 +157,7 @@ public class OfficerAPIController { @GetMapping("/getSettlementList") public ResponseEntity getBookingDetailsWithSettlement(HttpServletRequest request, @RequestParam String settlementsid) { BookingDetails bookingDetails = bookingServiceImpl.getBookingDetailsWithSettlement(Integer.parseInt(settlementsid)); + System.out.println("bookingDetails:12 " + bookingDetails); return ResponseEntity.ok(bookingDetails); } @@ -181,14 +189,27 @@ public class OfficerAPIController { @PathVariable("settlementId") int settlementId, @RequestParam("status") BookingDetails.RefundStatus status, @RequestParam("comments") String comments) { + Map response = new HashMap<>(); + try { + System.out.println("settlementId1: " + settlementId); + System.out.println("status"+status); + System.out.println("comments"+comments); + // Update settlement status Settlement updateSettlement = settlementService.updateSettlementStatus(settlementId, status, comments); if (updateSettlement == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - + System.out.println("updateSettlement12"+updateSettlement); + //ak + // Set approvedFlag and approvedFlagDate + updateSettlement.setApprovedFlag(1); + updateSettlement.setApprovedFlagDate(new Date()); + settlementRepository.save(updateSettlement); + //ak + // Log the action String adminname = (String) session.getAttribute("usertype"); Integer loginid = (Integer) session.getAttribute("id"); @@ -211,18 +232,36 @@ public class OfficerAPIController { // Process refund request String refundResponse = bookingServiceImpl.processRefundRequest(updateSettlement.getBookingDetails().getBookingId()); +//ak + // Prepare response map + + response.put("settlement", updateSettlement); + response.put("approvedFlag", updateSettlement.getApprovedFlag()); + response.put("approvedFlagDate", updateSettlement.getApprovedFlagDate()); if (refundResponse.contains("successful")) { // Refund success, return updated settlement and status - return new ResponseEntity<>(updateSettlement, HttpStatus.OK); + //return new ResponseEntity<>(updateSettlement, HttpStatus.OK); + return new ResponseEntity<>(response, HttpStatus.OK); } else { + // Refund failure, update refund status to FAILURE bookingService.updateRefundStatus(updateSettlement.getBookingDetails().getBookingId(), BookingDetails.RefundStatus.FAILURE); - return new ResponseEntity<>("Refund processing failed: " + refundResponse, HttpStatus.INTERNAL_SERVER_ERROR); + Map responses = new HashMap<>(); + responses.put("approvedFlag", 1); + responses.put("message", "Refund processing failed: " + refundResponse); + responses.put("status", "FAILURE"); + + return new ResponseEntity<>(responses, HttpStatus.INTERNAL_SERVER_ERROR); + //return new ResponseEntity<>("Refund processing failed: " + refundResponse, HttpStatus.INTERNAL_SERVER_ERROR); } } catch (Exception e) { - return new ResponseEntity<>("An error occurred while processing the settlement for Settlement ID: " + settlementId, HttpStatus.INTERNAL_SERVER_ERROR); + response.put("approvedFlag", 1); + response.put("message", "Exception while approving settlement: " + e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + + //return new ResponseEntity<>("An error occurred while processing the settlement for Settlement ID: " + settlementId, HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -336,6 +375,9 @@ public class OfficerAPIController { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } + //ak + + @PostMapping("/toggleStatus") public ResponseEntity toggleUserStatus( @RequestParam Integer userId, diff --git a/src/main/java/com/gcc/communityHall/controller/OfficerController.java b/src/main/java/com/gcc/communityHall/controller/OfficerController.java index 6880b4a9..7ab90696 100644 --- a/src/main/java/com/gcc/communityHall/controller/OfficerController.java +++ b/src/main/java/com/gcc/communityHall/controller/OfficerController.java @@ -198,12 +198,18 @@ public class OfficerController { model.addAttribute("baseURL", appConfig.getBaseUrl()); String zone = (String) session.getAttribute("zone"); model.addAttribute("zone", zone); + System.out.println("Zone: " + zone); List settlement = bookingDetailsRepository.findSettlementPendingByZone(zone); + //ak + List settlementIntiated = bookingDetailsRepository.findSettlementInitiatedPendingByZone(zone); List cancelledbookings = bookingDetailsRepository.findCancelledListByZone(zone); List rejectedbookings = bookingDetailsRepository.findRejectedListByZone(zone); model.addAttribute("settlementlist", settlement); + //AK + model.addAttribute("settlementIntiated", settlementIntiated); model.addAttribute("cancelledbookings", cancelledbookings); model.addAttribute("rejectedbookings", rejectedbookings); + System.out.println("settlementIntiated"+settlementIntiated); return "officer/settlement-list"; } else { session.invalidate(); diff --git a/src/main/java/com/gcc/communityHall/controller/UserAPIController.java b/src/main/java/com/gcc/communityHall/controller/UserAPIController.java index 744df340..03e9f802 100644 --- a/src/main/java/com/gcc/communityHall/controller/UserAPIController.java +++ b/src/main/java/com/gcc/communityHall/controller/UserAPIController.java @@ -239,8 +239,8 @@ public class UserAPIController { //System.out.println(purpose); //System.out.print("\n MobileNo---:"+mobileNo); Random rand = new Random(); -// int otp = rand.nextInt(90000) + 10000; - int otp = 11111; + int otp = rand.nextInt(90000) + 10000; + // int otp = 11111; System.out.print("\n otp---:" + otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); @@ -251,7 +251,7 @@ public class UserAPIController { System.out.println(urlString); System.out.println("\n urlString---: " + urlString); String bodyMessage = "" + otp; - /*try { + try { RestTemplate restTemplate = new RestTemplate(); String Response = restTemplate.getForObject(urlString, String.class); bodyMessage=Response; @@ -268,7 +268,7 @@ public class UserAPIController { } catch (Exception e) { // System.out.print("ERROR in Sending---: "+e); bodyMessage = "Error"; - }*/ + } HttpSession session = request.getSession(); session.setAttribute("otp", otp); return bodyMessage; diff --git a/src/main/java/com/gcc/communityHall/entity/Settlement.java b/src/main/java/com/gcc/communityHall/entity/Settlement.java index 9c108e20..256963b2 100644 --- a/src/main/java/com/gcc/communityHall/entity/Settlement.java +++ b/src/main/java/com/gcc/communityHall/entity/Settlement.java @@ -1,5 +1,6 @@ package com.gcc.communityHall.entity; +import java.time.Instant; import java.time.LocalDate; import java.util.Date; @@ -40,6 +41,15 @@ public class Settlement { private long challonnumber; private long challonamount; private long ddamount; + //ak + @Column(name = "approved_flag") +private Integer approvedFlag = 0; + +@Column(name = "approved_flag_date") +private Date approvedFlagDate; + + + @OneToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL) @JsonIgnore @@ -153,9 +163,30 @@ public class Settlement { public String getCollectionStatus() { return collectionStatus; } + public void setCollectionStatus(String collectionStatus) { this.collectionStatus = collectionStatus; } + // Getter for approvedFlag +public Integer getApprovedFlag() { + return approvedFlag; +} + +// Setter for approvedFlag +public void setApprovedFlag(Integer approvedFlag) { + this.approvedFlag = approvedFlag; +} + +// Getter for approvedFlagDate +public Date getApprovedFlagDate() { + return approvedFlagDate; +} + +// Setter for approvedFlagDate +public void setApprovedFlagDate(Date approvedFlagDate) { + this.approvedFlagDate = approvedFlagDate; +} + public Settlement(int settlementId, String comments, LocalDate cdate, double damageAmount, double ebAmount, double depositAmount, double refundedAmount, Date updatedDate, String updatedId, String challon, String dddate, long ddnumber, BookingDetails bookingDetails,double collectionPending, long ddamount, long challonnumber, String collectionStatus) { diff --git a/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java b/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java index b624c65a..6a2d13b1 100644 --- a/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java +++ b/src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java @@ -35,7 +35,7 @@ import java.time.LocalDate; import java.util.*; @Component -@EnableScheduling +// @EnableScheduling public class PaymentStatusScheduler { @Autowired diff --git a/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java b/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java index f63a69be..b74b71c4 100644 --- a/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java +++ b/src/main/java/com/gcc/communityHall/repository/BookingDetailsRepository.java @@ -142,6 +142,45 @@ public interface BookingDetailsRepository extends JpaRepository getBookingHallDetailsReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate); + //ak + /* @Query(value = "SELECT * \r" + + + "FROM \r" + + " settlement s\r" + + " JOIN booking_details b ON s.booking_details_booking_id = b.booking_id\r" + + + "WHERE \r" + + " DATE(b.booking_date) BETWEEN :fromDate AND :toDate\r" + + + "ORDER BY \r" + + " b.booking_date", nativeQuery = true) +List getSettlementInitiatedReport(@Param("fromDate") String fromDate, @Param("toDate") String toDate);*/ +@Query(value = "SELECT distinct(p.booking_id), " + + // "b.booking_id, " + + "b.booking_date, " + + "s.cdate, " + + "u.name, " + + "u.mobile_no, " + + "hd.hall_name, " + + "b.end_date, " + + "b.start_date, " + + "b.amount_received, " + + "s.refunded_amount, " + + "p.txansaction_id " + + "FROM booking_details b " + + "INNER JOIN settlement s ON b.booking_id = s.booking_details_booking_id " + + "INNER JOIN users u ON u.user_id = b.users_user_id " + + "INNER JOIN hall_details hd ON hd.hall_id = b.hall_details_hall_id " + + "inner join refund_response p on p.booking_id=b.booking_id " + + "WHERE DATE(b.booking_date) BETWEEN :fromDate AND :toDate " + + "ORDER BY b.booking_date DESC", + nativeQuery = true) +List getSettlementInitiatedReport(@Param("fromDate") String fromDate, + @Param("toDate") String toDate); + + + + @Query(value = "SELECT \r" + " COALESCE( SUM(\r" @@ -378,6 +417,11 @@ public interface BookingDetailsRepository extends JpaRepository findSettlementPendingByZone(String zone); + //ak + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'FAILURE' and b.hallDetails.zone=:zone") + List findSettlementInitiatedPendingByZone(String zone); + @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'FAILURE'") + List findSettlementInitiatedPending(); @Query("SELECT b FROM BookingDetails b JOIN FETCH b.settlement s WHERE b.refundStatus = 'APPROVED' and b.hallDetails.zone=:zone") List findSettlementApprovedByZone(String zone); diff --git a/src/main/java/com/gcc/communityHall/service/BookingService.java b/src/main/java/com/gcc/communityHall/service/BookingService.java index 2986a821..404fc709 100644 --- a/src/main/java/com/gcc/communityHall/service/BookingService.java +++ b/src/main/java/com/gcc/communityHall/service/BookingService.java @@ -218,4 +218,7 @@ public interface BookingService { List getAllHallWiseBookingList(String fromDate, String toDate); List getAllCounterWiseBookingList(String fromDate, String toDate); + //ak + List getSettlementInitiatedReport(String fromDate, String toDate); + } diff --git a/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java b/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java index f06bceff..c8ed9bf0 100644 --- a/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java +++ b/src/main/java/com/gcc/communityHall/service/Impl/BookingServiceImpl.java @@ -46,6 +46,7 @@ import com.gcc.communityHall.entity.HallDetailsConcession; import com.gcc.communityHall.entity.ReasonDocumentMaster; import com.gcc.communityHall.entity.ReasonMaster; import com.gcc.communityHall.entity.Settlement; +import com.gcc.communityHall.entity.SettlementHistory; import com.gcc.communityHall.entity.Users; import com.gcc.communityHall.exception.SlotOccupiedException; import com.gcc.communityHall.others.UserSession; @@ -65,6 +66,7 @@ import com.gcc.communityHall.repository.GccblockingDocumentsRepo; import com.gcc.communityHall.repository.HallDetailsConcessionRepo; import com.gcc.communityHall.repository.HallDetailsRepository; import com.gcc.communityHall.repository.ReasonMasterRepository; +import com.gcc.communityHall.repository.SettlementHistoryRepository; import com.gcc.communityHall.repository.SettlementRepository; import com.gcc.communityHall.repository.UsersRepository; import com.gcc.communityHall.service.ApplicationLogService; @@ -140,6 +142,8 @@ public class BookingServiceImpl implements BookingService { @Autowired private HttpSession session; + @Autowired + private SettlementHistoryRepository settlementHistoryRepository; @Autowired private HallDetailsConcessionRepo hallDetailsConcessionRepo; @@ -1372,15 +1376,172 @@ public class BookingServiceImpl implements BookingService { return null; } - @Override + /*@Override public BookingDetails getBookingDetailsWithSettlement(int settlementId) { Optional SettleBookingDetails = Optional.of(bookingDetailsRepository.findBySettlementIdWithBookingDetails(settlementId)); if (SettleBookingDetails.isPresent()) { + System.out.println("settlement list: " + SettleBookingDetails.get()); return SettleBookingDetails.get(); + } return null; + }*/ + //ak +/*@Override +public BookingDetails getBookingDetailsWithSettlement(int settlementId) { + // 🔹 Your existing logic (unchanged) + Optional SettleBookingDetails = + Optional.of(bookingDetailsRepository.findBySettlementIdWithBookingDetails(settlementId)); + + if (SettleBookingDetails.isPresent()) { + BookingDetails bookingDetails = SettleBookingDetails.get(); + System.out.println("settlement list: " + bookingDetails); + + // 🔹 Keep the same return behavior, but do reset before returning + if (bookingDetails.getSettlement() == null) { + Settlement settlement = bookingDetails.getSettlement(); + + // ✅ Auto-reset logic (only if approvedFlag=1 and approvedFlagDate != null) + if (settlement.getApprovedFlag() == 1 && settlement.getApprovedFlagDate() != null) { + long millisDiff = System.currentTimeMillis() - settlement.getApprovedFlagDate().getTime(); + long daysDiff = millisDiff / (1000 * 60 * 60 * 24); + + System.out.println("Approved Flag Date: " + settlement.getApprovedFlagDate()); + System.out.println("Current Java Date: " + new Date()); + System.out.println("Days Difference: " + daysDiff); + + if (daysDiff >= 4) { + settlement.setApprovedFlag(0); + settlement.setApprovedFlagDate(null); + settlementRepository.save(settlement); + System.out.println("✅ Approved flag reset after 4 days for Settlement ID: " + settlement.getSettlementId()); + } + } + } + + // ✅ Return same object (your original logic) + return bookingDetails; + } + + return null; +}*/ +@Override +public List getSettlementInitiatedReport(String fromDate, String toDate) { + return bookingDetailsRepository.getSettlementInitiatedReport(fromDate, toDate); +} +//ak +@Override +public BookingDetails getBookingDetailsWithSettlement(int settlementId) { + // 🔹 Your existing logic (unchanged) + Optional SettleBookingDetails = + Optional.ofNullable(bookingDetailsRepository.findBySettlementIdWithBookingDetails(settlementId)); + //ak + /* Optional settlementOptional = settlementRepository.findById(settlementId); + String adminname = (String) session.getAttribute("usertype"); + if (settlementOptional.isPresent()) { + Settlement settlement = settlementOptional.get(); + + SettlementHistory history = new SettlementHistory(); + history.setSettlementId(settlement.getSettlementId()); + history.setComments(settlement.getComments()); + history.setCdate(settlement.getCdate()); + history.setDamageAmount(settlement.getDamageAmount()); + history.setEbAmount(settlement.getEbAmount()); + history.setDepositAmount(settlement.getDepositAmount()); + history.setRefundedAmount(settlement.getRefundedAmount()); + history.setUpdatedDate(new Date()); + history.setUpdatedId(adminname); + history.setChallon(settlement.getChallon()); + history.setDddate(settlement.getDddate()); + history.setDdnumber(settlement.getDdnumber()); + history.setBookingDetails(settlement.getBookingDetails()); + history.setCollectionPending(settlement.getCollectionPending()); + history.setDdamount(settlement.getDdamount()); + history.setChallonnumber(settlement.getChallonnumber()); + history.setCollectionStatus(settlement.getCollectionStatus()); + history.setChallonamount(settlement.getChallonamount()); + history.setApprovedFlag(settlement.getApprovedFlag()); + history.setApprovedFlagDate(settlement.getApprovedFlagDate()); + history.setShDate(new Date()); + + settlementHistoryRepository.save(history); + System.out.println("✅ Record inserted into SettlementHistory for Settlement ID: " + settlementId); + }*/ + + + + if (SettleBookingDetails.isPresent()) { + BookingDetails bookingDetails = SettleBookingDetails.get(); + System.out.println("settlement list: " + bookingDetails); + + + // 🔹 Only do reset if settlement exists + if (bookingDetails.getSettlement() != null) { // ✅ FIXED HERE + Settlement settlement = bookingDetails.getSettlement(); + + // ✅ Auto-reset logic (only if approvedFlag=1 and approvedFlagDate != null) + if (settlement.getApprovedFlag() == 1 && settlement.getApprovedFlagDate() != null) { + long millisDiff = System.currentTimeMillis() - settlement.getApprovedFlagDate().getTime(); + long daysDiff = millisDiff / (1000 * 60 * 60 * 24); + + System.out.println("Approved Flag Date123: " + settlement.getApprovedFlagDate()); + System.out.println("Current Java Date: " + new Date()); + System.out.println("Days Difference: " + daysDiff); + + if (daysDiff > 4) { + //settlement histoty insert + Optional settlementOptional = settlementRepository.findById(settlementId); + String adminname = (String) session.getAttribute("usertype"); + if (settlementOptional.isPresent()) { + + + SettlementHistory history = new SettlementHistory(); + history.setSettlementId(settlement.getSettlementId()); + history.setComments(settlement.getComments()); + history.setCdate(settlement.getCdate()); + history.setDamageAmount(settlement.getDamageAmount()); + history.setEbAmount(settlement.getEbAmount()); + history.setDepositAmount(settlement.getDepositAmount()); + history.setRefundedAmount(settlement.getRefundedAmount()); + history.setUpdatedDate(new Date()); + history.setUpdatedId(adminname); + history.setChallon(settlement.getChallon()); + history.setDddate(settlement.getDddate()); + history.setDdnumber(settlement.getDdnumber()); + history.setBookingDetails(settlement.getBookingDetails()); + history.setCollectionPending(settlement.getCollectionPending()); + history.setDdamount(settlement.getDdamount()); + history.setChallonnumber(settlement.getChallonnumber()); + history.setCollectionStatus(settlement.getCollectionStatus()); + history.setChallonamount(settlement.getChallonamount()); + history.setApprovedFlag(settlement.getApprovedFlag()); + history.setApprovedFlagDate(settlement.getApprovedFlagDate()); + history.setShDate(new Date()); + + settlementHistoryRepository.save(history); + System.out.println("✅ Record inserted into SettlementHistory for Settlement ID: " + settlementId); + } + + settlement.setApprovedFlag(0); + settlement.setApprovedFlagDate(null); + settlementRepository.save(settlement); + System.out.println("✅ Approved flag reset after 3 days for Settlement ID: " + settlement.getSettlementId()); + } + } + } else { + System.out.println("⚠️ No settlement found for booking ID: " + bookingDetails.getBookingId()); + } + + // ✅ Return same object (your original logic) + return bookingDetails; } + return null; +} + + + + @Override public BookingDetails saveebdetails(int bookingId, double startingReading, MultipartFile startingReadingimage) { diff --git a/src/main/java/com/gcc/communityHall/service/Impl/SettlementServiceImpl.java b/src/main/java/com/gcc/communityHall/service/Impl/SettlementServiceImpl.java index 5966c3b0..3841455e 100644 --- a/src/main/java/com/gcc/communityHall/service/Impl/SettlementServiceImpl.java +++ b/src/main/java/com/gcc/communityHall/service/Impl/SettlementServiceImpl.java @@ -3,6 +3,8 @@ package com.gcc.communityHall.service.Impl; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Optional; import java.util.Date; @@ -16,125 +18,224 @@ import com.gcc.communityHall.entity.BookingDetails; import com.gcc.communityHall.entity.BookingHistory; import com.gcc.communityHall.entity.BookingDetails.RefundStatus; import com.gcc.communityHall.entity.Settlement; +import com.gcc.communityHall.entity.SettlementHistory; import com.gcc.communityHall.repository.BookingDetailsRepository; import com.gcc.communityHall.repository.BookingHistoryRepository; +import com.gcc.communityHall.repository.SettlementHistoryRepository; import com.gcc.communityHall.repository.SettlementRepository; import com.gcc.communityHall.service.SettlementService; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Optional; import jakarta.servlet.http.HttpSession; - @Service -public class SettlementServiceImpl implements SettlementService{ - +public class SettlementServiceImpl implements SettlementService { + // ak + @Autowired + private SettlementHistoryRepository settlementHistoryRepository; + @Autowired SettlementRepository settlementRepository; - + @Autowired BookingDetailsRepository bookingDetailsRepository; - + @Autowired private BookingHistoryRepository bookingHistoryRepository; - + @Autowired private HttpSession session; - - @Value("${file.upload.directory}") - private String UploadDirectory; - - @Value("${file.fullpath}") - private String serverPath; - - private final String settlementDirectory; - - private final String settlementPhotoUrl; - - - @Autowired - SettlementServiceImpl(SettlementRepository settlementRepository, - @Value("${file.settlement.upload.directory}") String settlementDirectory, - @Value("${file.settlement.fullpath}") String settlementPhotoUrl){ - this.settlementDirectory=settlementDirectory; - this.settlementPhotoUrl = settlementPhotoUrl; - } - -// @Override -// public Settlement getSettlementById(int settlementId) { -// Optional settlement= settlementRepository.findById(settlementId); -// if(settlement.isPresent()){ -// return settlement.get(); -// } -// return null; -// } - -// @Override -// public Settlement getSettlementById(int settlementId) { -// return settlementRepository.findByIdWithBookingDetails(settlementId); -// } - + + @Value("${file.upload.directory}") + private String UploadDirectory; + + @Value("${file.fullpath}") + private String serverPath; + + private final String settlementDirectory; + + private final String settlementPhotoUrl; + + @Autowired + SettlementServiceImpl(SettlementRepository settlementRepository, + @Value("${file.settlement.upload.directory}") String settlementDirectory, + @Value("${file.settlement.fullpath}") String settlementPhotoUrl) { + this.settlementDirectory = settlementDirectory; + this.settlementPhotoUrl = settlementPhotoUrl; + } + + // @Override + // public Settlement getSettlementById(int settlementId) { + // Optional settlement= settlementRepository.findById(settlementId); + // if(settlement.isPresent()){ + // return settlement.get(); + // } + // return null; + // } + + // @Override + // public Settlement getSettlementById(int settlementId) { + // return settlementRepository.findByIdWithBookingDetails(settlementId); + // } + @Override public Settlement getSettlementById(int settlementId) { - Optional settlementOptional = settlementRepository.findById(settlementId); - if (settlementOptional.isPresent()) { - Settlement settlement = settlementOptional.get(); - // Initialize the BookingDetails object - settlement.getBookingDetails(); - return settlement; - } - return null; + Optional settlementOptional = settlementRepository.findById(settlementId); + if (settlementOptional.isPresent()) { + Settlement settlement = settlementOptional.get(); + // Initialize the BookingDetails object + settlement.getBookingDetails(); + // System.out.println("✅ Approved flag reset after 4 days for Settlement ID: " + + // settlementId); + return settlement; + } + return null; } - + // ak + /* + * @Override + * public Settlement getSettlementById(int settlementId) { + * Optional settlementOptional = + * settlementRepository.findById(settlementId); + * + * if (settlementOptional.isPresent()) { + * Settlement settlement = settlementOptional.get(); + * + * // Initialize BookingDetails + * settlement.getBookingDetails(); + * System.out.println("settlement.getBookingDetails(): " + + * settlement.getBookingDetails()); + * + * // ✅ Auto-reset logic: if approved for 4+ days, reset flag + * if (settlement.getApprovedFlag() == 1 && settlement.getApprovedFlagDate() != + * null) { + * long millisDiff = System.currentTimeMillis() - + * settlement.getApprovedFlagDate().getTime(); + * long daysDiff = millisDiff / (1000 * 60 * 60 * 24); + * System.out.println("Approved Flag Date: " + + * settlement.getApprovedFlagDate()); + * System.out.println("Current Java Date: " + new Date()); + * System.out.println("Days Difference: " + daysDiff); + * + * + * if (daysDiff >= 4) { + * settlement.setApprovedFlag(0); + * settlement.setApprovedFlagDate(null); + * settlementRepository.save(settlement); + * System.out.println("✅ Approved flag reset after 4 days for Settlement ID: " + + * settlementId); + * } + * } + * + * return settlement; + * } + * + * return null; + * } + */ + @Override - public List getSettlementListWithWaitingRefund() { - return settlementRepository.findByBookingDetailsRefundStatus(RefundStatus.WAITING); - } + public List getSettlementListWithWaitingRefund() { + return settlementRepository.findByBookingDetailsRefundStatus(RefundStatus.WAITING); + } + @Override public Settlement updateSettlementStatus(int settlementId, BookingDetails.RefundStatus status, String comments) { - Optional settlementOptional = settlementRepository.findById(settlementId); - String adminname = (String) session.getAttribute("usertype"); - if (settlementOptional.isPresent()) { - Settlement settlement = settlementOptional.get(); - BookingDetails bookingDetails = settlement.getBookingDetails(); // Fetch associated BookingDetails - - // Update BookingDetails with new RefundStatus - //bookingDetails.setRefundStatus(status); - // If the refund status is COMPLETED, update the BookingStatus to COMPLETED -// if (status == BookingDetails.RefundStatus.COMPLETED) { -// bookingDetails.setBookingStatus(BookingDetails.BookingStatus.COMPLETED); -// }else { -// bookingDetails.setBookingStatus(BookingDetails.BookingStatus.APPROVED); -// } - bookingDetailsRepository.save(bookingDetails); - settlement.setUpdatedDate(new Date()); - // Update Settlement comments - settlement.setComments(comments); - - // Save and return updated Settlement - return settlementRepository.save(settlement); - } - - return null; + Optional settlementOptional = settlementRepository.findById(settlementId); + String adminname = (String) session.getAttribute("usertype"); + if (settlementOptional.isPresent()) { + Settlement settlement = settlementOptional.get(); + System.out.println("settlement@12345" + settlement); + BookingDetails bookingDetails = settlement.getBookingDetails(); // Fetch associated BookingDetails + + // Update BookingDetails with new RefundStatus + // bookingDetails.setRefundStatus(status); + // If the refund status is COMPLETED, update the BookingStatus to COMPLETED + // if (status == BookingDetails.RefundStatus.COMPLETED) { + // bookingDetails.setBookingStatus(BookingDetails.BookingStatus.COMPLETED); + // }else { + // bookingDetails.setBookingStatus(BookingDetails.BookingStatus.APPROVED); + // } + + // to maintain history for settlement + + + + bookingDetailsRepository.save(bookingDetails); + + //ak + //settlement histoty insert + + + if (settlementOptional.isPresent()) { + + + SettlementHistory history = new SettlementHistory(); + history.setSettlementId(settlement.getSettlementId()); + history.setComments(settlement.getComments()); + history.setCdate(settlement.getCdate()); + history.setDamageAmount(settlement.getDamageAmount()); + history.setEbAmount(settlement.getEbAmount()); + history.setDepositAmount(settlement.getDepositAmount()); + history.setRefundedAmount(settlement.getRefundedAmount()); + history.setUpdatedDate(new Date()); + history.setUpdatedId(adminname); + history.setChallon(settlement.getChallon()); + history.setDddate(settlement.getDddate()); + history.setDdnumber(settlement.getDdnumber()); + history.setBookingDetails(settlement.getBookingDetails()); + history.setCollectionPending(settlement.getCollectionPending()); + history.setDdamount(settlement.getDdamount()); + history.setChallonnumber(settlement.getChallonnumber()); + history.setCollectionStatus(settlement.getCollectionStatus()); + history.setChallonamount(settlement.getChallonamount()); + history.setApprovedFlag(settlement.getApprovedFlag()); + history.setApprovedFlagDate(settlement.getApprovedFlagDate()); + history.setShDate(new Date()); + + settlementHistoryRepository.save(history); + System.out.println("✅ Record inserted into SettlementHistory for Settlement ID: " + settlementId); + } + + + // checking ak + //settlement.setApprovedFlag(1); + //settlement.setApprovedFlagDate(new Date()); + + settlement.setUpdatedDate(new Date()); + // Update Settlement comments + settlement.setComments(comments); + + // Save and return updated Settlement + return settlementRepository.save(settlement); + } + + return null; } + // ak @Override - public Settlement updateRejectSettlementStatus(int settlementId, BookingDetails.RefundStatus status , String comments) { - Optional settlementOptional = settlementRepository.findById(settlementId); - - if (settlementOptional.isPresent()) { - Settlement settlement = settlementOptional.get(); - BookingDetails bookingDetails = settlement.getBookingDetails(); // Fetch associated BookingDetails - bookingDetails.setRefundStatus(status); - bookingDetailsRepository.save(bookingDetails); - - // Update Settlement comments - settlement.setComments(comments); - settlement.setUpdatedDate(new Date()); - - // Save and return updated Settlement - return settlementRepository.save(settlement); - } - - return null; + public Settlement updateRejectSettlementStatus(int settlementId, BookingDetails.RefundStatus status, + String comments) { + Optional settlementOptional = settlementRepository.findById(settlementId); + + if (settlementOptional.isPresent()) { + Settlement settlement = settlementOptional.get(); + BookingDetails bookingDetails = settlement.getBookingDetails(); // Fetch associated BookingDetails + bookingDetails.setRefundStatus(status); + bookingDetailsRepository.save(bookingDetails); + + // Update Settlement comments + settlement.setComments(comments); + settlement.setUpdatedDate(new Date()); + + // Save and return updated Settlement + return settlementRepository.save(settlement); + } + + return null; } @Override @@ -143,36 +244,37 @@ public class SettlementServiceImpl implements SettlementService{ return null; } - @Override - public Settlement uploadChallonDetails(int settlementId, long ddNumber, String ddDate,long ddamount, MultipartFile challonimage, long challonnumber, long challonamount) { - Optional settlementOptional = settlementRepository.findById(settlementId); - - if (settlementOptional.isPresent()) { - Settlement updateSettlement = settlementOptional.get(); - updateSettlement.setDdnumber(ddNumber); - updateSettlement.setDddate(ddDate); - updateSettlement.setChallonamount(challonamount); - updateSettlement.setChallonnumber(challonnumber); - updateSettlement.setDdamount(ddamount); - - if (challonimage != null && !challonimage.isEmpty()) { - String fileName = settlementId + "_" + challonimage.getOriginalFilename(); - String filePath = settlementDirectory + "/" + fileName; - - // Save the file to the specified directory - try (FileOutputStream fos = new FileOutputStream(filePath)) { - byte[] bytes = challonimage.getBytes(); - fos.write(bytes); - updateSettlement.setChallon(settlementPhotoUrl + "challonDetails/" + fileName); - } catch (Exception e) { - throw new RuntimeException("Error saving challon image", e); - } - } - - return settlementRepository.save(updateSettlement); - } else { - return null; - } - } + @Override + public Settlement uploadChallonDetails(int settlementId, long ddNumber, String ddDate, long ddamount, + MultipartFile challonimage, long challonnumber, long challonamount) { + Optional settlementOptional = settlementRepository.findById(settlementId); + + if (settlementOptional.isPresent()) { + Settlement updateSettlement = settlementOptional.get(); + updateSettlement.setDdnumber(ddNumber); + updateSettlement.setDddate(ddDate); + updateSettlement.setChallonamount(challonamount); + updateSettlement.setChallonnumber(challonnumber); + updateSettlement.setDdamount(ddamount); + + if (challonimage != null && !challonimage.isEmpty()) { + String fileName = settlementId + "_" + challonimage.getOriginalFilename(); + String filePath = settlementDirectory + "/" + fileName; + + // Save the file to the specified directory + try (FileOutputStream fos = new FileOutputStream(filePath)) { + byte[] bytes = challonimage.getBytes(); + fos.write(bytes); + updateSettlement.setChallon(settlementPhotoUrl + "challonDetails/" + fileName); + } catch (Exception e) { + throw new RuntimeException("Error saving challon image", e); + } + } + + return settlementRepository.save(updateSettlement); + } else { + return null; + } + } } diff --git a/src/main/java/com/gcc/communityHall/service/SettlementService.java b/src/main/java/com/gcc/communityHall/service/SettlementService.java index d5ad210d..a673d54f 100644 --- a/src/main/java/com/gcc/communityHall/service/SettlementService.java +++ b/src/main/java/com/gcc/communityHall/service/SettlementService.java @@ -1,6 +1,8 @@ package com.gcc.communityHall.service; +import java.time.Instant; import java.util.List; +import java.util.Optional; import org.springframework.web.multipart.MultipartFile; @@ -12,6 +14,8 @@ public interface SettlementService { public Settlement settlement(Settlement settlement); public Settlement getSettlementById(int settlementId); + //ak + public Settlement updateSettlementStatus(int settlementId, BookingDetails.RefundStatus status , String comments); diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 27a9a421..97b1c244 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -40,7 +40,7 @@ employee.api.url=https://erp.chennaicorporation.gov.in/pgr/external/mobileservic app.erpUrl=https://erp.chennaicorporation.gov.in/pgr/external/mobileservice? server.address=0.0.0.0 -server.port=8080 +server.port=8062 #fileHanding file.upload.directory=${user.dir}/communityHallDocuments @@ -70,5 +70,5 @@ app.getOtpUrl=https://tmegov.onex-aura.com/api/sms? app.manualRefundCode=8520 -app.fullUrl=http://localhost:8080 +app.fullUrl=http://localhost:8062 app.commErpUrl=http://coc-staging.egovernments.org:9980/pgr/external/mobileservice diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index bece02c8..be83116c 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,8 +1,11 @@ spring.application.name=communityHall -spring.datasource.url=jdbc:mysql://localhost:3306/communityhall_live +# spring.datasource.url=jdbc:mysql://localhost:3306/communityhall_live +# spring.datasource.username=root +# spring.datasource.password=gccroot +spring.datasource.url=jdbc:mysql://gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306/communityhall_live spring.datasource.username=root -spring.datasource.password=gccroot +spring.datasource.password=gcc-facial-password spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.hibernate.ddl-auto=update @@ -53,5 +56,5 @@ app.getOtpUrl=https://tmegov.onex-aura.com/api/sms? app.manualRefundCode=8520 -app.fullUrl=https://gccservices.chennaicorporation.gov.in/communityhall +app.fullUrl=https://gccservices.in/communityhall app.commErpUrl=https://erp.chennaicorporation.gov.in/pgr/external/mobileservice \ No newline at end of file diff --git a/src/main/resources/templates/admin/reports.html b/src/main/resources/templates/admin/reports.html index 097740ba..b336914b 100644 --- a/src/main/resources/templates/admin/reports.html +++ b/src/main/resources/templates/admin/reports.html @@ -128,6 +128,7 @@ + @@ -752,6 +753,53 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.NoBooking IDBooking DateSettlement InitatedUser NameMobileHall NameStart DateEnd DateAmount ReceivedRefunded AmountRefund Transaction IDAction
+ View +
+
+ + @@ -1679,7 +1727,7 @@ } // Tables using default buttons - $('#requestTable1, #requestTable2, #requestTable3, #requestTable8, #requestTable4, #requestTable5, #requestTable6, #requestTable7, #requestTable10, #hallwiseBookingTable, #counterDetailsTable').DataTable({ + $('#requestTable1, #requestTable2, #requestTable3, #requestTable8, #requestTable4, #requestTable5, #requestTable6, #requestTable7, #requestTable10, #requestTable11,#hallwiseBookingTable, #counterDetailsTable').DataTable({ dom: 'Bftip', columnDefs: [{ targets: 'no-sort', diff --git a/src/main/resources/templates/admin/settlement-list.html b/src/main/resources/templates/admin/settlement-list.html index 44eef482..a84a388a 100644 --- a/src/main/resources/templates/admin/settlement-list.html +++ b/src/main/resources/templates/admin/settlement-list.html @@ -63,6 +63,14 @@ GCC Blocked/Rejected Refund +
@@ -92,7 +100,9 @@ - + + @@ -218,6 +228,70 @@
+
+
+

Settlement Initiated

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.nosZoneDivisionHall NameBooking IdBooking DateSettlement IdSettlement raised DateDeposit AmountCollection PendingRefund AmountStatusLast Initade dateAction
+ + +

+ Approve +

+
+
+
+
+
@@ -761,6 +835,27 @@ var targetTable = $(e.target).attr('href'); // activated tab $(targetTable).find('.dataTable').DataTable().columns.adjust(); }); + //ak + // Initialize DataTable for SettlementInitiatedListTable + $('#SettlementInitiatedListTable').DataTable({ + dom: 'Bftip', + columnDefs: [ + { targets: 'no-sort', orderable: false } + ], + lengthMenu: [ + [50, 100, 200, 500, -1], + ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all'] + ], + buttons: buttons, + responsive: true, + searching: true, + select: false, + processing: false, + // Set width to 100% + "autoWidth": true + }); + + // Initialize DataTable for Settlement Approved tab $('#SettlementApprovedListTable').DataTable({ @@ -829,6 +924,11 @@ success: function (x) { showSettlementInfo(x) showDamageDetails(x); + if (x.settlement && x.settlement.approvedFlag === 1) { + $("#approvebutton").hide(); + } else { + $("#approvebutton").show(); + } } }); @@ -1091,13 +1191,48 @@ ); } }, - error: function (xhr, textStatus, errorThrown) { + /*error: function (xhr, textStatus, errorThrown) { loadingSwal.close(); // Close the loading popup Swal.fire( 'Error', 'Failed to accept the user', 'error' ); + },*/ + error: function (xhr, textStatus, errorThrown) { + loadingSwal.close(); + console.log("textstaus"+xhr.responseText); + + let responseData; + try { + responseData = JSON.parse(xhr.responseText); + } catch (e) { + responseData = null; + } + + /* if (responseData && responseData.approvedFlag === 1) { + $("#approvebutton").hide(); // hide approve button if already approved + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + );*/ + if (responseData && responseData.approvedFlag === 1) { + $("#approvebutton").hide(); // hide approve button if already approved + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + ).then(() => { + location.reload(); // reload page after user closes the alert + }); + } else { + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + ); + } }, complete: function() { // Re-enable the button after request completes (success or error) diff --git a/src/main/resources/templates/headquarters/settlement-list.html b/src/main/resources/templates/headquarters/settlement-list.html index 7ce79fc0..dd03d9ce 100644 --- a/src/main/resources/templates/headquarters/settlement-list.html +++ b/src/main/resources/templates/headquarters/settlement-list.html @@ -63,6 +63,14 @@ GCC Blocked/Rejected Refund +
@@ -92,7 +100,9 @@ - + + @@ -218,6 +228,71 @@
+
+
+

Settlement Initiated

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.nosZoneDivisionHall NameBooking IdBooking DateSettlement IdSettlement raised DateDeposit AmountCollection PendingRefund AmountStatusLast Initade dateAction
+ + +

+ Approve +

+
+
+
+
+
@@ -761,6 +836,27 @@ var targetTable = $(e.target).attr('href'); // activated tab $(targetTable).find('.dataTable').DataTable().columns.adjust(); }); + //ak + // Initialize DataTable for SettlementInitiatedListTable + $('#SettlementInitiatedListTable').DataTable({ + dom: 'Bftip', + columnDefs: [ + { targets: 'no-sort', orderable: false } + ], + lengthMenu: [ + [50, 100, 200, 500, -1], + ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all'] + ], + buttons: buttons, + responsive: true, + searching: true, + select: false, + processing: false, + // Set width to 100% + "autoWidth": true + }); + + // Initialize DataTable for Settlement Approved tab $('#SettlementApprovedListTable').DataTable({ @@ -829,7 +925,15 @@ success: function (x) { showSettlementInfo(x) showDamageDetails(x); + //ak for headquarters + if (x.settlement && x.settlement.approvedFlag === 1) { + $("#approvebutton").hide(); + } else { + $("#approvebutton").show(); + } } + + }); } @@ -1091,13 +1195,50 @@ ); } }, - error: function (xhr, textStatus, errorThrown) { + /*error: function (xhr, textStatus, errorThrown) { loadingSwal.close(); // Close the loading popup Swal.fire( 'Error', 'Failed to accept the user', 'error' - ); + );*/ + //ak for headquarters + error: function (xhr, textStatus, errorThrown) { + loadingSwal.close(); + console.log("textstaus"+xhr.responseText); + + let responseData; + try { + responseData = JSON.parse(xhr.responseText); + } catch (e) { + responseData = null; + } + console.log("Response Data:", responseData); + + /* if (responseData && responseData.approvedFlag === 1) { + $("#approvebutton").hide(); // hide approve button if already approved + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + );*/ + if (responseData && responseData.approvedFlag === 1) { + $("#approvebutton").hide(); // hide approve button if already approved + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + ).then(() => { + location.reload(); // reload page after user closes the alert + }); + } else { + Swal.fire( + 'Error', + 'Failed to Approve24 the Settlement', + 'error' + ); + } + }, complete: function() { // Re-enable the button after request completes (success or error) diff --git a/src/main/resources/templates/officer/settlement-list.html b/src/main/resources/templates/officer/settlement-list.html index 21c453e2..ce4451eb 100644 --- a/src/main/resources/templates/officer/settlement-list.html +++ b/src/main/resources/templates/officer/settlement-list.html @@ -53,6 +53,14 @@ GCC Blocked/Rejected Refund +
@@ -82,7 +90,9 @@ - + + @@ -208,6 +218,71 @@
+ +
+
+

Settlement Initiated

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
S.nosZoneDivisionHall NameBooking IdBooking DateSettlement IdSettlement raised DateDeposit AmountCollection PendingRefund AmountStatusLast Initade dateAction
+ + +

+ Approve +

+
+
+
+
+
@@ -751,6 +826,26 @@ var targetTable = $(e.target).attr('href'); // activated tab $(targetTable).find('.dataTable').DataTable().columns.adjust(); }); + //ak + // Initialize DataTable for SettlementInitiatedListTable + $('#SettlementInitiatedListTable').DataTable({ + dom: 'Bftip', + columnDefs: [ + { targets: 'no-sort', orderable: false } + ], + lengthMenu: [ + [50, 100, 200, 500, -1], + ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all'] + ], + buttons: buttons, + responsive: true, + searching: true, + select: false, + processing: false, + // Set width to 100% + "autoWidth": true + }); + // Initialize DataTable for Settlement Approved tab $('#SettlementApprovedListTable').DataTable({ @@ -819,6 +914,12 @@ success: function (x) { showSettlementInfo(x) showDamageDetails(x); + //ak for officer + if (x.settlement && x.settlement.approvedFlag === 1) { + $("#approvebutton").hide(); + } else { + $("#approvebutton").show(); + } } }); @@ -1081,14 +1182,51 @@ ); } }, - error: function (xhr, textStatus, errorThrown) { + /* error: function (xhr, textStatus, errorThrown) { loadingSwal.close(); // Close the loading popup Swal.fire( 'Error', 'Failed to Approve the Settlement', 'error' - ); + );*/ + //ak for officer + + error: function (xhr, textStatus, errorThrown) { + loadingSwal.close(); + console.log("textstaus"+xhr.responseText); + + let responseData; + try { + responseData = JSON.parse(xhr.responseText); + } catch (e) { + responseData = null; + } + + /* if (responseData && responseData.approvedFlag === 1) { + $("#approvebutton").hide(); // hide approve button if already approved + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + );*/ + if (responseData && responseData.approvedFlag === 1) { + $("#approvebutton").hide(); // hide approve button if already approved + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + ).then(() => { + location.reload(); // reload page after user closes the alert + }); + } else { + Swal.fire( + 'Error', + 'Failed to Approve the Settlement', + 'error' + ); + } }, + complete: function() { // Re-enable the button after request completes (success or error) acceptButton.disabled = false;