using CPRNIMS.Domain.Contracts.Finance; using CPRNIMS.Infrastructure.Database; using CPRNIMS.Infrastructure.Dto.Finance; using CPRNIMS.Infrastructure.Dto.Items; using CPRNIMS.Infrastructure.Entities.Finance; using CPRNIMS.Infrastructure.Entities.Purchasing; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CPRNIMS.Domain.Services.Finance { public class RR : IRR { private readonly NonInventoryDbContext _dbContext; public RR(NonInventoryDbContext dbContext) { _dbContext = dbContext; } public async Task> GetAllClosedPO(RRDetailsDto itemDto) { try { var allItems = await _dbContext.ForPayments .FromSqlRaw($"EXEC GetAllClosedPO @UserId = '{itemDto.UserId}'") .ToListAsync(); return allItems ?? new List(); } catch (SqlException ex) { ex.ToString(); throw; } } public async Task> GetRRDetailByPO(RRDetailsDto itemDto) { var allItems = await _dbContext.ReceivingDetails .FromSqlRaw($"EXEC GetRRDetailByPOFinance @PONo,@POTypeId,@UserId", new SqlParameter("@PONo", itemDto.PONo), new SqlParameter("@POTypeId", itemDto.POTypeId), new SqlParameter("@UserId", itemDto.UserId)) .ToListAsync(); return allItems ?? new List(); } public async Task PostPutPayment(RRDetailsDto itemDto) { try { await _dbContext.Database .ExecuteSqlRawAsync("EXEC PostPutPayment @UserId, @PONo, @POTypeId, @PRDetailsId", new SqlParameter("@UserId", itemDto.UserId), new SqlParameter("@PONo", itemDto.PONo), new SqlParameter("@POTypeId", itemDto.POTypeId), new SqlParameter("@PRDetailsId", itemDto.PRDetailsId)); return new RRDetail(); } catch (SqlException ex) { ex.ToString(); throw; } } } }