Search in sources :

Example 71 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testForDisplay.

// No Assertion, just to print the html
@Test(groups = "fast")
public void testForDisplay() throws Exception {
    final FixedPriceInvoiceItem fixedItemBRL = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("1499.95"), Currency.BRL);
    final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), UUID.randomUUID(), new Integer(234), new LocalDate(), new LocalDate(), Currency.BRL, false, InvoiceStatus.COMMITTED);
    invoice.addInvoiceItem(fixedItemBRL);
    final String template = "<html>\n" + "    <head>\n" + "        <style type=\"text/css\">\n" + "            #header td { width: 250px; }\n" + "            #header .company_info { width: 450px; }\n" + "            #header .label { text-align: right; font-weight: bold; }\n" + "            #header .label_value { padding-left: 10px; }\n" + "\n" + "            #invoice_items { margin-top: 50px; }\n" + "            #invoice_items th { border-bottom: solid 2px black; }\n" + "            #invoice_items td { width: 250px; }\n" + "            #invoice_items td.amount { width: 125px; }\n" + "            #invoice_items td.network { width: 350px; }\n" + "            #invoice_items .amount { text-align: right; }\n" + "            #invoice_items .label { text-align: right; font-weight: bold; }\n" + "        </style>\n" + "    </head>\n" + "    <body>\n" + "        <table id=\"header\">\n" + "            <tr>\n" + "                <td class=\"company_info\"/>\n" + "                <td />\n" + "                <td><h1>{{text.invoiceTitle}}</h1></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=\"3\"><img src=\"http://static.foo.com/www/0/main/gfx/front/logo.png\"/></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td class=\"company_info\" />\n" + "                <td class=\"label\">{{text.invoiceDate}}</td>\n" + "                <td class=\"label_value\">{{invoice.formattedInvoiceDate}}</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td class=\"company_info\" />\n" + "                <td class=\"label\">{{text.invoiceNumber}}</td>\n" + "                <td class=\"label_value\">{{invoice.invoiceNumber}}</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td class=\"company_info\">{{text.companyCountry}}</td>\n" + "                <td colspan=\"2\" />\n" + "            </tr>\n" + "            <tr>\n" + "                <td class=\"company_info\">{{text.companyUrl}}</td>\n" + "                <td colspan=\"2\" />\n" + "            </tr>\n" + "        </table>\n" + "\n" + "        <table id=\"invoice_items\">\n" + "            <tr>\n" + "                <th class=\"network\">{{text.invoiceItemBundleName}}</td>\n" + "                <th>{{text.invoiceItemDescription}}</td>\n" + "                <th>{{text.invoiceItemServicePeriod}}</td>\n" + "                <th>{{text.invoiceItemAmount}}</td>\n" + "            </tr>\n" + "            {{#invoice.invoiceItems}}\n" + "            <tr>\n" + "                <td class=\"network\">{{description}}</td>\n" + "                <td>{{planName}}</td>\n" + "                <td>{{formattedStartDate}}{{#formattedEndDate}} - {{formattedEndDate}}{{/formattedEndDate}}</td>\n" + "                <td class=\"amount\">{{formattedAmount}}</td>\n" + "            </tr>\n" + "            {{/invoice.invoiceItems}}\n" + "            <tr>\n" + "                <td colspan=\"4\" height=\"50px\"></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=\"2\" />\n" + "                <td class=\"label\">{{text.invoiceAmount}}</td>\n" + "                <td class=\"amount\"><strong>{{invoice.formattedChargedAmount}}</strong></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=\"2\" />\n" + "                <td class=\"label\">{{text.invoiceAmountPaid}}" + "                    {{#invoice.processedCurrency}}" + " (*)" + "                    {{/invoice.processedCurrency}}\n" + "                </td>\n" + "                <td class=\"amount\"><strong>{{invoice.formattedPaidAmount}}</strong></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=\"2\" />\n" + "                <td class=\"label\">{{text.invoiceBalance}}</td>\n" + "                <td class=\"amount\"><strong>{{invoice.formattedBalance}}</strong></td>\n" + "            </tr>\n" + "        </table>\n" + "        {{#invoice.processedCurrency}}" + "        {{text.processedPaymentCurrency}} {{invoice.processedCurrency}}." + "        {{#invoice.processedPaymentRate}}\n" + " {{text.processedPaymentRate}} {{invoice.processedPaymentRate}}.\n" + "        {{/invoice.processedPaymentRate}}" + "        {{/invoice.processedCurrency}}" + "    </body>\n" + "</html>\n";
    final Map<String, Object> data = new HashMap<String, Object>();
    final String bundlePath = "org/killbill/billing/util/template/translation/InvoiceTranslation";
    final ResourceBundle bundle = resourceBundleFactory.createBundle(Locale.US, bundlePath, ResourceBundleType.INVOICE_TRANSLATION, internalCallContext);
    final DefaultInvoiceTranslator translator = new DefaultInvoiceTranslator(bundle, null);
    data.put("text", translator);
    data.put("invoice", new DefaultInvoiceFormatter(config, invoice, Locale.US, currencyConversionApi, resourceBundleFactory, internalCallContext));
    final String formattedText = templateEngine.executeTemplateText(template, data);
    System.out.println(formattedText);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) HashMap(java.util.HashMap) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) DefaultInvoiceTranslator(org.killbill.billing.invoice.template.translator.DefaultInvoiceTranslator) ResourceBundle(java.util.ResourceBundle) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Test(org.testng.annotations.Test)

