Skip to content

Commit 7a218de

Browse files
authored
Merge pull request #8 from cardano-foundation/feat/enrich_transaction_view
feat: Add amountTotalLcy and enrich Transaction object response
2 parents 9abf222 + a33d98a commit 7a218de

File tree

4 files changed

+102
-19
lines changed

4 files changed

+102
-19
lines changed

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationViewService.java

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import lombok.extern.slf4j.Slf4j;
55
import lombok.val;
66
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.UserExtractionParameters;
7-
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.BatchStatistics;
8-
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.FilteringParameters;
9-
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.TransactionBatchEntity;
10-
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.TransactionEntity;
7+
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.*;
118
import org.cardanofoundation.lob.app.accounting_reporting_core.repository.TransactionBatchRepositoryGateway;
129
import org.cardanofoundation.lob.app.accounting_reporting_core.repository.TransactionRepositoryGateway;
1310
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.BatchSearchRequest;
@@ -18,12 +15,15 @@
1815
import org.jmolecules.ddd.annotation.Service;
1916
import org.springframework.transaction.annotation.Transactional;
2017

18+
import java.math.BigDecimal;
2119
import java.time.LocalDate;
22-
import java.util.List;
23-
import java.util.Optional;
24-
import java.util.Set;
20+
import java.util.*;
2521
import java.util.stream.Collectors;
2622

23+
import static org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Source.ERP;
24+
import static org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Violation.Severity.ERROR;
25+
import static org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.ViolationCode.AMOUNT_FCY_IS_ZERO;
26+
2727
@Service
2828
@org.springframework.stereotype.Service
2929
@Slf4j
@@ -152,20 +152,46 @@ private TransactionView getTransactionView(TransactionEntity transactionEntity)
152152
transactionEntity.getAutomatedValidationStatus(),
153153
transactionEntity.getTransactionApproved(),
154154
transactionEntity.getLedgerDispatchApproved(),
155+
getAmountLcy(transactionEntity),
155156
getTransactionItemView(transactionEntity),
156157
getViolation(transactionEntity),
157158
transactionEntity.getStatus()
158159
);
159160
}
160161

161162
private Set<TransactionItemView> getTransactionItemView(TransactionEntity transaction) {
162-
return transaction.getItems().stream().map(item -> new TransactionItemView(
163-
item.getId(),
164-
item.getAccountDebit(),
165-
item.getAccountCredit(),
166-
item.getAmountFcy(),
167-
item.getAmountLcy()
168-
)).collect(Collectors.toSet());
163+
return transaction.getItems().stream().map(item -> {
164+
165+
return new TransactionItemView(
166+
item.getId(),
167+
item.getAccountDebit().map(account -> account.getCode()).orElse(""),
168+
item.getAccountDebit().flatMap(account -> account.getName()).orElse(""),
169+
item.getAccountDebit().flatMap(account -> account.getRefCode()).orElse(""),
170+
item.getAccountCredit().map(account -> account.getCode()).orElse(""),
171+
item.getAccountCredit().flatMap(account -> account.getName()).orElse(""),
172+
item.getAccountCredit().flatMap(account -> account.getRefCode()).orElse(""),
173+
item.getAmountFcy(),
174+
item.getAmountLcy(),
175+
item.getFxRate(),
176+
item.getCostCenter().map(CostCenter::getCustomerCode).orElse(""),
177+
item.getCostCenter().flatMap(CostCenter::getExternalCustomerCode).orElse(""),
178+
item.getCostCenter().flatMap(CostCenter::getName).orElse(""),
179+
item.getProject().map(Project::getCustomerCode).orElse(""),
180+
item.getProject().flatMap(Project::getName).orElse(""),
181+
item.getProject().flatMap(Project::getExternalCustomerCode).orElse(""),
182+
item.getAccountEvent().map(AccountEvent::getCode).orElse(""),
183+
item.getAccountEvent().map(AccountEvent::getName).orElse(""),
184+
item.getDocument().map(Document::getNum).orElse(""),
185+
item.getDocument().map(document -> document.getCurrency().getCustomerCode()).orElse(""),
186+
item.getDocument().flatMap(document -> document.getVat().map(Vat::getCustomerCode)).orElse(""),
187+
item.getDocument().flatMap(document -> document.getVat().flatMap(Vat::getRate)).orElse(BigDecimal.ZERO),
188+
item.getDocument().flatMap(d -> d.getCounterparty().map(Counterparty::getCustomerCode)).orElse(""),
189+
item.getDocument().flatMap(d -> d.getCounterparty().map(Counterparty::getType)).orElse(org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Counterparty.Type.VENDOR),
190+
item.getDocument().flatMap(document -> document.getCounterparty().flatMap(Counterparty::getName)).orElse("")
191+
192+
193+
);
194+
}).collect(Collectors.toSet());
169195
}
170196

