Merge branch 'release/3.9.0'

Signed-off-by: James Cole <thegrumpydictator@gmail.com>

# Conflicts:
#	app/Helpers/Csv/Converter/BillName.php
This commit is contained in:
James Cole
2016-05-22 16:46:11 +02:00
559 changed files with 14471 additions and 12696 deletions

View File

@@ -1,5 +1,4 @@
<?php
declare(strict_types = 1);
/**
* AccountChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
@@ -8,6 +7,8 @@ declare(strict_types = 1);
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Account;
use Carbon\Carbon;
@@ -42,10 +43,10 @@ interface AccountChartGeneratorInterface
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param array $labels
* @param array $dataSet
*
* @return array
*/
public function single(Account $account, Carbon $start, Carbon $end): array;
public function single(Account $account, array $labels, array $dataSet): array;
}

View File

@@ -1,11 +1,18 @@
<?php
/**
* ChartJsAccountChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Account;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use Illuminate\Support\Collection;
use Steam;
/**
* Class ChartJsAccountChartGenerator
@@ -29,28 +36,6 @@ class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
'labels' => [], 'datasets' => [[
'label' => trans('firefly.spent'),
'data' => []]]];
$start->subDay();
$ids = $this->getIdsFromCollection($accounts);
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
$accounts->each(
function (Account $account) use ($startBalances, $endBalances) {
$id = $account->id;
$startBalance = $this->isInArray($startBalances, $id);
$endBalance = $this->isInArray($endBalances, $id);
$diff = bcsub($endBalance, $startBalance);
$account->difference = round($diff, 2);
}
);
$accounts = $accounts->sortByDesc(
function (Account $account) {
return $account->difference;
}
);
foreach ($accounts as $account) {
if ($account->difference > 0) {
$data['labels'][] = $account->name;
@@ -80,7 +65,7 @@ class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
}
foreach ($accounts as $account) {
$set = [
$data['datasets'][] = [
'label' => $account->name,
'fillColor' => 'rgba(220,220,220,0.2)',
'strokeColor' => 'rgba(220,220,220,1)',
@@ -88,20 +73,8 @@ class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
'pointStrokeColor' => '#fff',
'pointHighlightFill' => '#fff',
'pointHighlightStroke' => 'rgba(220,220,220,1)',
'data' => [],
'data' => $account->balances,
];
$current = clone $start;
$range = Steam::balanceInRange($account, $start, clone $end);
$previous = round(array_values($range)[0], 2);
while ($current <= $end) {
$format = $current->format('Y-m-d');
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
$set['data'][] = $balance;
$previous = $balance;
$current->addDay();
}
$data['datasets'][] = $set;
}
$data['count'] = count($data['datasets']);
@@ -110,71 +83,25 @@ class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param array $labels
* @param array $dataSet
*
* @return array
*/
public function single(Account $account, Carbon $start, Carbon $end): array
public function single(Account $account, array $labels, array $dataSet): array
{
// language:
$format = (string)trans('config.month_and_day');
$data = [
$data = [
'count' => 1,
'labels' => [],
'labels' => $labels,
'datasets' => [
[
'label' => $account->name,
'data' => [],
'data' => $dataSet,
],
],
];
$range = Steam::balanceInRange($account, $start, $end);
$current = clone $start;
$previous = array_values($range)[0];
while ($end >= $current) {
$theDate = $current->format('Y-m-d');
$balance = $range[$theDate] ?? $previous;
$data['labels'][] = $current->formatLocalized($format);
$data['datasets'][0]['data'][] = $balance;
$previous = $balance;
$current->addDay();
}
return $data;
}
/**
* @param Collection $collection
*
* @return array
*/
protected function getIdsFromCollection(Collection $collection): array
{
$ids = [];
foreach ($collection as $entry) {
$ids[] = $entry->id;
}
return array_unique($ids);
}
/**
* @param $array
* @param $entryId
*
* @return string
*/
protected function isInArray($array, $entryId): string
{
if (isset($array[$entryId])) {
return $array[$entryId];
}
return '0';
}
}

View File

@@ -1,5 +1,4 @@
<?php
declare(strict_types = 1);
/**
* BillChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
@@ -8,6 +7,8 @@ declare(strict_types = 1);
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Bill;

View File

@@ -1,5 +1,4 @@
<?php
declare(strict_types = 1);
/**
* ChartJsBillChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
@@ -8,6 +7,8 @@ declare(strict_types = 1);
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Bill;
use FireflyIII\Models\Bill;
@@ -54,11 +55,7 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
public function single(Bill $bill, Collection $entries): array
{
$format = (string)trans('config.month');
$data = [
'count' => 3,
'labels' => [],
'datasets' => [],
];
$data = ['count' => 3, 'labels' => [], 'datasets' => [],];
$minAmount = [];
$maxAmount = [];
$actualAmount = [];
@@ -67,9 +64,7 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
$data['labels'][] = $entry->date->formatLocalized($format);
$minAmount[] = round($bill->amount_min, 2);
$maxAmount[] = round($bill->amount_max, 2);
/*
* journalAmount has been collected in BillRepository::getJournals
*/
// journalAmount has been collected in BillRepository::getJournals
$actualAmount[] = round(TransactionJournal::amountPositive($entry), 2);
}

View File

