Search in sources :

Example 31 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_works_when_no_item_to_copy_from_found.

@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_works_when_no_item_to_copy_from_found() throws Exception {
    // given
    BudgetAssignmentService budgetAssignmentService = new BudgetAssignmentService() {

        @Override
        LeaseItem findItemToCopyFrom(final Lease lease) {
            return null;
        }
    };
    Charge charge = new Charge();
    BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
    budgetCalculationResult.setInvoiceCharge(charge);
    LocalDate termStartDate = new LocalDate(2018, 1, 1);
    InvoicingFrequency invoicingFrequencyGuess = InvoicingFrequency.QUARTERLY_IN_ADVANCE;
    PaymentMethod paymentMethodGuess = PaymentMethod.DIRECT_DEBIT;
    // 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(), invoicingFrequencyGuess, paymentMethodGuess, 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) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) LocalDate(org.joda.time.LocalDate) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) InvoicingFrequency(org.estatio.module.lease.dom.InvoicingFrequency) Test(org.junit.Test)

Example 32 with Charge

use of org.estatio.module.charge.dom.Charge 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 33 with Charge

use of org.estatio.module.charge.dom.Charge 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 34 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class Project_CreateMissingItems method chargesLinkedNotOnItems.

private List<Charge> chargesLinkedNotOnItems() {
    List<Charge> result = new ArrayList<>();
    Project_OrderItemsNotOnProjectItem orderItemsMixin = new Project_OrderItemsNotOnProjectItem(project);
    serviceRegistry2.injectServicesInto(orderItemsMixin);
    for (Charge chargeCandidate : orderItemsMixin.orderItemsNotOnProjectItem().stream().filter(x -> x.getCharge() != null).map(x -> x.getCharge()).collect(Collectors.toList())) {
        if (!result.contains(chargeCandidate)) {
            result.add(chargeCandidate);
        }
    }
    Project_InvoiceItemsNotOnProjectItem invoiceItemsMixin = new Project_InvoiceItemsNotOnProjectItem(project);
    serviceRegistry2.injectServicesInto(invoiceItemsMixin);
    for (Charge chargeCandidate : invoiceItemsMixin.invoiceItemsNotOnProjectItem().stream().filter(x -> x.getCharge() != null).map(x -> x.getCharge()).collect(Collectors.toList())) {
        if (!result.contains(chargeCandidate)) {
            result.add(chargeCandidate);
        }
    }
    return result;
}
Also used : Action(org.apache.isis.applib.annotation.Action) Project(org.estatio.module.capex.dom.project.Project) ServiceRegistry2(org.apache.isis.applib.services.registry.ServiceRegistry2) Project_InvoiceItemsNotOnProjectItem(org.estatio.module.capex.dom.invoice.contributions.Project_InvoiceItemsNotOnProjectItem) Charge(org.estatio.module.charge.dom.Charge) EstatioRole(org.estatio.module.base.dom.EstatioRole) Property(org.estatio.module.asset.dom.Property) Collectors(java.util.stream.Collectors) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) List(java.util.List) Project_OrderItemsNotOnProjectItem(org.estatio.module.capex.dom.order.contributions.Project_OrderItemsNotOnProjectItem) UserService(org.apache.isis.applib.services.user.UserService) Project_InvoiceItemsNotOnProjectItem(org.estatio.module.capex.dom.invoice.contributions.Project_InvoiceItemsNotOnProjectItem) Charge(org.estatio.module.charge.dom.Charge) ArrayList(java.util.ArrayList) Project_OrderItemsNotOnProjectItem(org.estatio.module.capex.dom.order.contributions.Project_OrderItemsNotOnProjectItem)

Example 35 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class InvoiceItemForLeaseDtoFactory method newDto.

