Skip to content

Commit 58d42fc

Browse files
authored
Merge pull request #174 from cardano-foundation/feat/enrich_extraction_fields
feat: Enrich extraction endpoint to include accountType and accountSu…
2 parents d853e61 + 8de8a55 commit 58d42fc

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/repository/TransactionItemExtractionRepository.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.springframework.stereotype.Service;
1717

1818
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.LedgerDispatchStatus;
19+
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.TxItemValidationStatus;
1920
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.TransactionItemEntity;
2021

2122
@Slf4j
@@ -25,20 +26,37 @@ public class TransactionItemExtractionRepository {
2526

2627
private final EntityManager em;
2728

28-
public List<TransactionItemEntity> findByItemAccount(LocalDate dateFrom, LocalDate dateTo, List<String> accountCode, List<String> costCenter, List<String> project) {
29+
public List<TransactionItemEntity> findByItemAccount(LocalDate dateFrom, LocalDate dateTo, List<String> accountCode, List<String> costCenter, List<String> project, List<String> accountType, List<String> accountSubType) {
2930
String jpql = STR."""
3031
SELECT ti FROM accounting_reporting_core.TransactionItemEntity ti INNER JOIN ti.transaction te
3132
""";
3233
String where = STR."""
3334
WHERE te.entryDate >= :dateFrom AND te.entryDate <= :dateTo
34-
AND ti.amountFcy <> 0
35+
AND ti.status = '\{TxItemValidationStatus.OK}'
3536
""";
3637

3738
if (null != accountCode && 0 < accountCode.stream().count()) {
3839
where += STR."""
3940
AND (ti.accountDebit.code in (\{accountCode.stream().map(code -> "'" + code + "'").collect(Collectors.joining(","))}) or ti.accountCredit.code in (\{accountCode.stream().map(code -> "'" + code + "'").collect(Collectors.joining(","))}))
4041
""";
4142
}
43+
if (null != accountSubType && 0 < accountSubType.stream().count()) {
44+
where += STR."""
45+
AND (
46+
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (\{accountSubType.stream().map(code -> "" + code + "").collect(Collectors.joining(","))})) or
47+
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (\{accountSubType.stream().map(code -> "" + code + "").collect(Collectors.joining(","))}))
48+
)
49+
""";
50+
}
51+
52+
if (null != accountType && 0 < accountType.stream().count()) {
53+
where += STR."""
54+
AND (
55+
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (select id from OrganisationChartOfAccountSubType where type.id in (\{accountType.stream().map(code -> "" + code + "").collect(Collectors.joining(","))}))) or
56+
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (select id from OrganisationChartOfAccountSubType where type.id in (\{accountType.stream().map(code -> "" + code + "").collect(Collectors.joining(","))})))
57+
)
58+
""";
59+
}
4260

4361
if (null != costCenter && 0 < costCenter.stream().count()) {
4462
where += STR."""
@@ -76,7 +94,7 @@ public List<TransactionItemEntity> findByItemAccountDate(String orgId, LocalDate
7694
String where = STR."""
7795
WHERE te.entryDate >= :dateFrom AND te.entryDate <= :dateTo
7896
AND te.organisation.id = '\{orgId}'
79-
AND ti.amountFcy <> 0
97+
AND ti.status = '\{TxItemValidationStatus.OK}'
8098
""";
8199

82100
if (!event.isEmpty()) {

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/ExtractionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ExtractionController {
4545
public ResponseEntity<ExtractionTransactionView> transactionSearch(@Valid @RequestBody ExtractionTransactionsRequest transactionsRequest) {
4646
return ResponseEntity
4747
.ok()
48-
.body(extractionItemService.findTransactionItems(transactionsRequest.getDateFrom(), transactionsRequest.getDateTo(), transactionsRequest.getAccountCode(), transactionsRequest.getCostCenter(), transactionsRequest.getProject()));
48+
.body(extractionItemService.findTransactionItems(transactionsRequest.getDateFrom(), transactionsRequest.getDateTo(), transactionsRequest.getAccountCode(), transactionsRequest.getCostCenter(), transactionsRequest.getProject(),transactionsRequest.getAccountType(),transactionsRequest.getAccountSubType()));
4949
}
5050

5151

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/presentation_layer_service/ExtractionItemService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class ExtractionItemService {
3030
private final TransactionItemExtractionRepository transactionItemRepositoryImpl;
3131

3232
@Transactional(readOnly = true)
33-
public ExtractionTransactionView findTransactionItems(LocalDate dateFrom, LocalDate dateTo, List<String> accountCode, List<String> costCenter, List<String> project) {
33+
public ExtractionTransactionView findTransactionItems(LocalDate dateFrom, LocalDate dateTo, List<String> accountCode, List<String> costCenter, List<String> project, List<String> accountType, List<String> accountSubType) {
3434

35-
List<ExtractionTransactionItemView> transactionItem = transactionItemRepositoryImpl.findByItemAccount(dateFrom, dateTo, accountCode, costCenter, project).stream().map(this::extractionTransactionItemViewBuilder).collect(Collectors.toList());
35+
List<ExtractionTransactionItemView> transactionItem = transactionItemRepositoryImpl.findByItemAccount(dateFrom, dateTo, accountCode, costCenter, project,accountType,accountSubType).stream().map(this::extractionTransactionItemViewBuilder).collect(Collectors.toList());
3636

3737
return ExtractionTransactionView.createSuccess(transactionItem);
3838
}

accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/requests/ExtractionTransactionsRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public class ExtractionTransactionsRequest {
3636
@Nullable
3737
private List<String> accountCode;
3838

39+
@ArraySchema(arraySchema = @Schema(example = "[\"2\",\"3\"]"))
40+
@Nullable
41+
private List<String> accountType;
42+
43+
@ArraySchema(arraySchema = @Schema(example = "[\"1\",\"4\"]"))
44+
@Nullable
45+
private List<String> accountSubType;
46+
3947
@ArraySchema(arraySchema = @Schema(example = "[\"4300\",\"5400\"]"))
4048
@Nullable
4149
private List<String> costCenter;

accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/repository/TransactionItemExtractionRepositoryTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ void findByItemAccountOnlyDates() {
3131
String query = """
3232
SELECT ti FROM accounting_reporting_core.TransactionItemEntity ti INNER JOIN ti.transaction te
3333
WHERE te.entryDate >= :dateFrom AND te.entryDate <= :dateTo
34-
AND ti.amountFcy <> 0
34+
AND ti.status = 'OK'
3535
AND (ti.accountDebit.code in ('AccountCode') or ti.accountCredit.code in ('AccountCode'))
36+
AND (
37+
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (accountSubType)) or
38+
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (accountSubType))
39+
)
40+
AND (
41+
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (select id from OrganisationChartOfAccountSubType where type.id in (accountType))) or
42+
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (select id from OrganisationChartOfAccountSubType where type.id in (accountType)))
43+
)
3644
AND ti.costCenter.externalCustomerCode in ('CostCenterCode')
3745
AND ti.project.customerCode in ('ProjectCode')
3846
AND te.ledgerDispatchStatus = 'FINALIZED'
@@ -46,7 +54,9 @@ AND ti.project.customerCode in ('ProjectCode')
4654
LocalDate.of(2023, Month.JANUARY, 31),
4755
List.of("AccountCode"),
4856
List.of("CostCenterCode"),
49-
List.of("ProjectCode")
57+
List.of("ProjectCode"),
58+
List.of("accountType"),
59+
List.of("accountSubType")
5060
);
5161
Mockito.verify(em, Mockito.times(1)).createQuery(query);
5262
}
@@ -61,11 +71,11 @@ void findByItemAccountDate() {
6171
"OrgId",
6272
LocalDate.of(2023, Month.JANUARY, 1),
6373
LocalDate.of(2023, Month.JANUARY, 31),
64-
Set.of("EventCode2","EventCode1"),
65-
Set.of("Currency2","Currency1"),
74+
Set.of("EventCode2", "EventCode1"),
75+
Set.of("Currency2", "Currency1"),
6676
Optional.of(BigDecimal.valueOf(100)),
6777
Optional.of(BigDecimal.valueOf(1000)),
68-
Set.of("TheHast2","TheHast1")
78+
Set.of("TheHast2", "TheHast1")
6979
);
7080
Mockito.verify(em, Mockito.times(1)).createQuery(anyString());
7181
}

accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/presentation_layer_service/ExtractionItemServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ void findTransactionItemsTest() {
5252

5353
item1.setTransaction(tx);
5454

55-
Mockito.when(transactionItemExtractionRepository.findByItemAccount(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(List.of(item1));
55+
Mockito.when(transactionItemExtractionRepository.findByItemAccount(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(List.of(item1));
5656
ExtractionItemService extractionItemService = new ExtractionItemService(transactionItemExtractionRepository);
5757

58-
ExtractionTransactionView result = extractionItemService.findTransactionItems(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
58+
ExtractionTransactionView result = extractionItemService.findTransactionItems(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
5959
assertInstanceOf(ExtractionTransactionView.class, result);
6060
assertEquals(1L, result.getTotal());
6161
verifyNoMoreInteractions(transactionItemExtractionRepository);

0 commit comments

Comments
 (0)