Search in sources :

Example 6 with CreditBalanceAdjInvoiceItem

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

the class TestInvoiceDao method testRefundWithCBAPartiallyConsumed.

@Test(groups = "slow")
public void testRefundWithCBAPartiallyConsumed() throws Exception {
    final UUID accountId = account.getId();
    // Create invoice 1
    // Scenario: single item with payment
    // * $10 item
    // Then, a repair occur:
    // * $-10 repair
    // * $10 generated CBA due to the repair (assume previous payment)
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final InvoiceItem fixedItem1 = new FixedPriceInvoiceItem(invoice1.getId(), invoice1.getAccountId(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), clock.getUTCToday(), BigDecimal.TEN, Currency.USD);
    final RepairAdjInvoiceItem repairAdjInvoiceItem = new RepairAdjInvoiceItem(fixedItem1.getInvoiceId(), fixedItem1.getAccountId(), fixedItem1.getStartDate(), fixedItem1.getEndDate(), fixedItem1.getAmount().negate(), fixedItem1.getCurrency(), fixedItem1.getId());
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem1 = new CreditBalanceAdjInvoiceItem(fixedItem1.getInvoiceId(), fixedItem1.getAccountId(), fixedItem1.getStartDate(), fixedItem1.getAmount(), fixedItem1.getCurrency());
    invoiceUtil.createInvoice(invoice1, context);
    invoiceUtil.createInvoiceItem(fixedItem1, context);
    invoiceUtil.createInvoiceItem(repairAdjInvoiceItem, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem1, context);
    final UUID paymentId = UUID.randomUUID();
    final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoice1.getId(), clock.getUTCNow().plusDays(12), new BigDecimal("10.0"), Currency.USD, Currency.USD, "cookie", true);
    invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), context);
    // Create invoice 2
    // Scenario: single item
    // * $5 item
    // * $-5 CBA used
    final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final InvoiceItem fixedItem2 = new FixedPriceInvoiceItem(invoice2.getId(), invoice1.getAccountId(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), clock.getUTCToday(), new BigDecimal("5"), Currency.USD);
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem2 = new CreditBalanceAdjInvoiceItem(fixedItem2.getInvoiceId(), fixedItem2.getAccountId(), fixedItem2.getStartDate(), fixedItem2.getAmount().negate(), fixedItem2.getCurrency());
    invoiceUtil.createInvoice(invoice2, context);
    invoiceUtil.createInvoiceItem(fixedItem2, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem2, context);
    // Verify scenario - half of the CBA should have been used
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 5.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 0.00, 10.00, context);
    invoiceUtil.verifyInvoice(invoice2.getId(), 0.00, -5.00, context);
    // Refund Payment before we can deleted CBA
    invoiceDao.createRefund(paymentId, new BigDecimal("10.0"), false, ImmutableMap.<UUID, BigDecimal>of(), UUID.randomUUID().toString(), context);
    // Verify all three invoices were affected
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 0.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 5.00, 5.00, context);
    invoiceUtil.verifyInvoice(invoice2.getId(), 0.00, -5.00, context);
}
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) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ParentInvoiceItem(org.killbill.billing.invoice.model.ParentInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) Test(org.testng.annotations.Test)

Example 7 with CreditBalanceAdjInvoiceItem

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

the class TestInvoiceDao method testRefundCBAFullyConsumedTwice.

