QR-Scanner: Kamera-Fallbacks und Foto-Upload; weitere Aenderungen
This commit is contained in:
1 parent
7a0406eaa2
commit
e2aef67099
13 files changed
+965
-58
No files matched your search
@@ -16,7 +16,6 @@ public class LexwareSyncResult
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public int CustomersCreated { get; set; }
|
||||
public int CustomersUpdated { get; set; }
|
||||
public int CustomersDeactivated { get; set; }
|
||||
public int TotalProcessed { get; set; }
|
||||
}
|
||||
|
||||
@@ -324,9 +323,6 @@ public class LexwareSyncService : ILexwareSyncService
|
||||
if (existing.Email != email) { existing.Email = email; changed = true; }
|
||||
if (existing.Notes != notes) { existing.Notes = notes; changed = true; }
|
||||
|
||||
// Reactivate if previously deactivated
|
||||
if (!existing.IsActive) { existing.IsActive = true; changed = true; }
|
||||
|
||||
if (changed)
|
||||
{
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
@@ -357,36 +353,17 @@ public class LexwareSyncService : ILexwareSyncService
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Deactivate customers not found in Lexware (Lexware is single source of truth)
|
||||
var lexwareCustomerNumbers = allContacts
|
||||
.Select(c => c.Roles?.Customer?.Number?.ToString())
|
||||
.Where(n => !string.IsNullOrEmpty(n))
|
||||
.ToHashSet();
|
||||
|
||||
var customersToDeactivate = await _context.Customers
|
||||
.Where(c => c.IsActive && !string.IsNullOrEmpty(c.CustomerNumber) && !lexwareCustomerNumbers.Contains(c.CustomerNumber))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var customer in customersToDeactivate)
|
||||
{
|
||||
customer.IsActive = false;
|
||||
customer.UpdatedAt = DateTime.UtcNow;
|
||||
result.CustomersDeactivated++;
|
||||
_logger.LogWarning("Customer {CustomerNumber} ({Name}) deactivated - not found in Lexware",
|
||||
customer.CustomerNumber, customer.FullName);
|
||||
}
|
||||
|
||||
if (customersToDeactivate.Count > 0)
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
// Note: customers not present in Lexware are intentionally left untouched.
|
||||
// The local IsActive flag is managed exclusively within this application.
|
||||
|
||||
// Update sync timestamp
|
||||
settings.LastSyncAt = DateTime.UtcNow;
|
||||
settings.LastSyncCount = result.TotalProcessed;
|
||||
settings.LastSyncResult = $"{result.CustomersCreated} erstellt, {result.CustomersUpdated} aktualisiert, {result.CustomersDeactivated} deaktiviert";
|
||||
settings.LastSyncResult = $"{result.CustomersCreated} erstellt, {result.CustomersUpdated} aktualisiert";
|
||||
await _siteSettingsService.SaveLexwareApiSettingsAsync(settings);
|
||||
|
||||
result.Success = true;
|
||||
result.Message = $"Synchronisierung erfolgreich: {result.CustomersCreated} erstellt, {result.CustomersUpdated} aktualisiert, {result.CustomersDeactivated} deaktiviert ({result.TotalProcessed} verarbeitet)";
|
||||
result.Message = $"Synchronisierung erfolgreich: {result.CustomersCreated} erstellt, {result.CustomersUpdated} aktualisiert ({result.TotalProcessed} verarbeitet)";
|
||||
|
||||
_logger.LogInformation("Lexware sync completed: {Message}", result.Message);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user