Search in sources :

Example 6 with Charge

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

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

the class InvoiceTest method first_item_with_charge_works.

@Test
public void first_item_with_charge_works() throws Exception {
    // given
    InvoiceForTesting invoice = new InvoiceForTesting();
    Charge charge1 = new Charge();
    Charge charge2 = new Charge();
    InvoiceItem itemWithCharge1 = new InvoiceItemForTesting(invoice);
    itemWithCharge1.setCharge(charge1);
    // done for sort order in SortedSet items
    itemWithCharge1.setSequence(VT.bi(1));
    InvoiceItem otherItemWithCharge1 = new InvoiceItemForTesting(invoice);
    otherItemWithCharge1.setCharge(charge1);
    // done for sort order SortedSet items
    otherItemWithCharge1.setSequence(VT.bi(2));
    InvoiceItem itemWithCharge2 = new InvoiceItemForTesting(invoice);
    itemWithCharge2.setCharge(charge2);
    invoice.getItems().addAll(Arrays.asList(itemWithCharge1, otherItemWithCharge1, itemWithCharge2));
    assertThat(invoice.getItems().size()).isEqualTo(3);
    // when, then
    assertThat(invoice.findFirstItemWithCharge(charge1)).isEqualTo(itemWithCharge1);
    assertThat(invoice.findFirstItemWithCharge(charge2)).isEqualTo(itemWithCharge2);
}
Also used : Charge(org.estatio.module.charge.dom.Charge) Test(org.junit.Test)

Example 8 with Charge

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

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

the class InvoiceCalculationService method createInvoiceItems.

/**
 * Calculates an invoice item with the difference between the already
 * invoiced and calculated value.
 */
void createInvoiceItems(final LeaseTerm leaseTerm, final InvoiceCalculationParameters parameters, final List<CalculationResult> results) {
    for (CalculationResult result : results) {
        // values on a normal run
        if (result.value().compareTo(BigDecimal.ZERO) != 0 || parameters.invoiceRunType().equals(InvoiceRunType.RETRO_RUN)) {
            final LocalDateInterval invoicingInterval = result.invoicingInterval().asLocalDateInterval();
            BigDecimal invoicedValue = invoiceItemForLeaseRepository.invoicedValue(leaseTerm, invoicingInterval);
            BigDecimal newValue = result.value().subtract(invoicedValue);
            // 
            LocalDateInterval calculationInterval = result.effectiveInterval();
            LocalDateInterval effectiveInterval = calculationInterval;
            Boolean adjustment = false;
            if (newValue.compareTo(BigDecimal.ZERO) != 0) {
                if (invoicedValue.compareTo(BigDecimal.ZERO) != 0) {
                    // Has been invoiced before
                    if (invoiceItemForLeaseRepository.findByLeaseTermAndEffectiveInterval(leaseTerm, calculationInterval).size() > 0) {
                        // this exact period has been invoiced before so it is an adjusment
                        adjustment = true;
                    } else {
                        // there is new calculated amount which is caused by tinkering the dates
                        effectiveInterval = attemptToCalculateRightSideLeftover(invoicingInterval, calculationInterval);
                    }
                }
                InvoiceItemForLease invoiceItem = invoiceItemForLeaseRepository.createUnapprovedInvoiceItem(leaseTerm, invoicingInterval, calculationInterval, effectiveInterval, parameters.invoiceDueDate(), interactionId);
                invoiceItem.setNetAmount(newValue);
                invoiceItem.setQuantity(BigDecimal.ONE);
                LeaseItem leaseItem = leaseTerm.getLeaseItem();
                Charge charge = leaseItem.getCharge();
                invoiceItem.setCharge(charge);
                invoiceItem.setTax(leaseItem.getEffectiveTax());
                final InvoiceItemAttributesVM vm = new InvoiceItemAttributesVM(invoiceItem);
                final String description = fragmentRenderService.render(vm, "description");
                invoiceItem.setDescription(description);
                invoiceItem.verify();
                invoiceItem.setAdjustment(adjustment);
            }
        }
    }
}
Also used : InvoiceItemAttributesVM(org.estatio.module.lease.dom.invoicing.ssrs.InvoiceItemAttributesVM) Charge(org.estatio.module.charge.dom.Charge) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) BigDecimal(java.math.BigDecimal) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 10 with Charge

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

the class IncomingInvoiceItemRepository_Test method upsert_works.

