Line data Source code
1 : // Copyright 2026 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/math/budget_prediction.dart';
5 : import 'package:app_finance/_classes/structure/bill_app_data.dart';
6 : import 'package:app_finance/_classes/structure/interface_app_data.dart';
7 : import 'package:app_finance/_classes/structure/invoice_app_data.dart';
8 : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
9 :
10 : typedef IntegrationImportResult = ({int added, int skipped, int pending});
11 :
12 : class IntegrationRecord {
13 0 : static InterfaceAppData toAppData({
14 : required double amount,
15 : required String? currency,
16 : required DateTime date,
17 : required String title,
18 : required String account,
19 : required String category,
20 : BudgetPrediction? prediction,
21 : }) {
22 0 : final code = currency != null ? CurrencyProvider.find(currency) : null;
23 0 : if (amount < 0) {
24 0 : final bill = BillAppData(
25 : account: account,
26 : category: category,
27 : title: title,
28 0 : details: amount.abs(),
29 : currency: code,
30 : createdAt: date,
31 : updatedAt: date,
32 : hidden: false,
33 : );
34 0 : final categories = prediction?.predict(bill) ?? const [];
35 0 : if (categories.isNotEmpty) {
36 0 : bill.category = categories.first;
37 : }
38 : return bill;
39 : }
40 0 : return InvoiceAppData(
41 : account: account,
42 : title: title,
43 : details: amount,
44 : currency: code,
45 : createdAt: date,
46 : updatedAt: date,
47 : hidden: false,
48 : );
49 : }
50 : }
|