Add support for invoice attachments
Introduced the `InvoiceAttachment` entity and its relationship with `ZugferdInvoice` to manage extracted invoice attachments. Updated `AppDbContext` and added a migration to create the `InvoiceAttachments` table with cascading delete behavior and an index for optimized queries. Enhanced the UI to display attachments in `Details.cshtml`, including file type icons, file size, and extraction date. Added a new `ViewAttachment` page to render or download attachments based on their type, with support for XML, plain text, images, and downloads. Implemented `AttachmentViewerService` to determine viewer types and MIME types for attachments. Registered the service in the DI container. Updated `Upload.cshtml.cs` to save extracted attachments to the database. Improved user experience with syntax highlighting for XML files and appropriate messages for unsupported file types.
This commit is contained in:
@@ -75,6 +75,29 @@ public class UploadModel(
|
||||
ImportedInvoice.ResultFilePath = ResultFilePath;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// 4. Attachments in DB speichern
|
||||
if (Result.HasAttachments)
|
||||
{
|
||||
foreach (var attachment in Result.Attachments)
|
||||
{
|
||||
var invoiceAttachment = new InvoiceAttachment
|
||||
{
|
||||
ZugferdInvoiceId = ImportedInvoice.Id,
|
||||
OriginalFileName = attachment.OriginalFileName,
|
||||
SavedFilePath = attachment.SavedFilePath,
|
||||
FileSizeBytes = attachment.FileSizeBytes,
|
||||
IsZugferdXml = attachment.IsZugferdXml,
|
||||
ExtractedAt = DateTime.UtcNow
|
||||
};
|
||||
db.InvoiceAttachments.Add(invoiceAttachment);
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
logger.LogInformation(
|
||||
"Rechnung '{InvoiceNumber}': {Count} Anhang/Anhänge in DB gespeichert.",
|
||||
ImportedInvoice.InvoiceNumber, Result.Attachments.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user