@Test(groups = "slow")
public void testRefundCBAFullyConsumedTwice() throws Exception {
    final UUID accountId = account.getId();
    // Create invoice 1
    // Scenario: single item with payment
    // * $10 item
    // Then, a repair occur:
    // * $-10 repair
    // * $10 generated CBA due to the repair (assume previous payment)
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final InvoiceItem fixedItem1 = new FixedPriceInvoiceItem(invoice1.getId(), invoice1.getAccountId(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), clock.getUTCToday(), BigDecimal.TEN, Currency.USD);
    final RepairAdjInvoiceItem repairAdjInvoiceItem = new RepairAdjInvoiceItem(fixedItem1.getInvoiceId(), fixedItem1.getAccountId(), fixedItem1.getStartDate(), fixedItem1.getEndDate(), fixedItem1.getAmount().negate(), fixedItem1.getCurrency(), fixedItem1.getId());
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem1 = new CreditBalanceAdjInvoiceItem(fixedItem1.getInvoiceId(), fixedItem1.getAccountId(), fixedItem1.getStartDate(), fixedItem1.getAmount(), fixedItem1.getCurrency());
    invoiceUtil.createInvoice(invoice1, context);
    invoiceUtil.createInvoiceItem(fixedItem1, context);
    invoiceUtil.createInvoiceItem(repairAdjInvoiceItem, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem1, context);
    final BigDecimal paymentAmount = new BigDecimal("10.00");
    final UUID paymentId = UUID.randomUUID();
    final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoice1.getId(), clock.getUTCNow().plusDays(12), paymentAmount, Currency.USD, Currency.USD, "cookie", true);
    invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), context);
    // Create invoice 2
    // Scenario: single item
    // * $5 item
    // * $-5 CBA used
    final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final InvoiceItem fixedItem2 = new FixedPriceInvoiceItem(invoice2.getId(), invoice1.getAccountId(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), clock.getUTCToday(), new BigDecimal("5"), Currency.USD);
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem2 = new CreditBalanceAdjInvoiceItem(fixedItem2.getInvoiceId(), fixedItem2.getAccountId(), fixedItem2.getStartDate(), fixedItem2.getAmount().negate(), fixedItem2.getCurrency());
    invoiceUtil.createInvoice(invoice2, context);
    invoiceUtil.createInvoiceItem(fixedItem2, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem2, context);
    // Create invoice 3
    // Scenario: single item
    // * $5 item
    // * $-5 CBA used
    final DefaultInvoice invoice3 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final InvoiceItem fixedItem3 = new FixedPriceInvoiceItem(invoice3.getId(), invoice1.getAccountId(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), clock.getUTCToday(), new BigDecimal("5"), Currency.USD);
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem3 = new CreditBalanceAdjInvoiceItem(fixedItem3.getInvoiceId(), fixedItem3.getAccountId(), fixedItem3.getStartDate(), fixedItem3.getAmount().negate(), fixedItem3.getCurrency());
    invoiceUtil.createInvoice(invoice3, context);
    invoiceUtil.createInvoiceItem(fixedItem3, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem3, context);
    // Verify scenario - all CBA should have been used
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 0.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 0.00, 10.00, context);
    invoiceUtil.verifyInvoice(invoice2.getId(), 0.00, -5.00, context);
    invoiceUtil.verifyInvoice(invoice3.getId(), 0.00, -5.00, context);
    invoiceDao.createRefund(paymentId, paymentAmount, false, ImmutableMap.<UUID, BigDecimal>of(), UUID.randomUUID().toString(), context);
    // Verify all three invoices were affected
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 0.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 10.00, 10.00, context);
    invoiceUtil.verifyInvoice(invoice2.getId(), 0.00, -5.00, context);
    invoiceUtil.verifyInvoice(invoice3.getId(), 0.00, -5.00, context);
}
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) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ParentInvoiceItem(org.killbill.billing.invoice.model.ParentInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) Test(org.testng.annotations.Test)

Example 8 with CreditBalanceAdjInvoiceItem

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

the class TestDefaultInvoiceFormatter method testMergeItems.

