Some code cleanup [skip ci]

This commit is contained in:
James Cole
2016-02-07 07:56:58 +01:00
parent b22774a599
commit 9429d84cf8
21 changed files with 65 additions and 55 deletions

View File

@@ -54,7 +54,7 @@ class AccountReportHelper implements AccountReportHelperInterface
->whereNull('transactions.deleted_at')
->where('transaction_journals.date', '<=', $yesterday->format('Y-m-d'))
->groupBy('accounts.id')
->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);
// and end:
$endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
@@ -64,7 +64,7 @@ class AccountReportHelper implements AccountReportHelperInterface
->whereNull('transactions.deleted_at')
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->groupBy('accounts.id')
->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);
$accounts->each(

View File

@@ -50,8 +50,8 @@ class ReportQuery implements ReportQueryInterface
->groupBy('dateFormatted')
->get(
[
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") AS `dateFormatted`'),
DB::Raw('SUM(`t_to`.`amount`) AS `sum`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") AS `dateFormatted`'),
DB::raw('SUM(`t_to`.`amount`) AS `sum`'),
]
);
$array = [];
@@ -164,8 +164,8 @@ class ReportQuery implements ReportQueryInterface
->groupBy('dateFormatted')
->get(
[
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") AS `dateFormatted`'),
DB::Raw('SUM(`t_from`.`amount`) AS `sum`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") AS `dateFormatted`'),
DB::raw('SUM(`t_from`.`amount`) AS `sum`'),
]
);
$array = [];

View File

@@ -65,7 +65,7 @@ class AccountController extends Controller
{
$typeName = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type);
$subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]);
$accountList = Expandedform::makeSelectList($repository->getAccounts([$account->accountType->type]), true);
$accountList = ExpandedForm::makeSelectList($repository->getAccounts([$account->accountType->type]), true);
unset($accountList[$account->id]);
// put previous url in session

View File

