Search in sources :

Example 11 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class Occupancy_Test method validateNewOccupancy_Passes_Test.

@Test
public void validateNewOccupancy_Passes_Test() {
    // given
    Lease lease = new Lease();
    LocalDate occStartDate = new LocalDate();
    // when
    Unit unit = new Unit() {

        @Override
        public boolean isActiveOn(final LocalDate date) {
            return true;
        }
    };
    // then
    assertThat(lease.validateNewOccupancy(occStartDate, unit)).isNull();
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Unit(org.estatio.module.asset.dom.Unit) LocalDate(org.joda.time.LocalDate) AbstractBeanPropertiesTest(org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest) Test(org.junit.Test)

Example 12 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class OccupancyRepository_Test method setup.

@Before
public void setup() {
    lease = new Lease();
    unit = new Unit();
    startDate = new LocalDate(2013, 4, 1);
    occupancyRepository = new OccupancyRepository() {

        @Override
        protected <T> T firstMatch(Query<T> query) {
            finderInteraction = new FinderInteraction(query, FinderMethod.FIRST_MATCH);
            return null;
        }

        @Override
        protected List<Occupancy> allInstances() {
            finderInteraction = new FinderInteraction(null, FinderMethod.ALL_INSTANCES);
            return null;
        }

        @Override
        protected <T> List<T> allMatches(Query<T> query) {
            finderInteraction = new FinderInteraction(query, FinderMethod.ALL_MATCHES);
            return null;
        }
    };
}
Also used : OccupancyRepository(org.estatio.module.lease.dom.occupancy.OccupancyRepository) List(java.util.List) Unit(org.estatio.module.asset.dom.Unit) LocalDate(org.joda.time.LocalDate) FinderInteraction(org.incode.module.unittestsupport.dom.repo.FinderInteraction) Before(org.junit.Before)

Example 13 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class KeyTable method generateItems.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
public KeyTable generateItems() {
    // delete old items
    for (Iterator<KeyItem> it = this.getItems().iterator(); it.hasNext(); ) {
        it.next().deleteBudgetKeyItem();
    }
    /*
        create list of input pairs: identifier - sourcevalue
        sourcevalue is determined by FoundationValueType
        */
    List<Distributable> input = new ArrayList<>();
    for (Unit unit : unitRepository.findByProperty(this.getBudget().getProperty())) {
        if (unitIntervalValidForThisKeyTable(unit)) {
            BigDecimal sourceValue;
            if (getFoundationValueType().valueOf(unit) != null) {
                sourceValue = getFoundationValueType().valueOf(unit);
            } else {
                sourceValue = BigDecimal.ZERO;
            }
            KeyItem newItem = new KeyItem();
            newItem.setSourceValue(sourceValue);
            newItem.setValue(BigDecimal.ZERO);
            newItem.setUnit(unit);
            newItem.setKeyTable(this);
            persistIfNotAlready(newItem);
            input.add(newItem);
        }
    }
    /*
        call distribute method
         */
    DistributionService distributionService = new DistributionService();
    distributionService.distribute(input, getKeyValueMethod().divider(this), getPrecision());
    return this;
}
Also used : Distributable(org.estatio.module.budget.dom.Distributable) ArrayList(java.util.ArrayList) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) Unit(org.estatio.module.asset.dom.Unit) BigDecimal(java.math.BigDecimal) DistributionService(org.estatio.module.budget.dom.DistributionService) Action(org.apache.isis.applib.annotation.Action)

Example 14 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class InvoiceItemForLeaseRepository method newInvoiceItem.

@Programmatic
public InvoiceItemForLease newInvoiceItem(final LeaseTerm leaseTerm, final LocalDateInterval interval, final LocalDateInterval calculationInterval, final LocalDateInterval effectiveInterval, final LocalDate dueDate, final String interactionId) {
    final Lease lease = leaseTerm.getLeaseItem().getLease();
    final InvoiceForLease invoice = invoiceRepository.findOrCreateMatchingInvoice(leaseTerm.getApplicationTenancy(), leaseTerm.getLeaseItem().getPaymentMethod(), lease, InvoiceStatus.NEW, dueDate, interactionId);
    final InvoiceItemForLease invoiceItem = newItem(invoice, dueDate);
    invoiceItem.setLeaseTerm(leaseTerm);
    invoiceItem.setStartDate(interval.startDate());
    invoiceItem.setEndDate(interval.endDate());
    invoiceItem.setEffectiveStartDate(effectiveInterval.startDate());
    invoiceItem.setEffectiveEndDate(effectiveInterval.endDate());
    invoiceItem.setCalculationStartDate(calculationInterval.startDate());
    invoiceItem.setCalculationEndDate(calculationInterval.endDate());
    // redundantly persist, these are immutable
    // assumes only one occupancy per lease...
    invoiceItem.setLease(lease);
    final Optional<Occupancy> occupancyIfAny = lease.primaryOccupancy();
    occupancyIfAny.ifPresent(occupancy -> {
        Unit unit = occupancy.getUnit();
        invoiceItem.setFixedAsset(unit);
    });
    persistIfNotAlready(invoiceItem);
    return invoiceItem;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Unit(org.estatio.module.asset.dom.Unit) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 15 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class KeyItemRepository_Test method negativeSourceValue.

@Test
public void negativeSourceValue() {
    // given
    KeyTable keyTable = new KeyTable();
    Unit unit = new Unit();
    BigDecimal sourcevalue = BigDecimal.valueOf(-0.001);
    BigDecimal keyValue = new BigDecimal(10);
    // when
    String validateNewBudgetKeyItem = keyItemRepository.validateNewItem(keyTable, unit, sourcevalue, keyValue);
    // then
    assertThat(validateNewBudgetKeyItem).isEqualTo("sourceValue cannot be zero or less than zero");
}
Also used : KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) Unit(org.estatio.module.asset.dom.Unit) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Unit (org.estatio.module.asset.dom.Unit)27 Test (org.junit.Test)10 BigDecimal (java.math.BigDecimal)8 Lease (org.estatio.module.lease.dom.Lease)8 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)8 LocalDate (org.joda.time.LocalDate)8 Programmatic (org.apache.isis.applib.annotation.Programmatic)6 Property (org.estatio.module.asset.dom.Property)5 ArrayList (java.util.ArrayList)3 KeyTable (org.estatio.module.budget.dom.keytable.KeyTable)3 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)3 Expectations (org.jmock.Expectations)3 Before (org.junit.Before)3 Action (org.apache.isis.applib.annotation.Action)2 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)2 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)2 Party (org.estatio.module.party.dom.Party)2 LandRegister (org.estatio.module.registration.dom.LandRegister)2 AbstractBeanPropertiesTest (org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest)2 List (java.util.List)1