using ComplianceDAL.DTO.GSTInward; using ComplianceDAL.Query.GSTInward; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using Microsoft.Extensions.Logging; namespace ComplianceDAL.CustomCode.GSTInward; public class GSTInwardDAL : IGSTInwardDAL { private readonly IQueryExecutor _qe; private readonly ILogger _logger; public GSTInwardDAL(IQueryExecutor qe, ILogger logger) { _qe = qe; _logger = logger; } public async Task GetInwardAsync(int inwardId, LoginDTO login, CancellationToken ct) { try { return await _qe.QuerySingleAsync(login, GSTInwardQB.GET_INWARD, new { InwardId = inwardId, login.ClientId, login.DatabaseName }).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Inward DAL: GetInwardAsync failed for InwardId {InwardId}", inwardId); throw; } } public async Task> GetInwardListAsync(GSTInwardFilterDTO filter, LoginDTO login, CancellationToken ct) { try { return await _qe.QueryAsync(login, GSTInwardQB.GET_INWARD_LIST, new { filter.OurGSTIN, filter.ReturnPeriod, filter.SupplierGSTIN, filter.Source, filter.AcceptanceStatus, filter.Page, filter.PageSize, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Inward DAL: GetInwardListAsync failed for OurGSTIN {OurGSTIN}, ReturnPeriod {ReturnPeriod}", filter.OurGSTIN, filter.ReturnPeriod); throw; } } public async Task UpsertInwardAsync(GSTInwardDTO dto, LoginDTO login, CancellationToken ct) { try { return await _qe.ExecuteIdentityAsync(login, GSTInwardQB.UPSERT_INWARD, new { dto.SupplierGSTIN, dto.SupplierName, dto.OurGSTIN, dto.ReturnPeriod, dto.InvoiceNumber, dto.InvoiceDate, dto.InvoiceValue, dto.TaxableValue, dto.IGSTAmount, dto.CGSTAmount, dto.SGSTAmount, dto.CessAmount, dto.ITCEligible, dto.Source, dto.SourceDocumentId, dto.ClientId, dto.DatabaseName, dto.CreatedById }).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Inward DAL: UpsertInwardAsync failed for OurGSTIN {OurGSTIN}, SupplierGSTIN {SupplierGSTIN}, InvoiceNumber {InvoiceNumber}", dto.OurGSTIN, dto.SupplierGSTIN, dto.InvoiceNumber); throw; } } public async Task UpdateMatchAsync(int inwardId, int? matchedDocumentId, string matchedEntityType, string acceptanceStatus, int modifiedById, LoginDTO login, CancellationToken ct) { try { return await _qe.ExecuteAsync(login, GSTInwardQB.UPDATE_MATCH, new { InwardId = inwardId, MatchedDocumentId = matchedDocumentId, MatchedEntityType = matchedEntityType, AcceptanceStatus = acceptanceStatus, ModifiedById = modifiedById, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Inward DAL: UpdateMatchAsync failed for InwardId {InwardId}", inwardId); throw; } } public async Task DeleteByPeriodAsync(string ourGSTIN, string returnPeriod, string source, LoginDTO login, CancellationToken ct) { try { return await _qe.ExecuteAsync(login, GSTInwardQB.DELETE_BY_PERIOD, new { OurGSTIN = ourGSTIN, ReturnPeriod = returnPeriod, Source = source, login.ClientId, login.DatabaseName }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GST Inward DAL: DeleteByPeriodAsync failed for OurGSTIN {OurGSTIN}, ReturnPeriod {ReturnPeriod}, Source {Source}", ourGSTIN, returnPeriod, source); throw; } } }