Search in sources :

Example 1 with Occupancy

use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.

the class BudgetAssignmentService method getCalculationResults.

public List<CalculationResultViewModel> getCalculationResults(final Budget budget) {
    List<CalculationResultViewModel> results = new ArrayList<>();
    for (BudgetCalculationRun run : budgetCalculationRunRepository.findByBudgetAndType(budget, BudgetCalculationType.BUDGETED)) {
        for (BudgetCalculationResult result : run.getBudgetCalculationResults()) {
            CalculationResultViewModel vm = new CalculationResultViewModel(run.getLease(), result.getInvoiceCharge(), run.getType() == BudgetCalculationType.BUDGETED ? result.getValue().add(result.getShortfall()) : BigDecimal.ZERO, run.getType() == BudgetCalculationType.BUDGETED ? result.getValue() : BigDecimal.ZERO, run.getType() == BudgetCalculationType.BUDGETED ? result.getShortfall() : BigDecimal.ZERO, run.getType() == BudgetCalculationType.ACTUAL ? result.getValue().add(result.getShortfall()) : BigDecimal.ZERO, run.getType() == BudgetCalculationType.ACTUAL ? result.getValue() : BigDecimal.ZERO, run.getType() == BudgetCalculationType.ACTUAL ? result.getShortfall() : BigDecimal.ZERO);
            String unitString = run.getLease().getOccupancies().first().getUnit().getReference();
            if (run.getLease().getOccupancies().size() > 1) {
                boolean skip = true;
                for (Occupancy occupancy : run.getLease().getOccupancies()) {
                    if (skip) {
                        skip = false;
                    } else {
                        unitString = unitString.concat(" | ").concat(occupancy.getUnit().getReference());
                    }
                }
            }
            vm.setUnit(unitString);
            results.add(vm);
        }
    }
    return results;
}
Also used : Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) ArrayList(java.util.ArrayList) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)

Example 2 with Occupancy

use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.

the class BudgetOverride method getCalculatedValueByBudget.

