LCOV - code coverage report
Current view: top level - lib/_classes/structure - bill_app_data.dart Coverage Total Hit
Test: lcov.info Lines: 70.4 % 54 38
Test Date: 2026-12-05 10:54:13 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2023 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/structure/abstract_app_data.dart';
       5              : import 'package:app_finance/_classes/structure/account_app_data.dart';
       6              : import 'package:app_finance/_classes/structure/budget_app_data.dart';
       7              : import 'package:app_finance/_classes/storage/app_data.dart';
       8              : import 'package:app_finance/_ext/date_time_ext.dart';
       9              : import 'package:app_finance/_mixins/storage_mixin.dart';
      10              : import 'package:material_ui/material_ui.dart';
      11              : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      12              : 
      13              : class BillAppData extends AbstractAppData with StorageMixin {
      14              :   String account;
      15              :   String category;
      16              :   double exchangeAccount;
      17              :   double exchangeCategory;
      18              :   bool hasChild;
      19              :   String? childOf;
      20              :   List<String> tags;
      21              : 
      22            1 :   BillAppData({
      23              :     required this.account,
      24              :     required this.category,
      25              :     super.uuid,
      26              :     super.title = '',
      27              :     super.details,
      28              :     super.currency,
      29              :     super.updatedAt,
      30              :     super.createdAt,
      31              :     super.createdAtFormatted,
      32              :     super.hidden,
      33              :     super.payment,
      34              :     this.exchangeAccount = 1.0,
      35              :     this.exchangeCategory = 1.0,
      36              :     this.hasChild = false,
      37              :     this.childOf,
      38              :     List<String>? tags,
      39            1 :   }) : tags = tags ?? [];
      40              : 
      41            1 :   @override
      42              :   String getClassName() => 'BillAppData';
      43              : 
      44            1 :   @override
      45              :   AppDataType getType() => AppDataType.bills;
      46              : 
      47            1 :   @override
      48              :   BillAppData clone() {
      49            1 :     return BillAppData(
      50            1 :       uuid: super.uuid,
      51            1 :       account: account,
      52            1 :       category: category,
      53            1 :       title: super.title,
      54            1 :       details: super.details,
      55            1 :       currency: super.currency,
      56            1 :       createdAt: super.createdAt,
      57            1 :       hidden: super.hidden,
      58            1 :       payment: super.payment,
      59            1 :       exchangeAccount: exchangeAccount,
      60            1 :       exchangeCategory: exchangeCategory,
      61            1 :       hasChild: hasChild,
      62            1 :       childOf: childOf,
      63            2 :       tags: [...tags],
      64              :     );
      65              :   }
      66              : 
      67            0 :   factory BillAppData.fromJson(Map<String, dynamic> json) {
      68            0 :     return BillAppData(
      69            0 :       uuid: json['uuid'],
      70            0 :       account: json['account'],
      71            0 :       category: json['category'],
      72            0 :       title: json['title'],
      73            0 :       details: 0.0 + json['details'],
      74            0 :       currency: CurrencyProvider.find(json['currency']),
      75            0 :       updatedAt: DateTime.parse(json['updatedAt']),
      76            0 :       createdAt: DateTime.parse(json['createdAt']),
      77            0 :       hidden: json['hidden'],
      78            0 :       payment: json['payment'],
      79            0 :       hasChild: json['hasChild'] ?? false,
      80            0 :       childOf: json['childOf'],
      81            0 :       tags: (json['tags'] as List<dynamic>?)?.cast<String>(),
      82              :     );
      83              :   }
      84              : 
      85            1 :   @override
      86            1 :   Map<String, dynamic> toJson() => {
      87            1 :         ...super.toJson(),
      88            2 :         'account': account,
      89            2 :         'category': category,
      90            2 :         'hasChild': hasChild,
      91            2 :         'childOf': childOf,
      92            2 :         'tags': tags,
      93              :       };
      94              : 
      95            4 :   String get detailsFormatted => (super.details as double).toCurrency(currency: currency, withPattern: false);
      96              : 
      97            1 :   @override
      98              :   String get description {
      99            3 :     AccountAppData? type = getState().getByUuid(account);
     100            5 :     return super.createdAt.monthDay() + (type != null ? ' (${type.title})' : '');
     101              :   }
     102              : 
     103            0 :   String get accountNamed => getState().getByUuid(account)?.title ?? '?';
     104              : 
     105            1 :   @override
     106              :   MaterialColor? get color {
     107            3 :     BudgetAppData? budget = getState().getByUuid(category);
     108            1 :     return budget?.color;
     109              :   }
     110              : 
     111            1 :   @override
     112              :   IconData? get icon {
     113            3 :     BudgetAppData? budget = getState().getByUuid(category);
     114            1 :     return budget?.icon;
     115              :   }
     116              : }
        

Generated by: LCOV version 2.0-1