use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.
the class OrderItemRepository_Test method upsert_works.
@Test
public void upsert_works() throws Exception {
// given
OrderItemRepository orderItemRepository = new OrderItemRepository() {
@Override
public OrderItem findByOrderAndCharge(final Order order, final Charge charge) {
return orderItem;
}
};
String description = new String("some description");
BigDecimal netAmount = BigDecimal.ZERO;
BigDecimal vatAmount = BigDecimal.ONE;
BigDecimal grossAmount = BigDecimal.TEN;
Tax tax = new Tax();
LocalDate startDate = new LocalDate(2017, 1, 1);
LocalDate endDate = new LocalDate(2017, 1, 2);
Property property = new Property();
Project project = new Project();
BudgetItem budgetItem = new BudgetItem();
assertThat(orderItem.getOrdr()).isNull();
assertThat(orderItem.getCharge()).isNull();
// when
orderItemRepository.upsert(mockOrder, mockCharge, description, netAmount, vatAmount, grossAmount, tax, startDate, endDate, property, project, budgetItem);
// then
assertThat(orderItem.getOrdr()).isNull();
assertThat(orderItem.getCharge()).isNull();
assertThat(orderItem.getDescription()).isEqualTo(description);
assertThat(orderItem.getNetAmount()).isEqualTo(netAmount);
assertThat(orderItem.getVatAmount()).isEqualTo(vatAmount);
assertThat(orderItem.getGrossAmount()).isEqualTo(grossAmount);
assertThat(orderItem.getTax()).isEqualTo(tax);
assertThat(orderItem.getStartDate()).isEqualTo(startDate);
assertThat(orderItem.getEndDate()).isEqualTo(endDate);
assertThat(orderItem.getProperty()).isEqualTo(property);
assertThat(orderItem.getProject()).isEqualTo(project);
assertThat(orderItem.getBudgetItem()).isEqualTo(budgetItem);
}
use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.
the class PartitioningBuilder method execute.
@Override
protected void execute(final ExecutionContext executionContext) {
checkParam("budget", executionContext, Budget.class);
defaultParam("startDate", executionContext, budget.getStartDate());
defaultParam("endDate", executionContext, budget.getEndDate());
defaultParam("budgetCalculationType", executionContext, BudgetCalculationType.BUDGETED);
Partitioning partitioning = partitioningRepository.newPartitioning(budget, startDate, endDate, budgetCalculationType);
executionContext.addResult(this, partitioning);
for (ItemSpec spec : itemSpec) {
final Charge itemCharge = spec.itemCharge;
final BudgetItem budgetItem = budget.findByCharge(itemCharge);
PartitionItem partitionItem = partitionItemRepository.newPartitionItem(partitioning, spec.charge, spec.keyTable, budgetItem, spec.percentage);
executionContext.addResult(this, partitionItem);
}
object = partitioning;
}
use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.
the class PartitionItemImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
Property property = propertyRepository.findPropertyByReference(propertyReference);
if (property == null)
throw new ApplicationException(String.format("Property with reference [%s] not found.", propertyReference));
final Budget budget = budgetRepository.findOrCreateBudget(property, startDate, endDate);
final KeyTable keyTable = keyTableRepository.findOrCreateBudgetKeyTable(budget, keyTableName, FoundationValueType.MANUAL, KeyValueMethod.PERCENT, 6);
findOrCreateBudgetKeyItem(keyTable, unitRepository.findUnitByReference(unitReference), keyValue, sourceValue);
final Charge charge = fetchCharge(budgetChargeReference);
final BudgetItem butgetItem = findOrCreateBudgetItem(budget, charge, budgetValue);
final Charge scheduleCharge = fetchCharge(invoiceChargeReference);
final Partitioning partitioning = findOrCreatePartitioning(budget);
findOrCreatePartitionItem(partitioning, scheduleCharge, butgetItem, keyTable, percentage);
return Lists.newArrayList();
}
use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.
the class PartitionItemImport method findOrCreateBudgetItem.
private BudgetItem findOrCreateBudgetItem(final Budget budget, final Charge charge, final BigDecimal value) {
BudgetItem budgetItem = budgetItemRepository.findByBudgetAndCharge(budget, charge);
if (budgetItem == null) {
budgetItem = budgetItemRepository.newBudgetItem(budget, charge);
budgetItem.newValue(value, budget.getStartDate(), BudgetCalculationType.BUDGETED);
return budgetItem;
}
return budgetItem;
}
use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.
the class Budget_Remove method removeBudget.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public void removeBudget(@ParameterLayout(named = "This will delete the budget and all associated data including keytables, calculations, runs, results and lease terms. (You may consider downloading the budget and the keytables beforehand.) Are you sure?") final boolean areYouSure) {
// delete results and runs
for (BudgetCalculationRun run : budgetCalculationRunRepository.allBudgetCalculationRuns().stream().filter(x -> x.getBudget().equals(budget)).collect(Collectors.toList())) {
for (BudgetCalculationResult result : run.getBudgetCalculationResults()) {
// delete links and lease terms
for (BudgetCalculationResultLink link : budgetCalculationResultLinkRepository.findByCalculationResult(result)) {
LeaseTermForServiceCharge leaseTermToRemove = null;
if (link.getLeaseTermForServiceCharge() != null) {
leaseTermToRemove = link.getLeaseTermForServiceCharge();
}
link.remove();
if (leaseTermToRemove != null) {
leaseTermToRemove.remove();
}
}
}
run.remove();
}
// delete overrides and values
for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(budget.getProperty(), budget.getStartDate())) {
for (BudgetOverride override : budgetOverrideRepository.findByLease(lease)) {
override.remove();
}
}
// delete partition items
for (BudgetItem budgetItem : budget.getItems()) {
for (PartitionItem item : partitionItemRepository.findByBudgetItem(budgetItem)) {
item.remove();
}
}
budget.remove();
}
Aggregations