Skip to content

Commit

Permalink
feat: Transaction items properties
Browse files Browse the repository at this point in the history
  • Loading branch information
M4rc0Russ0 committed Aug 1, 2024
1 parent f8c299a commit a33d98a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -152,20 +152,46 @@ private TransactionView getTransactionView(TransactionEntity transactionEntity)
transactionEntity.getAutomatedValidationStatus(),
transactionEntity.getTransactionApproved(),
transactionEntity.getLedgerDispatchApproved(),
getAmountLcy(transactionEntity),
getTransactionItemView(transactionEntity),
getViolation(transactionEntity),
transactionEntity.getStatus()
);
}

private Set<TransactionItemView> 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<ViolationView> getViolation(TransactionEntity transaction) {
Expand All @@ -179,4 +205,12 @@ private Set<ViolationView> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,10 +15,55 @@
@Setter
@AllArgsConstructor
public class TransactionItemView {

private String id;
private Optional<Account> accountDebit= Optional.empty();
private Optional<Account> 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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TransactionItemView> items = new LinkedHashSet<>();
private Set<ViolationView> violations = new LinkedHashSet<>();
private TransactionStatus status = TransactionStatus.OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a33d98a

Please sign in to comment.