Example 72 with DefaultInvoice

use of org.killbill.billing.invoice.model.DefaultInvoice 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(), null, plan.getName(), phase.getName(), null, 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, new AccountInvoices(null, null, existingInvoices), null, targetDate, currency, null, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertEquals(invoice.getNumberOfItems(), 5);
    assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), new LocalDate(2013, 6, 21));
    assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), new LocalDate(2013, 6, 26));
    assertTrue(repairAmount.negate().compareTo(invoice.getInvoiceItems().get(0).getAmount()) == 0);
    assertEquals(invoice.getInvoiceItems().get(1).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), new LocalDate(2013, 7, 15));
    assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), new LocalDate(2013, 8, 15));
    assertEquals(invoice.getInvoiceItems().get(2).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(2).getStartDate(), new LocalDate(2013, 8, 15));
    assertEquals(invoice.getInvoiceItems().get(2).getEndDate(), new LocalDate(2013, 9, 15));
    assertEquals(invoice.getInvoiceItems().get(3).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(3).getStartDate(), new LocalDate(2013, 9, 15));
    assertEquals(invoice.getInvoiceItems().get(3).getEndDate(), new LocalDate(2013, 10, 15));
    assertEquals(invoice.getInvoiceItems().get(4).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(4).getStartDate(), new LocalDate(2013, 10, 15));
    assertEquals(invoice.getInvoiceItems().get(4).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, new AccountInvoices(null, null, existingInvoices), null, targetDate, currency, null, 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) AccountInvoices(org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices) 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)

Example 73 with DefaultInvoice

use of org.killbill.billing.invoice.model.DefaultInvoice 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 product", "test plan", "test phase A", null, 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 product", "test plan", "test phase B", null, 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 product", "test plan", "test phase B", null, 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 product", "test plan", "test bla", null, 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, null);
    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 74 with DefaultInvoice

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

the class TestInvoiceDao method testDeleteConsumedCredit.

@Test(groups = "slow")
public void testDeleteConsumedCredit() throws Exception {
    final UUID accountId = account.getId();
    final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final RecurringInvoiceItem recurringItem = new RecurringInvoiceItem(invoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test product", "test plan", "test ZOO", null, clock.getUTCNow().plusMonths(-1).toLocalDate(), clock.getUTCNow().toLocalDate(), BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem1 = new CreditBalanceAdjInvoiceItem(invoice.getId(), invoice.getAccountId(), invoice.getInvoiceDate(), BigDecimal.ONE.negate(), invoice.getCurrency());
    invoiceUtil.createInvoice(invoice, context);
    invoiceUtil.createInvoiceItem(recurringItem, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem1, context);
    invoiceUtil.verifyInvoice(invoice.getId(), 9.00, -1.00, context);
    // Delete the CBA on invoice 1
    invoiceDao.deleteCBA(accountId, invoice.getId(), creditBalanceAdjInvoiceItem1.getId(), context);
    final InvoiceModelDao res = invoiceDao.getById(invoice.getId(), context);
    Assert.assertEquals(res.getInvoiceItems().size(), 2);
    Assert.assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(res).compareTo(BigDecimal.TEN), 0);
    Assert.assertEquals(InvoiceModelDaoHelper.getCBAAmount(res).compareTo(BigDecimal.ZERO), 0);
    final InvoiceItemModelDao cbaAdj = Iterables.tryFind(res.getInvoiceItems(), new Predicate<InvoiceItemModelDao>() {

        @Override
        public boolean apply(final InvoiceItemModelDao input) {
            return input.getType() == InvoiceItemType.CBA_ADJ && input.getAmount().compareTo(BigDecimal.ZERO) == 0;
        }
    }).orNull();
    Assert.assertNotNull(cbaAdj);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 75 with DefaultInvoice

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

the class TestInvoiceDao method testAccountBalanceWithNoInvoiceItems.

@Test(groups = "slow")
public void testAccountBalanceWithNoInvoiceItems() throws EntityPersistenceException {
    final UUID accountId = account.getId();
    final LocalDate targetDate1 = new LocalDate(2011, 10, 6);
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD);
    invoiceUtil.createInvoice(invoice1, context);
    final BigDecimal payment1 = new BigDecimal("48.0");
    final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD, Currency.USD, null, true);
    invoiceUtil.createPayment(payment, context);
    final BigDecimal balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(BigDecimal.ZERO.subtract(payment1)), 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) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) Test(org.testng.annotations.Test)

Aggregations

DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)92 Invoice (org.killbill.billing.invoice.api.Invoice)81 LocalDate (org.joda.time.LocalDate)64 Test (org.testng.annotations.Test)63 UUID (java.util.UUID)51 BigDecimal (java.math.BigDecimal)46 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)46 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)38 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)37 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)28 LinkedList (java.util.LinkedList)25 HashMap (java.util.HashMap)24 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)24 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)20 AccountInvoices (org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices)20 BillingEventSet (org.killbill.billing.junction.BillingEventSet)20 MockPlan (org.killbill.billing.catalog.MockPlan)18 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)18 BillingEvent (org.killbill.billing.junction.BillingEvent)18 Plan (org.killbill.billing.catalog.api.Plan)17