use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.
the class IncomingInvoice_IntegTest method when_discarded_reported_items_are_reversed_while_no_correction_item_is_added.
@Test
public void when_discarded_reported_items_are_reversed_while_no_correction_item_is_added() {
// given
incomingInvoiceSetup();
incomingInvoiceIsCompleted();
IncomingInvoiceItem reportedItem = firstItemIsReported();
// when
invoiceIsDiscarded();
// then
assertThat(incomingInvoice.getItems().size()).isEqualTo(3);
IncomingInvoiceItem reversal = (IncomingInvoiceItem) incomingInvoice.getItems().first();
assertThat(reversal.getReversalOf()).isEqualTo(reportedItem);
assertThat(reversal.getNetAmount()).isEqualTo(reportedItem.getNetAmount().negate());
assertThat(reversal.getReportedDate()).isNull();
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem 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.invoice.IncomingInvoiceItem 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.invoice.IncomingInvoiceItem in project estatio by estatio.
the class OrderInvoiceImportReport method getLines.
public List<OrderInvoiceImportReportLine> getLines() {
List<OrderInvoiceImportReportLine> result = new ArrayList<>();
Integer numberOfOrderlines;
Integer numberOfinvoicelines;
BigDecimal orderNetTotal;
BigDecimal orderVatTotal;
BigDecimal orderGrossTotal;
BigDecimal invoiceNetTotal;
BigDecimal invoiceVatTotal;
BigDecimal invoiceGrossTotal;
for (Project project : projectRepository.listAll()) {
for (String period : periodsPresent(project)) {
numberOfOrderlines = 0;
numberOfinvoicelines = 0;
orderNetTotal = BigDecimal.ZERO;
orderVatTotal = BigDecimal.ZERO;
orderGrossTotal = BigDecimal.ZERO;
invoiceNetTotal = BigDecimal.ZERO;
invoiceVatTotal = BigDecimal.ZERO;
invoiceGrossTotal = BigDecimal.ZERO;
for (OrderItem orderItem : orderItemRepository.findByProject(project)) {
if (orderItem.getPeriod().equals(period)) {
numberOfOrderlines = numberOfOrderlines + 1;
orderNetTotal = orderNetTotal.add(orderItem.getNetAmount());
orderVatTotal = orderItem.getVatAmount() == null ? orderVatTotal : orderVatTotal.add(orderItem.getVatAmount());
orderGrossTotal = orderGrossTotal.add(orderItem.getGrossAmount());
}
}
for (IncomingInvoiceItem invoiceItem : incomingInvoiceItemRepository.findByProject(project)) {
if (invoiceItem.getPeriod().equals(period)) {
numberOfinvoicelines = numberOfinvoicelines + 1;
invoiceNetTotal = invoiceNetTotal.add(invoiceItem.getNetAmount());
invoiceVatTotal = invoiceItem.getVatAmount() == null ? invoiceVatTotal : invoiceVatTotal.add(invoiceItem.getVatAmount());
invoiceGrossTotal = invoiceGrossTotal.add(invoiceItem.getGrossAmount());
}
}
result.add(new OrderInvoiceImportReportLine(project.getReference(), period, numberOfOrderlines, orderNetTotal, orderVatTotal, orderGrossTotal, numberOfinvoicelines, invoiceNetTotal, invoiceVatTotal, invoiceGrossTotal));
}
}
return result;
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.
the class OrderInvoiceImportReport method periodsPresent.
private List<String> periodsPresent(final Project project) {
List<String> result = new ArrayList<>();
for (OrderItem item : orderItemRepository.findByProject(project)) {
if (!result.contains(item.getPeriod())) {
result.add(item.getPeriod());
}
}
for (IncomingInvoiceItem item : incomingInvoiceItemRepository.findByProject(project)) {
if (!result.contains(item.getPeriod())) {
result.add(item.getPeriod());
}
}
Collections.sort(result);
return result;
}
Aggregations