From 1788e7f184aab45c01545f9eceb6c68585a2951f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 20 Jul 2025 18:14:03 +0200 Subject: [PATCH] Can disable dates extraction --- moneymgr_mobile/lib/routes/scan/scan_screen.dart | 8 +++++++- .../lib/routes/settings/settings_screen.dart | 13 +++++++++++++ moneymgr_mobile/lib/services/storage/prefs.dart | 8 ++++++++ moneymgr_mobile/lib/utils/ocr_utils.dart | 9 +++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/moneymgr_mobile/lib/routes/scan/scan_screen.dart b/moneymgr_mobile/lib/routes/scan/scan_screen.dart index 884ef21..f4d97ed 100644 --- a/moneymgr_mobile/lib/routes/scan/scan_screen.dart +++ b/moneymgr_mobile/lib/routes/scan/scan_screen.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:logging/logging.dart'; import 'package:moneymgr_mobile/services/storage/expenses.dart'; +import 'package:moneymgr_mobile/services/storage/prefs.dart'; import 'package:moneymgr_mobile/utils/ocr_utils.dart'; import 'package:moneymgr_mobile/utils/pdf_utils.dart'; import 'package:moneymgr_mobile/widgets/expense_editor.dart'; @@ -14,9 +15,14 @@ part 'scan_screen.g.dart'; /// Scan a document & return generated PDF as byte file @riverpod Future<(Uint8List?, BaseExpenseInfo?)> _scanDocument(Ref ref) async { + final prefs = ref.watch(prefsProvider).requireValue; + final pdf = await scanDocAsPDF(); final img = await renderPdf(pdfBytes: pdf); - final amount = await extractInfoFromBill(img); + final amount = await extractInfoFromBill( + imgBuff: img, + extractDates: !prefs.disableExtractDates(), + ); return (pdf, amount); } diff --git a/moneymgr_mobile/lib/routes/settings/settings_screen.dart b/moneymgr_mobile/lib/routes/settings/settings_screen.dart index 3e1c796..14eed7c 100644 --- a/moneymgr_mobile/lib/routes/settings/settings_screen.dart +++ b/moneymgr_mobile/lib/routes/settings/settings_screen.dart @@ -22,6 +22,11 @@ class SettingsScreen extends ConsumerWidget { ref.invalidate(prefsProvider); } + handleToggleDisableExtractDate(v) async { + await prefs.setDisableExtractDates(v); + ref.invalidate(prefsProvider); + } + return Scaffold( appBar: AppBar(title: const Text('Settings')), body: ListView( @@ -40,6 +45,14 @@ class SettingsScreen extends ConsumerWidget { "Do not start camera automatically on application startup", ), ), + SwitchListTile( + value: prefs.disableExtractDates(), + onChanged: handleToggleDisableExtractDate, + title: Text("Do not extract dates"), + subtitle: Text( + "Do not attempt to extract dates from scanned expenses", + ), + ), const Divider(), ListTile( leading: const Icon(Icons.info_outline), diff --git a/moneymgr_mobile/lib/services/storage/prefs.dart b/moneymgr_mobile/lib/services/storage/prefs.dart index 372c3f5..0f05c82 100644 --- a/moneymgr_mobile/lib/services/storage/prefs.dart +++ b/moneymgr_mobile/lib/services/storage/prefs.dart @@ -23,6 +23,14 @@ extension MoneyMgrSharedPreferences on SharedPreferencesWithCache { await setBool("startOnScansListScreen", start); } + bool disableExtractDates() { + return getBool("disableExtractDates") ?? false; + } + + Future setDisableExtractDates(bool disable) async { + await setBool("disableExtractDates", disable); + } + ServerConfig? serverConfig() { final json = getString("serverConfig"); if (json != null) return ServerConfig.fromJson(jsonDecode(json)); diff --git a/moneymgr_mobile/lib/utils/ocr_utils.dart b/moneymgr_mobile/lib/utils/ocr_utils.dart index f454f3c..175abfa 100644 --- a/moneymgr_mobile/lib/utils/ocr_utils.dart +++ b/moneymgr_mobile/lib/utils/ocr_utils.dart @@ -8,7 +8,10 @@ import 'package:logging/logging.dart'; import 'package:moneymgr_mobile/services/storage/expenses.dart'; /// Attempt to extract information from invoice image -Future extractInfoFromBill(Uint8List imgBuff) async { +Future extractInfoFromBill({ + required Uint8List imgBuff, + required bool extractDates, +}) async { final decodedImage = await decodeImageFromList(imgBuff); final byteData = await decodedImage.toByteData( @@ -74,6 +77,8 @@ Future extractInfoFromBill(Uint8List imgBuff) async { return BaseExpenseInfo( label: null, cost: highestCost, - time: newest?.isBefore(currDate) ?? false ? newest! : currDate, + time: extractDates && (newest?.isBefore(currDate) ?? false) + ? newest! + : currDate, ); }