Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHEE-680] Batch summary refactoring #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/org/apache/fineract/api/BatchApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public BatchPaginatedResponse getBatch(@RequestParam(value = "offset", required
}

@GetMapping("/batch")
public ResponseEntity<Object> batchDetails(@RequestParam(value = "batchId", required = false) String batchId,
public <T>ResponseEntity<T> batchDetails(@RequestParam(value = "batchId", required = false) String batchId,
@RequestParam(value = "requestId", required = false) String requestId) {
Batch batch = batchRepository.findByBatchId(batchId);

if (batch == null) {
String errorMessage = "Batch corresponding to batchId: " + batchId + " does not exist.";
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorMessage);
return (ResponseEntity<T>) ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorMessage);
}
return ResponseEntity.ok(generateBatchSummaryResponse(batch));
return (ResponseEntity<T>) ResponseEntity.ok((batchService.getBatchAndSubBatchSummary(batchId, requestId)));
}

@GetMapping("/batch/{batchId}")
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/apache/fineract/service/BatchServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,48 @@ public BatchAndSubBatchSummaryResponse getBatchAndSubBatchSummary(String batchId
return response;
}

public void populateBatchSummary(Batch batch){
double batchFailedPercent = 0;
double batchCompletedPercent = 0;

if(batch.getTotalTransactions() != null){
batchFailedPercent = ((double) batch.getFailed()) / batch.getTotalTransactions() * 100;
batchCompletedPercent = ((double) batch.getCompleted()) / batch.getTotalTransactions() * 100;
}

DecimalFormat decimalFormat = new DecimalFormat("#.##");
decimalFormat.setRoundingMode(RoundingMode.FLOOR);

Optional<Long> totalAmount = Optional.ofNullable(batch.getTotalAmount());
Optional<Long> completedAmount = Optional.ofNullable(batch.getCompletedAmount());
Optional<Long> ongoingAmount = Optional.ofNullable(batch.getOngoingAmount());
Optional<Long> failedAmount = Optional.ofNullable(batch.getFailedAmount());

Long nullValue = 0L;

BatchDTO batchDTO = new BatchDTO(batch.getBatchId(),
batch.getRequestId(), batch.getTotalTransactions(), batch.getOngoing(),
batch.getFailed(), batch.getCompleted(),
BigDecimal.valueOf(totalAmount.orElse(nullValue)),
BigDecimal.valueOf(completedAmount.orElse(nullValue)),
BigDecimal.valueOf(ongoingAmount.orElse(nullValue)),
BigDecimal.valueOf(failedAmount.orElse(nullValue)),
batch.getResult_file(), batch.getNote(),
decimalFormat.format(batchFailedPercent), decimalFormat.format(batchCompletedPercent),
batch.getRegisteringInstitutionId(), batch.getPayerFsp(), batch.getCorrelationId());

if (batch.getTotalTransactions() != null &&
batch.getCompleted() != null &&
batch.getTotalTransactions().longValue() == batch.getCompleted().longValue()) {
batchDTO.setStatus("COMPLETED");
} else if (batch.getOngoing() != null && batch.getOngoing() != 0 && batch.getCompletedAt() == null) {
batchDTO.setStatus("Pending");
} else {
batchDTO.setStatus("UNKNOWN");
}

}

@Override
public PaymentBatchDetail getPaymentBathDetail(String batchId, String clientCorrelationId, int offset, int limit, String orderBy, String sortBy) {
List<Batch> batchAndSubBatches = batchRepository.findAllByBatchId(batchId);
Expand Down