use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class IncomingDocAsOrderViewModel method init.
@Programmatic
public void init() {
final Order order = getDomainObject();
setOrderNumber(order.getOrderNumber());
setSellerOrderReference(order.getSellerOrderReference());
setOrderDate(order.getOrderDate());
setSeller(order.getSeller());
setBuyer(order.getBuyer());
setProperty(order.getProperty());
final Optional<OrderItem> firstItemIfAny = getFirstItemIfAny();
if (firstItemIfAny.isPresent()) {
OrderItem orderItem = firstItemIfAny.get();
setCharge(orderItem.getCharge());
setDescription(orderItem.getDescription());
setNetAmount(orderItem.getNetAmount());
setVatAmount(orderItem.getVatAmount());
setGrossAmount(orderItem.getGrossAmount());
setTax(orderItem.getTax());
setPeriod(periodFrom(orderItem.getStartDate(), orderItem.getEndDate()));
setProperty(orderItem.getProperty());
setProject(orderItem.getProject());
setBudgetItem(orderItem.getBudgetItem());
}
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class BudgetOverrideImportExport method importData.
// @Override
// public List<Class> importAfter() {
// return Lists.newArrayList();
// }
@Override
@Programmatic
public List<Object> importData(final Object previousRow) {
if (getInvoiceChargeReference() == null) {
throw new ApplicationException("Incoming charge reference cannot be empty");
}
if (getReason() == null) {
throw new ApplicationException("Reason cannot be empty");
}
BudgetCalculationType budgetCalculationType;
budgetCalculationType = getType() == null ? null : BudgetCalculationType.valueOf(getType());
BudgetOverride budgetOverride;
Charge incomingCharge = getIncomingChargeReference() == null ? null : fetchCharge(getIncomingChargeReference());
switch(getClassName()) {
case "BudgetOverrideForMax":
validate();
budgetOverride = budgetOverrideRepository.newBudgetOverrideForMax(getMaxValue(), fetchLease(getLeaseReference()), getStartDate(), getEndDate(), fetchCharge(getInvoiceChargeReference()), incomingCharge, budgetCalculationType, getReason());
break;
case "BudgetOverrideForFixed":
validate();
budgetOverride = budgetOverrideRepository.newBudgetOverrideForFixed(getFixedValue(), fetchLease(getLeaseReference()), getStartDate(), getEndDate(), fetchCharge(getInvoiceChargeReference()), incomingCharge, budgetCalculationType, getReason());
break;
case "BudgetOverrideForFlatRate":
validate();
budgetOverride = budgetOverrideRepository.newBudgetOverrideForFlatRate(getValuePerM2(), getWeightedArea(), fetchLease(getLeaseReference()), getStartDate(), getEndDate(), fetchCharge(getInvoiceChargeReference()), incomingCharge, budgetCalculationType, getReason());
break;
default:
throw new ApplicationException(String.format("Classname %s is not valid.", getClassName()));
}
return Lists.newArrayList(budgetOverride);
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class BudgetCalculationResult method calculate.
@Programmatic
public void calculate() throws IllegalArgumentException {
validateOverrides();
BigDecimal valueCalculatedByBudget = valueAsCalculatedByBudget();
BigDecimal annualOverrideValue = BigDecimal.ZERO;
List<Charge> incomingChargesOnOverrides = new ArrayList<>();
if (overrideValueForInvoiceCharge() != null) {
// SCENARIO: one override for all
annualOverrideValue = annualOverrideValue.add(overrideValueForInvoiceCharge().getValue());
} else {
// SCENARIO: overrides on incoming charge level
BigDecimal valueToSubtract = BigDecimal.ZERO;
for (BudgetOverrideValue value : getOverrideValues()) {
incomingChargesOnOverrides.add(value.getBudgetOverride().getIncomingCharge());
annualOverrideValue = annualOverrideValue.add(value.getValue());
}
for (Charge charge : incomingChargesOnOverrides) {
for (BudgetCalculation calculation : getBudgetCalculations().stream().filter(x -> x.getIncomingCharge().equals(charge)).collect(Collectors.toList())) {
valueToSubtract = valueToSubtract.add(calculation.getValue());
}
}
annualOverrideValue = annualOverrideValue.add(valueCalculatedByBudget).subtract(valueToSubtract);
}
BigDecimal overrideValue = annualOverrideValue.multiply(getFractionOfYear());
setValue(overrideValue.setScale(2, BigDecimal.ROUND_HALF_UP));
setShortfall(valueCalculatedByBudget.subtract(overrideValue).setScale(2, BigDecimal.ROUND_HALF_UP));
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class KeyItemImportExportLineItem method getKeyTable.
@Programmatic
public KeyTable getKeyTable() {
if (keyTable == null) {
Budget budget = budgetRepository.findByPropertyAndStartDate(getProperty(), getStartDate());
keyTable = keyTableRepository.findByBudgetAndName(budget, getKeyTableName());
}
return keyTable;
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class BudgetOverride method getCalculatedValueByBudget.
@Programmatic
BigDecimal getCalculatedValueByBudget(final LocalDate budgetStartDate, final BudgetCalculationType type) {
BigDecimal value = BigDecimal.ZERO;
List<Unit> unitsForLease = new ArrayList<>();
List<BudgetCalculation> calculationsForLeaseAndCharges = new ArrayList<>();
for (Occupancy occupancy : getLease().getOccupancies()) {
unitsForLease.add(occupancy.getUnit());
}
Budget budget = budgetRepository.findByPropertyAndDate(getLease().getProperty(), budgetStartDate);
if (getIncomingCharge() == null) {
for (Unit unit : unitsForLease) {
calculationsForLeaseAndCharges.addAll(budgetCalculationRepository.findByBudgetAndUnitAndInvoiceChargeAndType(budget, unit, getInvoiceCharge(), type));
}
} else {
for (Unit unit : unitsForLease) {
calculationsForLeaseAndCharges.addAll(budgetCalculationRepository.findByBudgetAndUnitAndInvoiceChargeAndIncomingChargeAndType(budget, unit, getInvoiceCharge(), getIncomingCharge(), type));
}
}
for (BudgetCalculation calculation : calculationsForLeaseAndCharges) {
value = value.add(calculation.getEffectiveValue());
}
return value;
}
Aggregations