wip
This commit is contained in:
@@ -5,6 +5,7 @@ using ROLAC.API.Data;
|
||||
using ROLAC.API.DTOs.Giving;
|
||||
using ROLAC.API.DTOs.Shared;
|
||||
using ROLAC.API.Entities;
|
||||
using ROLAC.API.Services.Storage;
|
||||
|
||||
namespace ROLAC.API.Services;
|
||||
|
||||
@@ -12,11 +13,13 @@ public class OfferingSessionService : IOfferingSessionService
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly IHttpContextAccessor _http;
|
||||
private readonly IFileStorage _storage;
|
||||
|
||||
public OfferingSessionService(AppDbContext db, IHttpContextAccessor http)
|
||||
public OfferingSessionService(AppDbContext db, IHttpContextAccessor http, IFileStorage storage)
|
||||
{
|
||||
_db = db;
|
||||
_http = http;
|
||||
_db = db;
|
||||
_http = http;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
private string CurrentUserId =>
|
||||
@@ -48,6 +51,7 @@ public class OfferingSessionService : IOfferingSessionService
|
||||
CashTotal = s.CashTotal, CheckTotal = s.CheckTotal,
|
||||
SystemTotal = s.SystemTotal, Difference = s.Difference,
|
||||
LineCount = counts.TryGetValue(s.Id, out var c) ? c : 0,
|
||||
HasProof = s.ProofPdfPath != null,
|
||||
}).ToList();
|
||||
|
||||
return new PagedResult<OfferingSessionListItemDto>
|
||||
@@ -81,6 +85,7 @@ public class OfferingSessionService : IOfferingSessionService
|
||||
Id = s.Id, SessionDate = s.SessionDate, Status = s.Status,
|
||||
CashTotal = s.CashTotal, CheckTotal = s.CheckTotal,
|
||||
SystemTotal = s.SystemTotal, Difference = s.Difference, Notes = s.Notes,
|
||||
HasProof = s.ProofPdfPath != null,
|
||||
Givings = lines.Select(l => new OfferingGivingLineDto
|
||||
{
|
||||
Id = l.Id, MemberId = l.MemberId,
|
||||
@@ -158,6 +163,41 @@ public class OfferingSessionService : IOfferingSessionService
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// ── Paper-proof PDF (one merged file per session) ────────────────────────
|
||||
|
||||
public async Task SaveProofAsync(int id, Stream content, string fileName)
|
||||
{
|
||||
var s = await _db.OfferingSessions.FindAsync(id)
|
||||
?? throw new KeyNotFoundException($"OfferingSession {id} not found.");
|
||||
|
||||
var path = $"finance/offering-proofs/{s.SessionDate.Year}/{s.SessionDate.Month}/{s.Id}-proof.pdf";
|
||||
if (s.ProofPdfPath != null && s.ProofPdfPath != path)
|
||||
await _storage.DeleteAsync(s.ProofPdfPath);
|
||||
var saved = await _storage.SaveAsync(content, path);
|
||||
s.ProofPdfPath = saved;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<(Stream stream, string contentType)?> OpenProofAsync(int id)
|
||||
{
|
||||
var s = await _db.OfferingSessions.AsNoTracking().FirstOrDefaultAsync(x => x.Id == id)
|
||||
?? throw new KeyNotFoundException($"OfferingSession {id} not found.");
|
||||
if (s.ProofPdfPath is null) return null;
|
||||
var stream = await _storage.OpenReadAsync(s.ProofPdfPath);
|
||||
if (stream is null) return null;
|
||||
return (stream, "application/pdf");
|
||||
}
|
||||
|
||||
public async Task DeleteProofAsync(int id)
|
||||
{
|
||||
var s = await _db.OfferingSessions.FindAsync(id)
|
||||
?? throw new KeyNotFoundException($"OfferingSession {id} not found.");
|
||||
if (s.ProofPdfPath is null) return;
|
||||
await _storage.DeleteAsync(s.ProofPdfPath);
|
||||
s.ProofPdfPath = null;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static Giving MapLine(OfferingGivingLineRequest line, DateOnly sessionDate) => new()
|
||||
{
|
||||
MemberId = line.IsAnonymous ? null : line.MemberId,
|
||||
|
||||
Reference in New Issue
Block a user