Compare commits
92 Commits
1.0.4
...
a98ed8b2ce
Author | SHA1 | Date | |
---|---|---|---|
a98ed8b2ce | |||
d57107cfc1 | |||
68a3eb4218 | |||
514f140527 | |||
4bac50b676 | |||
884b86daa9 | |||
64365916bd | |||
77c0640ec0 | |||
96c80eb18c | |||
0cde9f5635 | |||
5e35dae02f | |||
f321376990 | |||
86b86d4d68 | |||
35c629a339 | |||
da0d5adcb9 | |||
2214387010 | |||
667ce69be8 | |||
57f4ed53f6 | |||
deb884a1f0 | |||
0e5d878e30 | |||
b266cbcadb | |||
91bca2b6b1 | |||
a741662251 | |||
34f0493c51 | |||
b538b6fcb3 | |||
9d18d975d0 | |||
43049bc229 | |||
19ca17b43a | |||
572046f418 | |||
24af473dd3 | |||
8a57c57ec4 | |||
50a5e7745f | |||
675e4d9ecd | |||
83c214af7d | |||
bfa6af5749 | |||
6ab157504c | |||
bb98ea5e46 | |||
2d104a54b5 | |||
3b0ff29bc8 | |||
4ade72a0ee | |||
6021b44a13 | |||
eb92e8c0c5 | |||
d98305908c | |||
ae5ef99e3a | |||
2f592183e4 | |||
74291a258c | |||
df8cd6a046 | |||
079fbbf154 | |||
ba443629e6 | |||
2c07a69b90 | |||
0de551f1de | |||
2488ef0125 | |||
aa2e764262 | |||
1202219e98 | |||
112597084c | |||
4f64404ffa | |||
c39b53c721 | |||
bd2e343601 | |||
85ee2b2549 | |||
154551aeaf | |||
7b10c3508a | |||
61c96629a1 | |||
8644075a09 | |||
81bfa75eec | |||
de0dd4e36a | |||
f9d7a63738 | |||
0ef6f8288f | |||
2f23e4dadb | |||
5cf5fac8f4 | |||
8e143db354 | |||
1237c9706e | |||
1add0b4cfe | |||
6920d6d9b0 | |||
27e92660f1 | |||
743e5ba410 | |||
8039b1c807 | |||
9ef84ba63a | |||
56e5ae6629 | |||
4443131516 | |||
365d7589b1 | |||
23cc189e53 | |||
3098d12e8a | |||
0943104cc8 | |||
3beaba806a | |||
1788e7f184 | |||
71d32d72ef | |||
28f61a3099 | |||
f61e3541fb | |||
fb7891d913 | |||
d9ede224cf | |||
fc9334b20b | |||
c4cbd7ec8b |
@@ -12,7 +12,7 @@ steps:
|
|||||||
|
|
||||||
# Frontend
|
# Frontend
|
||||||
- name: web_build
|
- name: web_build
|
||||||
image: node:23
|
image: node:24
|
||||||
depends_on:
|
depends_on:
|
||||||
- fetch
|
- fetch
|
||||||
volumes:
|
volumes:
|
||||||
|
34
moneymgr_backend/Cargo.lock
generated
34
moneymgr_backend/Cargo.lock
generated
@@ -36,9 +36,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-files"
|
name = "actix-files"
|
||||||
version = "0.6.6"
|
version = "0.6.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0773d59061dedb49a8aed04c67291b9d8cf2fe0b60130a381aab53c6dd86e9be"
|
checksum = "22c8b5536deb14cd9c3e505bd0e3366e1a12383b659c92f2b4fa4d323d583599"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-http",
|
"actix-http",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
@@ -46,7 +46,7 @@ dependencies = [
|
|||||||
"actix-web",
|
"actix-web",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"bytes",
|
"bytes",
|
||||||
"derive_more 0.99.20",
|
"derive_more 2.0.1",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"http-range",
|
"http-range",
|
||||||
"log",
|
"log",
|
||||||
@@ -87,7 +87,7 @@ dependencies = [
|
|||||||
"mime",
|
"mime",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rand 0.9.1",
|
"rand 0.9.2",
|
||||||
"sha1",
|
"sha1",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -431,9 +431,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.98"
|
version = "1.0.99"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arbitrary"
|
name = "arbitrary"
|
||||||
@@ -724,9 +724,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.41"
|
version = "4.5.47"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9"
|
checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
@@ -734,9 +734,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.41"
|
version = "4.5.47"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d"
|
checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@@ -746,9 +746,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.41"
|
version = "4.5.47"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
|
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -2298,7 +2298,7 @@ dependencies = [
|
|||||||
"light-openid",
|
"light-openid",
|
||||||
"log",
|
"log",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"rand 0.9.1",
|
"rand 0.9.2",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"rust-s3",
|
"rust-s3",
|
||||||
"rust_xlsxwriter",
|
"rust_xlsxwriter",
|
||||||
@@ -2741,9 +2741,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.9.1"
|
version = "0.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_chacha 0.9.0",
|
"rand_chacha 0.9.0",
|
||||||
"rand_core 0.9.3",
|
"rand_core 0.9.3",
|
||||||
@@ -3232,9 +3232,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.140"
|
version = "1.0.142"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@@ -8,23 +8,23 @@ env_logger = "0.11.8"
|
|||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
diesel = { version = "2.2.12", features = ["postgres", "r2d2"] }
|
diesel = { version = "2.2.12", features = ["postgres", "r2d2"] }
|
||||||
diesel_migrations = "2.2.0"
|
diesel_migrations = "2.2.0"
|
||||||
clap = { version = "4.5.41", features = ["env", "derive"] }
|
clap = { version = "4.5.47", features = ["env", "derive"] }
|
||||||
actix-web = "4.11.0"
|
actix-web = "4.11.0"
|
||||||
actix-cors = "0.7.1"
|
actix-cors = "0.7.1"
|
||||||
actix-multipart = "0.7.2"
|
actix-multipart = "0.7.2"
|
||||||
actix-remote-ip = "0.1.0"
|
actix-remote-ip = "0.1.0"
|
||||||
actix-session = { version = "0.10.1", features = ["redis-session"] }
|
actix-session = { version = "0.10.1", features = ["redis-session"] }
|
||||||
actix-files = "0.6.6"
|
actix-files = "0.6.7"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
anyhow = "1.0.98"
|
anyhow = "1.0.99"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
rust-s3 = "0.36.0-beta.2"
|
rust-s3 = "0.36.0-beta.2"
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
tokio = "1.45.1"
|
tokio = "1.45.1"
|
||||||
futures-util = "0.3.31"
|
futures-util = "0.3.31"
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.142"
|
||||||
light-openid = "1.0.4"
|
light-openid = "1.0.4"
|
||||||
rand = "0.9.1"
|
rand = "0.9.2"
|
||||||
ipnet = { version = "2.11.0", features = ["serde"] }
|
ipnet = { version = "2.11.0", features = ["serde"] }
|
||||||
lazy-regex = "3.4.1"
|
lazy-regex = "3.4.1"
|
||||||
jwt-simple = { version = "0.12.12", default-features = false, features = ["pure-rust"] }
|
jwt-simple = { version = "0.12.12", default-features = false, features = ["pure-rust"] }
|
||||||
|
@@ -29,7 +29,7 @@ pub struct AppConfig {
|
|||||||
/// Unsecure : for development, bypass authentication, using the account with the given
|
/// Unsecure : for development, bypass authentication, using the account with the given
|
||||||
/// email address by default
|
/// email address by default
|
||||||
#[clap(long, env)]
|
#[clap(long, env)]
|
||||||
pub unsecure_auto_login_email: Option<String>,
|
unsecure_auto_login_email: Option<String>,
|
||||||
|
|
||||||
/// PostgreSQL database host
|
/// PostgreSQL database host
|
||||||
#[clap(long, env, default_value = "localhost")]
|
#[clap(long, env, default_value = "localhost")]
|
||||||
@@ -126,6 +126,14 @@ pub struct AppConfig {
|
|||||||
/// Redis password
|
/// Redis password
|
||||||
#[clap(long, env, default_value = "secretredis")]
|
#[clap(long, env, default_value = "secretredis")]
|
||||||
redis_password: String,
|
redis_password: String,
|
||||||
|
|
||||||
|
/// Application download URL
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
env,
|
||||||
|
default_value = "https://gitea.communiquons.org/pierre/MoneyMgr/releases/download/latest/moneymgr_mobile_arm64-v8a.apk"
|
||||||
|
)]
|
||||||
|
pub apk_download_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
@@ -140,9 +148,17 @@ impl AppConfig {
|
|||||||
&ARGS
|
&ARGS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get auto login email (if not empty)
|
||||||
|
pub fn unsecure_auto_login_email(&self) -> Option<&str> {
|
||||||
|
match self.unsecure_auto_login_email.as_deref() {
|
||||||
|
None | Some("") => None,
|
||||||
|
s => s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if auth is disabled
|
/// Check if auth is disabled
|
||||||
pub fn is_auth_disabled(&self) -> bool {
|
pub fn is_auth_disabled(&self) -> bool {
|
||||||
self.unsecure_auto_login_email.is_some()
|
self.unsecure_auto_login_email().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get auth cookie domain
|
/// Get auth cookie domain
|
||||||
|
@@ -70,6 +70,7 @@ impl Default for ServerConstraints {
|
|||||||
struct ServerConfig {
|
struct ServerConfig {
|
||||||
auth_disabled: bool,
|
auth_disabled: bool,
|
||||||
oidc_provider_name: &'static str,
|
oidc_provider_name: &'static str,
|
||||||
|
apk_download_url: &'static str,
|
||||||
accounts_types: &'static [AccountTypeDesc],
|
accounts_types: &'static [AccountTypeDesc],
|
||||||
constraints: ServerConstraints,
|
constraints: ServerConstraints,
|
||||||
}
|
}
|
||||||
@@ -79,6 +80,7 @@ impl Default for ServerConfig {
|
|||||||
Self {
|
Self {
|
||||||
auth_disabled: AppConfig::get().is_auth_disabled(),
|
auth_disabled: AppConfig::get().is_auth_disabled(),
|
||||||
oidc_provider_name: AppConfig::get().openid_provider().name,
|
oidc_provider_name: AppConfig::get().openid_provider().name,
|
||||||
|
apk_download_url: AppConfig::get().apk_download_url.as_str(),
|
||||||
constraints: Default::default(),
|
constraints: Default::default(),
|
||||||
accounts_types: &ACCOUNT_TYPES,
|
accounts_types: &ACCOUNT_TYPES,
|
||||||
}
|
}
|
||||||
|
@@ -182,7 +182,7 @@ impl FromRequest for AuthExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if login is hard-coded as program argument
|
// Check if login is hard-coded as program argument
|
||||||
if let Some(email) = &AppConfig::get().unsecure_auto_login_email {
|
if let Some(email) = &AppConfig::get().unsecure_auto_login_email() {
|
||||||
let user = users_service::get_user_by_email(email).map_err(|e| {
|
let user = users_service::get_user_by_email(email).map_err(|e| {
|
||||||
log::error!("Failed to retrieve dev user: {e}");
|
log::error!("Failed to retrieve dev user: {e}");
|
||||||
ErrorPreconditionFailed("Unable to retrieve dev user!")
|
ErrorPreconditionFailed("Unable to retrieve dev user!")
|
||||||
|
@@ -38,7 +38,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
db_connection::initialize_conn().expect("Failed to connect to PostgresSQL database!");
|
db_connection::initialize_conn().expect("Failed to connect to PostgresSQL database!");
|
||||||
|
|
||||||
// Auto create default account, if requested
|
// Auto create default account, if requested
|
||||||
if let Some(mail) = &AppConfig::get().unsecure_auto_login_email {
|
if let Some(mail) = &AppConfig::get().unsecure_auto_login_email() {
|
||||||
users_service::create_or_update_user(mail, "Anonymous")
|
users_service::create_or_update_user(mail, "Anonymous")
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create default account!");
|
.expect("Failed to create default account!");
|
||||||
|
@@ -1,45 +1,31 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:moneymgr_mobile/services/router/routes_list.dart';
|
||||||
import 'package:moneymgr_mobile/services/storage/expenses.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';
|
import 'package:moneymgr_mobile/widgets/expense_editor.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
import 'package:scanbot_sdk/scanbot_sdk.dart';
|
|
||||||
import 'package:scanbot_sdk/scanbot_sdk_ui_v2.dart' hide IconButton, EdgeInsets;
|
|
||||||
|
|
||||||
part 'scan_screen.g.dart';
|
part 'scan_screen.g.dart';
|
||||||
|
|
||||||
/// Scan a document & return generated PDF as byte file
|
/// Scan a document & return generated PDF as byte file
|
||||||
@riverpod
|
@riverpod
|
||||||
Future<Uint8List?> _scanDocument(Ref ref) async {
|
Future<(Uint8List?, BaseExpenseInfo?)> _scanDocument(Ref ref) async {
|
||||||
var configuration = DocumentScanningFlow(
|
final prefs = ref.watch(prefsProvider).requireValue;
|
||||||
appearance: DocumentFlowAppearanceConfiguration(
|
|
||||||
statusBarMode: StatusBarMode.DARK,
|
|
||||||
),
|
|
||||||
cleanScanningSession: true,
|
|
||||||
outputSettings: DocumentScannerOutputSettings(pagesScanLimit: 1),
|
|
||||||
screens: DocumentScannerScreens(
|
|
||||||
review: ReviewScreenConfiguration(enabled: false),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
var documentResult = await ScanbotSdkUiV2.startDocumentScanner(configuration);
|
|
||||||
|
|
||||||
if (documentResult.status != OperationStatus.OK) {
|
final pdf = await scanDocAsPDF();
|
||||||
throw Exception("Scanner failed with status ${documentResult.status}");
|
final img = await renderPdf(pdfBytes: pdf);
|
||||||
}
|
final amount = await extractInfoFromBill(
|
||||||
|
imgBuff: img,
|
||||||
// Convert result to PDF
|
extractDates: !prefs.disableExtractDates(),
|
||||||
var result = await ScanbotSdk.document.createPDFForDocument(
|
|
||||||
PDFFromDocumentParams(
|
|
||||||
documentID: documentResult.data!.uuid,
|
|
||||||
pdfConfiguration: PdfConfiguration(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
final pdfPath = result.pdfFileUri.replaceFirst("file://", "");
|
return (pdf, amount);
|
||||||
return File(pdfPath).readAsBytes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScanScreen extends HookConsumerWidget {
|
class ScanScreen extends HookConsumerWidget {
|
||||||
@@ -52,8 +38,8 @@ class ScanScreen extends HookConsumerWidget {
|
|||||||
|
|
||||||
restartScan() async {
|
restartScan() async {
|
||||||
try {
|
try {
|
||||||
final val = ref.refresh(_scanDocumentProvider);
|
ref.invalidate(_scanDocumentProvider);
|
||||||
Logger.root.info("Load again startup result: $val");
|
Logger.root.info("Load again startup");
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logger.root.shout("Failed to try again startup loading! $e $s");
|
Logger.root.shout("Failed to try again startup loading! $e $s");
|
||||||
}
|
}
|
||||||
@@ -62,21 +48,24 @@ class ScanScreen extends HookConsumerWidget {
|
|||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: switch (scanDocProvider) {
|
child: switch (scanDocProvider) {
|
||||||
AsyncData(:final value) when value != null => ExpenseEditor(
|
AsyncData(:final value) when value.$1 != null => ExpenseEditor(
|
||||||
file: value,
|
file: value.$1!,
|
||||||
|
initialData: value.$2,
|
||||||
onFinished: (expense) async {
|
onFinished: (expense) async {
|
||||||
await expenses.add(
|
await expenses.add(
|
||||||
info: expense,
|
info: expense,
|
||||||
fileContent: value,
|
fileContent: value.$1!,
|
||||||
fileMimeType: "application/pdf",
|
fileMimeType: "application/pdf",
|
||||||
);
|
);
|
||||||
restartScan();
|
if (context.mounted) {
|
||||||
|
context.pushReplacement(scansPage);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onRescan: restartScan,
|
onRescan: restartScan,
|
||||||
),
|
),
|
||||||
|
|
||||||
// No data
|
// No data
|
||||||
AsyncData(:final value) when value == null => ScanErrorScreen(
|
AsyncData(:final value) when value.$1 == null => ScanErrorScreen(
|
||||||
message: "No document scanned!",
|
message: "No document scanned!",
|
||||||
onTryAgain: restartScan,
|
onTryAgain: restartScan,
|
||||||
),
|
),
|
||||||
|
@@ -22,6 +22,11 @@ class SettingsScreen extends ConsumerWidget {
|
|||||||
ref.invalidate(prefsProvider);
|
ref.invalidate(prefsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleToggleDisableExtractDate(v) async {
|
||||||
|
await prefs.setDisableExtractDates(v);
|
||||||
|
ref.invalidate(prefsProvider);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text('Settings')),
|
appBar: AppBar(title: const Text('Settings')),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
@@ -40,6 +45,14 @@ class SettingsScreen extends ConsumerWidget {
|
|||||||
"Do not start camera automatically on application startup",
|
"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(),
|
const Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.info_outline),
|
leading: const Icon(Icons.info_outline),
|
||||||
|
@@ -23,6 +23,14 @@ extension MoneyMgrSharedPreferences on SharedPreferencesWithCache {
|
|||||||
await setBool("startOnScansListScreen", start);
|
await setBool("startOnScansListScreen", start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool disableExtractDates() {
|
||||||
|
return getBool("disableExtractDates") ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setDisableExtractDates(bool disable) async {
|
||||||
|
await setBool("disableExtractDates", disable);
|
||||||
|
}
|
||||||
|
|
||||||
ServerConfig? serverConfig() {
|
ServerConfig? serverConfig() {
|
||||||
final json = getString("serverConfig");
|
final json = getString("serverConfig");
|
||||||
if (json != null) return ServerConfig.fromJson(jsonDecode(json));
|
if (json != null) return ServerConfig.fromJson(jsonDecode(json));
|
||||||
|
86
moneymgr_mobile/lib/utils/ocr_utils.dart
Normal file
86
moneymgr_mobile/lib/utils/ocr_utils.dart
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:moneymgr_mobile/services/storage/expenses.dart';
|
||||||
|
|
||||||
|
/// Attempt to extract information from invoice image
|
||||||
|
Future<BaseExpenseInfo?> extractInfoFromBill({
|
||||||
|
required Uint8List imgBuff,
|
||||||
|
required bool extractDates,
|
||||||
|
}) async {
|
||||||
|
final decodedImage = await decodeImageFromList(imgBuff);
|
||||||
|
|
||||||
|
final byteData = await decodedImage.toByteData(
|
||||||
|
format: ui.ImageByteFormat.rawRgba,
|
||||||
|
);
|
||||||
|
|
||||||
|
final image = InputImage.fromBitmap(
|
||||||
|
bitmap: byteData!.buffer.asUint8List(),
|
||||||
|
width: decodedImage.width,
|
||||||
|
height: decodedImage.height,
|
||||||
|
);
|
||||||
|
|
||||||
|
final textRecognizer = TextRecognizer(script: TextRecognitionScript.latin);
|
||||||
|
final extractionResult = await textRecognizer.processImage(image);
|
||||||
|
|
||||||
|
Logger.root.fine("Expense text: ${extractionResult.text}");
|
||||||
|
|
||||||
|
// Check for highestCost amount on invoice
|
||||||
|
final costRegexp = RegExp(
|
||||||
|
r'([0-9]+([ ]*(\\.|,)[ ]*[0-9]{1,2}){0,1})([ \\t\\n]*(EUR|eur|€)|E)',
|
||||||
|
multiLine: true,
|
||||||
|
caseSensitive: false,
|
||||||
|
);
|
||||||
|
var highestCost = 0.0;
|
||||||
|
for (final match in costRegexp.allMatches(extractionResult.text)) {
|
||||||
|
if (match.groupCount == 0) continue;
|
||||||
|
|
||||||
|
// Process only numeric value
|
||||||
|
final value = (match.group(1) ?? "").replaceAll(",", ".");
|
||||||
|
highestCost = max(highestCost, double.tryParse(value) ?? 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for highestCost amount on invoice
|
||||||
|
final dateRegexp = RegExp(
|
||||||
|
r'([0-3][0-9])(\/|-)([0-1][0-9])(\/|-)((20|)[0-9]{2})',
|
||||||
|
multiLine: false,
|
||||||
|
caseSensitive: false,
|
||||||
|
);
|
||||||
|
final currDate = DateTime.now();
|
||||||
|
DateTime? newest;
|
||||||
|
for (final match in dateRegexp.allMatches(extractionResult.text)) {
|
||||||
|
if (match.groupCount < 6) continue;
|
||||||
|
|
||||||
|
int year = int.tryParse(match.group(5)!) ?? currDate.year;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final date = DateTime(
|
||||||
|
year > 99 ? year : (2000 + year),
|
||||||
|
int.tryParse(match.group(3)!) ?? currDate.month,
|
||||||
|
int.tryParse(match.group(1)!) ?? currDate.day,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newest == null) {
|
||||||
|
newest = date;
|
||||||
|
} else {
|
||||||
|
newest = DateTime.fromMillisecondsSinceEpoch(
|
||||||
|
max(newest.millisecondsSinceEpoch, date.millisecondsSinceEpoch),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
Logger.root.warning("Failed to parse date! $e$s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseExpenseInfo(
|
||||||
|
label: null,
|
||||||
|
cost: highestCost,
|
||||||
|
time: extractDates && (newest?.isBefore(currDate) ?? false)
|
||||||
|
? newest!
|
||||||
|
: currDate,
|
||||||
|
);
|
||||||
|
}
|
@@ -6,14 +6,40 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:pdf_image_renderer/pdf_image_renderer.dart';
|
import 'package:pdf_image_renderer/pdf_image_renderer.dart';
|
||||||
|
import 'package:scanbot_sdk/scanbot_sdk.dart';
|
||||||
|
import 'package:scanbot_sdk/scanbot_sdk_ui_v2.dart' hide IconButton, EdgeInsets;
|
||||||
|
|
||||||
|
/// Scan document as PDF
|
||||||
|
Future<Uint8List> scanDocAsPDF() async {
|
||||||
|
var configuration = DocumentScanningFlow(
|
||||||
|
appearance: DocumentFlowAppearanceConfiguration(
|
||||||
|
statusBarMode: StatusBarMode.DARK,
|
||||||
|
),
|
||||||
|
cleanScanningSession: true,
|
||||||
|
outputSettings: DocumentScannerOutputSettings(pagesScanLimit: 1),
|
||||||
|
screens: DocumentScannerScreens(
|
||||||
|
review: ReviewScreenConfiguration(enabled: false),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
var documentResult = await ScanbotSdkUiV2.startDocumentScanner(configuration);
|
||||||
|
|
||||||
|
if (documentResult.status != OperationStatus.OK) {
|
||||||
|
throw Exception("Scanner failed with status ${documentResult.status}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert result to PDF
|
||||||
|
var result = await ScanbotSdk.document.createPDFForDocument(
|
||||||
|
PDFFromDocumentParams(
|
||||||
|
documentID: documentResult.data!.uuid,
|
||||||
|
pdfConfiguration: PdfConfiguration(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final pdfPath = result.pdfFileUri.replaceFirst("file://", "");
|
||||||
|
return File(pdfPath).readAsBytes();
|
||||||
|
}
|
||||||
|
|
||||||
/// Render PDF to image bits
|
/// Render PDF to image bits
|
||||||
Future<Uint8List> renderPdf(
|
Future<Uint8List> renderPdf({String? path, Uint8List? pdfBytes}) async {
|
||||||
{
|
|
||||||
String? path,
|
|
||||||
Uint8List? pdfBytes,
|
|
||||||
}) async {
|
|
||||||
assert(path != null || pdfBytes != null);
|
assert(path != null || pdfBytes != null);
|
||||||
|
|
||||||
// Create temporary file if required
|
// Create temporary file if required
|
||||||
|
@@ -40,6 +40,20 @@ class ExpenseEditor extends HookConsumerWidget {
|
|||||||
|
|
||||||
final (:pending, :snapshot, :hasError) = useAsyncTask();
|
final (:pending, :snapshot, :hasError) = useAsyncTask();
|
||||||
|
|
||||||
|
// Force refresh of field if required
|
||||||
|
final previousData = useState<BaseExpenseInfo?>(null);
|
||||||
|
if (initialData != previousData.value) {
|
||||||
|
previousData.value = initialData;
|
||||||
|
labelController.text = initialData?.label ?? "";
|
||||||
|
costController.text = initialData?.cost.toString() ?? "";
|
||||||
|
timeController.value = initialData?.time ?? DateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear cost value
|
||||||
|
handleClearCost() {
|
||||||
|
costController.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
// Pick a new date
|
// Pick a new date
|
||||||
handlePickDate() async {
|
handlePickDate() async {
|
||||||
final date = await showDatePicker(
|
final date = await showDatePicker(
|
||||||
@@ -94,6 +108,19 @@ class ExpenseEditor extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open invoice in full screen
|
||||||
|
handleFullScreenInvoice() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (c) => Scaffold(
|
||||||
|
appBar: AppBar(title: Text("Expense")),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: PDFViewer(pdfBytes: file, fit: BoxFit.fitWidth),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Expense info"),
|
title: Text("Expense info"),
|
||||||
@@ -125,8 +152,11 @@ class ExpenseEditor extends HookConsumerWidget {
|
|||||||
children: [
|
children: [
|
||||||
// Expense preview
|
// Expense preview
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: handleFullScreenInvoice,
|
||||||
child: PDFViewer(pdfBytes: file, fit: BoxFit.contain),
|
child: PDFViewer(pdfBytes: file, fit: BoxFit.contain),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
|
|
||||||
@@ -137,7 +167,13 @@ class ExpenseEditor extends HookConsumerWidget {
|
|||||||
decimal: true,
|
decimal: true,
|
||||||
signed: false,
|
signed: false,
|
||||||
),
|
),
|
||||||
decoration: const InputDecoration(labelText: 'Cost'),
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Cost',
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
onPressed: handleClearCost,
|
||||||
|
icon: const Icon(Icons.clear),
|
||||||
|
),
|
||||||
|
),
|
||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@@ -488,6 +488,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "16.0.0"
|
version: "16.0.0"
|
||||||
|
google_mlkit_commons:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: google_mlkit_commons
|
||||||
|
sha256: "8f40fbac10685cad4715d11e6a0d86837d9ad7168684dfcad29610282a88e67a"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.11.0"
|
||||||
|
google_mlkit_text_recognition:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: google_mlkit_text_recognition
|
||||||
|
sha256: "96173ad4dd7fd06c660e22ac3f9e9f1798a517fe7e48bee68eeec83853224224"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.15.0"
|
||||||
graphs:
|
graphs:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@@ -49,7 +49,7 @@ dependencies:
|
|||||||
riverpod_annotation: ^2.6.1
|
riverpod_annotation: ^2.6.1
|
||||||
|
|
||||||
# Implement React hooks in Flutter
|
# Implement React hooks in Flutter
|
||||||
flutter_hooks: ^0.21.2
|
flutter_hooks: ^0.21.3+1
|
||||||
|
|
||||||
# Router
|
# Router
|
||||||
go_router: ^16.0.0
|
go_router: ^16.0.0
|
||||||
@@ -84,7 +84,7 @@ dependencies:
|
|||||||
# Document scanner
|
# Document scanner
|
||||||
# flutter_doc_scanner: ^0.0.16 # no bundled support yet
|
# flutter_doc_scanner: ^0.0.16 # no bundled support yet
|
||||||
# https://developers.google.com/ml-kit/tips/installation-paths
|
# https://developers.google.com/ml-kit/tips/installation-paths
|
||||||
scanbot_sdk: ^7.0.0
|
scanbot_sdk: ^7.0.1
|
||||||
|
|
||||||
# Get documents path
|
# Get documents path
|
||||||
path_provider: ^2.1.5
|
path_provider: ^2.1.5
|
||||||
@@ -93,6 +93,9 @@ dependencies:
|
|||||||
# PDF renderer
|
# PDF renderer
|
||||||
pdf_image_renderer: ^1.0.1
|
pdf_image_renderer: ^1.0.1
|
||||||
|
|
||||||
|
# Text extraction
|
||||||
|
google_mlkit_text_recognition: ^0.15.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
@@ -108,7 +111,7 @@ dev_dependencies:
|
|||||||
flutter_launcher_icons: ^0.14.4
|
flutter_launcher_icons: ^0.14.4
|
||||||
|
|
||||||
# Generate source code
|
# Generate source code
|
||||||
build_runner: ^2.5.4
|
build_runner: ^2.6.1
|
||||||
|
|
||||||
# Riverpod code generation
|
# Riverpod code generation
|
||||||
riverpod_generator: ^2.6.5
|
riverpod_generator: ^2.6.5
|
||||||
|
2806
moneymgr_web/package-lock.json
generated
2806
moneymgr_web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -18,32 +18,32 @@
|
|||||||
"@mdi/react": "^1.6.1",
|
"@mdi/react": "^1.6.1",
|
||||||
"@mui/icons-material": "^7.1.2",
|
"@mui/icons-material": "^7.1.2",
|
||||||
"@mui/material": "^7.1.2",
|
"@mui/material": "^7.1.2",
|
||||||
"@mui/x-charts": "^8.8.0",
|
"@mui/x-charts": "^8.10.2",
|
||||||
"@mui/x-data-grid": "^8.8.0",
|
"@mui/x-data-grid": "^8.9.2",
|
||||||
"@mui/x-date-pickers": "^8.8.0",
|
"@mui/x-date-pickers": "^8.9.2",
|
||||||
"date-and-time": "^3.6.0",
|
"date-and-time": "^3.6.0",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.18",
|
||||||
"filesize": "^10.1.6",
|
"filesize": "^10.1.6",
|
||||||
"qrcode.react": "^4.2.0",
|
"qrcode.react": "^4.2.0",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.1",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.1",
|
||||||
"react-router": "^7.6.3",
|
"react-router": "^7.6.3",
|
||||||
"react-router-dom": "^7.6.3",
|
"react-router-dom": "^7.6.3",
|
||||||
"ts-pattern": "^5.7.1"
|
"ts-pattern": "^5.8.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.31.0",
|
"@eslint/js": "^9.33.0",
|
||||||
"@types/react": "^19.1.8",
|
"@types/react": "^19.1.12",
|
||||||
"@types/react-dom": "^19.1.6",
|
"@types/react-dom": "^19.1.9",
|
||||||
"@vitejs/plugin-react": "^4.6.0",
|
"@vitejs/plugin-react": "^4.7.0",
|
||||||
"eslint": "^9.26.0",
|
"eslint": "^9.32.0",
|
||||||
"eslint-plugin-react-dom": "^1.49.0",
|
"eslint-plugin-react-dom": "^1.52.4",
|
||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^00.4.20",
|
"eslint-plugin-react-refresh": "^00.4.20",
|
||||||
"eslint-plugin-react-x": "^1.52.3",
|
"eslint-plugin-react-x": "^1.52.9",
|
||||||
"globals": "^16.3.0",
|
"globals": "^16.3.0",
|
||||||
"typescript": "~5.8.3",
|
"typescript": "~5.8.3",
|
||||||
"typescript-eslint": "^8.32.1",
|
"typescript-eslint": "^8.32.1",
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ import { APIClient } from "./ApiClient";
|
|||||||
export interface ServerConfig {
|
export interface ServerConfig {
|
||||||
auth_disabled: boolean;
|
auth_disabled: boolean;
|
||||||
oidc_provider_name: string;
|
oidc_provider_name: string;
|
||||||
|
apk_download_url: string;
|
||||||
accounts_types: AccountType[];
|
accounts_types: AccountType[];
|
||||||
constraints: ServerConstraints;
|
constraints: ServerConstraints;
|
||||||
}
|
}
|
||||||
|
@@ -280,6 +280,8 @@ function CreatedToken(p: { token: TokenWithSecret }): React.ReactElement {
|
|||||||
The API token was successfully created. Please note the following
|
The API token was successfully created. Please note the following
|
||||||
information as they won't be available next.
|
information as they won't be available next.
|
||||||
<br />
|
<br />
|
||||||
|
API URL : <CopyTextChip text={APIClient.ActualBackendURL()} />
|
||||||
|
<br />
|
||||||
Token ID: <CopyTextChip text={p.token.id.toString()} />
|
Token ID: <CopyTextChip text={p.token.id.toString()} />
|
||||||
<br />
|
<br />
|
||||||
Token value: <CopyTextChip text={p.token.token} />
|
Token value: <CopyTextChip text={p.token.token} />
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { mdiApi, mdiCash } from "@mdi/js";
|
import { mdiApi, mdiCash } from "@mdi/js";
|
||||||
import Icon from "@mdi/react";
|
import Icon from "@mdi/react";
|
||||||
|
import AndroidIcon from "@mui/icons-material/Android";
|
||||||
import CloudDownloadIcon from "@mui/icons-material/CloudDownload";
|
import CloudDownloadIcon from "@mui/icons-material/CloudDownload";
|
||||||
import LogoutIcon from "@mui/icons-material/Logout";
|
import LogoutIcon from "@mui/icons-material/Logout";
|
||||||
import SettingsIcon from "@mui/icons-material/Settings";
|
import SettingsIcon from "@mui/icons-material/Settings";
|
||||||
@@ -10,6 +11,7 @@ import MenuItem from "@mui/material/MenuItem";
|
|||||||
import Toolbar from "@mui/material/Toolbar";
|
import Toolbar from "@mui/material/Toolbar";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import { ServerApi } from "../api/ServerApi";
|
||||||
import { useAuthInfo } from "./BaseAuthenticatedPage";
|
import { useAuthInfo } from "./BaseAuthenticatedPage";
|
||||||
import { DarkThemeButton } from "./DarkThemeButtonWidget";
|
import { DarkThemeButton } from "./DarkThemeButtonWidget";
|
||||||
import { PublicModeButton } from "./PublicModeButtonWidget";
|
import { PublicModeButton } from "./PublicModeButtonWidget";
|
||||||
@@ -100,6 +102,18 @@ export function MoneyWebAppBar(p: {
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
|
|
||||||
|
{/* APK download */}
|
||||||
|
<RouterLink to={ServerApi.Config.apk_download_url}>
|
||||||
|
<MenuItem>
|
||||||
|
<ListItemIcon>
|
||||||
|
<AndroidIcon />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText secondary="Scan expenses from your smartphone">
|
||||||
|
Mobile Application
|
||||||
|
</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
</RouterLink>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
{/* Sign out */}
|
{/* Sign out */}
|
||||||
|
Reference in New Issue
Block a user