Add duplicate invoice detection and warning message
Added a warning message in `Upload.cshtml` to notify users when a duplicate invoice is detected. Introduced the `IsDuplicate` property in `UploadModel` to track duplicates and updated the `OnPostAsync` method to set this property based on the `ImportedAt` timestamp. Enhanced the `ImportAsync` method in `ZugferdImportService` to include duplicate detection by checking the database for invoices with the same `InvoiceNumber` and `SellerTaxId`. If a duplicate is found, it logs a warning and returns the existing invoice. Updated `ImportAsync` to accept an optional `guidelineId` parameter and added logging for duplicate detection and successful imports.
This commit is contained in:
@@ -21,6 +21,7 @@ public class UploadModel(
|
||||
public string? ErrorMessage { get; private set; }
|
||||
public ZugferdInvoice? ImportedInvoice { get; private set; }
|
||||
public string? ResultFilePath { get; private set; }
|
||||
public bool IsDuplicate { get; private set; }
|
||||
|
||||
public void OnGet()
|
||||
{ }
|
||||
@@ -56,10 +57,14 @@ public class UploadModel(
|
||||
if (Result.HasZugferdXml)
|
||||
{
|
||||
memStream.Position = 0;
|
||||
ImportedInvoice = await zugferdImportService.ImportAsync(memStream, "Upload");
|
||||
ImportedInvoice = await zugferdImportService.ImportAsync(memStream, "Upload", Result.ZugferdGuidelineId);
|
||||
|
||||
// 3. Result-Package erstellen (nur wenn Import erfolgreich)
|
||||
if (ImportedInvoice is not null)
|
||||
// Duplikat erkennen: vorhandener Eintrag hat ImportedAt von früher
|
||||
if (ImportedInvoice is not null && ImportedInvoice.ImportedAt < DateTime.UtcNow.AddSeconds(-5))
|
||||
IsDuplicate = true;
|
||||
|
||||
// 3. Result-Package erstellen (nur wenn Import erfolgreich UND kein Duplikat)
|
||||
if (ImportedInvoice is not null && !IsDuplicate)
|
||||
{
|
||||
ResultFilePath = await resultPackageService.CreateResultPackageAsync(
|
||||
originalBytes, PdfFile.FileName, ImportedInvoice);
|
||||
|
||||
Reference in New Issue
Block a user