Search in sources :

Example 66 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testFormattedAmountUSAndBRL.

@Test(groups = "fast")
public void testFormattedAmountUSAndBRL() 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.BRL);
    final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.BRL);
    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>R$2,635.14</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>R$0.00</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>R$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 67 with DefaultInvoice

use of org.killbill.billing.invoice.model.DefaultInvoice 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(), UUID.randomUUID().toString(), null, 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(), null);
    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 68 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testFormattedAmountFranceAndEUR.

@Test(groups = "fast", enabled = false, description = "JDK dependent")
public void testFormattedAmountFranceAndEUR() throws Exception {
    final FixedPriceInvoiceItem fixedItemEUR = 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.EUR);
    final Invoice invoiceEUR = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.EUR);
    invoiceEUR.addInvoiceItem(fixedItemEUR);
    checkOutput(invoiceEUR, "<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.FRANCE);
}
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 69 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testFormattedAmountUSAndBTC.

@Test(groups = "fast")
public void testFormattedAmountUSAndBTC() 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("1105.28843439"), Currency.BTC);
    final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.BTC);
    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,105.28843439</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>Ƀ0.00000000</strong></td>\n" + "</tr>\n" + "<tr>\n" + "    <td class=\"amount\"><strong>Ƀ1,105.28843439</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 70 with DefaultInvoice

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

the class TestDefaultInvoiceFormatter method testProcessedCurrencyExists.

@Test(groups = "fast")
public void testProcessedCurrencyExists() throws Exception {
    // Use InvoiceModelDao to build the invoice to be able to set the processedCurrency (No suitable CTOR for DefaultInvoice on purpose)
    final InvoiceModelDao invoiceModelDao = new InvoiceModelDao(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.BRL, false);
    invoiceModelDao.setProcessedCurrency(Currency.USD);
    final Invoice invoice = new DefaultInvoice(invoiceModelDao);
    checkOutput(invoice, "{{#invoice.processedCurrency}}" + "<tr>\n" + "    <td class=\"processedCurrency\"><strong>{{invoice.processedCurrency}}</strong></td>\n" + "</tr>\n" + "{{/invoice.processedCurrency}}", "<tr>\n" + "    <td class=\"processedCurrency\"><strong>USD</strong></td>\n" + "</tr>\n", Locale.US);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) 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