From a33d98a40119610e2895393aa685b72586c7e64d Mon Sep 17 00:00:00 2001 From: Marco Russo Date: Tue, 30 Jul 2024 13:55:22 +0100 Subject: [PATCH] feat: Transaction items properties --- ...AccountingCorePresentationViewService.java | 62 ++++++++++++++----- .../resource/views/TransactionItemView.java | 52 +++++++++++++++- .../resource/views/TransactionView.java | 2 + ...countingCorePresentationConverterTest.java | 5 +- 4 files changed, 102 insertions(+), 19 deletions(-) diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationViewService.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationViewService.java index 5e63a9e6..3c5b02ec 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationViewService.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationViewService.java @@ -4,10 +4,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.UserExtractionParameters; -import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.BatchStatistics; -import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.FilteringParameters; -import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.TransactionBatchEntity; -import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.TransactionEntity; +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.*; import org.cardanofoundation.lob.app.accounting_reporting_core.repository.TransactionBatchRepositoryGateway; import org.cardanofoundation.lob.app.accounting_reporting_core.repository.TransactionRepositoryGateway; import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.BatchSearchRequest; @@ -18,12 +15,15 @@ import org.jmolecules.ddd.annotation.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.time.LocalDate; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; +import static org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Source.ERP; +import static org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Violation.Severity.ERROR; +import static org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.ViolationCode.AMOUNT_FCY_IS_ZERO; + @Service @org.springframework.stereotype.Service @Slf4j @@ -152,6 +152,7 @@ private TransactionView getTransactionView(TransactionEntity transactionEntity) transactionEntity.getAutomatedValidationStatus(), transactionEntity.getTransactionApproved(), transactionEntity.getLedgerDispatchApproved(), + getAmountLcy(transactionEntity), getTransactionItemView(transactionEntity), getViolation(transactionEntity), transactionEntity.getStatus() @@ -159,13 +160,38 @@ private TransactionView getTransactionView(TransactionEntity transactionEntity) } private Set getTransactionItemView(TransactionEntity transaction) { - return transaction.getItems().stream().map(item -> new TransactionItemView( - item.getId(), - item.getAccountDebit(), - item.getAccountCredit(), - item.getAmountFcy(), - item.getAmountLcy() - )).collect(Collectors.toSet()); + return transaction.getItems().stream().map(item -> { + + return new TransactionItemView( + item.getId(), + item.getAccountDebit().map(account -> account.getCode()).orElse(""), + item.getAccountDebit().flatMap(account -> account.getName()).orElse(""), + item.getAccountDebit().flatMap(account -> account.getRefCode()).orElse(""), + item.getAccountCredit().map(account -> account.getCode()).orElse(""), + item.getAccountCredit().flatMap(account -> account.getName()).orElse(""), + item.getAccountCredit().flatMap(account -> account.getRefCode()).orElse(""), + item.getAmountFcy(), + item.getAmountLcy(), + item.getFxRate(), + item.getCostCenter().map(CostCenter::getCustomerCode).orElse(""), + item.getCostCenter().flatMap(CostCenter::getExternalCustomerCode).orElse(""), + item.getCostCenter().flatMap(CostCenter::getName).orElse(""), + item.getProject().map(Project::getCustomerCode).orElse(""), + item.getProject().flatMap(Project::getName).orElse(""), + item.getProject().flatMap(Project::getExternalCustomerCode).orElse(""), + item.getAccountEvent().map(AccountEvent::getCode).orElse(""), + item.getAccountEvent().map(AccountEvent::getName).orElse(""), + item.getDocument().map(Document::getNum).orElse(""), + item.getDocument().map(document -> document.getCurrency().getCustomerCode()).orElse(""), + item.getDocument().flatMap(document -> document.getVat().map(Vat::getCustomerCode)).orElse(""), + item.getDocument().flatMap(document -> document.getVat().flatMap(Vat::getRate)).orElse(BigDecimal.ZERO), + item.getDocument().flatMap(d -> d.getCounterparty().map(Counterparty::getCustomerCode)).orElse(""), + item.getDocument().flatMap(d -> d.getCounterparty().map(Counterparty::getType)).orElse(org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Counterparty.Type.VENDOR), + item.getDocument().flatMap(document -> document.getCounterparty().flatMap(Counterparty::getName)).orElse("") + + + ); + }).collect(Collectors.toSet()); } private Set getViolation(TransactionEntity transaction) { @@ -179,4 +205,12 @@ private Set getViolation(TransactionEntity transaction) { )).collect(Collectors.toSet()); } + private BigDecimal getAmountLcy(TransactionEntity tx) { + BigDecimal total = BigDecimal.ZERO; + for (val txItem : tx.getItems()) { + total = total.add(txItem.getAmountLcy()); + } + return total; + } + } diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionItemView.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionItemView.java index cc66c19a..54ae238e 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionItemView.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionItemView.java @@ -3,7 +3,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.Account; +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Counterparty.Type; +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.*; import java.math.BigDecimal; import java.util.LinkedHashSet; @@ -14,10 +15,55 @@ @Setter @AllArgsConstructor public class TransactionItemView { + private String id; - private Optional accountDebit= Optional.empty(); - private Optional accountCredit= Optional.empty(); + + private String accountDebitCode; + + private String accountDebitName; + + private String accountDebitRefCode; + + private String accountCreditCode; + + private String accountCreditName; + + private String accountCreditRefCode; + private BigDecimal amountFcy; + private BigDecimal amountLcy; + private BigDecimal fxRate; + + private String costCenterCustomerCode; + + private String costCenterExternalCustomerCode; + + private String costCenterName; + + private String projectCustomerCode; + + private String projectName; + + private String projectExternalCustomerCode; + + private String accountEventCode; + + private String accountEventName; + + private String documentNum; + + private String documentCurrencyCustomerCode; + + private String vatCustomerCode; + + private BigDecimal vatRate; + + private String counterpartyCustomerCode; + + private Type counterpartyType; + + private String counterpartyName; + } diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionView.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionView.java index eed3f9fe..c46aa0e9 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionView.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionView.java @@ -8,6 +8,7 @@ import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.TransactionType; import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.ValidationStatus; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.LinkedHashSet; import java.util.Set; @@ -30,6 +31,7 @@ public class TransactionView { private ValidationStatus validationStatus = ValidationStatus.VALIDATED; private boolean transactionApproved = false; private boolean ledgerDispatchApproved = false; + private BigDecimal amountTotalLcy; private Set items = new LinkedHashSet<>(); private Set violations = new LinkedHashSet<>(); private TransactionStatus status = TransactionStatus.OK; diff --git a/accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationConverterTest.java b/accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationConverterTest.java index d3f103e6..0d7688e7 100644 --- a/accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationConverterTest.java +++ b/accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationConverterTest.java @@ -117,8 +117,8 @@ void testAllTransactions() { assertEquals(BigDecimal.valueOf(1000), result.get(0).getItems().stream().findFirst().get().getAmountFcy()); assertEquals(BigDecimal.valueOf(1000), result.get(0).getItems().stream().findFirst().get().getAmountLcy()); - assertEquals("debit-code", result.get(0).getItems().stream().findFirst().get().getAccountDebit().get().getCode()); - assertEquals("credit-code", result.get(0).getItems().stream().findFirst().get().getAccountCredit().get().getCode()); + assertEquals("debit-code", result.get(0).getItems().stream().findFirst().get().getAccountDebitCode()); + assertEquals("credit-code", result.get(0).getItems().stream().findFirst().get().getAccountCreditCode()); assertEquals(Optional.of("tx-item-id"), result.get(0).getViolations().stream().findFirst().get().getTransactionItemId()); @@ -147,6 +147,7 @@ void testBatchDetail() { TransactionItemEntity transactionItem = new TransactionItemEntity(); transactionItem.setId("txItemId"); + transactionItem.setAmountLcy(BigDecimal.valueOf(100)); Violation violation = new Violation(); violation.setTxItemId(Optional.of("txItemId")); LocalDate from = LocalDate.now();