171197
private Set<ViolationView> getViolation(TransactionEntity transaction) {
@@ -179,4 +205,12 @@ private Set<ViolationView> getViolation(TransactionEntity transaction) {
179205
)).collect(Collectors.toSet());
180206
}
181207

208+
private BigDecimal getAmountLcy(TransactionEntity tx) {
209+
BigDecimal total = BigDecimal.ZERO;
210+
for (val txItem : tx.getItems()) {
211+
total = total.add(txItem.getAmountLcy());
212+
}
213+
return total;
214+
}
215+
182216
}

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionItemView.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import lombok.AllArgsConstructor;
44
import lombok.Getter;
55
import lombok.Setter;
6-
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.Account;
6+
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Counterparty.Type;
7+
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.*;
78

89
import java.math.BigDecimal;
910
import java.util.LinkedHashSet;
@@ -14,10 +15,55 @@
1415
@Setter
1516
@AllArgsConstructor
1617
public class TransactionItemView {
18+
1719
private String id;
18-
private Optional<Account> accountDebit= Optional.empty();
19-
private Optional<Account> accountCredit= Optional.empty();
20+
21+
private String accountDebitCode;
22+
23+
private String accountDebitName;
24+
25+
private String accountDebitRefCode;
26+
27+
private String accountCreditCode;
28+
29+
private String accountCreditName;
30+
31+
private String accountCreditRefCode;
32+
2033
private BigDecimal amountFcy;
34+
2135
private BigDecimal amountLcy;
2236

37+
private BigDecimal fxRate;
38+
39+
private String costCenterCustomerCode;
40+
41+
private String costCenterExternalCustomerCode;
42+
43+
private String costCenterName;
44+
45+
private String projectCustomerCode;
46+
47+
private String projectName;
48+
49+
private String projectExternalCustomerCode;
50+
51+
private String accountEventCode;
52+
53+
private String accountEventName;
54+
55+
private String documentNum;
56+
57+
private String documentCurrencyCustomerCode;
58+
59+
private String vatCustomerCode;
60+
61+
private BigDecimal vatRate;
62+
63+
private String counterpartyCustomerCode;
64+
65+
private Type counterpartyType;
66+
67+
private String counterpartyName;
68+
2369
}

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/views/TransactionView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.TransactionType;
99
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.ValidationStatus;
1010

11+
import java.math.BigDecimal;
1112
import java.time.LocalDate;
1213
import java.util.LinkedHashSet;
1314
import java.util.Set;
@@ -30,6 +31,7 @@ public class TransactionView {
3031
private ValidationStatus validationStatus = ValidationStatus.VALIDATED;
3132
private boolean transactionApproved = false;
3233
private boolean ledgerDispatchApproved = false;
34+
private BigDecimal amountTotalLcy;
3335
private Set<TransactionItemView> items = new LinkedHashSet<>();
3436
private Set<ViolationView> violations = new LinkedHashSet<>();
3537
private TransactionStatus status = TransactionStatus.OK;

accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/model/AccountingCorePresentationConverterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ void testAllTransactions() {
117117

118118
assertEquals(BigDecimal.valueOf(1000), result.get(0).getItems().stream().findFirst().get().getAmountFcy());
119119
assertEquals(BigDecimal.valueOf(1000), result.get(0).getItems().stream().findFirst().get().getAmountLcy());
120-
assertEquals("debit-code", result.get(0).getItems().stream().findFirst().get().getAccountDebit().get().getCode());
121-
assertEquals("credit-code", result.get(0).getItems().stream().findFirst().get().getAccountCredit().get().getCode());
120+
assertEquals("debit-code", result.get(0).getItems().stream().findFirst().get().getAccountDebitCode());
121+
assertEquals("credit-code", result.get(0).getItems().stream().findFirst().get().getAccountCreditCode());
122122

123123
assertEquals(Optional.of("tx-item-id"), result.get(0).getViolations().stream().findFirst().get().getTransactionItemId());
124124

@@ -147,6 +147,7 @@ void testBatchDetail() {
147147

148148
TransactionItemEntity transactionItem = new TransactionItemEntity();
149149
transactionItem.setId("txItemId");
150+
transactionItem.setAmountLcy(BigDecimal.valueOf(100));
150151
Violation violation = new Violation();
151152
violation.setTxItemId(Optional.of("txItemId"));
152153
LocalDate from = LocalDate.now();

0 commit comments

Comments
 (0)