Code cleanup.

This commit is contained in:
James Cole 2015-12-28 07:12:47 +01:00
parent f263844793
commit 51b45b4ed4
22 changed files with 209 additions and 211 deletions

View File

@ -25,13 +25,13 @@ class ChartJsBillChartGenerator implements BillChartGenerator
bcscale(2);
$data = [
[
'value' => round($unpaid,2),
'value' => round($unpaid, 2),
'color' => 'rgba(53, 124, 165,0.7)',
'highlight' => 'rgba(53, 124, 165,0.9)',
'label' => trans('firefly.unpaid'),
],
[
'value' => round($paid * -1,2), // paid is negative, must be positive.
'value' => round($paid * -1, 2), // paid is negative, must be positive.
'color' => 'rgba(0, 141, 76, 0.7)',
'highlight' => 'rgba(0, 141, 76, 0.9)',
'label' => trans('firefly.paid'),
@ -73,7 +73,7 @@ class ChartJsBillChartGenerator implements BillChartGenerator
/*
* journalAmount has been collected in BillRepository::getJournals
*/
$actualAmount[] = round(($entry->journalAmount * -1), 2);
$actualAmount[] = round(($entry->journalAmount * -1), 2);
}
$data['datasets'][] = [

View File

@ -49,53 +49,13 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
return $data;
}
/**
* @param Collection $entries
*
* @return array
*/
public function frontpage(Collection $entries)
{
$data = [
'count' => 1,
'labels' => [],
'datasets' => [
[
'label' => trans('firefly.spent'),
'data' => []
]
],
];
foreach ($entries as $entry) {
if ($entry['sum'] != 0) {
$data['labels'][] = $entry['name'];
$data['datasets'][0]['data'][] = round(($entry['sum'] * -1), 2);
}
}
return $data;
}
/**
* @codeCoverageIgnore
*
* @param Collection $entries
*
* @return array
*/
public function period(Collection $entries)
{
return $this->all($entries);
}
/**
* @param Collection $categories
* @param Collection $entries
*
* @return array
*/
public function spentInYear(Collection $categories, Collection $entries)
public function earnedInPeriod(Collection $categories, Collection $entries)
{
// language:
@ -122,13 +82,90 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
}
/**
* @param Collection $entries
*
* @return array
*/
public function frontpage(Collection $entries)
{
$data = [
'count' => 1,
'labels' => [],
'datasets' => [
[
'label' => trans('firefly.spent'),
'data' => []
]
],
];
foreach ($entries as $entry) {
if ($entry['sum'] != 0) {
$data['labels'][] = $entry['name'];
$data['datasets'][0]['data'][] = round(($entry['sum'] * -1), 2);
}
}
return $data;
}
/**
* @param Collection $entries
*
* @return array
*/
public function multiYear(Collection $entries)
{
// dataset:
$data = [
'count' => 0,
'labels' => [],
'datasets' => [],
];
// get labels from one of the categories (assuming there's at least one):
$first = $entries->first();
foreach ($first['spent'] as $year => $noInterest) {
$data['labels'][] = strval($year);
}
// then, loop all entries and create datasets:
foreach ($entries as $entry) {
$name = $entry['name'];
$spent = $entry['spent'];
$earned = $entry['earned'];
if (array_sum(array_values($spent)) != 0) {
$data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
}
if (array_sum(array_values($earned)) != 0) {
$data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
}
}
$data['count'] = count($data['datasets']);
return $data;
}
/**
* @codeCoverageIgnore
*
* @param Collection $entries
*
* @return array
*/
public function period(Collection $entries)
{
return $this->all($entries);
}
/**
* @param Collection $categories
* @param Collection $entries
*
* @return array
*/
public function earnedInPeriod(Collection $categories, Collection $entries)
public function spentInYear(Collection $categories, Collection $entries)
{
// language:
@ -187,41 +224,4 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
return $data;
}
/**
* @param Collection $entries
*
* @return array
*/
public function multiYear(Collection $entries)
{
// dataset:
$data = [
'count' => 0,
'labels' => [],
'datasets' => [],
];
// get labels from one of the categories (assuming there's at least one):
$first = $entries->first();
foreach ($first['spent'] as $year => $noInterest) {
$data['labels'][] = strval($year);
}
// then, loop all entries and create datasets:
foreach ($entries as $entry) {
$name = $entry['name'];
$spent = $entry['spent'];
$earned = $entry['earned'];
if (array_sum(array_values($spent)) != 0) {
$data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
}
if (array_sum(array_values($earned)) != 0) {
$data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
}
}
$data['count'] = count($data['datasets']);
return $data;
}
}

