Search in sources :

Example 31 with DefaultInvoice

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

the class InvoiceOptimizerExp method getInvoices.

@Override
public AccountInvoices getInvoices(final InternalCallContext callContext) {
    final Period maxInvoiceLimit = invoiceConfig.getMaxInvoiceLimit(callContext);
    boolean isMaxInvoiceLimitSet = maxInvoiceLimit != null && !maxInvoiceLimit.equals(UNSPECIFIED_PERIOD);
    final LocalDate cutoffDt = isMaxInvoiceLimitSet ? callContext.toLocalDate(clock.getUTCNow()).minus(maxInvoiceLimit) : null;
    // 
    // We need to compute a 'cutoffDt' for junction (billing events) that is at least one period less than the one computed for invoice
    // to support in-arrear trailing pro-ration use cases - i.e cancellation did not occur EOT.
    // The strategy is to use the existing config to remove one more period than what has been specified for invoice.
    // Note that it's ok to return more but returning not enough would lead to unexpected REPAIR
    // (See TestWithInvoiceOptimization#testRecurringInArrear5 for instance)
    // 
    final LocalDate beCutoffDt = isMaxInvoiceLimitSet ? cutoffDt.minus(maxInvoiceLimit) : null;
    final List<Invoice> existingInvoices = new LinkedList<Invoice>();
    final List<InvoiceModelDao> invoicesByAccount = invoiceDao.getInvoicesByAccount(false, cutoffDt, null, callContext);
    for (final InvoiceModelDao invoiceModelDao : invoicesByAccount) {
        existingInvoices.add(new DefaultInvoice(invoiceModelDao));
    }
    return new AccountInvoicesExp(cutoffDt, beCutoffDt, existingInvoices);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) Period(org.joda.time.Period) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) LinkedList(java.util.LinkedList)

Example 32 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testFormattedAmountUSAndGBP.

@Test(groups = "fast")
public void testFormattedAmountUSAndGBP() throws Exception {
    final FixedPriceInvoiceItem fixedItem = 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.GBP);
    final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.GBP);
    invoice.addInvoiceItem(fixedItem);
    checkOutput(invoice, "<tr>\n" + "    <td class=\"amount\"><strong>{{invoice.formattedChargedAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>{{invoice.formattedPaidAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>{{invoice.formattedBalance}}</strong></td>\n" + "</tr>", "<tr>\n" + "    <td class=\"amount\"><strong>£1,499.95</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>£0.00</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>£1,499.95</strong></td>\n" + "</tr>", Locale.US);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 33 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testFormattedAmountUSAndEUR.

@Test(groups = "fast")
public void testFormattedAmountUSAndEUR() throws Exception {
    final FixedPriceInvoiceItem fixedItem = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("2635.14"), Currency.EUR);
    final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.EUR);
    invoice.addInvoiceItem(fixedItem);
    checkOutput(invoice, "<tr>\n" + "    <td class=\"amount\"><strong>{{invoice.formattedChargedAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>{{invoice.formattedPaidAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>{{invoice.formattedBalance}}</strong></td>\n" + "</tr>", "<tr>\n" + "    <td class=\"amount\"><strong>€2,635.14</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>€0.00</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>€2,635.14</strong></td>\n" + "</tr>", Locale.US);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 34 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testProcessedCurrencyDoesNotExist.

@Test(groups = "fast")
public void testProcessedCurrencyDoesNotExist() throws Exception {
    final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), UUID.randomUUID(), new Integer(234), new LocalDate(), new LocalDate(), Currency.USD, false, InvoiceStatus.COMMITTED);
    checkOutput(invoice, "{{#invoice.processedCurrency}}" + "<tr>\n" + "    <td class=\"processedCurrency\"><strong>{{invoice.processedCurrency}}</strong></td>\n" + "</tr>\n" + "{{/invoice.processedCurrency}}", "", Locale.US);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 35 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testIgnoreZeroAdjustments.

@Test(groups = "fast")
public void testIgnoreZeroAdjustments() throws Exception {
    // Scenario: single item with payment
    // * $10 item
    // * $-10 CBA
    // * $10 CBA
    final FixedPriceInvoiceItem fixedItem = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), BigDecimal.TEN, Currency.USD);
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem = new CreditBalanceAdjInvoiceItem(fixedItem.getInvoiceId(), fixedItem.getAccountId(), fixedItem.getStartDate(), fixedItem.getAmount(), fixedItem.getCurrency());
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem2 = new CreditBalanceAdjInvoiceItem(fixedItem.getInvoiceId(), fixedItem.getAccountId(), fixedItem.getStartDate(), fixedItem.getAmount().negate(), fixedItem.getCurrency());
    final Invoice invoice = new DefaultInvoice(fixedItem.getInvoiceId(), fixedItem.getAccountId(), null, new LocalDate(), new LocalDate(), Currency.USD, false, InvoiceStatus.COMMITTED);
    invoice.addInvoiceItem(fixedItem);
    invoice.addInvoiceItem(creditBalanceAdjInvoiceItem);
    invoice.addInvoiceItem(creditBalanceAdjInvoiceItem2);
    // Check the scenario
    Assert.assertEquals(invoice.getBalance().doubleValue(), 10.00);
    Assert.assertEquals(invoice.getCreditedAmount().doubleValue(), 0.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(), 1);
    Assert.assertEquals(invoiceItems.get(0).getInvoiceItemType(), InvoiceItemType.FIXED);
    Assert.assertEquals(invoiceItems.get(0).getAmount().doubleValue(), 10.00);
}
Also used : InvoiceFormatter(org.killbill.billing.invoice.api.formatters.InvoiceFormatter) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) 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) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) 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