@@ -5,6 +5,7 @@ namespace FireflyIII\Http\Controllers;
use Crypt;
use File;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Requests\AttachmentFormRequest;
use FireflyIII\Models\Attachment;
@@ -73,7 +74,8 @@ class AttachmentController extends Controller
* @param Attachment $attachment
* @param AttachmentHelperInterface $helper
*
* @return string
* @throws FireflyException
*
*/
public function download(Attachment $attachment, AttachmentHelperInterface $helper)
{
@@ -95,9 +97,8 @@ class AttachmentController extends Controller
->header('Pragma', 'public')
->header('Content-Length', $attachment->size);
} else {
abort(404);
}
throw new FireflyException('Could not find the indicated attachment. The file is no longer there.');
}
/**

View File

@@ -73,12 +73,13 @@ class ReportController extends Controller
}
/**
* @param $reportType
* @param string $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return View
* @throws FireflyException
*/
public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{

View File

@@ -60,7 +60,7 @@ class RuleGroupController extends Controller
{
$subTitle = trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
$ruleGroupList = Expandedform::makeSelectList($repository->get(), true);
$ruleGroupList = ExpandedForm::makeSelectList($repository->get(), true);
unset($ruleGroupList[$ruleGroup->id]);
// put previous url in session

View File

@@ -137,6 +137,7 @@ class TransactionController extends Controller
* @param TransactionJournal $journal
*
* @return $this
* @throws FireflyException
*/
public function edit(ARI $repository, TransactionJournal $journal)
{

View File

@@ -46,7 +46,7 @@ class RouteServiceProvider extends ServiceProvider
public function map(Router $router)
{
$router->group(
['namespace' => $this->namespace], function ($router) {
['namespace' => $this->namespace], function (Router $router) {
/** @noinspection PhpIncludeInspection */
require app_path('Http/routes.php');
}

View File

@@ -134,7 +134,7 @@ class AccountRepository implements AccountRepositoryInterface
'accounts.*',
'ccType.data as ccType',
'accountRole.data as accountRole',
DB::Raw('SUM(`transactions`.`amount`) AS `balance`'),
DB::raw('SUM(`transactions`.`amount`) AS `balance`'),
]
);
@@ -329,7 +329,7 @@ class AccountRepository implements AccountRepositoryInterface
$balance = Steam::balance($account, $date, true);
/** @var PiggyBank $p */
foreach ($account->piggybanks()->get() as $p) {
foreach ($account->piggyBanks()->get() as $p) {
$balance = bcsub($p->currentRelevantRep()->currentamount, $balance);
}
@@ -351,7 +351,7 @@ class AccountRepository implements AccountRepositoryInterface
->transactionTypes([TransactionType::OPENING_BALANCE])
->orderBy('created_at', 'ASC')
->first(['transaction_journals.*']);
if(is_null($journal)) {
if (is_null($journal)) {
return new TransactionJournal;
}

View File

@@ -48,7 +48,7 @@ class BillRepository implements BillRepositoryInterface
->get(
[
'bills.*',
DB::Raw('(`bills`.`amount_min` + `bills`.`amount_max` / 2) as `expectedAmount`'),
DB::raw('(`bills`.`amount_min` + `bills`.`amount_max` / 2) as `expectedAmount`'),
]
)->sortBy('name');
@@ -83,7 +83,7 @@ class BillRepository implements BillRepositoryInterface
[
'transaction_journals.bill_id',
'transaction_journals.id',
DB::Raw('SUM(`transactions`.`amount`) as `journalAmount`'),
DB::raw('SUM(`transactions`.`amount`) as `journalAmount`'),
]
);
@@ -173,7 +173,7 @@ class BillRepository implements BillRepositoryInterface
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
}
)
->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
->first([DB::raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
$sumAmount = $paid->sum_amount ?? '0';
$amount = bcadd($amount, $sumAmount);
}
@@ -208,7 +208,7 @@ class BillRepository implements BillRepositoryInterface
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0);
}
)
->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
->first([DB::raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
$sumAmount = $paid->sum_amount ?? '0';
$paidBill = bcadd($sumAmount, $paidBill);
}
@@ -257,7 +257,7 @@ class BillRepository implements BillRepositoryInterface
'transactions', function (JoinClause $join) {
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0);
}
)->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
)->first([DB::raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
$amount = bcadd($amount, $set->sum_amount);
} else {

View File

@@ -135,8 +135,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->get(
[
'budgets.*',
DB::Raw('DATE_FORMAT(`limit_repetitions`.`startdate`,"%Y") as `dateFormatted`'),
DB::Raw('SUM(`limit_repetitions`.`amount`) as `budgeted`'),
DB::raw('DATE_FORMAT(`limit_repetitions`.`startdate`,"%Y") as `dateFormatted`'),
DB::raw('SUM(`limit_repetitions`.`amount`) as `budgeted`'),
]
);
@@ -191,8 +191,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->get(
[
'budgets.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
DB::Raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
DB::raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
]
);
@@ -254,8 +254,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->get(
[
'budgets.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y") AS `dateFormatted`'),
DB::Raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y") AS `dateFormatted`'),
DB::raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
]
);
@@ -365,7 +365,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->where('transactions.amount', '<', 0)
->groupBy('transaction_journals.date')
->orderBy('transaction_journals.date')
->get(['transaction_journals.date', DB::Raw('SUM(`transactions`.`amount`) as `dailyAmount`')]);
->get(['transaction_journals.date', DB::raw('SUM(`transactions`.`amount`) as `dailyAmount`')]);
return $set;
}
@@ -395,8 +395,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->orderBy('transaction_journals.date')
->get(
[
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
DB::Raw('SUM(`transactions`.`amount`) as `monthlyAmount`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
DB::raw('SUM(`transactions`.`amount`) as `monthlyAmount`'),
]
);
@@ -447,11 +447,11 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
public function getJournals(Budget $budget, LimitRepetition $repetition = null, int $take = 50)
{
$offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0;
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
$setQuery = $budget->transactionjournals()->withRelevantData()->take($take)->offset($offset)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC');
$countQuery = $budget->transactionJournals();
$countQuery = $budget->transactionjournals();
if (!is_null($repetition->id)) {
@@ -519,7 +519,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
}
)
->transactionTypes([TransactionType::WITHDRAWAL])
->first([DB::Raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
if (is_null($entry->journalAmount)) {
return '';
}
@@ -561,7 +561,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->groupBy('dateFormatted')
->get(
['transaction_journals.date as dateFormatted', 'budget_transaction_journal.budget_id',
DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]
DB::raw('SUM(`transactions`.`amount`) AS `sum`')]
);
$return = [];
@@ -618,7 +618,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->get(
[
't_from.account_id', 'budget_transaction_journal.budget_id',
DB::Raw('SUM(`t_from`.`amount`) AS `spent`'),
DB::raw('SUM(`t_from`.`amount`) AS `spent`'),
]
);
@@ -643,13 +643,13 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
public function spentPerDay(Budget $budget, Carbon $start, Carbon $end)
{
/** @var Collection $query */
$query = $budget->transactionJournals()
$query = $budget->transactionjournals()
->transactionTypes([TransactionType::WITHDRAWAL])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.amount', '<', 0)
->before($end)
->after($start)
->groupBy('dateFormatted')->get(['transaction_journals.date as dateFormatted', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
->groupBy('dateFormatted')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
$return = [];
foreach ($query->toArray() as $entry) {

View File

@@ -60,8 +60,8 @@ class CategoryRepository implements CategoryRepositoryInterface
->get(
[
'categories.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
DB::Raw('SUM(`t_dest`.`amount`) AS `earned`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
DB::raw('SUM(`t_dest`.`amount`) AS `earned`'),
]
);
@@ -121,9 +121,9 @@ class CategoryRepository implements CategoryRepositoryInterface
->get(
[
'categories.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
'transaction_types.type',
DB::Raw('SUM(`amount`) as `sum`'),
DB::raw('SUM(`amount`) as `sum`'),
]
);
@@ -198,8 +198,8 @@ class CategoryRepository implements CategoryRepositoryInterface
$collection = $query->get(
[
'categories.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
DB::Raw('SUM(`t_src`.`amount`) AS `spent`'),
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
DB::raw('SUM(`t_src`.`amount`) AS `spent`'),
]
);
@@ -272,7 +272,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$single = $query->first(
[
DB::Raw('SUM(`transactions`.`amount`) as `sum`'),
DB::raw('SUM(`transactions`.`amount`) as `sum`'),
]
);
if (!is_null($single)) {

View File

@@ -72,13 +72,13 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
public function earnedPerDay(Category $category, Carbon $start, Carbon $end)
{
/** @var Collection $query */
$query = $category->transactionJournals()
$query = $category->transactionjournals()
->transactionTypes([TransactionType::DEPOSIT])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.amount', '>', 0)
->before($end)
->after($start)
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
$return = [];
foreach ($query->toArray() as $entry) {
@@ -115,7 +115,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
{
$offset = $page > 0 ? $page * 50 : 0;
return $category->transactionJournals()->withRelevantData()->take(50)->offset($offset)
return $category->transactionjournals()->withRelevantData()->take(50)->offset($offset)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
@@ -137,7 +137,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
{
$offset = $page > 0 ? $page * 50 : 0;
return $category->transactionJournals()
return $category->transactionjournals()
->after($start)
->before($end)
->withRelevantData()->take(50)->offset($offset)
@@ -186,13 +186,13 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
public function spentPerDay(Category $category, Carbon $start, Carbon $end)
{
/** @var Collection $query */
$query = $category->transactionJournals()
$query = $category->transactionjournals()
->transactionTypes([TransactionType::WITHDRAWAL])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.amount', '<', 0)
->before($end)
->after($start)
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
$return = [];
foreach ($query->toArray() as $entry) {

View File

@@ -48,7 +48,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/
public function getEventSummarySet(PiggyBank $piggyBank)
{
return DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::Raw('SUM(`amount`) AS `sum`')]);
return DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::raw('SUM(`amount`) AS `sum`')]);
}
/**

View File

@@ -58,7 +58,7 @@ class TagRepository implements TagRepositoryInterface
->get(
[
't_to.account_id',
DB::Raw('SUM(`t_to`.`amount`) as `sum`'),
DB::raw('SUM(`t_to`.`amount`) as `sum`'),
]
);

View File

@@ -88,7 +88,7 @@ class Steam
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->groupBy('transaction_journals.date')
->get(['transaction_journals.date', DB::Raw('SUM(`transactions`.`amount`) as `modified`')]);
->get(['transaction_journals.date', DB::raw('SUM(`transactions`.`amount`) as `modified`')]);
$currentBalance = $startBalance;
foreach ($set as $entry) {
$currentBalance = bcadd($currentBalance, $entry->modified);
@@ -128,7 +128,7 @@ class Steam
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->groupBy('transactions.account_id')
->whereIn('transactions.account_id', $ids)
->get(['transactions.account_id', DB::Raw('sum(`transactions`.`amount`) as aggregate')]);
->get(['transactions.account_id', DB::raw('sum(`transactions`.`amount`) as aggregate')]);
$result = [];
foreach ($balances as $entry) {

View File

@@ -4,7 +4,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Twig;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties;
use Twig_Extension;

View File

@@ -3,6 +3,8 @@
/**
* Class BasicTest
*/
/** @noinspection PhpUndefinedClassInspection */
class BasicTest extends TestCase
{
/**

View File

@@ -6,6 +6,8 @@ use FireflyIII\User;
/**
* Class TestCase
*/
/** @noinspection PhpUndefinedClassInspection */
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**

View File

@@ -10,6 +10,8 @@
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:40:28.
*/
/** @noinspection PhpUndefinedClassInspection */
class AuthControllerTest extends TestCase
{

View File

@@ -7,6 +7,8 @@
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
/** @noinspection PhpUndefinedClassInspection */
class HomeControllerTest extends TestCase
{
/**