use of org.estatio.module.capex.dom.invoice.IncomingInvoiceType 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.IncomingInvoiceType in project estatio by estatio.
the class CodaMappingImport method handleRow.
@Override
public void handleRow(final CodaMappingImport previousRow) {
atPath = atPath == null && previousRow != null ? previousRow.atPath : atPath;
if (codaElementName == null) {
String.format("");
}
if ((documentType != null || incomingInvoiceType != null) && chargeName != null) {
IncomingInvoiceType incomingInvoiceTypeEnum = IncomingInvoiceType.valueOf(incomingInvoiceType);
DocumentType documentTypeEnum = incomingInvoiceTypeEnum == null ? DocumentType.valueOf(documentType) : DocumentType.INVOICE_IN;
CodaElementLevel codaElementLevelEnum = CodaElementLevel.valueOf(codaElementLevel);
CodaElement codaElement = codaElementRepository.findOrCreate(codaElementLevelEnum, codaElementCode, codaElementName);
Charge charge = chargeRepository.findOrCreate(atPath, chargeReference != null ? chargeReference : chargeNameToReference(chargeName), chargeName, "", Applicability.INCOMING);
final LocalDateInterval interval = period == null ? new LocalDateInterval() : PeriodUtil.yearFromPeriod(period);
final CodaTransactionType codaTransactionType = valueOfElseDefault(transactionType, CodaTransactionType.STAT);
codaMappingRepository.findOrCreate(atPath, documentTypeEnum, incomingInvoiceTypeEnum, codaTransactionType, charge, propertyFullyOwned(propertyOwnershipType), interval.startDate(), interval.endDate(), startDate, endDate, codaElement);
}
}
Aggregations