@Test
public void upsert_works() throws Exception {
    // given
    IncomingInvoiceItemRepository incomingInvoiceItemRepository = new IncomingInvoiceItemRepository() {

        @Override
        public IncomingInvoiceItem findByInvoiceAndChargeAndSequence(final IncomingInvoice invoice, final Charge charge, final BigInteger sequence) {
            return invoiceItem;
        }
    };
    BigInteger sequence = new BigInteger("1");
    String description = "";
    Tax tax = new Tax();
    LocalDate dueDate = new LocalDate(2017, 1, 1);
    LocalDate startDate = new LocalDate(2017, 1, 2);
    LocalDate endDate = new LocalDate(2017, 1, 3);
    Property property = new Property();
    Project project = new Project();
    BudgetItem budgetItem = new BudgetItem();
    IncomingInvoiceType type = IncomingInvoiceType.CORPORATE_EXPENSES;
    invoiceItem.setInvoice(mockInvoice);
    assertThat(invoiceItem.getInvoice()).isEqualTo(mockInvoice);
    assertThat(invoiceItem.getIncomingInvoiceType()).isNull();
    assertThat(invoiceItem.getCharge()).isNull();
    assertThat(invoiceItem.getSequence()).isNull();
    assertThat(invoiceItem.getDescription()).isNull();
    assertThat(invoiceItem.getNetAmount()).isNull();
    assertThat(invoiceItem.getVatAmount()).isNull();
    assertThat(invoiceItem.getGrossAmount()).isNull();
    assertThat(invoiceItem.getTax()).isNull();
    assertThat(invoiceItem.getDueDate()).isNull();
    assertThat(invoiceItem.getStartDate()).isNull();
    assertThat(invoiceItem.getEndDate()).isNull();
    assertThat(invoiceItem.getFixedAsset()).isNull();
    assertThat(invoiceItem.getProject()).isNull();
    // when
    incomingInvoiceItemRepository.upsert(sequence, mockInvoice, type, mockCharge, description, BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN, tax, dueDate, startDate, endDate, property, project, budgetItem);
    // then
    // should not updated
    assertThat(invoiceItem.getInvoice()).isEqualTo(mockInvoice);
    // should not updated
    assertThat(invoiceItem.getCharge()).isNull();
    // should not be updated
    assertThat(invoiceItem.getIncomingInvoiceType()).isNull();
    assertThat(invoiceItem.getSequence()).isEqualTo(sequence);
    assertThat(invoiceItem.getDescription()).isEqualTo(description);
    assertThat(invoiceItem.getNetAmount()).isEqualTo(BigDecimal.ZERO);
    assertThat(invoiceItem.getVatAmount()).isEqualTo(BigDecimal.ONE);
    assertThat(invoiceItem.getGrossAmount()).isEqualTo(BigDecimal.TEN);
    assertThat(invoiceItem.getTax()).isEqualTo(tax);
    assertThat(invoiceItem.getDueDate()).isEqualTo(dueDate);
    assertThat(invoiceItem.getStartDate()).isEqualTo(startDate);
    assertThat(invoiceItem.getEndDate()).isEqualTo(endDate);
    assertThat(invoiceItem.getFixedAsset()).isEqualTo(property);
    assertThat(invoiceItem.getProject()).isEqualTo(project);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Charge(org.estatio.module.charge.dom.Charge) BigInteger(java.math.BigInteger) Tax(org.estatio.module.tax.dom.Tax) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) Test(org.junit.Test)

Aggregations

Charge (org.estatio.module.charge.dom.Charge)41 Test (org.junit.Test)18 BigDecimal (java.math.BigDecimal)14 LocalDate (org.joda.time.LocalDate)14 Lease (org.estatio.module.lease.dom.Lease)11 Programmatic (org.apache.isis.applib.annotation.Programmatic)10 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)9 Project (org.estatio.module.capex.dom.project.Project)9 Tax (org.estatio.module.tax.dom.Tax)9 Property (org.estatio.module.asset.dom.Property)7 LeaseItem (org.estatio.module.lease.dom.LeaseItem)6 ApplicationException (org.apache.isis.applib.ApplicationException)4 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)4 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)4 Action (org.apache.isis.applib.annotation.Action)3 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)3 Organisation (org.estatio.module.party.dom.Organisation)3 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)3 Expectations (org.jmock.Expectations)3 ArrayList (java.util.ArrayList)2