Search in sources :

Example 1 with IncomingInvoiceType

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;
}
Also used : Order(org.estatio.module.capex.dom.order.Order) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) IncomingInvoiceType(org.estatio.module.capex.dom.invoice.IncomingInvoiceType) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Charge(org.estatio.module.charge.dom.Charge) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder)

Example 2 with IncomingInvoiceType

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);
    }
}
Also used : IncomingInvoiceType(org.estatio.module.capex.dom.invoice.IncomingInvoiceType) CodaElementLevel(org.estatio.module.capex.dom.coda.CodaElementLevel) CodaElement(org.estatio.module.capex.dom.coda.CodaElement) Charge(org.estatio.module.charge.dom.Charge) DocumentType(org.estatio.module.capex.dom.coda.DocumentType) CodaTransactionType(org.estatio.module.capex.dom.coda.CodaTransactionType) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval)

Aggregations

IncomingInvoiceType (org.estatio.module.capex.dom.invoice.IncomingInvoiceType)2 Charge (org.estatio.module.charge.dom.Charge)2 Action (org.apache.isis.applib.annotation.Action)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 CodaElement (org.estatio.module.capex.dom.coda.CodaElement)1 CodaElementLevel (org.estatio.module.capex.dom.coda.CodaElementLevel)1 CodaTransactionType (org.estatio.module.capex.dom.coda.CodaTransactionType)1 DocumentType (org.estatio.module.capex.dom.coda.DocumentType)1 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)1 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)1 Order (org.estatio.module.capex.dom.order.Order)1 OrderItem (org.estatio.module.capex.dom.order.OrderItem)1 OrderItemInvoiceItemLink (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink)1 LocalDateInterval (org.incode.module.base.dom.valuetypes.LocalDateInterval)1