Search in sources :

Example 41 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testFullRepairPruneLogic1.

// Will test the case A from ItemsNodeInterval#prune logic (when we delete a node while walking the tree)
@Test(groups = "fast")
public void testFullRepairPruneLogic1() {
    final LocalDate startDate1 = new LocalDate(2015, 1, 1);
    final LocalDate endDate1 = new LocalDate(2015, 2, 1);
    final LocalDate startDate2 = endDate1;
    final LocalDate endDate2 = new LocalDate(2015, 3, 1);
    final LocalDate startDate3 = endDate2;
    final LocalDate endDate3 = new LocalDate(2015, 4, 1);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate1, endDate1, monthlyAmount, monthlyRate, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate2, endDate2, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repairMonthly2 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate2, endDate2, new BigDecimal("-12.00"), currency, monthly2.getId());
    final InvoiceItem monthly3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate3, endDate3, monthlyAmount, monthlyRate, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly1);
    expectedResult.add(monthly3);
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.addItem(repairMonthly2);
    tree.addItem(monthly3);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) 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 42 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testAnnualFullRepairFollowedByMonthly.

@Test(groups = "fast")
public void testAnnualFullRepairFollowedByMonthly() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate firstMonthlyEndDate = new LocalDate(2014, 2, 1);
    final LocalDate secondMonthlyEndDate = new LocalDate(2014, 3, 1);
    final LocalDate endDate = new LocalDate(2015, 2, 1);
    final BigDecimal rate1 = new BigDecimal("120.00");
    final BigDecimal amount1 = rate1;
    final BigDecimal rate2 = new BigDecimal("10.00");
    final BigDecimal amount2 = rate2;
    final InvoiceItem annual = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, amount1.negate(), currency, annual.getId());
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", startDate, firstMonthlyEndDate, amount2, rate2, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", firstMonthlyEndDate, secondMonthlyEndDate, amount2, rate2, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly1);
    expectedResult.add(monthly2);
    SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(annual);
    tree.addItem(repair);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(repair);
    tree.addItem(annual);
    tree.addItem(monthly2);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.addItem(annual);
    tree.addItem(repair);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) 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 43 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testFullRepairByPartsPruneLogic2.

// Will test the case A and B from ItemsNodeInterval#prune logic
@Test(groups = "fast")
public void testFullRepairByPartsPruneLogic2() {
    final LocalDate startDate = new LocalDate(2015, 2, 1);
    final LocalDate intermediate1 = new LocalDate(2015, 2, 8);
    final LocalDate intermediate2 = new LocalDate(2015, 2, 16);
    final LocalDate intermediate3 = new LocalDate(2015, 2, 24);
    final LocalDate endDate = new LocalDate(2015, 3, 1);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repair11 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, new BigDecimal("-12.00"), currency, monthly1.getId());
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repair21 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, intermediate1, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem repair22 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate1, intermediate2, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem repair23 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate2, intermediate3, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem repair24 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate3, endDate, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem monthly3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly3);
    // First test with items in order
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(repair11);
    tree.addItem(monthly2);
    tree.addItem(repair21);
    tree.addItem(repair22);
    tree.addItem(repair23);
    tree.addItem(repair24);
    tree.addItem(monthly3);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) 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 44 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testSimpleRepair.

@Test(groups = "fast")
public void testSimpleRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final LocalDate repairDate = new LocalDate(2014, 1, 23);
    final BigDecimal rate1 = new BigDecimal("12.00");
    final BigDecimal amount1 = rate1;
    final BigDecimal rate2 = new BigDecimal("14.85");
    final BigDecimal amount2 = rate2;
    final InvoiceItem initial = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency);
    final InvoiceItem newItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", repairDate, endDate, amount2, rate2, currency);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, repairDate, endDate, amount1.negate(), currency, initial.getId());
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, repairDate, new BigDecimal("8.52"), rate1, currency);
    expectedResult.add(expected1);
    final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", repairDate, endDate, amount2, rate2, currency);
    expectedResult.add(expected2);
    // First test with items in order
    SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(initial);
    tree.addItem(newItem);
    tree.addItem(repair);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(repair);
    tree.addItem(newItem);
    tree.addItem(initial);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(repair);
    tree.addItem(initial);
    tree.addItem(newItem);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) 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 45 with RepairAdjInvoiceItem

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

the class TestDefaultInvoiceGenerator method testRegressionFor170.

