From d5852f2bb3c17790daa81fb561673c8e267dc257 Mon Sep 17 00:00:00 2001 From: AJ Date: Sun, 12 Oct 2025 17:51:19 -0400 Subject: [PATCH] Add automatic receipt parsing after upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Receipts are now automatically parsed using OpenAI Vision API immediately after upload. The parsing runs in the background and triggers auto-mapping if successful. This streamlines the workflow - users just upload a receipt and it's automatically parsed and mapped to the matching transaction without any additional clicks. The parsing happens asynchronously via Task.Run to not block the upload response. If parsing fails, the upload is still considered successful. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- MoneyMap/Services/ReceiptManager.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/MoneyMap/Services/ReceiptManager.cs b/MoneyMap/Services/ReceiptManager.cs index dd8605a..a6d9c3e 100644 --- a/MoneyMap/Services/ReceiptManager.cs +++ b/MoneyMap/Services/ReceiptManager.cs @@ -27,14 +27,16 @@ namespace MoneyMap.Services private readonly MoneyMapContext _db; private readonly IWebHostEnvironment _environment; private readonly IConfiguration _configuration; + private readonly IServiceProvider _serviceProvider; private const long MaxFileSize = 10 * 1024 * 1024; // 10MB private static readonly string[] AllowedExtensions = { ".jpg", ".jpeg", ".png", ".pdf", ".gif", ".heic" }; - public ReceiptManager(MoneyMapContext db, IWebHostEnvironment environment, IConfiguration configuration) + public ReceiptManager(MoneyMapContext db, IWebHostEnvironment environment, IConfiguration configuration, IServiceProvider serviceProvider) { _db = db; _environment = environment; _configuration = configuration; + _serviceProvider = serviceProvider; } private string GetReceiptsBasePath() @@ -128,6 +130,21 @@ namespace MoneyMap.Services _db.Receipts.Add(receipt); await _db.SaveChangesAsync(); + // Automatically parse the receipt after upload (in background, don't wait for result) + _ = Task.Run(async () => + { + try + { + using var scope = _serviceProvider.CreateScope(); + var parser = scope.ServiceProvider.GetRequiredService(); + await parser.ParseReceiptAsync(receipt.Id); + } + catch + { + // Silently fail - upload was successful, parsing is optional + } + }); + return ReceiptUploadResult.Success(receipt, duplicateWarnings); }