Skip to content

Commit

Permalink
Merge pull request #174 from cardano-foundation/feat/enrich_extractio…
Browse files Browse the repository at this point in the history
…n_fields

feat: Enrich extraction endpoint to include accountType and accountSu…
  • Loading branch information
M4rc0Russ0 authored Mar 4, 2025
2 parents d853e61 + 8de8a55 commit 58d42fc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.stereotype.Service;

import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.LedgerDispatchStatus;
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.TxItemValidationStatus;
import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.TransactionItemEntity;

@Slf4j
Expand All @@ -25,20 +26,37 @@ public class TransactionItemExtractionRepository {

private final EntityManager em;

public List<TransactionItemEntity> findByItemAccount(LocalDate dateFrom, LocalDate dateTo, List<String> accountCode, List<String> costCenter, List<String> project) {
public List<TransactionItemEntity> findByItemAccount(LocalDate dateFrom, LocalDate dateTo, List<String> accountCode, List<String> costCenter, List<String> project, List<String> accountType, List<String> accountSubType) {
String jpql = STR."""
SELECT ti FROM accounting_reporting_core.TransactionItemEntity ti INNER JOIN ti.transaction te
""";
String where = STR."""
WHERE te.entryDate >= :dateFrom AND te.entryDate <= :dateTo
AND ti.amountFcy <> 0
AND ti.status = '\{TxItemValidationStatus.OK}'
""";

if (null != accountCode && 0 < accountCode.stream().count()) {
where += STR."""
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(","))}))
""";
}
if (null != accountSubType && 0 < accountSubType.stream().count()) {
where += STR."""
AND (
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (\{accountSubType.stream().map(code -> "" + code + "").collect(Collectors.joining(","))})) or
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (\{accountSubType.stream().map(code -> "" + code + "").collect(Collectors.joining(","))}))
)
""";
}

if (null != accountType && 0 < accountType.stream().count()) {
where += STR."""
AND (
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
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(","))})))
)
""";
}

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

if (!event.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ExtractionController {
public ResponseEntity<ExtractionTransactionView> transactionSearch(@Valid @RequestBody ExtractionTransactionsRequest transactionsRequest) {
return ResponseEntity
.ok()
.body(extractionItemService.findTransactionItems(transactionsRequest.getDateFrom(), transactionsRequest.getDateTo(), transactionsRequest.getAccountCode(), transactionsRequest.getCostCenter(), transactionsRequest.getProject()));
.body(extractionItemService.findTransactionItems(transactionsRequest.getDateFrom(), transactionsRequest.getDateTo(), transactionsRequest.getAccountCode(), transactionsRequest.getCostCenter(), transactionsRequest.getProject(),transactionsRequest.getAccountType(),transactionsRequest.getAccountSubType()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class ExtractionItemService {
private final TransactionItemExtractionRepository transactionItemRepositoryImpl;

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

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

return ExtractionTransactionView.createSuccess(transactionItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public class ExtractionTransactionsRequest {
@Nullable
private List<String> accountCode;

@ArraySchema(arraySchema = @Schema(example = "[\"2\",\"3\"]"))
@Nullable
private List<String> accountType;

@ArraySchema(arraySchema = @Schema(example = "[\"1\",\"4\"]"))
@Nullable
private List<String> accountSubType;

@ArraySchema(arraySchema = @Schema(example = "[\"4300\",\"5400\"]"))
@Nullable
private List<String> costCenter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ void findByItemAccountOnlyDates() {
String query = """
SELECT ti FROM accounting_reporting_core.TransactionItemEntity ti INNER JOIN ti.transaction te
WHERE te.entryDate >= :dateFrom AND te.entryDate <= :dateTo
AND ti.amountFcy <> 0
AND ti.status = 'OK'
AND (ti.accountDebit.code in ('AccountCode') or ti.accountCredit.code in ('AccountCode'))
AND (
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (accountSubType)) or
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (accountSubType))
)
AND (
ti.accountDebit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (select id from OrganisationChartOfAccountSubType where type.id in (accountType))) or
ti.accountCredit.code in (select Id.customerCode from OrganisationChartOfAccount where subType.id in (select id from OrganisationChartOfAccountSubType where type.id in (accountType)))
)
AND ti.costCenter.externalCustomerCode in ('CostCenterCode')
AND ti.project.customerCode in ('ProjectCode')
AND te.ledgerDispatchStatus = 'FINALIZED'
Expand All @@ -46,7 +54,9 @@ AND ti.project.customerCode in ('ProjectCode')
LocalDate.of(2023, Month.JANUARY, 31),
List.of("AccountCode"),
List.of("CostCenterCode"),
List.of("ProjectCode")
List.of("ProjectCode"),
List.of("accountType"),
List.of("accountSubType")
);
Mockito.verify(em, Mockito.times(1)).createQuery(query);
}
Expand All @@ -61,11 +71,11 @@ void findByItemAccountDate() {
"OrgId",
LocalDate.of(2023, Month.JANUARY, 1),
LocalDate.of(2023, Month.JANUARY, 31),
Set.of("EventCode2","EventCode1"),
Set.of("Currency2","Currency1"),
Set.of("EventCode2", "EventCode1"),
Set.of("Currency2", "Currency1"),
Optional.of(BigDecimal.valueOf(100)),
Optional.of(BigDecimal.valueOf(1000)),
Set.of("TheHast2","TheHast1")
Set.of("TheHast2", "TheHast1")
);
Mockito.verify(em, Mockito.times(1)).createQuery(anyString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ void findTransactionItemsTest() {

item1.setTransaction(tx);

Mockito.when(transactionItemExtractionRepository.findByItemAccount(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(List.of(item1));
Mockito.when(transactionItemExtractionRepository.findByItemAccount(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(List.of(item1));
ExtractionItemService extractionItemService = new ExtractionItemService(transactionItemExtractionRepository);

ExtractionTransactionView result = extractionItemService.findTransactionItems(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
ExtractionTransactionView result = extractionItemService.findTransactionItems(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
assertInstanceOf(ExtractionTransactionView.class, result);
assertEquals(1L, result.getTotal());
verifyNoMoreInteractions(transactionItemExtractionRepository);
Expand Down

0 comments on commit 58d42fc

Please sign in to comment.