use of org.estatio.module.charge.dom.Charge in project estatio by estatio.
the class BudgetOverrideValueRepository_IntegTest method findOrCreateBudgetOverrideValueWorks.
@Test
public void findOrCreateBudgetOverrideValueWorks() {
BudgetOverrideForFixed budgetOverrideForFixed;
BudgetOverrideValue budgetOverrideValue;
BigDecimal calculatedValue = new BigDecimal("1234.56");
// given
Lease leaseTopModel = Lease_enum.OxfTopModel001Gb.findUsing(serviceRegistry);
Charge invoiceCharge = Charge_enum.GbServiceCharge.findUsing(serviceRegistry);
BigDecimal overrideValue = new BigDecimal("1234.56");
String reason = "Some reason";
budgetOverrideForFixed = wrap(budgetOverrideRepository).newBudgetOverrideForFixed(overrideValue, leaseTopModel, null, null, invoiceCharge, null, null, reason);
assertThat(budgetOverrideValueRepository.allBudgetOverrideValues().size()).isEqualTo(0);
// when
budgetOverrideValue = wrap(budgetOverrideValueRepository).findOrCreateOverrideValue(calculatedValue, budgetOverrideForFixed, BudgetCalculationType.BUDGETED);
// then
assertThat(budgetOverrideValueRepository.allBudgetOverrideValues().size()).isEqualTo(1);
assertThat(budgetOverrideValue.getValue()).isEqualTo(calculatedValue);
assertThat(budgetOverrideValue.getBudgetOverride()).isEqualTo(budgetOverrideForFixed);
assertThat(budgetOverrideValue.getType()).isEqualTo(BudgetCalculationType.BUDGETED);
assertThat(budgetOverrideValue.getStatus()).isEqualTo(Status.NEW);
assertThat(budgetOverrideValue.getApplicationTenancy()).isEqualTo(budgetOverrideForFixed.getApplicationTenancy());
// and when again
budgetOverrideValue = wrap(budgetOverrideValueRepository).findOrCreateOverrideValue(calculatedValue, budgetOverrideForFixed, BudgetCalculationType.BUDGETED);
// then still
assertThat(budgetOverrideValueRepository.allBudgetOverrideValues().size()).isEqualTo(1);
}
use of org.estatio.module.charge.dom.Charge 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.charge.dom.Charge in project estatio by estatio.
the class Order_Test method minimalRequiredDataToComplete.
@Test
public void minimalRequiredDataToComplete() throws Exception {
// given
Order order = new Order();
OrderItem item1 = new OrderItem();
order.getItems().add(item1);
// when
String result = order.reasonIncomplete();
// then
assertThat(result).isEqualTo("order number, buyer, seller, (on item) description, charge, start date, end date, net amount, gross amount required");
// and when
order.setOrderNumber("123");
item1.setNetAmount(new BigDecimal("100"));
result = order.reasonIncomplete();
// then
assertThat(result).isEqualTo("buyer, seller, (on item) description, charge, start date, end date, gross amount required");
// and when
order.setBuyer(new Organisation());
order.setSeller(new Organisation());
item1.setDescription("blah");
item1.setGrossAmount(BigDecimal.ZERO);
item1.setCharge(new Charge());
item1.setStartDate(new LocalDate());
item1.setEndDate(new LocalDate());
result = order.reasonIncomplete();
// then
assertThat(result).isNull();
}
use of org.estatio.module.charge.dom.Charge in project estatio by estatio.
the class Project_Test method getBudgetedAmount_checks_items_on_normal_project.
@Test
public void getBudgetedAmount_checks_items_on_normal_project() throws Exception {
// given
Project project = new Project();
ProjectItem projectItem1 = new ProjectItem();
projectItem1.setBudgetedAmount(new BigDecimal("10.00"));
project.getItems().add(projectItem1);
ProjectItem projectItem2 = new ProjectItem();
projectItem2.setBudgetedAmount(new BigDecimal("2.34"));
// done for comparable for getItems returns sorted set
projectItem2.setCharge(new Charge());
project.getItems().add(projectItem2);
// when
BigDecimal budgetAmountParent = project.getBudgetedAmount();
// then
Assertions.assertThat(budgetAmountParent).isEqualTo(new BigDecimal("12.34"));
}
use of org.estatio.module.charge.dom.Charge in project estatio by estatio.
the class IncomingDocAsInvoiceViewModel method save.
@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "1")
public IncomingInvoice save() {
IncomingInvoice incomingInvoice = getDomainObject();
IncomingInvoiceType previousType = incomingInvoice.getType();
incomingInvoice.setType(getIncomingInvoiceType());
incomingInvoice.setInvoiceNumber(getInvoiceNumber());
incomingInvoice.setBuyer(getBuyer());
incomingInvoice.setSeller(getSeller());
incomingInvoice.setInvoiceDate(getInvoiceDate());
incomingInvoice.setDueDate(getDueDate());
incomingInvoice.setPaymentMethod(getPaymentMethod());
incomingInvoice.setCurrency(getCurrency());
incomingInvoice.setDateReceived(getDateReceived());
incomingInvoice.setBankAccount(getBankAccount());
incomingInvoice.setNetAmount(getNetAmount());
incomingInvoice.setGrossAmount(getGrossAmount());
// if changed the type, then we need to re-evaluate the state machine
if (previousType != getIncomingInvoiceType()) {
stateTransitionService.trigger(incomingInvoice, IncomingInvoiceApprovalStateTransition.class, null, null, null);
}
// upsert invoice item
// this will also update the parent header's property with that from the first item
Optional<IncomingInvoiceItem> firstItemIfAny = getFirstItemIfAny();
IncomingInvoiceItem firstItem;
if (firstItemIfAny.isPresent()) {
IncomingInvoiceItem item = firstItemIfAny.get();
item.setIncomingInvoiceType(getIncomingInvoiceType());
item.setCharge(getCharge());
item.setDescription(getDescription());
item.setNetAmount(getNetAmount());
item.setVatAmount(getVatAmount());
item.setGrossAmount(getGrossAmount());
item.setTax(getTax());
item.setStartDate(getStartDateFromPeriod());
item.setEndDate(getEndDateFromPeriod());
item.setFixedAsset(getProperty());
item.setProject(getProject());
item.setBudgetItem(getBudgetItem());
firstItem = item;
} else {
firstItem = incomingInvoiceItemRepository.create(incomingInvoice.nextItemSequence(), incomingInvoice, incomingInvoiceType, getCharge(), getDescription(), getNetAmount(), getVatAmount(), getGrossAmount(), getTax(), getDueDate(), getStartDateFromPeriod(), getEndDateFromPeriod(), getProperty(), getProject(), getBudgetItem());
}
// 'switch view' will not be available subsequently because the Invoice/Item is "too complex")
if (getOrderItem() != null) {
Order order = getOrderItem().getOrdr();
Charge chargeFromWrapper = getOrderItem().getCharge();
OrderItem orderItemToLink = orderItemRepository.findByOrderAndCharge(order, chargeFromWrapper);
orderItemInvoiceItemLinkRepository.findOrCreateLink(orderItemToLink, firstItem, firstItem.getNetAmount());
} else {
// remove all (or the one and only) link.
final Optional<OrderItemInvoiceItemLink> links = orderItemInvoiceItemLinkRepository.findByInvoiceItem(firstItem);
links.ifPresent(link -> {
link.remove();
});
}
return incomingInvoice;
}
Aggregations