@@ -1,5 +1,4 @@
<?php
declare(strict_types = 1);
/**
* BudgetChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
@@ -8,6 +7,8 @@ declare(strict_types = 1);
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Budget;
use Illuminate\Support\Collection;
@@ -19,19 +20,14 @@ use Illuminate\Support\Collection;
*/
interface BudgetChartGeneratorInterface
{
/**
* @param Collection $entries
*
* @return array
*/
public function budget(Collection $entries): array;
/**
* @param Collection $entries
* @param string $dateFormat
*
* @return array
*/
public function budgetLimit(Collection $entries): array;
public function budgetLimit(Collection $entries, string $dateFormat): array;
/**
* @param Collection $entries
@@ -47,6 +43,14 @@ interface BudgetChartGeneratorInterface
*/
public function multiYear(Collection $entries): array;
/**
* @param Collection $entries
* @param string $viewRange
*
* @return array
*/
public function period(Collection $entries, string $viewRange) : array;
/**
* @param Collection $budgets
* @param Collection $entries

View File

@@ -1,11 +1,18 @@
<?php
/**
* ChartJsBudgetChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Budget;
use Config;
use Illuminate\Support\Collection;
use Preferences;
use Navigation;
/**
* Class ChartJsBudgetChartGenerator
@@ -14,20 +21,17 @@ use Preferences;
*/
class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
{
/**
*
* @param Collection $entries
* @param string $dateFormat
*
* @return array
*/
public function budget(Collection $entries, $dateFormat = 'month'): array
public function budgetLimit(Collection $entries, string $dateFormat = 'month_and_day'): array
{
// language:
$language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
$format = Config::get('firefly.' . $dateFormat . '.' . $language);
$data = [
$format = strval(trans('config.' . $dateFormat));
$data = [
'labels' => [],
'datasets' => [
[
@@ -49,17 +53,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
return $data;
}
/**
*
* @param Collection $entries
*
* @return array
*/
public function budgetLimit(Collection $entries): array
{
return $this->budget($entries, 'monthAndDay');
}
/**
* @param Collection $entries
*
@@ -139,6 +132,42 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
}
/**
* @param Collection $entries
* @param string $viewRange
*
* @return array
*/
public function period(Collection $entries, string $viewRange) : array
{
$data = [
'labels' => [],
'datasets' => [
0 => [
'label' => trans('firefly.budgeted'),
'data' => [],
],
1 => [
'label' => trans('firefly.spent'),
'data' => [],
],
],
'count' => 2,
];
foreach ($entries as $entry) {
$label = Navigation::periodShow($entry['date'], $viewRange);
$data['labels'][] = $label;
// data set 0 is budgeted
// data set 1 is spent:
$data['datasets'][0]['data'][] = $entry['budgeted'];
$data['datasets'][1]['data'][] = round(($entry['spent'] * -1), 2);
}
return $data;
}
/**
* @param Collection $budgets
* @param Collection $entries

View File

@@ -1,5 +1,4 @@
<?php
declare(strict_types = 1);
/**
* CategoryChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
@@ -8,6 +7,8 @@ declare(strict_types = 1);
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Category;
use Illuminate\Support\Collection;

View File

@@ -1,4 +1,12 @@
<?php
/**
* ChartJsCategoryChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Category;
@@ -20,8 +28,6 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
*/
public function all(Collection $entries): array
{
$data = [
'count' => 2,
'labels' => [],
@@ -42,8 +48,8 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
$spent = $entry[2];
$earned = $entry[3];
$data['datasets'][0]['data'][] = bccomp($spent, '0') === 0 ? null : bcmul($spent, '-1');
$data['datasets'][1]['data'][] = bccomp($earned, '0') === 0 ? null : $earned;
$data['datasets'][0]['data'][] = bccomp($spent, '0') === 0 ? null : round(bcmul($spent, '-1'), 4);
$data['datasets'][1]['data'][] = bccomp($earned, '0') === 0 ? null : round($earned, 4);
}
return $data;
@@ -116,18 +122,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
*/
public function multiYear(Collection $entries): array
{
// dataset:
$data = [
'count' => 0,
'labels' => [],
'datasets' => [],
];
// get labels from one of the categories (assuming there's at least one):
$first = $entries->first();
$keys = array_keys($first['spent']);
foreach ($keys as $year) {
$data['labels'][] = strval($year);
}
$data = ['count' => 0, 'labels' => array_keys($first['spent']), 'datasets' => [],];
// then, loop all entries and create datasets:
foreach ($entries as $entry) {
@@ -144,7 +141,6 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
$data['count'] = count($data['datasets']);
return $data;
}
/**

View File

@@ -1,4 +1,12 @@
<?php
/**
* ChartJsPiggyBankChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\PiggyBank;
@@ -36,9 +44,9 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGeneratorInterface
],
];
$sum = '0';
foreach ($set as $entry) {
$date = new Carbon($entry->date);
$sum = bcadd($sum, $entry->sum);
foreach ($set as $key => $value) {
$date = new Carbon($key);
$sum = bcadd($sum, $value);
$data['labels'][] = $date->formatLocalized($format);
$data['datasets'][0]['data'][] = round($sum, 2);
}

View File

@@ -1,13 +1,14 @@
<?php
declare(strict_types = 1);
/**
* PiggyBankChartGenerator.php
* PiggyBankChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\PiggyBank;
use Illuminate\Support\Collection;

View File

@@ -1,4 +1,12 @@
<?php
/**
* ChartJsReportChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Report;

View File

@@ -1,13 +1,14 @@
<?php
declare(strict_types = 1);
/**
* ReportChartGenerator.php
* ReportChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Report;
use Illuminate\Support\Collection;