Enhance financial report accuracy by including closing journals in profit and loss calculations and trial balances; add idempotency check for journal entry creation.
This commit is contained in:
@@ -31,6 +31,18 @@ namespace General_Ledger_Service.Services
|
||||
|
||||
public async Task<ApiResponse> CreateAsync(CreateJournalEntryRequest request)
|
||||
{
|
||||
// Idempotency guard for service-to-service callers: the same sourceModule + reference is only ever
|
||||
// posted once, so a retry after a timeout returns the existing entry instead of double-posting.
|
||||
if (request.Correction is null
|
||||
&& !string.IsNullOrWhiteSpace(request.SourceModule) && !string.IsNullOrWhiteSpace(request.Reference))
|
||||
{
|
||||
var existing = await _journalEntryRepository.GetJournalEntryBySourceReferenceAsync(request.SourceModule, request.Reference);
|
||||
if (existing is not null)
|
||||
{
|
||||
return ResponseHelpers.Ok("Journal entry already exists for this sourceModule and reference", existing);
|
||||
}
|
||||
}
|
||||
|
||||
var period = await _fiscalCalendarRepository.GetPeriodByIdAsync(request.PeriodId)
|
||||
?? throw new NotFoundException("Period not found");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user