|
|
@ -3,6 +3,8 @@ package com.gcc.communityHall.service.Impl; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.time.Instant; |
|
|
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
@ -16,16 +18,23 @@ import com.gcc.communityHall.entity.BookingDetails; |
|
|
import com.gcc.communityHall.entity.BookingHistory; |
|
|
import com.gcc.communityHall.entity.BookingHistory; |
|
|
import com.gcc.communityHall.entity.BookingDetails.RefundStatus; |
|
|
import com.gcc.communityHall.entity.BookingDetails.RefundStatus; |
|
|
import com.gcc.communityHall.entity.Settlement; |
|
|
import com.gcc.communityHall.entity.Settlement; |
|
|
|
|
|
import com.gcc.communityHall.entity.SettlementHistory; |
|
|
import com.gcc.communityHall.repository.BookingDetailsRepository; |
|
|
import com.gcc.communityHall.repository.BookingDetailsRepository; |
|
|
import com.gcc.communityHall.repository.BookingHistoryRepository; |
|
|
import com.gcc.communityHall.repository.BookingHistoryRepository; |
|
|
|
|
|
import com.gcc.communityHall.repository.SettlementHistoryRepository; |
|
|
import com.gcc.communityHall.repository.SettlementRepository; |
|
|
import com.gcc.communityHall.repository.SettlementRepository; |
|
|
import com.gcc.communityHall.service.SettlementService; |
|
|
import com.gcc.communityHall.service.SettlementService; |
|
|
|
|
|
import java.time.Instant; |
|
|
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpSession; |
|
|
import jakarta.servlet.http.HttpSession; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class SettlementServiceImpl implements SettlementService { |
|
|
public class SettlementServiceImpl implements SettlementService { |
|
|
|
|
|
// ak |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private SettlementHistoryRepository settlementHistoryRepository; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
SettlementRepository settlementRepository; |
|
|
SettlementRepository settlementRepository; |
|
|
@ -49,7 +58,6 @@ public class SettlementServiceImpl implements SettlementService{ |
|
|
|
|
|
|
|
|
private final String settlementPhotoUrl; |
|
|
private final String settlementPhotoUrl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
SettlementServiceImpl(SettlementRepository settlementRepository, |
|
|
SettlementServiceImpl(SettlementRepository settlementRepository, |
|
|
@Value("${file.settlement.upload.directory}") String settlementDirectory, |
|
|
@Value("${file.settlement.upload.directory}") String settlementDirectory, |
|
|
@ -79,21 +87,67 @@ public class SettlementServiceImpl implements SettlementService{ |
|
|
Settlement settlement = settlementOptional.get(); |
|
|
Settlement settlement = settlementOptional.get(); |
|
|
// Initialize the BookingDetails object |
|
|
// Initialize the BookingDetails object |
|
|
settlement.getBookingDetails(); |
|
|
settlement.getBookingDetails(); |
|
|
|
|
|
// System.out.println("✅ Approved flag reset after 4 days for Settlement ID: " + |
|
|
|
|
|
// settlementId); |
|
|
return settlement; |
|
|
return settlement; |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
// ak |
|
|
|
|
|
/* |
|
|
|
|
|
* @Override |
|
|
|
|
|
* public Settlement getSettlementById(int settlementId) { |
|
|
|
|
|
* Optional<Settlement> 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 |
|
|
@Override |
|
|
public List<Settlement> getSettlementListWithWaitingRefund() { |
|
|
public List<Settlement> getSettlementListWithWaitingRefund() { |
|
|
return settlementRepository.findByBookingDetailsRefundStatus(RefundStatus.WAITING); |
|
|
return settlementRepository.findByBookingDetailsRefundStatus(RefundStatus.WAITING); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Settlement updateSettlementStatus(int settlementId, BookingDetails.RefundStatus status, String comments) { |
|
|
public Settlement updateSettlementStatus(int settlementId, BookingDetails.RefundStatus status, String comments) { |
|
|
Optional<Settlement> settlementOptional = settlementRepository.findById(settlementId); |
|
|
Optional<Settlement> settlementOptional = settlementRepository.findById(settlementId); |
|
|
String adminname = (String) session.getAttribute("usertype"); |
|
|
String adminname = (String) session.getAttribute("usertype"); |
|
|
if (settlementOptional.isPresent()) { |
|
|
if (settlementOptional.isPresent()) { |
|
|
Settlement settlement = settlementOptional.get(); |
|
|
Settlement settlement = settlementOptional.get(); |
|
|
|
|
|
System.out.println("settlement@12345" + settlement); |
|
|
BookingDetails bookingDetails = settlement.getBookingDetails(); // Fetch associated BookingDetails |
|
|
BookingDetails bookingDetails = settlement.getBookingDetails(); // Fetch associated BookingDetails |
|
|
|
|
|
|
|
|
// Update BookingDetails with new RefundStatus |
|
|
// Update BookingDetails with new RefundStatus |
|
|
@ -104,7 +158,52 @@ public class SettlementServiceImpl implements SettlementService{ |
|
|
// }else { |
|
|
// }else { |
|
|
// bookingDetails.setBookingStatus(BookingDetails.BookingStatus.APPROVED); |
|
|
// bookingDetails.setBookingStatus(BookingDetails.BookingStatus.APPROVED); |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// to maintain history for settlement |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bookingDetailsRepository.save(bookingDetails); |
|
|
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()); |
|
|
settlement.setUpdatedDate(new Date()); |
|
|
// Update Settlement comments |
|
|
// Update Settlement comments |
|
|
settlement.setComments(comments); |
|
|
settlement.setComments(comments); |
|
|
@ -115,9 +214,11 @@ public class SettlementServiceImpl implements SettlementService{ |
|
|
|
|
|
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
// ak |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Settlement updateRejectSettlementStatus(int settlementId, BookingDetails.RefundStatus status , String comments) { |
|
|
|
|
|
|
|
|
public Settlement updateRejectSettlementStatus(int settlementId, BookingDetails.RefundStatus status, |
|
|
|
|
|
String comments) { |
|
|
Optional<Settlement> settlementOptional = settlementRepository.findById(settlementId); |
|
|
Optional<Settlement> settlementOptional = settlementRepository.findById(settlementId); |
|
|
|
|
|
|
|
|
if (settlementOptional.isPresent()) { |
|
|
if (settlementOptional.isPresent()) { |
|
|
@ -144,7 +245,8 @@ public class SettlementServiceImpl implements SettlementService{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Settlement uploadChallonDetails(int settlementId, long ddNumber, String ddDate,long ddamount, MultipartFile challonimage, long challonnumber, long challonamount) { |
|
|
|
|
|
|
|
|
public Settlement uploadChallonDetails(int settlementId, long ddNumber, String ddDate, long ddamount, |
|
|
|
|
|
MultipartFile challonimage, long challonnumber, long challonamount) { |
|
|
Optional<Settlement> settlementOptional = settlementRepository.findById(settlementId); |
|
|
Optional<Settlement> settlementOptional = settlementRepository.findById(settlementId); |
|
|
|
|
|
|
|
|
if (settlementOptional.isPresent()) { |
|
|
if (settlementOptional.isPresent()) { |
|
|
|