killbill-memoizeit

invoice: Fix issue with recurring billing in arrear In a case

9/2/2015 11:26:22 PM

Details

diff --git a/invoice/src/main/java/org/killbill/billing/invoice/generator/BillingIntervalDetail.java b/invoice/src/main/java/org/killbill/billing/invoice/generator/BillingIntervalDetail.java
index 51f2845..76843fd 100644
--- a/invoice/src/main/java/org/killbill/billing/invoice/generator/BillingIntervalDetail.java
+++ b/invoice/src/main/java/org/killbill/billing/invoice/generator/BillingIntervalDetail.java
@@ -140,8 +140,8 @@ public class BillingIntervalDetail {
         }
         proposedDate = alignProposedBillCycleDate(proposedDate, billingCycleDay);
 
-        // The proposedDate is greater to our endDate => return it
-        if (endDate != null && endDate.isBefore(proposedDate)) {
+        // We honor the endDate as long as it does not go beyond our targetDate (by construction this cannot be after the nextProposedDate neither.
+        if (endDate != null && !endDate.isAfter(targetDate)) {
             effectiveEndDate = endDate;
         } else {
             effectiveEndDate = proposedDate;