use of org.estatio.module.capex.dom.project.Project 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.project.Project in project estatio by estatio.
the class ProjectImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
if (previousRow != null) {
// TODO: support sparse sheets ?
}
Project parent = null;
if (getParentReference() != null) {
parent = projectRepository.findByReference(getParentReference());
if (parent == null) {
throw new ApplicationException(String.format("Parent with reference %s not found.", getParentReference()));
}
if (!parent.getAtPath().equals(getAtPath())) {
throw new ApplicationException(String.format("AtPath parent %s does not match %s.", getParentReference(), getAtPath()));
}
if (!parent.getItems().isEmpty()) {
// TODO: (ECP-438) until we find out more about the process, prevent a the choice of a project having items
throw new ApplicationException(String.format("Parent with reference %s has items and cannot be a parent therefore.", getAtPath()));
}
}
Project project = findOrCreateProjectAndUpdateParent(getReference(), getName(), getStartDate(), getEndDate(), getAtPath(), parent);
if (getItemChargeReference() != null) {
Charge charge = chargeRepository.findByReference(getItemChargeReference());
Property property = propertyRepository.findPropertyByReference(getItemPropertyReference());
Tax tax = taxRepository.findByReference(getItemTaxReference());
wrapperFactory.wrap(project).addItem(charge, getItemDescription(), getItemBudgetedAmount(), getItemStartDate(), getItemEndDate(), property, tax);
}
return Lists.newArrayList(project);
}
use of org.estatio.module.capex.dom.project.Project 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);
}
use of org.estatio.module.capex.dom.project.Project in project estatio by estatio.
the class OrderItemRepository_Test method orderItemsWithoutProjectItem_works.
@Test
public void orderItemsWithoutProjectItem_works() throws Exception {
// given
Project project = new Project();
ProjectItem item1 = new ProjectItem();
Charge chargeOnProjectItem = new Charge();
item1.setCharge(chargeOnProjectItem);
project.getItems().add(item1);
Charge chargeNOTOnProjectItem = new Charge();
OrderItem orderItemToBeFound = new OrderItem();
orderItemToBeFound.setCharge(chargeNOTOnProjectItem);
OrderItem orderItemNOTToBeFound = new OrderItem();
orderItemNOTToBeFound.setCharge(chargeOnProjectItem);
OrderItemRepository orderItemRepository = new OrderItemRepository() {
@Override
public List<OrderItem> findByProject(final Project project) {
return Arrays.asList(orderItemNOTToBeFound, orderItemToBeFound);
}
};
// when
List<OrderItem> result = orderItemRepository.orderItemsNotOnProjectItem(project);
// then
Assertions.assertThat(result.size()).isEqualTo(1);
Assertions.assertThat(result.get(0)).isEqualTo(orderItemToBeFound);
Assertions.assertThat(result.get(0).getCharge()).isEqualTo(chargeNOTOnProjectItem);
}
use of org.estatio.module.capex.dom.project.Project in project estatio by estatio.
the class Order_Test method minimalRequiredDataToComplete_consitent_dimensions_for_property_project.
@Test
public void minimalRequiredDataToComplete_consitent_dimensions_for_property_project() throws Exception {
// given
Order order = new Order();
OrderItem item1 = new OrderItem();
order.getItems().add(item1);
order.setOrderNumber("123");
order.setBuyer(new Organisation());
order.setSeller(new Organisation());
item1.setNetAmount(new BigDecimal("100"));
item1.setDescription("blah");
item1.setGrossAmount(BigDecimal.ZERO);
item1.setCharge(new Charge());
item1.setStartDate(new LocalDate());
item1.setEndDate(new LocalDate());
// when
item1.setProject(new Project());
String result = order.reasonIncomplete();
// then
assertThat(result).isEqualTo("(on item) when project filled in then property required");
}
Aggregations