Fix company logo missing from PDFs and add AI photo save logging

When a tenant uploads a logo it is stored in Azure Blob Storage and
LogoData (the legacy DB byte[]) is cleared. All PDF controllers were
still reading the now-null LogoData, so logos never appeared on any
PDF after upload. Fixed by injecting ICompanyLogoService into all six
affected controllers (Quotes, Invoices, Deposits, GiftCertificates,
PurchaseOrders, CatalogItems) and loading the blob-stored logo first
before falling back to the legacy DB field.

Also added structured logging to the AI photo promotion path in
QuotesController Create/Edit POST so upload failures are visible in
production logs instead of silently swallowed.

Added onclick safety net to the Create and Edit quote submit buttons
so dynamically-injected hidden fields (AiPhotoTempIds) are written
before iOS Safari collects the form data on submit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 12:27:18 -04:00
parent ca4fb959aa
commit a8fb56e8ec
8 changed files with 231 additions and 22 deletions
@@ -27,6 +27,7 @@ public class InvoicesController : Controller
private readonly ITenantContext _tenantContext;
private readonly INotificationService _notificationService;
private readonly IAccountBalanceService _accountBalanceService;
private readonly ICompanyLogoService _logoService;
public InvoicesController(
IUnitOfWork unitOfWork,
@@ -36,7 +37,8 @@ public class InvoicesController : Controller
IPdfService pdfService,
ITenantContext tenantContext,
INotificationService notificationService,
IAccountBalanceService accountBalanceService)
IAccountBalanceService accountBalanceService,
ICompanyLogoService logoService)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
@@ -46,6 +48,7 @@ public class InvoicesController : Controller
_tenantContext = tenantContext;
_notificationService = notificationService;
_accountBalanceService = accountBalanceService;
_logoService = logoService;
}
// -----------------------------------------------------------------------
@@ -1624,8 +1627,9 @@ public class InvoicesController : Controller
DefaultTerms = prefs?.InDefaultTerms
};
var (logoData, logoContentType) = await LoadCompanyLogoAsync(company);
var dto = await BuildInvoiceDtoAsync(invoice);
return await _pdfService.GenerateInvoicePdfAsync(dto, company?.LogoData, company?.LogoContentType, companyInfo, template);
return await _pdfService.GenerateInvoicePdfAsync(dto, logoData, logoContentType, companyInfo, template);
}
// -----------------------------------------------------------------------
@@ -2444,4 +2448,19 @@ public class InvoicesController : Controller
return false;
}
/// <summary>
/// Returns logo bytes and content type for PDF generation.
/// Prefers blob-stored logos (LogoFilePath) over the legacy DB column (LogoData).
/// </summary>
private async Task<(byte[]? LogoData, string? LogoContentType)> LoadCompanyLogoAsync(Company? company)
{
if (company == null) return (null, null);
if (!string.IsNullOrEmpty(company.LogoFilePath))
{
var (ok, content, contentType, _) = await _logoService.GetCompanyLogoAsync(company.LogoFilePath);
if (ok) return (content, contentType);
}
return (company.LogoData, company.LogoContentType);
}
}