Search in sources :

Example 36 with Lease

use of org.estatio.module.lease.dom.Lease in project estatio by estatio.

the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_works_when_item_to_copy_from_found.

@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_works_when_item_to_copy_from_found() throws Exception {
    // given
    LeaseItem leaseItemToCopyFrom = new LeaseItem();
    leaseItemToCopyFrom.setInvoicingFrequency(InvoicingFrequency.QUARTERLY_IN_ADVANCE);
    leaseItemToCopyFrom.setPaymentMethod(PaymentMethod.CHEQUE);
    BudgetAssignmentService budgetAssignmentService = new BudgetAssignmentService() {

        @Override
        LeaseItem findItemToCopyFrom(final Lease lease) {
            return leaseItemToCopyFrom;
        }
    };
    Charge charge = new Charge();
    BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
    budgetCalculationResult.setInvoiceCharge(charge);
    LocalDate termStartDate = new LocalDate(2018, 1, 1);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLease).findFirstActiveItemOfTypeAndChargeOnDate(LeaseItemType.SERVICE_CHARGE, charge, termStartDate);
            will(returnValue(null));
            oneOf(mockLease).newItem(LeaseItemType.SERVICE_CHARGE, LeaseAgreementRoleTypeEnum.LANDLORD, budgetCalculationResult.getInvoiceCharge(), leaseItemToCopyFrom.getInvoicingFrequency(), leaseItemToCopyFrom.getPaymentMethod(), termStartDate);
        }
    });
    // when
    budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(mockLease, budgetCalculationResult, termStartDate);
}
Also used : Expectations(org.jmock.Expectations) Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) LocalDate(org.joda.time.LocalDate) LeaseItem(org.estatio.module.lease.dom.LeaseItem) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) Test(org.junit.Test)

Example 37 with Lease

use of org.estatio.module.lease.dom.Lease in project estatio by estatio.

the class BudgetOverrideRepository_IntegTest method findByLeaseAndInvoiceCharge.

@Test
public void findByLeaseAndInvoiceCharge() {
    // given
    Lease leaseTopModel = Lease_enum.OxfTopModel001Gb.findUsing(serviceRegistry);
    Charge invoiceCharge = Charge_enum.GbServiceCharge.findUsing(serviceRegistry);
    BigDecimal overrideValue = new BigDecimal("1234.56");
    String reason = "Some reason";
    // when
    BudgetOverrideForFixed budgetOverrideForFixed = wrap(budgetOverrideRepository).newBudgetOverrideForFixed(overrideValue, leaseTopModel, null, null, invoiceCharge, null, null, reason);
    // then
    assertThat(budgetOverrideRepository.findByLeaseAndInvoiceCharge(leaseTopModel, invoiceCharge).size()).isEqualTo(1);
    assertThat(budgetOverrideRepository.findByLeaseAndInvoiceCharge(leaseTopModel, invoiceCharge).get(0)).isEqualTo(budgetOverrideForFixed);
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) BudgetOverrideForFixed(org.estatio.module.budgetassignment.dom.override.BudgetOverrideForFixed) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 38 with Lease

use of org.estatio.module.lease.dom.Lease in project estatio by estatio.

the class Invoice_DocumentManagement_IntegTest method findInvoice.

Invoice findInvoice(final InvoiceStatus invoiceStatus) {
    // clears out queryResultsCache
    transactionService.nextTransaction();
    final Party seller = InvoiceForLease_enum.OxfPoison003Gb.getSeller_d().findUsing(serviceRegistry);
    final Party buyer = InvoiceForLease_enum.OxfPoison003Gb.getBuyer_d().findUsing(serviceRegistry);
    final Lease lease = InvoiceForLease_enum.OxfPoison003Gb.getLease_d().findUsing(serviceRegistry);
    final LocalDate invoiceStartDate = InvoiceForLease_enum.OxfPoison003Gb.getLease_d().getStartDate().plusYears(1);
    List<InvoiceForLease> matchingInvoices = findMatchingInvoices(seller, buyer, lease, invoiceStartDate, invoiceStatus);
    assertThat(matchingInvoices.size()).isLessThanOrEqualTo(1);
    return matchingInvoices.isEmpty() ? null : matchingInvoices.get(0);
}
Also used : Party(org.estatio.module.party.dom.Party) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) LocalDate(org.joda.time.LocalDate)

Example 39 with Lease

use of org.estatio.module.lease.dom.Lease in project estatio by estatio.