@Test(groups = "fast")
public void testMergeItems() throws Exception {
    // Scenario: single item with payment
    // * $10 item
    // Then, a repair occur:
    // * $-10 repair
    // * $10 generated CBA due to the repair (assume previous payment)
    // Then, the invoice is adjusted for $1:
    // * $-1 credit adjustment
    // * $1 generated CBA due to the credit adjustment
    final FixedPriceInvoiceItem fixedItem = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), new LocalDate(), BigDecimal.TEN, Currency.USD);
    final RepairAdjInvoiceItem repairAdjInvoiceItem = new RepairAdjInvoiceItem(fixedItem.getInvoiceId(), fixedItem.getAccountId(), fixedItem.getStartDate(), fixedItem.getEndDate(), fixedItem.getAmount().negate(), fixedItem.getCurrency(), fixedItem.getId());
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem = new CreditBalanceAdjInvoiceItem(fixedItem.getInvoiceId(), fixedItem.getAccountId(), fixedItem.getStartDate(), fixedItem.getAmount(), fixedItem.getCurrency());
    final CreditAdjInvoiceItem creditAdjInvoiceItem = new CreditAdjInvoiceItem(fixedItem.getInvoiceId(), fixedItem.getAccountId(), fixedItem.getStartDate(), null, BigDecimal.ONE.negate(), fixedItem.getCurrency());
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem2 = new CreditBalanceAdjInvoiceItem(fixedItem.getInvoiceId(), fixedItem.getAccountId(), fixedItem.getStartDate(), creditAdjInvoiceItem.getAmount().negate(), fixedItem.getCurrency());
    final DefaultInvoice invoice = new DefaultInvoice(fixedItem.getInvoiceId(), fixedItem.getAccountId(), null, new LocalDate(), new LocalDate(), Currency.USD, false, InvoiceStatus.COMMITTED);
    invoice.addInvoiceItem(fixedItem);
    invoice.addInvoiceItem(repairAdjInvoiceItem);
    invoice.addInvoiceItem(creditBalanceAdjInvoiceItem);
    invoice.addInvoiceItem(creditAdjInvoiceItem);
    invoice.addInvoiceItem(creditBalanceAdjInvoiceItem2);
    invoice.addPayment(new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice.getId(), clock.getUTCNow(), BigDecimal.TEN, Currency.USD, Currency.USD, null, true));
    invoice.addPayment(new DefaultInvoicePayment(InvoicePaymentType.REFUND, UUID.randomUUID(), invoice.getId(), clock.getUTCNow(), BigDecimal.ONE.negate(), Currency.USD, Currency.USD, null, true));
    // Check the scenario
    Assert.assertEquals(invoice.getBalance().doubleValue(), 1.00);
    Assert.assertEquals(invoice.getCreditedAmount().doubleValue(), 11.00);
    Assert.assertEquals(invoice.getRefundedAmount().doubleValue(), -1.00);
    // Verify the merge
    final InvoiceFormatter formatter = new DefaultInvoiceFormatter(config, invoice, Locale.US, null, resourceBundleFactory, internalCallContext);
    final List<InvoiceItem> invoiceItems = formatter.getInvoiceItems();
    Assert.assertEquals(invoiceItems.size(), 4);
    Assert.assertEquals(invoiceItems.get(0).getInvoiceItemType(), InvoiceItemType.FIXED);
    Assert.assertEquals(invoiceItems.get(0).getAmount().doubleValue(), 10.00);
    Assert.assertEquals(invoiceItems.get(1).getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
    Assert.assertEquals(invoiceItems.get(1).getAmount().doubleValue(), -10.00);
    Assert.assertEquals(invoiceItems.get(2).getInvoiceItemType(), InvoiceItemType.CBA_ADJ);
    Assert.assertEquals(invoiceItems.get(2).getAmount().doubleValue(), 11.00);
    Assert.assertEquals(invoiceItems.get(3).getInvoiceItemType(), InvoiceItemType.CREDIT_ADJ);
    Assert.assertEquals(invoiceItems.get(3).getAmount().doubleValue(), -1.00);
}
Also used : InvoiceFormatter(org.killbill.billing.invoice.api.formatters.InvoiceFormatter) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) Test(org.testng.annotations.Test)

Example 9 with CreditBalanceAdjInvoiceItem

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

the class TestInvoiceDao method testAccountBalanceWithAllSortsOfThings.

