use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.
the class IncomingInvoiceDownloadManager method report.
@Action(semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE)
public IncomingInvoiceDownloadManager report() {
LocalDate reportedDate = clockService.now();
final List<IncomingInvoiceItem> invoiceItems = getInvoiceItems();
for (IncomingInvoiceItem invoiceItem : invoiceItems) {
if (invoiceItem.getReportedDate() == null) {
invoiceItem.setReportedDate(reportedDate);
}
}
return new IncomingInvoiceDownloadManager(property, reportedDate, incomingInvoiceType);
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem 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.invoice.IncomingInvoiceItem in project estatio by estatio.
the class IncomingInvoiceBuilder method execute.
@Override
protected void execute(final ExecutionContext ec) {
checkParam("officeAdministrator", ec, Person.class);
checkParam("document", ec, Document.class);
checkParam("buyer", ec, Organisation.class);
checkParam("seller", ec, Organisation.class);
checkParam("sellerBankAccount", ec, BankAccount.class);
checkParam("property", ec, Property.class);
checkParam("dueDate", ec, LocalDate.class);
checkParam("invoiceDate", ec, LocalDate.class);
checkParam("dateReceived", ec, LocalDate.class);
checkParam("itemTax", ec, Tax.class);
checkParam("item1InvoiceType", ec, IncomingInvoiceType.class);
// checkParam("item1Project", ec, Project.class); // optional
checkParam("item1Charge", ec, Charge.class);
checkParam("item1Description", ec, String.class);
checkParam("item1NetAmount", ec, BigDecimal.class);
checkParam("item1VatAmount", ec, BigDecimal.class);
checkParam("item1GrossAmount", ec, BigDecimal.class);
checkParam("item1Period", ec, String.class);
if (getItem2InvoiceType() != null) {
checkParam("item2InvoiceType", ec, IncomingInvoiceType.class);
// checkParam("item2Project", ec, Project.class); // optional
checkParam("item2Charge", ec, Charge.class);
checkParam("item2Description", ec, String.class);
checkParam("item2NetAmount", ec, BigDecimal.class);
checkParam("item2VatAmount", ec, BigDecimal.class);
checkParam("item2GrossAmount", ec, BigDecimal.class);
checkParam("item2Period", ec, String.class);
}
// checkParam("orderDocument", ec, Document.class); // optional
if (order != null) {
checkParam("orderItemLinkAmount", ec, BigDecimal.class);
}
if (propertyManager != null) {
checkParam("propertyManager", ec, Person.class);
checkParam("assetManager", ec, Person.class);
checkParam("countryDirector", ec, Person.class);
checkParam("treasurer", ec, Person.class);
}
sudoService.sudo(officeAdministrator.getUsername(), (Runnable) () -> wrap(mixin(Document_categoriseAsPropertyInvoice.class, document)).act(property, ""));
final String documentName = document.getName();
IncomingInvoice invoice = incomingInvoiceRepository.findIncomingInvoiceByDocumentName(documentName).get(0);
invoice.setDateReceived(dateReceived);
invoice.setSeller(seller);
invoice.setBankAccount(sellerBankAccount);
invoice.setBuyer(buyer);
invoice.setType(invoiceType);
invoice.setDueDate(dueDate);
invoice.setInvoiceNumber(invoiceNumber);
invoice.setPaymentMethod(paymentMethod);
invoice.setInvoiceDate(invoiceDate);
invoice.setNetAmount(netAmount);
invoice.setGrossAmount(grossAmount);
invoice.addItem(item1InvoiceType, item1Charge, item1Description, item1NetAmount, item1VatAmount, item1GrossAmount, itemTax, dueDate, item1Period, property, item1Project, null);
if (order != null) {
IncomingInvoiceItem invoiceItemToLink = (IncomingInvoiceItem) invoice.getItems().first();
OrderItem orderItemToLink = order.getItems().first();
mixin(IncomingInvoiceItem_createOrderItemLink.class, invoiceItemToLink).act(orderItemToLink, orderItemLinkAmount);
}
if (item2InvoiceType != null) {
invoice.addItem(item2InvoiceType, item2Charge, item2Description, item2NetAmount, item2VatAmount, item2GrossAmount, itemTax, dueDate, item2Period, property, item2Project, null);
}
if (propertyManager != null) {
// complete and approve invoice and verify bankaccount
sudoService.sudo(propertyManager.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, invoice)).act("PROPERTY_MANAGER", null, null));
sudoService.sudo(assetManager.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_approve.class, invoice)).act("ASSET_MANAGER", null, null, false));
sudoService.sudo(countryDirector.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_approveAsCountryDirector.class, invoice)).act(null, false));
sudoService.sudo(treasurer.getUsername(), (Runnable) () -> wrap(mixin(BankAccount_verify.class, sellerBankAccount)).act(null));
}
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.
the class OrderItemInvoiceItemLink method remove.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
public IncomingInvoiceItem remove() {
final IncomingInvoiceItem invoiceItem = getInvoiceItem();
repository.removeLink(this);
return invoiceItem;
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.
the class OrderItem_Test method isInvoiced_works_when_no_netamount_on_orderItem.
@Test
public void isInvoiced_works_when_no_netamount_on_orderItem() throws Exception {
// given
OrderItem orderItem = new OrderItem();
// explicit for this test
orderItem.setNetAmount(null);
IncomingInvoiceItem item1 = newIncomingInvoiceItem();
IncomingInvoiceItem item2 = newIncomingInvoiceItem();
// when
orderItem.orderItemInvoiceItemLinkRepository = setupOrderItemInvoiceItemLinkRepository(item1, item2);
// then
assertThat(orderItem.isInvoiced()).isFalse();
}
Aggregations