44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FKGees;
|
|
|
|
public class DocumentsService
|
|
{
|
|
private readonly IDbContextFactory<PcmDbContext> _dbContextFactory;
|
|
|
|
public DocumentsService(IDbContextFactory<PcmDbContext> dbContextFactory)
|
|
{
|
|
_dbContextFactory = dbContextFactory;
|
|
}
|
|
|
|
public async Task<IReadOnlyList<Dok>> Fetch(int[] typdok, DateTime dataOd, DateTime dataDo)
|
|
{
|
|
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
|
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
|
|
|
var documents = await context.Dok
|
|
.Include(x => x.DokKontr).ThenInclude(x => x.Kontr)
|
|
.Include(x => x.DokKasa)
|
|
.Include(x => x.TekstDok)
|
|
.Include(x => x.PozDok)
|
|
.Include(x => x.RozliczaRozliczanyDok).ThenInclude(x => x.Dok)
|
|
.Include(x => x.DokKasa).ThenInclude(x => x.Kasa)
|
|
.Where(x => typdok.Contains(x.TypDok) && x.Data >= dataOd && x.Data <= dataDo)
|
|
.ToListAsync();
|
|
return documents;
|
|
|
|
}
|
|
|
|
public string WzNrFaktury(decimal dokId)
|
|
{
|
|
using var context = _dbContextFactory.CreateDbContext();
|
|
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
|
|
|
var dok = context.Rozlicza
|
|
.Include(x => x.RozliczanyDok)
|
|
.FirstOrDefault(x => x.DokId == dokId);
|
|
|
|
|
|
return dok?.RozliczanyDok.NrDok ?? string.Empty;
|
|
}
|
|
} |