Search in sources :

Example 6 with Tax

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

the class ProjectImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    if (previousRow != null) {
    // TODO: support sparse sheets ?
    }
    Project parent = null;
    if (getParentReference() != null) {
        parent = projectRepository.findByReference(getParentReference());
        if (parent == null) {
            throw new ApplicationException(String.format("Parent with reference %s not found.", getParentReference()));
        }
        if (!parent.getAtPath().equals(getAtPath())) {
            throw new ApplicationException(String.format("AtPath parent %s does not match %s.", getParentReference(), getAtPath()));
        }
        if (!parent.getItems().isEmpty()) {
            // TODO: (ECP-438) until we find out more about the process, prevent a the choice of a project having items
            throw new ApplicationException(String.format("Parent with reference %s has items and cannot be a parent therefore.", getAtPath()));
        }
    }
    Project project = findOrCreateProjectAndUpdateParent(getReference(), getName(), getStartDate(), getEndDate(), getAtPath(), parent);
    if (getItemChargeReference() != null) {
        Charge charge = chargeRepository.findByReference(getItemChargeReference());
        Property property = propertyRepository.findPropertyByReference(getItemPropertyReference());
        Tax tax = taxRepository.findByReference(getItemTaxReference());
        wrapperFactory.wrap(project).addItem(charge, getItemDescription(), getItemBudgetedAmount(), getItemStartDate(), getItemEndDate(), property, tax);
    }
    return Lists.newArrayList(project);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) ApplicationException(org.apache.isis.applib.ApplicationException) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 7 with Tax

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

the class Order_Test method splitItem_mixin_works.

@Test
public void splitItem_mixin_works() throws Exception {
    // given
    Order order = new Order();
    order.orderItemRepository = mockOrderItemRepository;
    String description = "some description";
    Tax tax = new Tax();
    Charge charge = new Charge();
    Property property = new Property();
    Project project = new Project();
    BudgetItem budgetItem = new BudgetItem();
    String period = "F2018";
    OrderItem itemToSplit = new OrderItem();
    BigDecimal newItemNetAmount = new BigDecimal("50.00");
    BigDecimal newItemVatAmount = new BigDecimal("10");
    BigDecimal newItemGrossAmount = new BigDecimal("60.00");
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderItemRepository).upsert(order, charge, description, newItemNetAmount, newItemVatAmount, newItemGrossAmount, tax, PeriodUtil.yearFromPeriod(period).startDate(), PeriodUtil.yearFromPeriod(period).endDate(), property, project, budgetItem);
        }
    });
    // when
    order.splitItem(itemToSplit, description, newItemNetAmount, newItemVatAmount, tax, newItemGrossAmount, charge, property, project, budgetItem, period);
}
Also used : Expectations(org.jmock.Expectations) Project(org.estatio.module.capex.dom.project.Project) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) Property(org.estatio.module.asset.dom.Property) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 8 with Tax

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

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

use of org.estatio.module.tax.dom.Tax 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)13 Charge (org.estatio.module.charge.dom.Charge)9 BigDecimal (java.math.BigDecimal)5 Project (org.estatio.module.capex.dom.project.Project)5 LocalDate (org.joda.time.LocalDate)5 Programmatic (org.apache.isis.applib.annotation.Programmatic)4 Property (org.estatio.module.asset.dom.Property)4 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)4 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)4 Test (org.junit.Test)4 TaxRate (org.estatio.module.tax.dom.TaxRate)3 FixedAsset (org.estatio.module.asset.dom.FixedAsset)2 Lease (org.estatio.module.lease.dom.Lease)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 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)2 Before (org.junit.Before)2 BigInteger (java.math.BigInteger)1