use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.
the class InvoiceCalculationParameters method toString.
public String toString() {
TitleBuffer tb = new TitleBuffer();
tb.append(" -", property().getReference()).append(" -", leasesToReferences()).append(" -", leaseItemTypes()).append(" -", invoiceDueDate()).append(" -", new LocalDateInterval(startDueDate, nextDueDate, IntervalEnding.EXCLUDING_END_DATE)).toString();
return tb.toString();
}
use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.
the class InvoiceCalculationService method calculateDueDateRange.
/**
* Calculates a term with a given invoicing frequency
*/
@Programmatic
public List<CalculationResult> calculateDueDateRange(final LeaseTerm leaseTerm, final InvoiceCalculationParameters parameters) {
final LocalDateInterval dueDateRangeInterval = parameters.invoiceRunType().equals(InvoiceRunType.RETRO_RUN) && leaseTerm.getLeaseItem().getLease().getStartDate().compareTo(parameters.dueDateRange().startDate()) < 0 ? new LocalDateInterval(leaseTerm.getLeaseItem().getLease().getStartDate(), parameters.dueDateRange().endDateExcluding(), IntervalEnding.EXCLUDING_END_DATE) : parameters.dueDateRange();
// performance, EST-315, should get some attention.
if (dueDateRangeInterval.isValid()) {
final List<InvoicingInterval> intervals = leaseTerm.getLeaseItem().getInvoicingFrequency().intervalsInDueDateRange(dueDateRangeInterval, leaseTerm.getInterval());
final LocalDate dueDateForCalculation = parameters.dueDateRange().endDateExcluding().minusDays(1);
return calculateTerm(leaseTerm, intervals);
}
return Lists.newArrayList();
}
use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.
the class InvoiceCalculationService method createInvoiceItems.
/**
* Calculates an invoice item with the difference between the already
* invoiced and calculated value.
*/
void createInvoiceItems(final LeaseTerm leaseTerm, final InvoiceCalculationParameters parameters, final List<CalculationResult> results) {
for (CalculationResult result : results) {
// values on a normal run
if (result.value().compareTo(BigDecimal.ZERO) != 0 || parameters.invoiceRunType().equals(InvoiceRunType.RETRO_RUN)) {
final LocalDateInterval invoicingInterval = result.invoicingInterval().asLocalDateInterval();
BigDecimal invoicedValue = invoiceItemForLeaseRepository.invoicedValue(leaseTerm, invoicingInterval);
BigDecimal newValue = result.value().subtract(invoicedValue);
//
LocalDateInterval calculationInterval = result.effectiveInterval();
LocalDateInterval effectiveInterval = calculationInterval;
Boolean adjustment = false;
if (newValue.compareTo(BigDecimal.ZERO) != 0) {
if (invoicedValue.compareTo(BigDecimal.ZERO) != 0) {
// Has been invoiced before
if (invoiceItemForLeaseRepository.findByLeaseTermAndEffectiveInterval(leaseTerm, calculationInterval).size() > 0) {
// this exact period has been invoiced before so it is an adjusment
adjustment = true;
} else {
// there is new calculated amount which is caused by tinkering the dates
effectiveInterval = attemptToCalculateRightSideLeftover(invoicingInterval, calculationInterval);
}
}
InvoiceItemForLease invoiceItem = invoiceItemForLeaseRepository.createUnapprovedInvoiceItem(leaseTerm, invoicingInterval, calculationInterval, effectiveInterval, parameters.invoiceDueDate(), interactionId);
invoiceItem.setNetAmount(newValue);
invoiceItem.setQuantity(BigDecimal.ONE);
LeaseItem leaseItem = leaseTerm.getLeaseItem();
Charge charge = leaseItem.getCharge();
invoiceItem.setCharge(charge);
invoiceItem.setTax(leaseItem.getEffectiveTax());
final InvoiceItemAttributesVM vm = new InvoiceItemAttributesVM(invoiceItem);
final String description = fragmentRenderService.render(vm, "description");
invoiceItem.setDescription(description);
invoiceItem.verify();
invoiceItem.setAdjustment(adjustment);
}
}
}
}
use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.
the class Lease method verifyUntil.
@Action(semantics = SemanticsOf.IDEMPOTENT)
public Lease verifyUntil(final LocalDate date) {
for (LeaseItem item : getItems()) {
LocalDateInterval effectiveInterval = item.getEffectiveInterval();
item.verifyUntil(ObjectUtils.min(effectiveInterval == null ? null : effectiveInterval.endDateExcluding(), date));
}
return this;
}
use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.
the class LeaseTermRepository method findTermsWithInvalidInterval.
@Action(semantics = SemanticsOf.SAFE)
@MemberOrder(sequence = "30")
public List<LeaseTerm> findTermsWithInvalidInterval() {
List<LeaseTerm> lts = allLeaseTerms();
List<LeaseTerm> returnList = new ArrayList<>();
LocalDateInterval ldi;
for (LeaseTerm lt : lts) {
try {
if ((ldi = lt.getEffectiveInterval()) == null) {
returnList.add(lt);
continue;
}
if (!ldi.isValid()) {
returnList.add(lt);
continue;
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
returnList.add(lt);
}
}
if (returnList.isEmpty()) {
return null;
} else {
return returnList;
}
}
Aggregations