use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class LeaseUpgradeService method upgradeLinkedItems.
public BigInteger upgradeLinkedItems() {
BigInteger numberOfItemsLinkedIfNotAlready = BigInteger.ZERO;
for (Lease lease : leaseRepository.allLeases()) {
for (LeaseItem depositItem : lease.findItemsOfType(LeaseItemType.DEPOSIT)) {
for (LeaseItem rentItem : lease.findItemsOfType(LeaseItemType.RENT)) {
depositItem.findOrCreateSourceItem(rentItem);
numberOfItemsLinkedIfNotAlready = numberOfItemsLinkedIfNotAlready.add(BigInteger.ONE);
}
}
for (LeaseItem trItem : lease.findItemsOfType(LeaseItemType.TURNOVER_RENT)) {
for (LeaseItem rentItem : lease.findItemsOfType(LeaseItemType.RENT)) {
trItem.findOrCreateSourceItem(rentItem);
numberOfItemsLinkedIfNotAlready = numberOfItemsLinkedIfNotAlready.add(BigInteger.ONE);
}
}
for (LeaseItem taxItem : lease.findItemsOfType(LeaseItemType.TAX)) {
for (LeaseItem rentItem : lease.findItemsOfType(LeaseItemType.RENT)) {
taxItem.findOrCreateSourceItem(rentItem);
numberOfItemsLinkedIfNotAlready = numberOfItemsLinkedIfNotAlready.add(BigInteger.ONE);
}
}
}
return numberOfItemsLinkedIfNotAlready;
}
use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class LeaseStatusService_Test method testItem.
LeaseItem testItem(LocalDate startDate, LeaseItemStatus status) {
LeaseItem item = new LeaseItem();
item.setStartDate(startDate);
item.setStatus(status);
return item;
}
use of org.estatio.module.lease.dom.LeaseItem 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.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class InvoiceCalculationService method calculateAndInvoice.
@Programmatic
public String calculateAndInvoice(InvoiceCalculationParameters parameters) {
String lastInteractionId = null;
invoiceForLeaseRepository.removeRuns(parameters);
try {
startInteraction(parameters.toString());
final List<Lease> leases = parameters.leases();
for (Lease lease : leases.size() == 0 ? leaseRepository.findLeasesByProperty(parameters.property()) : leases) {
lease.verifyUntil(parameters.dueDateRange().endDateExcluding());
if (lease.getStatus() != LeaseStatus.SUSPENDED) {
SortedSet<LeaseItem> leaseItems = parameters.leaseItem() == null ? lease.getItems() : new TreeSet<>(Arrays.asList(parameters.leaseItem()));
for (LeaseItem leaseItem : leaseItems) {
if (!leaseItem.getStatus().equals(LeaseItemStatus.SUSPENDED) && leaseItem.getInvoicedBy().equals(LeaseAgreementRoleTypeEnum.LANDLORD)) {
// TODO: We only filter the Landlords
if (parameters.leaseItemTypes() == null || parameters.leaseItemTypes().contains(leaseItem.getType())) {
SortedSet<LeaseTerm> leaseTerms = parameters.leaseTerm() == null ? leaseItem.getTerms() : new TreeSet<>(Arrays.asList(parameters.leaseTerm()));
for (LeaseTerm leaseTerm : leaseTerms) {
final List<CalculationResult> results;
results = calculateDueDateRange(leaseTerm, parameters);
createInvoiceItems(leaseTerm, parameters, results);
}
}
}
}
}
}
} finally {
lastInteractionId = interactionId;
endInteraction();
}
return lastInteractionId;
}
use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class BudgetAssignmentService_Test method itemToCopyFrom_when_no_items_on_lease_returns_null.
@Test
public void itemToCopyFrom_when_no_items_on_lease_returns_null() throws Exception {
// given
Lease lease = new Lease();
// when
LeaseItem itemFound = budgetAssignmentService.findItemToCopyFrom(lease);
// then
assertThat(itemFound).isNull();
}
Aggregations