Java Code Examples for org.joda.time.LocalDate.toDateTimeAtStartOfDay()

The following are Jave code examples for showing how to use toDateTimeAtStartOfDay() of the org.joda.time.LocalDate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: killbill-easytax-plugin   File: SimpleTaxDateResolver.java   Source Code and License Vote up 4 votes
@Override
public DateTime taxDateForInvoiceItem(UUID kbTenantId, Account account, Invoice invoice,
        InvoiceItem item, Iterable<PluginProperty> pluginProperties) {
    LocalDate applicableDate = null;
    switch (mode) {
        case Invoice:
            applicableDate = invoice.getInvoiceDate();
            break;

        case Start:
        case StartThenEnd:
            applicableDate = item.getStartDate();
            if (applicableDate == null && mode == DateMode.StartThenEnd) {
                applicableDate = item.getEndDate();
            }
            break;

        default:
            applicableDate = item.getEndDate();
            if (applicableDate == null && mode == DateMode.EndThenStart) {
                applicableDate = item.getStartDate();
            }
    }

    if (applicableDate == null && fallBackToInvoiceDate) {
        applicableDate = invoice.getInvoiceDate();
    }
    if (applicableDate != null) {
        DateTimeZone taxationTimeZone = account.getTimeZone();
        if (taxationTimeZone == null) {
            taxationTimeZone = defaultTimeZone;
        }
        return applicableDate.toDateTimeAtStartOfDay(taxationTimeZone);
    }
    // use item or invoice creation dates
    if (fallBackToInvoiceItemCreatedDate && item.getCreatedDate() != null) {
        return item.getCreatedDate();
    }
    if (fallBackToInvoiceCreatedDate && invoice.getCreatedDate() != null) {
        return invoice.getCreatedDate();
    }
    return null;
}