diff --git a/lib/pages/report.dart b/lib/pages/report.dart index 8c76bd7..6f2235a 100644 --- a/lib/pages/report.dart +++ b/lib/pages/report.dart @@ -70,26 +70,45 @@ class SummaryCardForTotals extends StatelessWidget { if (!snapshot.hasData) { return Text('Loading $summaryTypeLabel Section...'); } - // TODO: Do not show all 3 sections or any text for Assets. + + // Calculate the total fields based on item type. double dailyTotal = 0, monthlyTotal = 0, yearlyTotal = 0; + bool isAsset = false; for (TrackedItem e in snapshot.data!) { - dailyTotal += e.calcComparableAmountDaily(); - monthlyTotal += e.calcComparableAmountYearly() / 12; - yearlyTotal += e.calcComparableAmountYearly(); + if (e.type == ItemType.asset) { + monthlyTotal += e.amount; + isAsset = true; + } else { + dailyTotal += e.calcComparableAmountDaily(); + monthlyTotal += e.calcComparableAmountYearly() / 12; + yearlyTotal += e.calcComparableAmountYearly(); + } } + + // Determine what needs displayed for the item type. String dailyEstimate = dailyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~", monthlyEstimate = monthlyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~", yearlyEstimate = yearlyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~"; + String leftText = "", middleText = "", rightText = ""; + if (isAsset) { + middleText = "$monthlyEstimate${monthlyTotal.toStringAsFixed(2)}"; + } else { + leftText = "$dailyEstimate${dailyTotal.toStringAsFixed(2)} Daily"; + middleText = + "$monthlyEstimate${monthlyTotal.toStringAsFixed(2)} Monthly"; + rightText = + "$yearlyEstimate${yearlyTotal.toStringAsFixed(2)} Yearly"; + } + + // Return the UI element. return SummaryCard( name: "$summaryTypeLabel Totals", - leftText: "$dailyEstimate${dailyTotal.toStringAsFixed(2)} Daily", - middleText: - "$monthlyEstimate${monthlyTotal.toStringAsFixed(2)} Monthly", - rightText: - "$yearlyEstimate${yearlyTotal.toStringAsFixed(2)} Yearly", + leftText: leftText, + middleText: middleText, + rightText: rightText, ); }); }