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/math/abstract_recalculation.dart'; 5 : import 'package:app_finance/_classes/structure/budget_app_data.dart'; 6 : 7 : class BudgetRecalculation extends AbstractRecalculation { 8 : BudgetAppData change; 9 : BudgetAppData? initial; 10 : 11 1 : BudgetRecalculation({ 12 : required this.change, 13 : this.initial, 14 : }); 15 : 16 1 : @override 17 : double getDelta() { 18 2 : if (initial?.amountLimit == 0 && change.amountLimit > 0) { 19 0 : return (initial?.amount ?? 0.0) / change.amountLimit; 20 4 : } else if (!change.hidden && initial?.hidden == false && change.amountLimit > 0) { 21 0 : return initial!.amountLimit * initial!.progress / change.amountLimit; 22 : } else { 23 : return 0.0; 24 : } 25 : } 26 : 27 1 : BudgetRecalculation updateBudget() { 28 3 : change.progress = getDelta(); 29 3 : change.amount = initial?.amount ?? 0.0; 30 : return this; 31 : } 32 : }