Skip to content

Firefly III: a personal finances manager

Fixed some duplication.

James Colea4cc25175a2a
diff --git a/app/Generator/Chart/Account/GoogleAccountChartGenerator.php b/app/Generator/Chart/Account/GoogleAccountChartGenerator.php
index 3859175b3d..ab84e168ce 100644
--- a/app/Generator/Chart/Account/GoogleAccountChartGenerator.php
+++ b/app/Generator/Chart/Account/GoogleAccountChartGenerator.php
@@ -64,32 +64,7 @@ class GoogleAccountChartGenerator implements AccountChartGenerator
*/
public function frontpage(Collection $accounts, Carbon $start, Carbon $end)
{
- $chart = new GChart;
- $chart->addColumn(trans('firefly.dayOfMonth'), 'date');
-
- $index = 1;
- /** @var Account $account */
- foreach ($accounts as $account) {
- $chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number');
- $chart->addCertainty($index);
- $index++;
- }
- $current = clone $start;
- $current->subDay();
- $today = Carbon::now();
- while ($end >= $current) {
- $row = [clone $current];
- $certain = $current < $today;
- foreach ($accounts as $account) {
- $row[] = Steam::balance($account, $current);
- $row[] = $certain;
- }
- $chart->addRowArray($row);
- $current->addDay();
- }
- $chart->generate();
-
- return $chart->getData();
+ return $this->all($accounts, $start, $end);
}
/**
diff --git a/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php b/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
index c7ba8172d5..8580bbf1b2 100644
--- a/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
+++ b/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
@@ -31,12 +31,13 @@ class ChartJsBillChartGenerator implements BillChartGenerator
$unpaidDescriptions = [];
$unpaidAmount = 0;
+ bcscale(2);
/** @var TransactionJournal $entry */
foreach ($paid as $entry) {
$paidDescriptions[] = $entry->description;
- $paidAmount += floatval($entry->amount);
+ $paidAmount = bcadd($paidAmount, $entry->amount);
}
// loop unpaid:
@@ -45,7 +46,7 @@ class ChartJsBillChartGenerator implements BillChartGenerator
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
$amount = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
$unpaidDescriptions[] = $description;
- $unpaidAmount += $amount;
+ $unpaidAmount = bcadd($unpaidAmount, $amount);
unset($amount, $description);
}
diff --git a/app/Generator/Chart/Bill/GoogleBillChartGenerator.php b/app/Generator/Chart/Bill/GoogleBillChartGenerator.php
index 8864bb8306..87960405ec 100644
--- a/app/Generator/Chart/Bill/GoogleBillChartGenerator.php
+++ b/app/Generator/Chart/Bill/GoogleBillChartGenerator.php
@@ -30,12 +30,14 @@ class GoogleBillChartGenerator implements BillChartGenerator
$unpaidDescriptions = [];
$unpaidAmount = 0;
+ bcscale(2);
+
/** @var TransactionJournal $entry */
foreach ($paid as $entry) {
$paidDescriptions[] = $entry->description;
- $paidAmount += floatval($entry->amount);
+ $paidAmount = bcadd($paidAmount, $entry->amount);
}
// loop unpaid:
@@ -44,7 +46,7 @@ class GoogleBillChartGenerator implements BillChartGenerator
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
$amount = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
$unpaidDescriptions[] = $description;
- $unpaidAmount += $amount;
+ $unpaidAmount = bcadd($unpaidAmount, $amount);
unset($amount, $description);
}
@@ -77,7 +79,11 @@ class GoogleBillChartGenerator implements BillChartGenerator
/** @var TransactionJournal $result */
foreach ($entries as $result) {
- $chart->addRow(clone $result->date, floatval($bill->amount_max), floatval($bill->amount_min), floatval($result->amount));
+ $chart->addRow(
+ clone $result->date,
+ floatval($bill->amount_max),
+ floatval($bill->amount_min),
+ floatval($result->amount));
}
$chart->generate();
diff --git a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php
index e7665fe9b9..d91a293286 100644
--- a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php
+++ b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php
@@ -28,7 +28,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
$format = Config::get('firefly.' . $dateFormat . '.' . $language);
$data = [
- 'count' => 1,
'labels' => [],
'datasets' => [
[
@@ -45,6 +44,8 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
}
+ $data['count'] = count($data['datasets']);
+
return $data;
}
@@ -118,7 +119,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
$format = Config::get('firefly.month.' . $language);
$data = [
- 'count' => 0,
'labels' => [],
'datasets' => [],
];