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 0478e27
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 17 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,44 @@ 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(),
item.getAccountCredit(),
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(""),
//Doocu
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 +203,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 @@ -15,9 +16,38 @@
@AllArgsConstructor
public class TransactionItemView {
private String id;
private Optional<Account> accountDebit= Optional.empty();
private Optional<Account> accountCredit= Optional.empty();
private Optional<Account> accountDebit = Optional.empty();
private Optional<Account> accountCredit = Optional.empty();
private BigDecimal amountFcy;
private BigDecimal amountLcy;
private BigDecimal fxRate;
//private CostCenter costCenter;
private String costCenterCustomerCode;
private String costCenterExternalCustomerCode;
private String costCenterName;

//private Project project;
private String projectCustomerCode;
private String projectName;
private String projectExternalCustomerCode;

//private AccountEvent accountEvent;
private String accountEventCode;
private String accountEventName;


//private Document document;
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 @@ -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 0478e27

Please sign in to comment.