Search in sources :

Example 1 with TaxRate

use of org.estatio.module.tax.dom.TaxRate 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 2 with TaxRate

use of org.estatio.module.tax.dom.TaxRate in project estatio by estatio.

the class TaxBuilder method execute.

@Override
protected void execute(final ExecutionContext executionContext) {
    checkParam("ref", executionContext, String.class);
    checkParam("country", executionContext, Country.class);
    checkParam("applicationTenancy", executionContext, ApplicationTenancy.class);
    checkParam("rates", executionContext, List.class);
    Tax tax = taxRepository.findByReference(ref);
    if (tax == null) {
        defaultParam("description", executionContext, getRef());
        final String name = "Value Added Tax (Standard, " + country.getReference() + ")";
        tax = taxRepository.newTax(ref, name, applicationTenancy);
        for (RateData rate : rates) {
            final TaxRate taxRate = tax.newRate(rate.date, rate.rateValue);
            tax.getRates().add(taxRate);
        }
    }
    object = tax;
}
Also used : TaxRate(org.estatio.module.tax.dom.TaxRate) Tax(org.estatio.module.tax.dom.Tax) ToString(lombok.ToString)

Example 3 with TaxRate

use of org.estatio.module.tax.dom.TaxRate in project estatio by estatio.

the class TaxImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    final ApplicationTenancy applicationTenancy = securityApplicationTenancyRepository.findByPath(atPath);
    final Tax tax = taxRepository.findOrCreate(reference, name, applicationTenancy);
    tax.setExternalReference(externalReference);
    tax.setDescription(description);
    final TaxRate rate = tax.newRate(rateStartDate, ratePercentage);
    rate.setExternalReference(rateExternalReference);
    return Lists.newArrayList(tax);
}
Also used : TaxRate(org.estatio.module.tax.dom.TaxRate) Tax(org.estatio.module.tax.dom.Tax) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Tax (org.estatio.module.tax.dom.Tax)3 TaxRate (org.estatio.module.tax.dom.TaxRate)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 ToString (lombok.ToString)1 InvoiceItemDto (org.estatio.canonical.invoice.v1.InvoiceItemDto)1 FixedAsset (org.estatio.module.asset.dom.FixedAsset)1 Charge (org.estatio.module.charge.dom.Charge)1 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)1 Lease (org.estatio.module.lease.dom.Lease)1 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)1 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)1 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)1 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)1 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)1