Search in sources :

Example 16 with InvoiceModelDao

use of org.killbill.billing.invoice.dao.InvoiceModelDao in project killbill by killbill.

the class TestInvoiceHelper method createInvoice.

public void createInvoice(final Invoice invoice, final InternalCallContext internalCallContext) throws EntityPersistenceException {
    final InvoiceModelDao invoiceModelDao = new InvoiceModelDao(invoice);
    final List<InvoiceItemModelDao> invoiceItemModelDaos = ImmutableList.<InvoiceItemModelDao>copyOf(Collections2.transform(invoice.getInvoiceItems(), new Function<InvoiceItem, InvoiceItemModelDao>() {

        @Override
        public InvoiceItemModelDao apply(final InvoiceItem input) {
            return new InvoiceItemModelDao(input);
        }
    }));
    invoiceSqlDao.create(invoiceModelDao, internalCallContext);
    for (final InvoiceItem invoiceItem : invoice.getInvoiceItems()) {
        createInvoiceItem(invoiceItem, internalCallContext);
    }
}
Also used : Function(com.google.common.base.Function) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) InvoiceItemModelDao(org.killbill.billing.invoice.dao.InvoiceItemModelDao) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao)

Example 17 with InvoiceModelDao

use of org.killbill.billing.invoice.dao.InvoiceModelDao in project killbill by killbill.

the class TestDefaultInvoiceMigrationApi method createAndCheckMigrationInvoice.

private UUID createAndCheckMigrationInvoice(final UUID accountId) throws InvoiceApiException {
    final InvoiceItem recurringItem = new RecurringInvoiceItem(null, accountId, null, null, "planName", "phaseName", new LocalDate(2016, 2, 1), new LocalDate(2016, 3, 1), MIGRATION_INVOICE_AMOUNT, MIGRATION_INVOICE_AMOUNT, MIGRATION_INVOICE_CURRENCY);
    final UUID migrationInvoiceId = invoiceUserApi.createMigrationInvoice(accountId, date_migrated, ImmutableList.of(recurringItem), callContext);
    Assert.assertNotNull(migrationInvoiceId);
    //Double check it was created and values are correct
    final InvoiceModelDao invoice = invoiceDao.getById(migrationInvoiceId, internalCallContext);
    Assert.assertNotNull(invoice);
    Assert.assertEquals(invoice.getAccountId(), accountId);
    //temp to avoid tz test artifact
    Assert.assertEquals(invoice.getTargetDate().compareTo(date_migrated), 0);
    //		Assert.assertEquals(invoice.getTargetDate(),now);
    Assert.assertEquals(invoice.getInvoiceItems().size(), 1);
    Assert.assertEquals(invoice.getInvoiceItems().get(0).getAmount().compareTo(MIGRATION_INVOICE_AMOUNT), 0);
    Assert.assertEquals(invoice.getInvoiceItems().get(0).getType(), InvoiceItemType.RECURRING);
    Assert.assertEquals(InvoiceModelDaoHelper.getBalance(invoice).compareTo(BigDecimal.ZERO), 0);
    Assert.assertEquals(invoice.getCurrency(), MIGRATION_INVOICE_CURRENCY);
    Assert.assertTrue(invoice.isMigrated());
    return migrationInvoiceId;
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate)

Example 18 with InvoiceModelDao

use of org.killbill.billing.invoice.dao.InvoiceModelDao 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

InvoiceModelDao (org.killbill.billing.invoice.dao.InvoiceModelDao)18 InvoiceItemModelDao (org.killbill.billing.invoice.dao.InvoiceItemModelDao)10 Invoice (org.killbill.billing.invoice.api.Invoice)9 BigDecimal (java.math.BigDecimal)8 UUID (java.util.UUID)7 LocalDate (org.joda.time.LocalDate)7 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)7 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)6 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)5 Test (org.testng.annotations.Test)5 Currency (org.killbill.billing.catalog.api.Currency)4 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)4 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)4 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)4 Function (com.google.common.base.Function)3 ArrayList (java.util.ArrayList)3 DateTime (org.joda.time.DateTime)3 AccountApiException (org.killbill.billing.account.api.AccountApiException)3 MockPlan (org.killbill.billing.catalog.MockPlan)3 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)3