@Test(groups = "slow")
public void testAccountBalanceWithAllSortsOfThings() throws EntityPersistenceException {
    final UUID accountId = account.getId();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate targetDate1 = new LocalDate(2011, 10, 6);
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD);
    invoiceUtil.createInvoice(invoice1, context);
    final LocalDate startDate = new LocalDate(2011, 3, 1);
    final LocalDate endDate = startDate.plusMonths(1);
    final BigDecimal amount1 = new BigDecimal("5.0");
    final BigDecimal rate1 = new BigDecimal("20.0");
    final BigDecimal rate2 = new BigDecimal("10.0");
    // Fixed Item
    final FixedPriceInvoiceItem item1 = new FixedPriceInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate, amount1, Currency.USD);
    invoiceUtil.createInvoiceItem(item1, context);
    BigDecimal balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("5.00")), 0);
    // Recurring item
    final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate, endDate, rate1, rate1, Currency.USD);
    invoiceUtil.createInvoiceItem(item2, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("25.00")), 0);
    // Pay the whole thing
    final BigDecimal payment1 = amount1.add(rate1);
    final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD, Currency.USD, null, true);
    invoiceUtil.createPayment(payment, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("0.00")), 0);
    // Repair previous item with rate 2
    final RepairAdjInvoiceItem item2Repair = new RepairAdjInvoiceItem(invoice1.getId(), accountId, startDate, endDate, rate1.negate(), Currency.USD, item2.getId());
    final RecurringInvoiceItem item2Replace = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate, endDate, rate2, rate2, Currency.USD);
    invoiceUtil.createInvoiceItem(item2Repair, context);
    invoiceUtil.createInvoiceItem(item2Replace, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("-10.00")), 0);
    // CBA
    final CreditBalanceAdjInvoiceItem cbaItem = new CreditBalanceAdjInvoiceItem(invoice1.getId(), accountId, new LocalDate(), balance.negate(), Currency.USD);
    invoiceUtil.createInvoiceItem(cbaItem, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("-10.00")), 0);
    BigDecimal cba = invoiceDao.getAccountCBA(accountId, context);
    assertEquals(cba.compareTo(new BigDecimal("10.00")), 0);
    // partial REFUND on the payment (along with CBA generated by the system)
    final InvoicePayment refund = new DefaultInvoicePayment(UUID.randomUUID(), InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), rate2.negate(), Currency.USD, Currency.USD, null, payment.getId());
    invoiceUtil.createPayment(refund, context);
    final CreditBalanceAdjInvoiceItem cbaItem2 = new CreditBalanceAdjInvoiceItem(invoice1.getId(), accountId, new LocalDate(), rate2.negate(), Currency.USD);
    invoiceUtil.createInvoiceItem(cbaItem2, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(BigDecimal.ZERO), 0);
    cba = invoiceDao.getAccountCBA(accountId, context);
    assertEquals(cba.compareTo(BigDecimal.ZERO), 0);
    // NEXT RECURRING on invoice 2
    final Invoice invoice2 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1.plusMonths(1), Currency.USD);
    invoiceUtil.createInvoice(invoice2, context);
    final RecurringInvoiceItem nextItem = new RecurringInvoiceItem(invoice2.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test bla", startDate.plusMonths(1), endDate.plusMonths(1), rate2, rate2, Currency.USD);
    invoiceUtil.createInvoiceItem(nextItem, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("10.00")), 0);
    cba = invoiceDao.getAccountCBA(accountId, context);
    assertEquals(cba.compareTo(new BigDecimal("0.00")), 0);
    // FINALLY ISSUE A CREDIT ADJ
    final CreditAdjInvoiceItem creditItem = new CreditAdjInvoiceItem(invoice2.getId(), accountId, new LocalDate(), null, rate2.negate(), Currency.USD);
    invoiceUtil.createInvoiceItem(creditItem, context);
    balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(new BigDecimal("0.00")), 0);
    cba = invoiceDao.getAccountCBA(accountId, context);
    assertEquals(cba.compareTo(new BigDecimal("0.00")), 0);
}
Also used : InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 10 with CreditBalanceAdjInvoiceItem

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

the class TestInvoiceItemDao method testCreditBalanceInvoiceSqlDao.

@Test(groups = "slow")
public void testCreditBalanceInvoiceSqlDao() throws EntityPersistenceException {
    final UUID invoiceId = UUID.randomUUID();
    final UUID accountId = account.getId();
    final LocalDate creditDate = new LocalDate(2012, 4, 1);
    final InvoiceItem creditInvoiceItem = new CreditBalanceAdjInvoiceItem(invoiceId, accountId, creditDate, TEN, Currency.USD);
    invoiceUtil.createInvoiceItem(creditInvoiceItem, context);
    final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(creditInvoiceItem.getId(), context);
    assertSameInvoiceItem(creditInvoiceItem, savedItem);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

CreditBalanceAdjInvoiceItem (org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem)10 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)9 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)9 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)9 UUID (java.util.UUID)8 Invoice (org.killbill.billing.invoice.api.Invoice)8 Test (org.testng.annotations.Test)8 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)7 CreditAdjInvoiceItem (org.killbill.billing.invoice.model.CreditAdjInvoiceItem)7 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)7 LocalDate (org.joda.time.LocalDate)6 DefaultInvoicePayment (org.killbill.billing.invoice.model.DefaultInvoicePayment)6 BigDecimal (java.math.BigDecimal)5 ExternalChargeInvoiceItem (org.killbill.billing.invoice.model.ExternalChargeInvoiceItem)5 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)4 ParentInvoiceItem (org.killbill.billing.invoice.model.ParentInvoiceItem)4 DateTime (org.joda.time.DateTime)3 InvoicePayment (org.killbill.billing.invoice.api.InvoicePayment)3 HashMap (java.util.HashMap)2 InvoiceFormatter (org.killbill.billing.invoice.api.formatters.InvoiceFormatter)2