View File

@ -3,9 +3,7 @@
namespace FireflyIII\Generator\Chart\PiggyBank;
use Carbon\Carbon;
use Config;
use Illuminate\Support\Collection;
use Preferences;
/**
@ -25,7 +23,7 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
{
// language:
$format = trans('config.month_and_day');
$format = trans('config.month_and_day');
$data = [
'count' => 1,

View File

@ -2,9 +2,7 @@
namespace FireflyIII\Generator\Chart\Report;
use Config;
use Illuminate\Support\Collection;
use Preferences;
/**
* Class ChartJsReportChartGenerator
@ -14,40 +12,6 @@ use Preferences;
class ChartJsReportChartGenerator implements ReportChartGenerator
{
/**
* @param Collection $entries
*
* @return array
*/
public function yearInOut(Collection $entries)
{
// language:
$format = trans('config.month');
$data = [
'count' => 2,
'labels' => [],
'datasets' => [
[
'label' => trans('firefly.income'),
'data' => []
],
[
'label' => trans('firefly.expenses'),
'data' => []
]
],
];
foreach ($entries as $entry) {
$data['labels'][] = $entry[0]->formatLocalized($format);
$data['datasets'][0]['data'][] = round($entry[1], 2);
$data['datasets'][1]['data'][] = round($entry[2], 2);
}
return $data;
}
/**
* Same as above but other translations.
*
@ -81,6 +45,71 @@ 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;
}
/**
* @param Collection $entries
*
* @return array
*/
public function yearInOut(Collection $entries)
{
// language:
$format = trans('config.month');
$data = [
'count' => 2,
'labels' => [],
'datasets' => [
[
'label' => trans('firefly.income'),
'data' => []
],
[
'label' => trans('firefly.expenses'),
'data' => []
]
],
];
foreach ($entries as $entry) {
$data['labels'][] = $entry[0]->formatLocalized($format);
$data['datasets'][0]['data'][] = round($entry[1], 2);
$data['datasets'][1]['data'][] = round($entry[2], 2);
}
return $data;
}
/**
* @param string $income
* @param string $expense
@ -112,35 +141,4 @@ 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;
}
}

View File

@ -161,15 +161,15 @@ class ReportQuery implements ReportQueryInterface
}
}
);
// $data = $data->filter(
// function (TransactionJournal $journal) {
// if ($journal->amount != 0) {
// return $journal;
// }
//
// return null;
// }
// );
// $data = $data->filter(
// function (TransactionJournal $journal) {
// if ($journal->amount != 0) {
// return $journal;
// }
//
// return null;
// }
// );
return $data;
}

View File

@ -236,7 +236,7 @@ class BudgetController extends Controller
// we already have amount, startdate and enddate.
// if this "is" a limit repetition (as opposed to a budget without one entirely)
// depends on whether startdate and enddate are null.
$name = $budget->name;
$name = $budget->name;
if (is_null($budget->startdate) && is_null($budget->enddate)) {
$currentStart = clone $start;
$currentEnd = clone $end;
@ -252,7 +252,7 @@ class BudgetController extends Controller
$amount = $budget->amount;
// smaller than 1 means spent MORE than budget allows.
$left = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? 0 : bcadd($budget->amount, $expenses);
$spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? ($amount*-1) : $expenses;
$spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? ($amount * -1) : $expenses;
$overspent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcadd($budget->amount, $expenses) : 0;
}

View File

@ -1,7 +1,6 @@
<?php namespace FireflyIII\Http\Controllers;
use Auth;
use Config;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

View File

@ -1,15 +1,12 @@
<?php namespace FireflyIII\Http\Controllers;
use Artisan;
use Auth;
use Carbon\Carbon;
use Config;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Input;
use Log;
use Preferences;
use Route;
use Session;
use Steam;

View File

@ -64,9 +64,12 @@ class ReportController extends Controller
$accountList = join(',', $accountIds);
return view('reports.index', compact('months', 'accounts', 'start', 'accountList',
'startOfMonth', 'endOfMonth', 'startOfYear', 'endOfYear'
));
return view(
'reports.index', compact(
'months', 'accounts', 'start', 'accountList',
'startOfMonth', 'endOfMonth', 'startOfYear', 'endOfYear'
)
);
}
/**

View File

@ -4,7 +4,6 @@ use App;
use Auth;
use Carbon\Carbon;
use Closure;
use Config;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Preferences;
@ -61,9 +60,9 @@ class Authenticate
}
// if logged in, set user language:
$pref = Preferences::get('language', env('DEFAULT_LANGUAGE','en_US'));
$pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));
App::setLocale($pref->data);
Carbon::setLocale(substr($pref->data,0,2));
Carbon::setLocale(substr($pref->data, 0, 2));
$locale = explode(',', trans('config.locale'));
$locale = array_map('trim', $locale);

View File

@ -78,7 +78,7 @@ class Budget extends Model
*/
public function getDates()
{
return ['created_at', 'updated_at', 'deleted_at','startdate','enddate'];
return ['created_at', 'updated_at', 'deleted_at', 'startdate', 'enddate'];
}
/**

View File

@ -115,16 +115,16 @@ class BillRepository implements BillRepositoryInterface
}
$set = $bill->transactionjournals()
->leftJoin(
'transactions', function (JoinClause $join) {
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('amount', '<', 0);
}
)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*', 'transactions.amount as journalAmount']);
->leftJoin(
'transactions', function (JoinClause $join) {
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('amount', '<', 0);
}
)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*', 'transactions.amount as journalAmount']);
$cache->store($set);
return $set;

View File

@ -108,6 +108,7 @@ interface BudgetRepositoryInterface
/**
* @deprecated
*
* @param Budget $budget
*
* @return Carbon
@ -116,6 +117,7 @@ interface BudgetRepositoryInterface
/**
* @deprecated
*
* @param Budget $budget
* @param Carbon $date
*

View File

@ -53,7 +53,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
$cache = new CacheProperties;
$cache->addProperty('category-list');
if($cache->has()) {
if ($cache->has()) {
return $cache->get();
}

View File

@ -46,7 +46,6 @@ class ComponentRepository
}
$entry = $object->transactionjournals()
->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE])
->before($end)

View File

@ -328,7 +328,7 @@ return [
'Default account' => 'Asset account',
'Expense account' => 'Expense account',
'Revenue account' => 'Revenue account',
'Initial balance account' => 'Initial balance account',
'Initial balance account' => 'Initial balance account',
'budgets' => 'Budgets',
'tags' => 'Tags',
'reports' => 'Reports',
@ -364,13 +364,13 @@ return [
'profile' => 'Profile',
// reports
'report_default' => 'Default financial report for :start until :end',
'quick_link_reports' => 'Quick links',
'quick_link_default_report' => 'Default financial report',
'report_this_month_quick' => 'Current month, all accounts',
'report_this_year_quick' => 'Current year, all accounts',
'report_all_time_quick' => 'All-time, all accounts',
'reports_can_bookmark' => 'Remember that reports can be bookmarked.',
'report_default' => 'Default financial report for :start until :end',
'quick_link_reports' => 'Quick links',
'quick_link_default_report' => 'Default financial report',
'report_this_month_quick' => 'Current month, all accounts',
'report_this_year_quick' => 'Current year, all accounts',
'report_all_time_quick' => 'All-time, all accounts',
'reports_can_bookmark' => 'Remember that reports can be bookmarked.',
'incomeVsExpenses' => 'Income vs. expenses',
'accountBalances' => 'Account balances',
'balanceStartOfYear' => 'Balance at start of year',
@ -389,7 +389,7 @@ return [
'outsideOfBudgets' => 'Outside of budgets',
'leftInBudget' => 'Left in budget',
'sumOfSums' => 'Sum of sums',
'noCategory' => '(no category)',
'noCategory' => '(no category)',
'notCharged' => 'Not charged (yet)',
'inactive' => 'Inactive',
'difference' => 'Difference',
@ -399,18 +399,18 @@ return [
'showTheRest' => 'Show everything',
'hideTheRest' => 'Show only the top :number',
'sum_of_year' => 'Sum of year',
'sum_of_years' => 'Sum of years',
'sum_of_years' => 'Sum of years',
'average_of_year' => 'Average of year',
'average_of_years' => 'Average of years',
'average_of_years' => 'Average of years',
'categories_earned_in_year' => 'Categories (by earnings)',
'categories_spent_in_year' => 'Categories (by spendings)',
'report_type' => 'Report type',
'report_type_default' => 'Default financial report',
'report_included_accounts' => 'Included accounts',
'report_date_range' => 'Date range',
'report_include_help' => 'In all cases, transfers to shared accounts count as expenses, and transfers from shared accounts count as income.',
'report_preset_ranges' => 'Pre-set ranges',
'shared' => 'Shared',
'report_type' => 'Report type',
'report_type_default' => 'Default financial report',
'report_included_accounts' => 'Included accounts',
'report_date_range' => 'Date range',
'report_include_help' => 'In all cases, transfers to shared accounts count as expenses, and transfers from shared accounts count as income.',
'report_preset_ranges' => 'Pre-set ranges',
'shared' => 'Shared',
// charts
'dayOfMonth' => 'Day of the month',

View File

@ -35,7 +35,7 @@ return [
"in" => ":attribute is ongeldig.",
"integer" => ":attribute moet een getal zijn.",
"ip" => ":attribute moet een geldig IP-adres zijn.",
'json' => 'De :attribute moet een JSON tekst zijn.',
'json' => 'De :attribute moet een JSON tekst zijn.',
"max.numeric" => ":attribute mag niet hoger dan :max zijn.",
"max.file" => ":attribute mag niet meer dan :max kilobytes zijn.",
"max.string" => ":attribute mag niet uit meer dan :max karakters bestaan.",
@ -50,7 +50,7 @@ return [
"regex" => ":attribute formaat is ongeldig.",
"required" => ":attribute is verplicht.",
"required_if" => ":attribute is verplicht indien :other gelijk is aan :value.",
'required_unless' => ':attribute is verplicht tenzij :other gelijk is aan :values.',
'required_unless' => ':attribute is verplicht tenzij :other gelijk is aan :values.',
"required_with" => ":attribute is verplicht i.c.m. :values",
"required_with_all" => ":attribute is verplicht i.c.m. :values",
"required_without" => ":attribute is verplicht als :values niet ingevuld is.",

View File

@ -35,7 +35,7 @@ return [
"in" => "O campo :attribute não contém um valor válido.",
"integer" => "O campo :attribute deverá conter um número inteiro.",
"ip" => "O campo :attribute deverá conter um IP válido.",
'json' => 'O campo :attribute deverá conter uma string JSON válida.',
'json' => 'O campo :attribute deverá conter uma string JSON válida.',
"max.numeric" => "O campo :attribute não deverá conter um valor superior a :max.",
"max.file" => "O campo :attribute não deverá ter um tamanho superior a :max kilobytes.",
"max.string" => "O campo :attribute não deverá conter mais de :max caracteres.",
@ -50,7 +50,7 @@ return [
"regex" => "O formato do valor para o campo :attribute é inválido.",
"required" => "O campo :attribute é obrigatório.",
"required_if" => "O campo :attribute é obrigatório quando o valor do campo :other é igual a :value.",
'required_unless' => 'O campo :attribute é obrigatório a menos que :other esteja presente em :values.',
'required_unless' => 'O campo :attribute é obrigatório a menos que :other esteja presente em :values.',
"required_with" => "O campo :attribute é obrigatório quando :values está presente.",
"required_with_all" => "O campo :attribute é obrigatório quando um dos :values está presente.",
"required_without" => "O campo :attribute é obrigatório quanto :values não está presente.",

View File

@ -60,6 +60,7 @@
</script>
</body>

View File

@ -5,7 +5,8 @@
<div class="input-group">
<div class="input-group-btn">
<button type="button"
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown" aria-expanded="false">
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown"
aria-expanded="false">
<span id="currency_select_symbol_{{ name }}">{{ defaultCurrency.symbol|raw }}</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu currency-dropdown-menu" role="menu">

View File

@ -5,7 +5,8 @@
<div class="input-group">
<div class="input-group-btn">
<button type="button"
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown" aria-expanded="false">
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown"
aria-expanded="false">
<span id="currency_select_symbol_{{ name }}">{{ defaultCurrency.symbol|raw }}</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu currency-dropdown-menu" role="menu">

View File

@ -184,7 +184,7 @@
var language = "{{ language }}";
var currencyCode = '{{ getCurrencyCode() }}';
var currencySymbol = '{{ getCurrencySymbol()|raw }}';
var mon_decimal_point = "{{ localeconv.mon_decimal_point }}";
var mon_decimal_point = "{{ localeconv.mon_decimal_point }}";
var mon_thousands_sep = "{{ localeconv.mon_thousands_sep }}";
var frac_digits = {{ localeconv.frac_digits }};