the class InvoiceForLeaseDtoFactory method newDto.

@Programmatic
public InvoiceDto newDto(final InvoiceForLease invoiceForLease) {
    InvoiceDto dto = new InvoiceDto();
    dto.setSelf(mappingHelper.oidDtoFor(invoiceForLease));
    dto.setAtPath(invoiceForLease.getApplicationTenancyPath());
    dto.setBuyerParty(mappingHelper.oidDtoFor(invoiceForLease.getBuyer()));
    dto.setSellerParty(mappingHelper.oidDtoFor(invoiceForLease.getSeller()));
    dto.setDueDate(asXMLGregorianCalendar(invoiceForLease.getDueDate()));
    dto.setInvoiceDate(asXMLGregorianCalendar(invoiceForLease.getInvoiceDate()));
    dto.setInvoiceNumber(invoiceForLease.getInvoiceNumber());
    dto.setPaymentMethod(toDto(invoiceForLease.getPaymentMethod()));
    dto.setCollectionNumber(invoiceForLease.getCollectionNumber());
    final Lease lease = invoiceForLease.getLease();
    if (lease != null) {
        dto.setAgreementReference(lease.getReference());
        final BankMandate paidBy = lease.getPaidBy();
        if (paidBy != null) {
            dto.setPaidByMandate(mappingHelper.oidDtoFor(paidBy));
            dto.setBuyerBankAccount(mappingHelper.oidDtoFor(paidBy.getBankAccount()));
        }
    }
    final Optional<FixedAsset> fixedAssetIfAny = Optional.ofNullable(invoiceForLease.getFixedAsset());
    if (fixedAssetIfAny.isPresent()) {
        final FixedAsset fixedAsset = fixedAssetIfAny.get();
        dto.setFixedAssetReference(fixedAsset.getReference());
        dto.setFixedAssetExternalReference(fixedAsset.getExternalReference());
        // there should be only one
        dto.setSellerBankAccount(mappingHelper.oidDtoFor(invoiceForLease.getSellerBankAccount()));
    }
    invoiceForLease.getItems().stream().forEach(item -> dto.getItems().add(invoiceItemForLeaseDtoFactory.newDto(item)));
    dto.setNetAmount(dto.getItems().stream().map(x -> valueElseZero(x.getNetAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
    dto.setGrossAmount(dto.getItems().stream().map(x -> valueElseZero(x.getGrossAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
    dto.setVatAmount(dto.getItems().stream().map(x -> valueElseZero(x.getVatAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
    return dto;
}
Also used : InvoiceDto(org.estatio.canonical.invoice.v1.InvoiceDto) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) FixedAsset(org.estatio.module.asset.dom.FixedAsset) BankMandate(org.estatio.module.bankmandate.dom.BankMandate) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 40 with Lease

use of org.estatio.module.lease.dom.Lease in project estatio by estatio.

the class LeaseMenu method verifyLeasesUntil.

@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "4")
public String verifyLeasesUntil(final LeaseItemType leaseItemType, final LocalDate untilDate) {
    DateTime start = DateTime.now();
    List<Lease> leases = allLeases();
    for (Lease lease : leases) {
        for (LeaseItem leaseItem : lease.getItems()) {
            if (leaseItem.getType().equals(leaseItemType)) {
                leaseItem.verifyUntil(untilDate);
            }
        }
    }
    Period p = new Period(start, DateTime.now());
    return String.format("Verified %d leases in %s", leases.size(), JodaPeriodUtils.asString(p));
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) LeaseItem(org.estatio.module.lease.dom.LeaseItem) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder)

Aggregations

Lease (org.estatio.module.lease.dom.Lease)57 LocalDate (org.joda.time.LocalDate)17 Programmatic (org.apache.isis.applib.annotation.Programmatic)16 ApplicationException (org.apache.isis.applib.ApplicationException)11 Charge (org.estatio.module.charge.dom.Charge)11 Test (org.junit.Test)11 LeaseItem (org.estatio.module.lease.dom.LeaseItem)10 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)10 Unit (org.estatio.module.asset.dom.Unit)9 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)9 Property (org.estatio.module.asset.dom.Property)7 Party (org.estatio.module.party.dom.Party)6 Action (org.apache.isis.applib.annotation.Action)5 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PaymentMethod (org.estatio.module.invoice.dom.PaymentMethod)4 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)4 BigDecimal (java.math.BigDecimal)3