Skip to content

Firefly III: a personal finances manager

New charts (slight variations of previous charts)

James Cole29dc122ad386
diff --git a/app/Generator/Chart/Report/ChartJsReportChartGenerator.php b/app/Generator/Chart/Report/ChartJsReportChartGenerator.php
index 0a49d2354a..00d4484eb6 100644
--- a/app/Generator/Chart/Report/ChartJsReportChartGenerator.php
+++ b/app/Generator/Chart/Report/ChartJsReportChartGenerator.php
@@ -49,6 +49,39 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
return $data;
}
+ /**
+ * Same as above but other translations.
+ *
+ * @param Collection $entries
+ *
+ * @return array
+ */
+ public function multiYearInOut(Collection $entries)
+ {
+ $data = [
+ 'count' => 2,
+ 'labels' => [],
+ 'datasets' => [
+ [
+ 'label' => trans('firefly.income'),
+ 'data' => []
+ ],
+ [
+ 'label' => trans('firefly.expenses'),
+ 'data' => []
+ ]
+ ],
+ ];
+
+ foreach ($entries as $entry) {
+ $data['labels'][] = $entry[0]->formatLocalized('%Y');
+ $data['datasets'][0]['data'][] = round($entry[1], 2);
+ $data['datasets'][1]['data'][] = round($entry[2], 2);
+ }
+
+ return $data;
+ }
+
/**
* @param string $income
* @param string $expense
@@ -80,4 +113,35 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
return $data;
}
+
+ /**
+ * @param string $income
+ * @param string $expense
+ * @param int $count
+ *
+ * @return array
+ */
+ public function multiYearInOutSummarized($income, $expense, $count)
+ {
+ $data = [
+ 'count' => 2,
+ 'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
+ 'datasets' => [
+ [
+ 'label' => trans('firefly.income'),
+ 'data' => []
+ ],
+ [
+ 'label' => trans('firefly.expenses'),
+ 'data' => []
+ ]
+ ],
+ ];
+ $data['datasets'][0]['data'][] = round($income, 2);
+ $data['datasets'][1]['data'][] = round( $expense, 2);
+ $data['datasets'][0]['data'][] = round(($income / $count), 2);
+ $data['datasets'][1]['data'][] = round(( $expense / $count), 2);
+
+ return $data;
+ }
}
diff --git a/app/Generator/Chart/Report/ReportChartGenerator.php b/app/Generator/Chart/Report/ReportChartGenerator.php
index 7e3c3039b0..f77ef80e03 100644
--- a/app/Generator/Chart/Report/ReportChartGenerator.php
+++ b/app/Generator/Chart/Report/ReportChartGenerator.php
@@ -12,12 +12,19 @@ use Illuminate\Support\Collection;
interface ReportChartGenerator
{
+ /**
+ * @param Collection $entries
+ *
+ * @return array
+ */
+ public function yearInOut(Collection $entries);
+
/**
* @param Collection $entries
*
* @return array
*/
- public function yearInOut(Collection $entries);
+ public function multiYearInOut(Collection $entries);
/**
* @param string $income
@@ -28,4 +35,13 @@ interface ReportChartGenerator
*/
public function yearInOutSummarized($income, $expense, $count);
+ /**
+ * @param string $income
+ * @param string $expense
+ * @param int $count
+ *
+ * @return array
+ */
+ public function multiYearInOutSummarized($income, $expense, $count);
+
}