// Regression test for #170 (see https://github.com/killbill/killbill/pull/173)
@Test(groups = "fast")
public void testRegressionFor170() throws EntityPersistenceException, InvoiceApiException, CatalogApiException {
    final UUID accountId = account.getId();
    final Currency currency = Currency.USD;
    final SubscriptionBase subscription = createSubscription();
    final MockInternationalPrice recurringPrice = new MockInternationalPrice(new DefaultPrice(new BigDecimal("2.9500"), Currency.USD));
    final MockPlanPhase phase = new MockPlanPhase(recurringPrice, null);
    final Plan plan = new MockPlan(phase);
    final LocalDate targetDate = new LocalDate(2013, 10, 30);
    final Invoice existingInvoice = new DefaultInvoice(UUID.randomUUID(), accountId, null, clock.getUTCToday(), targetDate, currency, false, InvoiceStatus.COMMITTED);
    // Set the existing recurring invoice item 2013/06/15 - 2013/07/15
    final LocalDate startDate = new LocalDate(2013, 06, 15);
    final LocalDate endDate = new LocalDate(2013, 07, 15);
    final InvoiceItem recurringInvoiceItem = new RecurringInvoiceItem(existingInvoice.getId(), accountId, subscription.getBundleId(), subscription.getId(), plan.getName(), phase.getName(), startDate, endDate, recurringPrice.getPrice(currency), recurringPrice.getPrice(currency), Currency.USD);
    existingInvoice.addInvoiceItem(recurringInvoiceItem);
    // Set an existing repair item
    final LocalDate repairStartDate = new LocalDate(2013, 06, 21);
    final LocalDate repairEndDate = new LocalDate(2013, 06, 26);
    final BigDecimal repairAmount = new BigDecimal("0.4900").negate();
    final InvoiceItem repairItem = new RepairAdjInvoiceItem(existingInvoice.getId(), accountId, repairStartDate, repairEndDate, repairAmount, currency, recurringInvoiceItem.getId());
    existingInvoice.addInvoiceItem(repairItem);
    // Create the billing event associated with the subscription creation
    //
    // Note : this is the interesting part of the test; it does not provide the blocking billing events, which force invoice
    // to un repair what was previously repaired.
    final BillingEventSet events = new MockBillingEventSet();
    final BillingEvent event = invoiceUtil.createMockBillingEvent(null, subscription, new DateTime("2013-06-15", DateTimeZone.UTC), plan, phase, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 15, BillingMode.IN_ADVANCE, "testEvent", 1L, SubscriptionBaseTransitionType.CREATE);
    events.add(event);
    final List<Invoice> existingInvoices = new LinkedList<Invoice>();
    existingInvoices.add(existingInvoice);
    // Generate a new invoice
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, existingInvoices, targetDate, currency, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertEquals(invoice.getNumberOfItems(), 7);
    assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), new LocalDate(2013, 6, 15));
    assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), new LocalDate(2013, 7, 15));
    assertEquals(invoice.getInvoiceItems().get(1).getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
    assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), new LocalDate(2013, 6, 15));
    assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), new LocalDate(2013, 6, 21));
    assertEquals(invoice.getInvoiceItems().get(2).getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
    assertEquals(invoice.getInvoiceItems().get(2).getStartDate(), new LocalDate(2013, 6, 26));
    assertEquals(invoice.getInvoiceItems().get(2).getEndDate(), new LocalDate(2013, 7, 15));
    assertEquals(invoice.getInvoiceItems().get(3).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(3).getStartDate(), new LocalDate(2013, 7, 15));
    assertEquals(invoice.getInvoiceItems().get(3).getEndDate(), new LocalDate(2013, 8, 15));
    assertEquals(invoice.getInvoiceItems().get(4).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(4).getStartDate(), new LocalDate(2013, 8, 15));
    assertEquals(invoice.getInvoiceItems().get(4).getEndDate(), new LocalDate(2013, 9, 15));
    assertEquals(invoice.getInvoiceItems().get(5).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(5).getStartDate(), new LocalDate(2013, 9, 15));
    assertEquals(invoice.getInvoiceItems().get(5).getEndDate(), new LocalDate(2013, 10, 15));
    assertEquals(invoice.getInvoiceItems().get(6).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(6).getStartDate(), new LocalDate(2013, 10, 15));
    assertEquals(invoice.getInvoiceItems().get(6).getEndDate(), new LocalDate(2013, 11, 15));
    // Add newly generated invoice to existing invoices
    existingInvoices.add(invoice);
    // Generate next invoice (no-op)
    final InvoiceWithMetadata newInvoiceWithMetdata = generator.generateInvoice(account, events, existingInvoices, targetDate, currency, internalCallContext);
    final Invoice newInvoice = newInvoiceWithMetdata.getInvoice();
    assertNull(newInvoice);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) Currency(org.killbill.billing.catalog.api.Currency) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Aggregations

RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)50 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)48 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)48 Test (org.testng.annotations.Test)47 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)46 BigDecimal (java.math.BigDecimal)45 LocalDate (org.joda.time.LocalDate)45 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)45 UUID (java.util.UUID)19 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)19 Invoice (org.killbill.billing.invoice.api.Invoice)18 LinkedList (java.util.LinkedList)11 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)11 BillingEventSet (org.killbill.billing.junction.BillingEventSet)11 SubscriptionFutureNotificationDates (org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates)10 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)9 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)9 MockPlan (org.killbill.billing.catalog.MockPlan)9 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)9 Plan (org.killbill.billing.catalog.api.Plan)9