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;
}
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();
}
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;
}
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);
}
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;
}
Aggregations