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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations