Search in sources :

Example 6 with ChargeGroup

use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.

the class ChargeImport method importData.

@Override
@Programmatic
public List<Object> importData(Object previousRow) {
    ChargeGroup chargeGroup = null;
    if (getChargeGroupReference() != null) {
        chargeGroup = findOrCreateChargeGroup(chargeGroupReference, chargeGroupName);
    }
    final ApplicationTenancy applicationTenancy = securityApplicationTenancyRepository.findByPath(atPath);
    final Applicability applicability = this.applicability != null ? Applicability.valueOf(this.applicability) : Applicability.IN_AND_OUT;
    Tax tax = null;
    if (getTaxReference() != null) {
        tax = taxRepository.findOrCreate(taxReference, taxReference, applicationTenancy);
    }
    if (getReference() == null) {
        setReference(getName());
    }
    final Charge charge = chargeRepository.upsert(getReference(), getName(), getDescription(), applicationTenancy, applicability, tax, chargeGroup);
    if (getParent() != null) {
        Charge parentCharge = chargeRepository.findByReference(getParent());
        if (parentCharge != null) {
            charge.setParent(parentCharge);
        }
    }
    if (externalReference != null) {
        charge.setExternalReference(externalReference);
    }
    if (sortOrder != null) {
        charge.setSortOrder(sortOrder);
    }
    return Lists.newArrayList(charge);
}
Also used : ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) Applicability(org.estatio.module.charge.dom.Applicability) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 7 with ChargeGroup

use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.

the class ChargeImport method findOrCreateChargeGroup.

private ChargeGroup findOrCreateChargeGroup(final String reference, final String name) {
    ChargeGroup chargeGroup = chargeGroupRepository.findChargeGroup(reference);
    if (chargeGroup == null) {
        chargeGroup = chargeGroupRepository.createChargeGroup(reference, name);
    }
    chargeGroup.setName(name);
    return chargeGroup;
}
Also used : ChargeGroup(org.estatio.module.charge.dom.ChargeGroup)

Example 8 with ChargeGroup

use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.

the class InvoiceForLeaseDtoFactory_Test method newItem.

private static InvoiceItemForTesting newItem(final Invoice invoice, final String netAmt, final String grossAmt, final String vatAmt) {
    final InvoiceItemForTesting invoiceItem = new InvoiceItemForTesting(invoice);
    invoiceItem.setInvoice(invoice);
    final ChargeGroup chargeGroup = new ChargeGroup();
    final Charge charge = new Charge();
    charge.setGroup(chargeGroup);
    invoiceItem.setCharge(charge);
    final Tax tax = new Tax();
    invoiceItem.setTax(tax);
    invoiceItem.setNetAmount(new BigDecimal(netAmt));
    invoiceItem.setGrossAmount(new BigDecimal(grossAmt));
    invoiceItem.setVatAmount(new BigDecimal(vatAmt));
    return invoiceItem;
}
Also used : InvoiceItemForTesting(org.estatio.module.invoice.dom.InvoiceItemForTesting) ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) BigDecimal(java.math.BigDecimal)

Example 9 with ChargeGroup

use of org.estatio.module.charge.dom.ChargeGroup 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 10 with ChargeGroup

use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.

the class LeaseItemForDepositBuilder method execute.

@Override
protected void execute(final ExecutionContext ec) {
    defaultParam("charge", ec, Charge_enum.ItDeposit.findUsing(serviceRegistry));
    final ChargeGroup group = getCharge().getGroup();
    final ChargeGroup_enum expectedGroup = ChargeGroup_enum.Deposit;
    if (group != expectedGroup.findUsing(serviceRegistry)) {
        throw new IllegalArgumentException("Charge's group must be " + expectedGroup.getRef());
    }
    LeaseItem leaseItem = new LeaseItemBuilder().setLease(lease).setCharge(charge).setLeaseItemType(LEASE_ITEM_TYPE).setInvoicingFrequency(INVOICING_FREQUENCY).setSequence(sequence).setInvoicedBy(invoicedBy).setPaymentMethod(paymentMethod).setStatus(status).build(this, ec).getObject();
    if (sourceItem != null) {
        if (leaseItem.getSourceItems().isEmpty()) {
            leaseItem.newSourceItem(sourceItem);
        }
    }
    for (LeaseTermForDepositBuilder.TermSpec termSpec : termSpecs) {
        final LeaseTermForDeposit term = new LeaseTermForDepositBuilder().setLeaseItem(leaseItem).setStartDate(termSpec.startDate).setEndDate(termSpec.endDate).setFraction(termSpec.fraction).build(this, ec).getObject();
        terms.add(term);
    }
    object = leaseItem;
}
Also used : ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) ChargeGroup_enum(org.estatio.module.charge.fixtures.chargegroups.enums.ChargeGroup_enum) LeaseTermForDeposit(org.estatio.module.lease.dom.LeaseTermForDeposit) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Aggregations

ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)15 ChargeGroup_enum (org.estatio.module.charge.fixtures.chargegroups.enums.ChargeGroup_enum)10 LeaseItem (org.estatio.module.lease.dom.LeaseItem)10 Charge (org.estatio.module.charge.dom.Charge)4 Tax (org.estatio.module.tax.dom.Tax)4 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 Lease (org.estatio.module.lease.dom.Lease)2 LeaseTermForFixed (org.estatio.module.lease.dom.LeaseTermForFixed)2 LeaseTermForIndexable (org.estatio.module.lease.dom.LeaseTermForIndexable)2 LeaseTermForServiceCharge (org.estatio.module.lease.dom.LeaseTermForServiceCharge)2 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)2 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)2 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)2 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)2 BigDecimal (java.math.BigDecimal)1 InvoiceItemDto (org.estatio.canonical.invoice.v1.InvoiceItemDto)1 FixedAsset (org.estatio.module.asset.dom.FixedAsset)1 Unit (org.estatio.module.asset.dom.Unit)1 Applicability (org.estatio.module.charge.dom.Applicability)1 InvoiceItemForTesting (org.estatio.module.invoice.dom.InvoiceItemForTesting)1