Search in sources :

Example 31 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testWithFreeRecurring.

@Test(groups = "fast")
public void testWithFreeRecurring() {
    final LocalDate startDate = new LocalDate(2012, 8, 1);
    final LocalDate endDate = new LocalDate(2012, 9, 1);
    final BigDecimal monthlyRate1 = new BigDecimal("12.00");
    final BigDecimal monthlyRate2 = new BigDecimal("24.00");
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem freeMonthly = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, BigDecimal.ZERO, BigDecimal.ZERO, currency);
    tree.addItem(freeMonthly);
    final InvoiceItem payingMonthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyRate1, monthlyRate1, currency);
    tree.addItem(payingMonthly1);
    tree.flatten(true);
    final InvoiceItem proposedPayingMonthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyRate2, monthlyRate2, currency);
    tree.mergeProposedItem(proposedPayingMonthly2);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(proposedPayingMonthly2);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, monthlyRate1.negate(), currency, payingMonthly1.getId());
    expectedResult.add(repair);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 32 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testMergeMonthlyToAnnualWithNoProRation.

@Test(groups = "fast")
public void testMergeMonthlyToAnnualWithNoProRation() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endMonthly1 = new LocalDate(2014, 2, 1);
    final LocalDate endMonthly2 = new LocalDate(2014, 3, 1);
    final LocalDate switchToAnnualDate = new LocalDate(2014, 2, 23);
    final LocalDate endDate = new LocalDate(2015, 2, 23);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final BigDecimal yearlyRate = new BigDecimal("100.00");
    final BigDecimal yearlyAmount = yearlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endMonthly1, monthlyAmount, monthlyRate, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, endMonthly1, endMonthly2, monthlyAmount, monthlyRate, currency);
    // First test with items in order
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.flatten(true);
    final InvoiceItem proposed = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, switchToAnnualDate, endDate, yearlyAmount, yearlyRate, currency);
    final InvoiceItem proposedMonthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endMonthly1, monthlyAmount, monthlyRate, currency);
    tree.mergeProposedItem(proposedMonthly1);
    final InvoiceItem proRatedMonthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, endMonthly1, switchToAnnualDate, monthlyAmount, monthlyRate, currency);
    tree.mergeProposedItem(proRatedMonthly2);
    tree.mergeProposedItem(proposed);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, switchToAnnualDate, endMonthly2, new BigDecimal("-2.57"), currency, monthly2.getId());
    expectedResult.add(proposed);
    expectedResult.add(repair);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 33 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testBlockAcrossPeriod.

@Test(groups = "fast")
public void testBlockAcrossPeriod() {
    final LocalDate startDate1 = new LocalDate(2014, 1, 1);
    final LocalDate blockDate = new LocalDate(2014, 1, 25);
    final LocalDate startDate2 = new LocalDate(2014, 2, 1);
    final LocalDate unblockDate = new LocalDate(2014, 2, 7);
    final LocalDate endDate = new LocalDate(2014, 3, 1);
    final BigDecimal rate1 = new BigDecimal("12.00");
    final BigDecimal amount1 = rate1;
    final InvoiceItem first = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate1, startDate2, amount1, rate1, currency);
    final InvoiceItem second = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate2, endDate, amount1, rate1, currency);
    final InvoiceItem block1 = new RepairAdjInvoiceItem(invoiceId, accountId, blockDate, startDate2, amount1.negate(), currency, first.getId());
    final InvoiceItem block2 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate2, unblockDate, amount1.negate(), currency, first.getId());
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate1, blockDate, new BigDecimal("9.29"), rate1, currency);
    final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, unblockDate, endDate, new BigDecimal("9.43"), rate1, currency);
    expectedResult.add(expected1);
    expectedResult.add(expected2);
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(first);
    tree.addItem(second);
    tree.addItem(block1);
    tree.addItem(block2);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 34 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testMonthlyToAnnualWithLeadingProRation.

@Test(groups = "fast")
public void testMonthlyToAnnualWithLeadingProRation() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endMonthly1 = new LocalDate(2014, 2, 1);
    final LocalDate endMonthly2 = new LocalDate(2014, 3, 1);
    final LocalDate switchToAnnualDate = new LocalDate(2014, 2, 23);
    final LocalDate endDate = new LocalDate(2015, 3, 1);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final BigDecimal yearlyRate = new BigDecimal("100.00");
    final BigDecimal yearlyAmount = yearlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endMonthly1, monthlyAmount, monthlyRate, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, endMonthly1, endMonthly2, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, switchToAnnualDate, endMonthly2, monthlyAmount.negate(), currency, monthly2.getId());
    final InvoiceItem leadingAnnualProration = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, switchToAnnualDate, endMonthly2, yearlyAmount, yearlyRate, currency);
    final InvoiceItem annual = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, endMonthly2, endDate, yearlyAmount, yearlyRate, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly1);
    final InvoiceItem monthly2Prorated = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, endMonthly1, switchToAnnualDate, new BigDecimal("9.43"), monthlyRate, currency);
    expectedResult.add(monthly2Prorated);
    expectedResult.add(leadingAnnualProration);
    expectedResult.add(annual);
    // First test with items in order
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.addItem(repair);
    tree.addItem(leadingAnnualProration);
    tree.addItem(annual);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 35 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testMergeCancellationWithFinalRepair.

@Test(groups = "fast")
public void testMergeCancellationWithFinalRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate cancelDate = new LocalDate(2014, 1, 25);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final BigDecimal monthlyRate1 = new BigDecimal("12.00");
    final BigDecimal monthlyAmount1 = monthlyRate1;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.addItem(monthly1);
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, cancelDate, monthlyAmount1, monthlyRate1, currency);
    tree.mergeProposedItem(proposed1);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, cancelDate, endDate, new BigDecimal("-2.71"), currency, monthly1.getId());
    expectedResult.add(repair);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Aggregations

RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)98 Test (org.testng.annotations.Test)90 LocalDate (org.joda.time.LocalDate)89 BigDecimal (java.math.BigDecimal)82 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)73 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)69 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)69 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)65 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)39 Invoice (org.killbill.billing.invoice.api.Invoice)38 UUID (java.util.UUID)34 MockPlan (org.killbill.billing.catalog.MockPlan)16 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)16 Plan (org.killbill.billing.catalog.api.Plan)16 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)16 AccountInvoices (org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices)16 BillingEventSet (org.killbill.billing.junction.BillingEventSet)16 HashMap (java.util.HashMap)15 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)15 BillingEvent (org.killbill.billing.junction.BillingEvent)15