use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink 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;
}
use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.
the class IncomingInvoice_LinkedOrderItems method linkedOrderItems.
@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<LinkedOrderItemViewModel> linkedOrderItems() {
List<LinkedOrderItemViewModel> result = new ArrayList<>();
for (OrderItemInvoiceItemLink link : orderItemInvoiceItemLinkRepository.findByInvoice(incomingInvoice)) {
OrderItem item = link.getOrderItem();
BigDecimal netAmount = item.getNetAmount();
BigDecimal netAmountInvoiced = orderItemInvoiceItemLinkRepository.calculateNetAmountLinkedToOrderItem(item);
result.add(new LinkedOrderItemViewModel(item, netAmount, netAmountInvoiced));
}
return result;
}
use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.
the class ProjectService_Test method moveOrderItemToProject_works_when_no_invoice_items_linked.
@Test
public void moveOrderItemToProject_works_when_no_invoice_items_linked() throws Exception {
// given
ProjectService projectService = new ProjectService();
projectService.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
Project project = new Project();
OrderItem orderItem = new OrderItem();
IncomingInvoiceItem incomingInvoiceItem = new IncomingInvoiceItem();
OrderItemInvoiceItemLink link = new OrderItemInvoiceItemLink();
link.setInvoiceItem(incomingInvoiceItem);
link.setOrderItem(orderItem);
// expect
context.checking(new Expectations() {
{
oneOf(mockOrderItemInvoiceItemLinkRepository).findByOrderItem(orderItem);
will(returnValue(Arrays.asList(link)));
}
});
// when
projectService.moveOrderItemToProject(orderItem, project);
// then
Assertions.assertThat(orderItem.getProject()).isEqualTo(project);
Assertions.assertThat(incomingInvoiceItem.getProject()).isEqualTo(project);
}
use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.
the class ProjectService_Test method moveIncomingInvoiceItemToProject_works_when_invoice_item_linked_to_order_item.
@Test
public void moveIncomingInvoiceItemToProject_works_when_invoice_item_linked_to_order_item() throws Exception {
// given
ProjectService projectService = new ProjectService();
projectService.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
Project project = new Project();
OrderItem orderItem = new OrderItem();
IncomingInvoiceItem incomingInvoiceItem = new IncomingInvoiceItem();
IncomingInvoiceItem otherLinkedItem = new IncomingInvoiceItem();
OrderItemInvoiceItemLink link1 = new OrderItemInvoiceItemLink();
link1.setInvoiceItem(incomingInvoiceItem);
link1.setOrderItem(orderItem);
OrderItemInvoiceItemLink link2 = new OrderItemInvoiceItemLink();
link2.setInvoiceItem(otherLinkedItem);
link2.setOrderItem(orderItem);
// expect
context.checking(new Expectations() {
{
oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(incomingInvoiceItem);
will(returnValue(Optional.of(link1)));
oneOf(mockOrderItemInvoiceItemLinkRepository).findByOrderItem(orderItem);
will(returnValue(Arrays.asList(link1, link2)));
}
});
// when
projectService.moveIncomingInvoiceItemToProject(incomingInvoiceItem, project);
// then
Assertions.assertThat(incomingInvoiceItem.getProject()).isEqualTo(project);
Assertions.assertThat(otherLinkedItem.getProject()).isEqualTo(project);
Assertions.assertThat(orderItem.getProject()).isEqualTo(project);
}
use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.
the class ProjectInvoiceItemTransferManager_Test method getInvoiceItemsHavingNoOrder_works.
@Test
public void getInvoiceItemsHavingNoOrder_works() throws Exception {
// given
Project source = new Project();
ProjectInvoiceItemTransferManager manager = new ProjectInvoiceItemTransferManager(null, source);
manager.incomingInvoiceItemRepository = mockIncomingInvoiceItemRepository;
manager.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
IncomingInvoiceItem itemLinked = new IncomingInvoiceItem();
IncomingInvoiceItem itemNotLinked = new IncomingInvoiceItem();
OrderItemInvoiceItemLink link = new OrderItemInvoiceItemLink();
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceItemRepository).findByProject(source);
will(returnValue(Arrays.asList(itemLinked, itemNotLinked)));
oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(itemLinked);
will(returnValue(Optional.of(link)));
oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(itemNotLinked);
will(returnValue(Optional.empty()));
}
});
// when
List<IncomingInvoiceItem> items = manager.getInvoiceItemsHavingNoOrder();
// then
Assertions.assertThat(items).contains(itemNotLinked);
Assertions.assertThat(items).doesNotContain(itemLinked);
}
Aggregations