Search in sources :

Example 76 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class AgreementCommunicationChannelLocator method current.

@Programmatic
public List<CommunicationChannel> current(final Agreement agreement, final String art, final String arcct, final List<CommunicationChannelType> communicationChannelTypes) {
    final List<CommunicationChannel> communicationChannels = Lists.newArrayList();
    final AgreementRoleType partyInRoleOf = agreementRoleTypeRepository.findByTitle(art);
    final AgreementRoleCommunicationChannelType commChannelInRoleOf = agreementRoleCommunicationChannelTypeRepository.findByTitle(arcct);
    final SortedSet<AgreementRole> agreementRoles = agreement.getRoles();
    for (final AgreementRole role : agreementRoles) {
        if (role.getType() == partyInRoleOf) {
            final SortedSet<AgreementRoleCommunicationChannel> rolesOfChannels = role.getCommunicationChannels();
            for (AgreementRoleCommunicationChannel roleOfChannel : rolesOfChannels) {
                if (roleOfChannel.getType() == commChannelInRoleOf) {
                    final CommunicationChannel communicationChannel = roleOfChannel.getCommunicationChannel();
                    if (roleOfChannel.isCurrent() && communicationChannelTypes.contains(communicationChannel.getType())) {
                        communicationChannels.add(communicationChannel);
                    }
                }
            }
        }
    }
    return communicationChannels;
}
Also used : AgreementRoleCommunicationChannelType(org.estatio.module.agreement.dom.AgreementRoleCommunicationChannelType) AgreementRole(org.estatio.module.agreement.dom.AgreementRole) AgreementRoleType(org.estatio.module.agreement.dom.role.AgreementRoleType) AgreementRoleCommunicationChannel(org.estatio.module.agreement.dom.AgreementRoleCommunicationChannel) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) AgreementRoleCommunicationChannel(org.estatio.module.agreement.dom.AgreementRoleCommunicationChannel) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 77 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class InvoiceCalculationService method calculateDueDateRange.

/**
 * Calculates a term with a given invoicing frequency
 */
@Programmatic
public List<CalculationResult> calculateDueDateRange(final LeaseTerm leaseTerm, final InvoiceCalculationParameters parameters) {
    final LocalDateInterval dueDateRangeInterval = parameters.invoiceRunType().equals(InvoiceRunType.RETRO_RUN) && leaseTerm.getLeaseItem().getLease().getStartDate().compareTo(parameters.dueDateRange().startDate()) < 0 ? new LocalDateInterval(leaseTerm.getLeaseItem().getLease().getStartDate(), parameters.dueDateRange().endDateExcluding(), IntervalEnding.EXCLUDING_END_DATE) : parameters.dueDateRange();
    // performance, EST-315, should get some attention.
    if (dueDateRangeInterval.isValid()) {
        final List<InvoicingInterval> intervals = leaseTerm.getLeaseItem().getInvoicingFrequency().intervalsInDueDateRange(dueDateRangeInterval, leaseTerm.getInterval());
        final LocalDate dueDateForCalculation = parameters.dueDateRange().endDateExcluding().minusDays(1);
        return calculateTerm(leaseTerm, intervals);
    }
    return Lists.newArrayList();
}
Also used : InvoicingInterval(org.estatio.module.invoice.dom.InvoicingInterval) LocalDate(org.joda.time.LocalDate) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 78 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic 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 79 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class InvoiceForLeaseRepository method findOrCreateMatchingInvoice.

@Programmatic
public InvoiceForLease findOrCreateMatchingInvoice(final ApplicationTenancy applicationTenancy, final PaymentMethod paymentMethod, final Lease lease, final InvoiceStatus invoiceStatus, final LocalDate dueDate, final String interactionId) {
    Party buyer = lease.getSecondaryParty();
    Party seller = lease.getPrimaryParty();
    return findOrCreateMatchingInvoice(applicationTenancy, seller, buyer, paymentMethod, lease, invoiceStatus, dueDate, interactionId);
}
Also used : Party(org.estatio.module.party.dom.Party) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 80 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class InvoiceItemForLeaseRepository method newInvoiceItem.

@Programmatic
public InvoiceItemForLease newInvoiceItem(final LeaseTerm leaseTerm, final LocalDateInterval interval, final LocalDateInterval calculationInterval, final LocalDateInterval effectiveInterval, final LocalDate dueDate, final String interactionId) {
    final Lease lease = leaseTerm.getLeaseItem().getLease();
    final InvoiceForLease invoice = invoiceRepository.findOrCreateMatchingInvoice(leaseTerm.getApplicationTenancy(), leaseTerm.getLeaseItem().getPaymentMethod(), lease, InvoiceStatus.NEW, dueDate, interactionId);
    final InvoiceItemForLease invoiceItem = newItem(invoice, dueDate);
    invoiceItem.setLeaseTerm(leaseTerm);
    invoiceItem.setStartDate(interval.startDate());
    invoiceItem.setEndDate(interval.endDate());
    invoiceItem.setEffectiveStartDate(effectiveInterval.startDate());
    invoiceItem.setEffectiveEndDate(effectiveInterval.endDate());
    invoiceItem.setCalculationStartDate(calculationInterval.startDate());
    invoiceItem.setCalculationEndDate(calculationInterval.endDate());
    // redundantly persist, these are immutable
    // assumes only one occupancy per lease...
    invoiceItem.setLease(lease);
    final Optional<Occupancy> occupancyIfAny = lease.primaryOccupancy();
    occupancyIfAny.ifPresent(occupancy -> {
        Unit unit = occupancy.getUnit();
        invoiceItem.setFixedAsset(unit);
    });
    persistIfNotAlready(invoiceItem);
    return invoiceItem;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Unit(org.estatio.module.asset.dom.Unit) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Programmatic (org.apache.isis.applib.annotation.Programmatic)162 Party (org.estatio.module.party.dom.Party)21 Lease (org.estatio.module.lease.dom.Lease)16 DomainObject (org.apache.isis.applib.annotation.DomainObject)11 BankAccount (org.estatio.module.financial.dom.BankAccount)11 Charge (org.estatio.module.charge.dom.Charge)10 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)10 LocalDate (org.joda.time.LocalDate)10 BigDecimal (java.math.BigDecimal)9 Bookmark (org.apache.isis.applib.services.bookmark.Bookmark)9 ApplicationException (org.apache.isis.applib.ApplicationException)8 Property (org.estatio.module.asset.dom.Property)8 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)8 ArrayList (java.util.ArrayList)7 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)7 InvoiceItem (org.estatio.module.invoice.dom.InvoiceItem)7 LeaseItem (org.estatio.module.lease.dom.LeaseItem)7 Inject (javax.inject.Inject)6 Unit (org.estatio.module.asset.dom.Unit)6 Document (org.incode.module.document.dom.impl.docs.Document)6