use of org.estatio.module.lease.dom.Lease 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;
}
use of org.estatio.module.lease.dom.Lease in project estatio by estatio.
the class LeaseBuilder method execute.
@Override
protected void execute(final ExecutionContext executionContext) {
checkParam("reference", executionContext, String.class);
checkParam("name", executionContext, String.class);
checkParam("property", executionContext, Unit.class);
checkParam("landlord", executionContext, Party.class);
checkParam("tenant", executionContext, Party.class);
checkParam("startDate", executionContext, LocalDate.class);
checkParam("endDate", executionContext, LocalDate.class);
defaultParam("invoiceAddressCreationPolicy", executionContext, InvoiceAddressCreationPolicy.DONT_CREATE);
defaultParam("addressesCreationPolicy", executionContext, AddressesCreationPolicy.DONT_CREATE);
landlord.addRole(LeaseRoleTypeEnum.LANDLORD);
tenant.addRole(LeaseRoleTypeEnum.TENANT);
final ApplicationTenancy atPath = ApplicationTenancy_enum.Global.findUsing(serviceRegistry);
final LeaseType leaseType = leaseTypeRepository.findOrCreate("STD", "Standard", atPath);
Lease lease = leaseRepository.newLease(property.getApplicationTenancy(), reference, name, leaseType, startDate, null, endDate, landlord, tenant);
executionContext.addResult(this, lease.getReference(), lease);
if (manager != null) {
final AgreementRole role = lease.createRole(agreementRoleTypeRepository.find(LeaseAgreementRoleTypeEnum.MANAGER), manager, null, null);
executionContext.addResult(this, role);
}
for (final OccupancySpec spec : occupancySpecs) {
Occupancy occupancy = occupancyRepository.newOccupancy(lease, spec.unit, spec.startDate);
occupancy.setEndDate(spec.endDate);
occupancy.setBrandName(spec.brand, spec.brandCoverage, spec.countryOfOrigin);
occupancy.setSectorName(spec.sector);
occupancy.setActivityName(spec.activity);
executionContext.addResult(this, occupancy);
}
if (invoiceAddressCreationPolicy == InvoiceAddressCreationPolicy.CREATE) {
addInvoiceAddressForTenant(lease, tenant, CommunicationChannelType.EMAIL_ADDRESS);
}
if (addressesCreationPolicy == AddressesCreationPolicy.CREATE) {
createAddress(lease, AgreementRoleCommunicationChannelTypeEnum.ADMINISTRATION_ADDRESS);
createAddress(lease, AgreementRoleCommunicationChannelTypeEnum.INVOICE_ADDRESS);
}
if (leaseRepository.findLeaseByReference(reference) == null) {
throw new RuntimeException("could not find lease reference='" + reference + "'");
}
object = lease;
}
use of org.estatio.module.lease.dom.Lease in project estatio by estatio.
the class CommunicationChannelImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
List<Object> results = new ArrayList<>();
// Party
final Party party = fetchParty(partyReference);
if (party == null)
throw new ApplicationException(String.format("Party with reference [%s] not found", partyReference));
// Address
if (address1 != null || address2 != null || address3 != null) {
final Country country = countryRepository.findCountry(countryCode);
PostalAddress comm = (PostalAddress) postalAddressRepository.findByAddress(party, address1, address2, address3, postalCode, city, country);
if (comm == null) {
comm = communicationChannelRepository.newPostal(party, CommunicationChannelType.POSTAL_ADDRESS, address1, address2, address3, postalCode, city, stateRepository.findState(stateCode), countryRepository.findCountry(countryCode));
}
if (legal != null && legal) {
comm.setLegal(true);
}
// attach to lease
if (leaseReference != null) {
Lease lease = fetchLease(leaseReference);
if (lease != null && addressType != null) {
final AgreementRoleType art = agreementRoleTypeRepository.find(LeaseAgreementRoleTypeEnum.TENANT);
final AgreementRoleCommunicationChannelType arcct = agreementRoleCommunicationChannelTypeRepository.findByTitle(addressType);
lease.findRoleWithType(art, lease.getStartDate()).addCommunicationChannel(arcct, comm, lease.getStartDate());
}
}
}
// Phone
if (phoneNumber != null) {
CommunicationChannel comm = phoneOrFaxNumberRepository.findByPhoneOrFaxNumber(party, phoneNumber);
if (comm == null) {
comm = communicationChannelRepository.newPhoneOrFax(party, CommunicationChannelType.PHONE_NUMBER, phoneNumber);
comm.setReference(leaseReference);
}
}
// Fax
if (faxNumber != null) {
CommunicationChannel comm = phoneOrFaxNumberRepository.findByPhoneOrFaxNumber(party, faxNumber);
if (comm == null) {
comm = communicationChannelRepository.newPhoneOrFax(party, CommunicationChannelType.FAX_NUMBER, faxNumber);
comm.setReference(leaseReference);
}
}
// Email
if (emailAddress != null) {
CommunicationChannel comm = emailAddressRepository.findByEmailAddress(party, emailAddress);
if (comm == null) {
comm = communicationChannelRepository.newEmail(party, CommunicationChannelType.EMAIL_ADDRESS, emailAddress);
comm.setReference(leaseReference);
}
}
return results;
}
use of org.estatio.module.lease.dom.Lease in project estatio by estatio.
the class ClassificationForOccImport method importData.
@Override
public List<Object> importData(final Object previousRow) {
final Lease lease = leaseRepository.findLeaseByReference(getLeaseReference());
if (lease == null) {
throw new IllegalArgumentException(String.format("No lease found for '%s'", getLeaseReference()));
}
final Unit unit = unitRepository.findUnitByReference(getUnitReference());
if (unit == null) {
throw new IllegalArgumentException(String.format("No unit found for '%s'", getUnitReference()));
}
final Occupancy occupancy = occupancyRepository.findByLease(lease).stream().filter(x -> x.getUnit().equals(unit)).findFirst().get();
if (occupancy == null) {
throw new IllegalArgumentException(String.format("No occupancy found for lease '%s' and unit '%s'", getLeaseReference(), getUnitReference()));
}
final Taxonomy taxonomy = (Taxonomy) categoryRepository.findByReference(getTaxonomyReference());
if (taxonomy == null) {
throw new IllegalArgumentException(String.format("No taxonomy found for '%s'", getTaxonomyReference()));
}
final Category category = categoryRepository.findByTaxonomyAndReference(taxonomy, getCategoryReference());
if (category == null) {
throw new IllegalArgumentException(String.format("No category found for '%s'", getCategoryReference()));
}
final Classification classification = classificationRepository.create(category, occupancy);
return Lists.newArrayList(classification);
}
use of org.estatio.module.lease.dom.Lease in project estatio by estatio.
the class InvoiceImportLine method importData.
@Override
@Programmatic
public List<Object> importData(final Object previousRow) {
List<Object> result = new ArrayList<>();
Lease lease = fetchLease(getLeaseReference());
PaymentMethod paymentMethod = fetchPaymentMethod(getPaymentMethod());
String atPath = lease.getApplicationTenancyPath().concat("/").concat(lease.getPrimaryParty().getReference());
ApplicationTenancy applicationTenancy = applicationTenancyRepository.findByPath(atPath);
Invoice invoice = invoiceForLeaseRepository.newInvoice(applicationTenancy, lease.getPrimaryParty(), lease.getSecondaryParty(), paymentMethod, currencyRepository.findCurrency("EUR"), getDueDate(), lease, null);
InvoiceItem invoiceItem = factoryService.mixin(InvoiceForLease._newItem.class, invoice).$$(fetchCharge(getItemChargeReference()), BigDecimal.ONE, getItemNetAmount(), getItemStartDate(), getItemEndDate());
if (getItemDescription() != null) {
invoiceItem.setDescription(getItemDescription());
}
result.add(invoice);
return result;
}
Aggregations