Search in sources :

Example 26 with InvoiceModelDao

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

the class TestInvoiceHelper method verifyInvoice.

public void verifyInvoice(final UUID invoiceId, final double balance, final double cbaAmount, final InternalTenantContext context) throws InvoiceApiException {
    final InvoiceModelDao invoice = invoiceDao.getById(invoiceId, context);
    Assert.assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(invoice).doubleValue(), balance);
    Assert.assertEquals(InvoiceModelDaoHelper.getCBAAmount(invoice).doubleValue(), cbaAmount);
}
Also used : InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao)

Example 27 with InvoiceModelDao

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

the class InvoiceOptimizerNoop method getInvoices.

@Override
public AccountInvoices getInvoices(final InternalCallContext callContext) {
    logDisabledFeatureIfNeeded(callContext);
    final List<Invoice> existingInvoices = new LinkedList<Invoice>();
    final List<InvoiceModelDao> invoicesByAccount = invoiceDao.getInvoicesByAccount(false, callContext);
    for (final InvoiceModelDao invoiceModelDao : invoicesByAccount) {
        existingInvoices.add(new DefaultInvoice(invoiceModelDao));
    }
    return new AccountInvoices(null, null, existingInvoices);
}
Also used : DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Invoice(org.killbill.billing.invoice.api.Invoice) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) LinkedList(java.util.LinkedList)

Example 28 with InvoiceModelDao

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

the class DefaultInvoiceUserApi method voidInvoice.

@Override
public void voidInvoice(final UUID invoiceId, final CallContext context) throws InvoiceApiException {
    final UUID accountId = getInvoiceInternal(invoiceId, context).getAccountId();
    final WithAccountLock withAccountLock = new WithAccountLock() {

        @Override
        public Iterable<DefaultInvoice> prepareInvoices() throws InvoiceApiException {
            final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(invoiceId, ObjectType.INVOICE, context);
            final InvoiceModelDao rawInvoice = dao.getById(invoiceId, internalCallContext);
            if (rawInvoice.getStatus() == InvoiceStatus.COMMITTED) {
                checkInvoiceNotRepaired(rawInvoice);
                checkInvoiceDoesContainUsedGeneratedCredit(accountId, rawInvoice, context);
            }
            final Invoice currentInvoice = new DefaultInvoice(rawInvoice, getCatalogSafelyForPrettyNames(internalCallContext));
            checkInvoiceNotPaid(currentInvoice);
            dao.changeInvoiceStatus(invoiceId, InvoiceStatus.VOID, internalCallContext);
            final DefaultInvoice invoice = getInvoiceInternal(invoiceId, context);
            return ImmutableList.of(invoice);
        }
    };
    final LinkedList<PluginProperty> properties = new LinkedList<PluginProperty>();
    properties.add(new PluginProperty(INVOICE_OPERATION, "void", false));
    invoiceApiHelper.dispatchToInvoicePluginsAndInsertItems(accountId, false, withAccountLock, properties, context);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Invoice(org.killbill.billing.invoice.api.Invoice) HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) WithAccountLock(org.killbill.billing.invoice.api.WithAccountLock) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) LinkedList(java.util.LinkedList)

Example 29 with InvoiceModelDao

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

the class DefaultInvoiceUserApi method getInvoiceByPayment.

@Override
public Invoice getInvoiceByPayment(final UUID paymentId, final TenantContext context) throws InvoiceApiException {
    final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(paymentId, ObjectType.PAYMENT, context);
    final UUID invoiceId = dao.getInvoiceIdByPaymentId(paymentId, internalTenantContext);
    if (invoiceId == null) {
        throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, paymentId);
    }
    final InvoiceModelDao invoiceModelDao = dao.getById(invoiceId, internalTenantContext);
    return new DefaultInvoice(invoiceModelDao, getCatalogSafelyForPrettyNames(internalTenantContext));
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice)

Example 30 with InvoiceModelDao

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

the class DefaultInvoiceUserApi method getInvoicesByAccount.

@Override
public List<Invoice> getInvoicesByAccount(final UUID accountId, boolean includesMigrated, final boolean includeVoidedInvoices, final TenantContext context) {
    final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(accountId, context);
    final List<InvoiceModelDao> invoicesByAccount = includesMigrated ? dao.getAllInvoicesByAccount(includeVoidedInvoices, internalTenantContext) : dao.getInvoicesByAccount(includeVoidedInvoices, internalTenantContext);
    return fromInvoiceModelDao(invoicesByAccount, getCatalogSafelyForPrettyNames(internalTenantContext));
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao)

Aggregations

InvoiceModelDao (org.killbill.billing.invoice.dao.InvoiceModelDao)40 InvoiceItemModelDao (org.killbill.billing.invoice.dao.InvoiceItemModelDao)23 LocalDate (org.joda.time.LocalDate)22 Invoice (org.killbill.billing.invoice.api.Invoice)21 BigDecimal (java.math.BigDecimal)18 Test (org.testng.annotations.Test)16 UUID (java.util.UUID)15 Account (org.killbill.billing.account.api.Account)12 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)12 DateTime (org.joda.time.DateTime)11 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)11 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)10 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)10 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)9 LinkedList (java.util.LinkedList)6 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)6 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)6 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)5 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)5