Search in sources :

Example 16 with InvoiceForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceForLease 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 17 with InvoiceForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceForLease 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)

Example 18 with InvoiceForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceForLease 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;
}
Also used : Invoice(org.estatio.module.invoice.dom.Invoice) InvoiceItem(org.estatio.module.invoice.dom.InvoiceItem) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) ArrayList(java.util.ArrayList) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) DomainObject(org.apache.isis.applib.annotation.DomainObject) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 19 with InvoiceForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceForLease in project estatio by estatio.

the class DocumentCommunicationSupportForDocumentsAttachedToInvoiceForLease method inferToHeader.

private <T extends CommunicationChannel> void inferToHeader(final Document document, final CommHeaderAbstract<T> header, final CommunicationChannelType channelType) {
    final List<Paperclip> paperclips = paperclipRepository.findByDocument(document);
    for (final Paperclip paperclip : paperclips) {
        final Object attachedTo = paperclip.getAttachedTo();
        if (attachedTo instanceof InvoiceForLease) {
            final InvoiceForLease invoice = (InvoiceForLease) attachedTo;
            addTo(invoice, header, channelType);
        }
    }
    if (header.getToChoices().isEmpty()) {
        header.setDisabledReason("Could not find a communication channel to use");
    }
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease)

Example 20 with InvoiceForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceForLease in project estatio by estatio.

the class InvoiceSummaryForPropertyDueDateStatus_resetDescriptions method act.

@Action(semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE)
public InvoiceSummaryForPropertyDueDateStatus act() {
    final List<InvoiceForLease> invoices = summary.getInvoices();
    for (final InvoiceForLease ninvoice : invoices) {
        updateAttribute(ninvoice, InvoiceAttributeName.INVOICE_DESCRIPTION);
        updateAttribute(ninvoice, InvoiceAttributeName.PRELIMINARY_LETTER_DESCRIPTION);
    }
    return summary;
}
Also used : InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) Action(org.apache.isis.applib.annotation.Action)

Aggregations

InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)22 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)8 LocalDate (org.joda.time.LocalDate)8 Lease (org.estatio.module.lease.dom.Lease)7 Property (org.estatio.module.asset.dom.Property)6 Test (org.junit.Test)6 Property_calculateInvoices (org.estatio.module.lease.contributions.Property_calculateInvoices)4 Programmatic (org.apache.isis.applib.annotation.Programmatic)3 Unit (org.estatio.module.asset.dom.Unit)3 Invoice (org.estatio.module.invoice.dom.Invoice)3 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)3 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)3 Before (org.junit.Before)3 Action (org.apache.isis.applib.annotation.Action)2 InvoiceDto (org.estatio.canonical.invoice.v1.InvoiceDto)2 FixedAsset (org.estatio.module.asset.dom.FixedAsset)2 Charge (org.estatio.module.charge.dom.Charge)2 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)2 LeaseTerm (org.estatio.module.lease.dom.LeaseTerm)2 Tax (org.estatio.module.tax.dom.Tax)2