Skip to content

Commit

Permalink
Merge pull request #6 from AMCAsimulagro/feature/graficas
Browse files Browse the repository at this point in the history
Feature/graficas
  • Loading branch information
AMCAsimulagro authored Nov 25, 2023
2 parents 4bee943 + 4b738f8 commit 2bfca70
Show file tree
Hide file tree
Showing 28 changed files with 1,865 additions and 540 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
3 changes: 2 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -209,6 +209,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
9 changes: 5 additions & 4 deletions lib/data/api/farming_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class FarmingApi {

Future<void> deleteTransitoryFarming(String id);

Future<List<CostAndExpense>> getCostsAndExpensesByFarming();
Future<List<CostAndExpense>> getCostsAndExpensesByFarming(String farmingId);

Future<TransitoryFarming> getTransitoryFarmingById(String farmingId);

Expand Down Expand Up @@ -181,9 +181,10 @@ class FarmingApiAdapter extends FarmingApi {
}

@override
Future<List<CostAndExpense>> getCostsAndExpensesByFarming() {
// TODO: implement getCostsAndExpensesByFarming
throw UnimplementedError();
Future<List<CostAndExpense>> getCostsAndExpensesByFarming(
String farmingId) async {
final result = await getTransitoryFarmingById(farmingId);
return result.costsAndExpenses ?? [];
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/data/repository/farming_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FarmingRepositoryAdapter extends FarmingRepository {

@override
Future<List<CostAndExpense>> getCostsAndExpensesByFarming(String farmingId) {
return _api.getCostsAndExpensesByFarming();
return _api.getCostsAndExpensesByFarming(farmingId);
}

@override
Expand Down
30 changes: 30 additions & 0 deletions lib/domain/model/bar_data_ui.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:amca/domain/model/chart_data.dart';

class BarDataUI {
final int month;

double? totalCost;

BarDataUI({
required this.month,
this.totalCost,
});

String get monthName {
final months = {
1: 'Ene',
2: 'Feb',
3: 'Mar',
4: 'Abr',
5: 'May',
6: 'Jun',
7: 'Jul',
8: 'Ago',
9: 'Sep',
10: 'Oct',
11: 'Nov',
12: 'Dic'
};
return months[month] ?? '';
}
}
42 changes: 42 additions & 0 deletions lib/domain/model/chart_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:amca/domain/model/cost_expense.dart';

class ChartDataYear {
final int year;
final List<ChartDataMonth>? monthsData;

ChartDataYear({
required this.year,
this.monthsData,
});
}

class ChartDataMonth {
final int? month;
final List<CostAndExpense>? costAndExpense;

ChartDataMonth({
this.month,
this.costAndExpense,
});

List<CostAndExpense> get costs =>
costAndExpense?.where((element) => element.isCost).toList() ?? [];

List<CostAndExpense> get expenses =>
costAndExpense?.where((element) => !element.isCost).toList() ?? [];

bool get hasCosts => costs.isNotEmpty;
bool get hasExpenses => expenses.isNotEmpty;

double? get totalCost => costs.isNotEmpty
? costs
.map((cost) => cost.priceDouble)
.reduce((valorAnterior, valorActual) => valorAnterior + valorActual)
: null;

double? get totalExpense => expenses.isNotEmpty
? expenses
.map((cost) => cost.priceDouble)
.reduce((valorAnterior, valorActual) => valorAnterior + valorActual)
: null;
}
10 changes: 10 additions & 0 deletions lib/domain/model/cost_expense.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ class CostAndExpense with _$CostAndExpense {
factory CostAndExpense.fromJson(Map<String, Object?> json) =>
_$CostAndExpenseFromJson(json);
}

extension CostAndExpenseExtension on CostAndExpense {
bool get isCost => description.costOrExpense == 'Costos';

int get year => createDate.year;

int get month => createDate.month;

double get priceDouble => double.parse(price.replaceAll(',', ''));
}
20 changes: 20 additions & 0 deletions lib/domain/model/pie_data_ui.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:amca/ui/utils/amca_palette.dart';
import 'package:flutter/material.dart';

class PieDataUI {
final double value;

final double percentageInThePie;
final bool? isCost;

PieDataUI({
required this.value,
this.isCost = false,
required this.percentageInThePie,
});

String get percentage => '${percentageInThePie.toStringAsFixed(2)}%';

Color get color =>
isCost! ? AmcaPalette.pieCostColor : AmcaPalette.pieExpenseColor;
}
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:jiffy/jiffy.dart';
import 'package:provider/provider.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

Expand All @@ -18,6 +19,7 @@ void main() async {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FlutterNativeSplash.remove();
DependecyInjection.registerInjections();
await Jiffy.setLocale('es');
runApp(const MyApp());
}

Expand Down Expand Up @@ -65,6 +67,7 @@ class MyApp extends StatelessWidget {
],
supportedLocales: const [
Locale('es'),
Locale('es_us'),
],
home: SplashPage.create(),
),
Expand Down
Loading

0 comments on commit 2bfca70

Please sign in to comment.