Search in sources :

Example 16 with LeaseItem

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;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) BigInteger(java.math.BigInteger) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 17 with LeaseItem

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;
}
Also used : LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 18 with LeaseItem

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);
            }
        }
    }
}
Also used : InvoiceItemAttributesVM(org.estatio.module.lease.dom.invoicing.ssrs.InvoiceItemAttributesVM) Charge(org.estatio.module.charge.dom.Charge) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) BigDecimal(java.math.BigDecimal) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 19 with LeaseItem

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;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 20 with LeaseItem

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();
}
Also used : Lease(org.estatio.module.lease.dom.Lease) LeaseItem(org.estatio.module.lease.dom.LeaseItem) Test(org.junit.Test)

Aggregations

LeaseItem (org.estatio.module.lease.dom.LeaseItem)35 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)10 ChargeGroup_enum (org.estatio.module.charge.fixtures.chargegroups.enums.ChargeGroup_enum)10 Lease (org.estatio.module.lease.dom.Lease)10 Programmatic (org.apache.isis.applib.annotation.Programmatic)7 Charge (org.estatio.module.charge.dom.Charge)6 LeaseTerm (org.estatio.module.lease.dom.LeaseTerm)6 LocalDate (org.joda.time.LocalDate)6 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)5 Test (org.junit.Test)5 LeaseTermForIndexable (org.estatio.module.lease.dom.LeaseTermForIndexable)4 LeaseTermForServiceCharge (org.estatio.module.lease.dom.LeaseTermForServiceCharge)4 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)4 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)3 LeaseItemStatus (org.estatio.module.lease.dom.LeaseItemStatus)3 LeaseTermForDeposit (org.estatio.module.lease.dom.LeaseTermForDeposit)3 LeaseTermForFixed (org.estatio.module.lease.dom.LeaseTermForFixed)3 LeaseTermForTurnoverRent (org.estatio.module.lease.dom.LeaseTermForTurnoverRent)2 LocalDateInterval (org.incode.module.base.dom.valuetypes.LocalDateInterval)2 Expectations (org.jmock.Expectations)2