using ComplianceDAL.DTO.GSTInward; using ComplianceDAL.Query.GSTRecon; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using Microsoft.Extensions.Logging; namespace ComplianceDAL.CustomCode.GSTRecon; public class GSTReconDAL : IGSTReconDAL { private readonly IQueryExecutor _qe; private readonly ILogger _logger; public GSTReconDAL(IQueryExecutor qe, ILogger logger) { _qe = qe; _logger = logger; } public async Task GetReconAsync(int reconId, LoginDTO login, CancellationToken ct) { try { return await _qe.QuerySingleAsync(login, GSTReconQB.GET_RECON, new { ReconId = reconId, login.ClientId, login.DatabaseName }).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Recon DAL: GetReconAsync failed for ReconId {ReconId}", reconId); throw; } } public async Task> GetReconListAsync(GSTReconFilterDTO filter, LoginDTO login, CancellationToken ct) { try { return await _qe.QueryAsync(login, GSTReconQB.GET_RECON_LIST, new { filter.OurGSTIN, filter.Period, filter.ReconType, filter.Status, filter.Page, filter.PageSize, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Recon DAL: GetReconListAsync failed for OurGSTIN {OurGSTIN}, Period {Period}, ReconType {ReconType}", filter.OurGSTIN, filter.Period, filter.ReconType); throw; } } public async Task> GetReconSummaryAsync(string ourGSTIN, string period, string reconType, LoginDTO login, CancellationToken ct) { try { return await _qe.QueryAsync(login, GSTReconQB.GET_RECON_SUMMARY, new { OurGSTIN = ourGSTIN, Period = period, ReconType = reconType, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Recon DAL: GetReconSummaryAsync failed for OurGSTIN {OurGSTIN}, Period {Period}, ReconType {ReconType}", ourGSTIN, period, reconType); throw; } } public async Task UpsertReconInwardAsync(GSTReconDTO dto, LoginDTO login, CancellationToken ct) { try { return await _qe.ExecuteIdentityAsync(login, GSTReconQB.UPSERT_RECON_INWARD, new { dto.ReconType, dto.Period, dto.OurGSTIN, dto.InwardId, dto.Status, dto.DiffTaxableValue, dto.DiffIGST, dto.DiffCGST, dto.DiffSGST, dto.DiffCess, dto.ClientId, dto.DatabaseName, dto.CreatedById }).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Recon DAL: UpsertReconInwardAsync failed for OurGSTIN {OurGSTIN}, Period {Period}, ReconType {ReconType}, InwardId {InwardId}", dto.OurGSTIN, dto.Period, dto.ReconType, dto.InwardId); throw; } } public async Task ResolveReconAsync(int reconId, string status, string notes, int resolvedById, LoginDTO login, CancellationToken ct) { try { return await _qe.ExecuteAsync(login, GSTReconQB.RESOLVE_RECON, new { ReconId = reconId, Status = status, Notes = notes, ResolvedById = resolvedById, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Recon DAL: ResolveReconAsync failed for ReconId {ReconId}, Status {Status}", reconId, status); throw; } } public async Task DeleteByPeriodAsync(string ourGSTIN, string period, string reconType, LoginDTO login, CancellationToken ct) { try { return await _qe.ExecuteAsync(login, GSTReconQB.DELETE_BY_PERIOD, new { OurGSTIN = ourGSTIN, Period = period, ReconType = reconType, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Recon DAL: DeleteByPeriodAsync failed for OurGSTIN {OurGSTIN}, Period {Period}, ReconType {ReconType}", ourGSTIN, period, reconType); throw; } } }