@Programmatic
public InvoiceItemDto newDto(final InvoiceItem item) {
    InvoiceItemDto dto = new InvoiceItemDto();
    if (item instanceof InvoiceItemForLease) {
        InvoiceItemForLease invoiceItemForLease = (InvoiceItemForLease) item;
        final Lease lease = invoiceItemForLease.getLease();
        if (lease != null) {
            dto.setAgreementReference(lease.getReference());
        }
        final FixedAsset fixedAsset = invoiceItemForLease.getFixedAsset();
        if (fixedAsset != null) {
            dto.setFixedAssetReference(fixedAsset.getReference());
            dto.setFixedAssetExternalReference(fixedAsset.getExternalReference());
        }
    }
    final Charge charge = item.getCharge();
    dto.setChargeReference(charge.getReference());
    dto.setChargeDescription(charge.getDescription());
    dto.setChargeExternalReference(charge.getExternalReference());
    dto.setChargeName(charge.getName());
    final ChargeGroup group = charge.getGroup();
    dto.setChargeGroupReference(group.getReference());
    dto.setChargeGroupName(group.getName());
    final Tax tax = item.getTax();
    final TaxRate rate = item.getTaxRate();
    dto.setTaxReference(tax.getReference());
    dto.setTaxName(tax.getName());
    dto.setTaxDescription(tax.getDescription());
    dto.setTaxExternalReference(rate == null || rate.getExternalReference() == null ? tax.getExternalReference() : rate.getExternalReference());
    dto.setNetAmount(item.getNetAmount());
    dto.setGrossAmount(item.getGrossAmount());
    dto.setVatAmount(item.getVatAmount());
    dto.setDescription(item.getDescription());
    dto.setStartDate(asXMLGregorianCalendar(item.getStartDate()));
    dto.setEndDate(asXMLGregorianCalendar(item.getEndDate()));
    dto.setEffectiveStartDate(asXMLGregorianCalendar(firstNonNull(item.getEffectiveStartDate(), item.getStartDate())));
    dto.setEffectiveEndDate(asXMLGregorianCalendar(firstNonNull(item.getEffectiveEndDate(), item.getEndDate())));
    if (item instanceof InvoiceItemForLease) {
        final InvoiceItemForLease invoiceItemForLease = (InvoiceItemForLease) item;
        final InvoiceForLease invoice = (InvoiceForLease) invoiceItemForLease.getInvoice();
        final Lease leaseIfAny = invoice.getLease();
        if (leaseIfAny != null) {
            final SortedSet<Occupancy> occupancies = leaseIfAny.getOccupancies();
            if (!occupancies.isEmpty()) {
                // final Optional<Occupancy> occupancyIfAny =
                // occupancies.stream().filter(x -> x.getInterval().overlaps(item.getEffectiveInterval())).findFirst();
                final Optional<Occupancy> occupancyIfAny = Optional.ofNullable(occupancies.first());
                if (occupancyIfAny.isPresent()) {
                    final Occupancy occupancy = occupancyIfAny.orElse(occupancies.last());
                    final Brand brand = occupancy.getBrand();
                    dto.setOccupancyBrand(brand == null ? null : brand.getName());
                    if (dto.getFixedAssetReference() == null) {
                        // the unit was not retrieved through the invoice item, so get it from the occupancy then.
                        dto.setFixedAssetReference(occupancy.getUnit().getReference());
                        dto.setFixedAssetExternalReference(occupancy.getUnit().getExternalReference());
                    }
                } else {
                    // throw new IllegalArgumentException("Invoice has an effective date range outside the scope of the occupanies");
                    throw new IllegalArgumentException("No Occupancy Found");
                }
            }
        }
    }
    return dto;
}
Also used : InvoiceItemDto(org.estatio.canonical.invoice.v1.InvoiceItemDto) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) Charge(org.estatio.module.charge.dom.Charge) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) Tax(org.estatio.module.tax.dom.Tax) FixedAsset(org.estatio.module.asset.dom.FixedAsset) Brand(org.estatio.module.lease.dom.occupancy.tags.Brand) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) TaxRate(org.estatio.module.tax.dom.TaxRate) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Charge (org.estatio.module.charge.dom.Charge)41 Test (org.junit.Test)18 BigDecimal (java.math.BigDecimal)14 LocalDate (org.joda.time.LocalDate)14 Lease (org.estatio.module.lease.dom.Lease)11 Programmatic (org.apache.isis.applib.annotation.Programmatic)10 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)9 Project (org.estatio.module.capex.dom.project.Project)9 Tax (org.estatio.module.tax.dom.Tax)9 Property (org.estatio.module.asset.dom.Property)7 LeaseItem (org.estatio.module.lease.dom.LeaseItem)6 ApplicationException (org.apache.isis.applib.ApplicationException)4 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)4 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)4 Action (org.apache.isis.applib.annotation.Action)3 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)3 Organisation (org.estatio.module.party.dom.Organisation)3 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)3 Expectations (org.jmock.Expectations)3 ArrayList (java.util.ArrayList)2