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:
2026-10-20 18:52:04 +05:30
parent 3f16e0cb44
commit 21c7ba54ea
10 changed files with 56 additions and 26 deletions
+12
View File
@@ -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");