Skip to content

Commit

Permalink
incorrectly calculated rent payment plan fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
burakpadr committed Jul 10, 2024
1 parent 821b0cd commit 1ce80ce
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ private void throwExceptionIfRentalContractAlreadyPusblished(Long realEstateId)
}

private List<Invoice> prepareRentInvoices(RentalContract rentalContract) {
Long rentalContractValidityPeriodAsMonths = DateUtil.differenceBetween(ChronoUnit.MONTHS,
rentalContract.getStartDate(), rentalContract.getEndDate()) + 1;
long rentalContractValidityPeriodAsMonths = DateUtil.differenceBetween(ChronoUnit.MONTHS,
rentalContract.getStartDate(), rentalContract.getEndDate()) + 2;

return LongStream.range(0, rentalContractValidityPeriodAsMonths).boxed().map(index -> {
int invoiceYear = rentalContract.getStartDate().plusMonths(index).getYear();
Expand All @@ -121,11 +121,9 @@ private List<Invoice> prepareRentInvoices(RentalContract rentalContract) {
int daysInMonth = yearMonth.lengthOfMonth();

LocalDate dateOfInvoice;
BigDecimal invoiceFeePaid = BigDecimal.ZERO;
BigDecimal invoiceFeePaid;

if (index == 0) {
long numberOfDaysInvoicePaid;

int rentalContractStartDay = rentalContract.getStartDate().getDayOfMonth();
int rentalContractEndDay = rentalContract.getEndDate().getDayOfMonth();

Expand All @@ -137,9 +135,6 @@ private List<Invoice> prepareRentInvoices(RentalContract rentalContract) {
dateOfInvoice = rentalContract.getStartDate();
}

numberOfDaysInvoicePaid = DateUtil.differenceBetween(ChronoUnit.DAYS,
rentalContract.getStartDate(), rentalContract.getEndDate()) + 1;

invoiceFeePaid = rentalContract.getMonthlyRentFee();
} else {
dateOfInvoice = rentalContract.getStartDate()
Expand All @@ -150,17 +145,17 @@ private List<Invoice> prepareRentInvoices(RentalContract rentalContract) {
invoiceMonth,
rentalContract.getRentalPaymentDay());

numberOfDaysInvoicePaid = daysInMonth - rentalContract.getStartDate().getDayOfMonth() + 1;
long numberOfDaysInvoicePaid = daysInMonth - rentalContract.getStartDate().getDayOfMonth() + 1;

invoiceFeePaid = rentalContract.getMonthlyRentFee()
.divide(new BigDecimal(daysInMonth), 2, RoundingMode.HALF_UP)
.multiply(new BigDecimal(numberOfDaysInvoicePaid));
}

} else if (index == rentalContractValidityPeriodAsMonths - 1) {
} else if (index.equals(rentalContractValidityPeriodAsMonths - 1)) {
dateOfInvoice = rentalContract.getEndDate()
.getDayOfMonth() > rentalContract
.getRentalPaymentDay().intValue() ? LocalDate.of(invoiceYear, invoiceMonth,
.getRentalPaymentDay() ? LocalDate.of(invoiceYear, invoiceMonth,
rentalContract.getRentalPaymentDay())
: rentalContract.getEndDate();

Expand Down

0 comments on commit 1ce80ce

Please sign in to comment.