@Programmatic
BigDecimal getCalculatedValueByBudget(final LocalDate budgetStartDate, final BudgetCalculationType type) {
    BigDecimal value = BigDecimal.ZERO;
    List<Unit> unitsForLease = new ArrayList<>();
    List<BudgetCalculation> calculationsForLeaseAndCharges = new ArrayList<>();
    for (Occupancy occupancy : getLease().getOccupancies()) {
        unitsForLease.add(occupancy.getUnit());
    }
    Budget budget = budgetRepository.findByPropertyAndDate(getLease().getProperty(), budgetStartDate);
    if (getIncomingCharge() == null) {
        for (Unit unit : unitsForLease) {
            calculationsForLeaseAndCharges.addAll(budgetCalculationRepository.findByBudgetAndUnitAndInvoiceChargeAndType(budget, unit, getInvoiceCharge(), type));
        }
    } else {
        for (Unit unit : unitsForLease) {
            calculationsForLeaseAndCharges.addAll(budgetCalculationRepository.findByBudgetAndUnitAndInvoiceChargeAndIncomingChargeAndType(budget, unit, getInvoiceCharge(), getIncomingCharge(), type));
        }
    }
    for (BudgetCalculation calculation : calculationsForLeaseAndCharges) {
        value = value.add(calculation.getEffectiveValue());
    }
    return value;
}
Also used : Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) ArrayList(java.util.ArrayList) Budget(org.estatio.module.budget.dom.budget.Budget) Unit(org.estatio.module.asset.dom.Unit) BigDecimal(java.math.BigDecimal) BudgetCalculation(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 3 with Occupancy

use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.

the class LeaseBuilderLEGACY method createLease.

protected Lease createLease(String reference, String name, String unitReference, String brand, BrandCoverage brandCoverage, String countryOfOriginRef, String sector, String activity, String landlordReference, String tenantReference, LocalDate startDate, LocalDate endDate, boolean createManagerRole, boolean createLeaseUnitAndTags, Party manager, ExecutionContext fixtureResults) {
    Unit unit = unitRepository.findUnitByReference(unitReference);
    Party landlord = findPartyByReferenceOrNameElseNull(landlordReference);
    Party tenant = findPartyByReferenceOrNameElseNull(tenantReference);
    Lease lease = leaseRepository.newLease(unit.getApplicationTenancy(), reference, name, null, startDate, null, endDate, landlord, tenant);
    fixtureResults.addResult(this, lease.getReference(), lease);
    if (createManagerRole) {
        final AgreementRole role = lease.createRole(agreementRoleTypeRepository.findByTitle(LeaseAgreementRoleTypeEnum.MANAGER.getTitle()), manager, null, null);
        fixtureResults.addResult(this, role);
    }
    if (createLeaseUnitAndTags) {
        Country countryOfOrigin = countryRepository.findCountry(countryOfOriginRef);
        Occupancy occupancy = occupancyRepository.newOccupancy(lease, unit, startDate);
        occupancy.setBrandName(brand, brandCoverage, countryOfOrigin);
        occupancy.setSectorName(sector);
        occupancy.setActivityName(activity);
        fixtureResults.addResult(this, occupancy);
    }
    if (leaseRepository.findLeaseByReference(reference) == null) {
        throw new RuntimeException("could not find lease reference='" + reference + "'");
    }
    return lease;
}
Also used : Party(org.estatio.module.party.dom.Party) AgreementRole(org.estatio.module.agreement.dom.AgreementRole) Lease(org.estatio.module.lease.dom.Lease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Country(org.incode.module.country.dom.impl.Country) Unit(org.estatio.module.asset.dom.Unit)

Example 4 with Occupancy

use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.

the class FreemarkerModelOfPrelimLetterOrInvoiceDocForEmailCover method doNewRendererModel.

@Override
protected Object doNewRendererModel(final DocumentTemplate documentTemplate, final Document prelimLetterOrInvoiceNoteDoc) {
    boolean isPrimaryType = DocumentTypeData.isPrimaryType(prelimLetterOrInvoiceNoteDoc);
    if (!isPrimaryType) {
        final String docTypeRef2 = prelimLetterOrInvoiceNoteDoc.getType().getReference();
        throw new IllegalArgumentException(String.format("Document must be a prelim letter or invoice (provided document's type is '%s')", docTypeRef2));
    }
    final InvoiceForLease invoice = paperclipRepository.paperclipAttaches(prelimLetterOrInvoiceNoteDoc, InvoiceForLease.class);
    final DataModel dataModel = new DataModel();
    dataModel.setInvoice(invoice);
    dataModel.setTenant(invoice.getBuyer());
    dataModel.setProperty(invoice.getLease().getProperty());
    final Optional<Occupancy> occupancyIfAny = invoice.getLease().primaryOccupancy();
    if (occupancyIfAny.isPresent()) {
        final Occupancy occupancy = occupancyIfAny.get();
        final Unit unit = occupancy.getUnit();
        dataModel.setUnit(unit);
        dataModel.setBrand(occupancy.getBrand());
    }
    dataModel.setDocument(prelimLetterOrInvoiceNoteDoc);
    return dataModel;
}
Also used : InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Unit(org.estatio.module.asset.dom.Unit)

Example 5 with Occupancy

use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.

the class Lease method newOccupancy.

/**
 * The action to relate a lease to a unit. A lease can occupy unlimited
 * units.
 *
 * @param unit
 * @param startDate
 * @return
 */
public Occupancy newOccupancy(@Parameter(optionality = Optionality.OPTIONAL) final LocalDate startDate, final Unit unit) {
    Occupancy occupancy = occupancyRepository.newOccupancy(this, unit, startDate);
    occupancies.add(occupancy);
    return occupancy;
}
Also used : Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy)

Aggregations

Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)17 Lease (org.estatio.module.lease.dom.Lease)9 Unit (org.estatio.module.asset.dom.Unit)8 Programmatic (org.apache.isis.applib.annotation.Programmatic)6 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)3 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)3 LocalDate (org.joda.time.LocalDate)3 ArrayList (java.util.ArrayList)2 AgreementRole (org.estatio.module.agreement.dom.AgreementRole)2 Property (org.estatio.module.asset.dom.Property)2 Budget (org.estatio.module.budget.dom.budget.Budget)2 Charge (org.estatio.module.charge.dom.Charge)2 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)2 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)2 Tax (org.estatio.module.tax.dom.Tax)2 Expectations (org.jmock.Expectations)2 Before (org.junit.Before)2 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 SortedSet (java.util.SortedSet)1