Code clean up.

This commit is contained in:
James Cole 2016-05-15 15:39:22 +02:00
parent 4164ebcc69
commit bd818b2dea
13 changed files with 8 additions and 333 deletions

View File

@ -70,9 +70,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
Log::debug('Build new report.');
// build a balance header:
$header = new BalanceHeader;
$budgets = $this->budgetRepository->getBudgets();
$limitRepetitions = $this->budgetRepository->getAllBudgetLimitRepetitions($start, $end);
$spentData = $this->budgetRepository->journalsInPeriod($budgets, $accounts, $start, $end);
foreach ($accounts as $account) {
$header->addAccount($account);
Log::debug('Add account #' . $account->id . ' to header.');

View File

@ -54,7 +54,6 @@ class BudgetReportHelper implements BudgetReportHelperInterface
// spent for budget in time range:
$spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
// $spent = array_sum($totalSpent);
if ($spent > 0) {
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget);

View File

@ -180,8 +180,8 @@ class BudgetController extends Controller
/**
* Do some cleanup:
* TODO reimplement the deletion of budget_limits and limit_repetitions with amount 0
*/
// $repository->cleanupBudgets();
// loop the budgets:
/** @var Budget $budget */

View File

@ -9,7 +9,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Models\LimitRepetition;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
@ -110,7 +109,7 @@ class BudgetController extends Controller
$cache->addProperty($repetition->id);
if ($cache->has()) {
return Response::json($cache->get());
return Response::json($cache->get());
}
$entries = new Collection;
@ -135,11 +134,9 @@ class BudgetController extends Controller
*
* @param BudgetRepositoryInterface $repository
*
* @param ARI $accountRepository
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function frontpage(BudgetRepositoryInterface $repository, ARI $accountRepository)
public function frontpage(BudgetRepositoryInterface $repository)
{
$start = session('start', Carbon::now()->startOfMonth());
$end = session('end', Carbon::now()->endOfMonth());

View File

@ -151,10 +151,6 @@ class HomeController extends Controller
{
// these routes are not relevant for the help pages:
$ignore = [
// 'logout', 'register', 'bills.rescan', 'attachments.download', 'attachments.preview',
// 'budgets.income', 'csv.download-config', 'currency.default', 'export.status', 'export.download',
// 'json.', 'help.', 'piggy-banks.addMoney', 'piggy-banks.removeMoney', 'rules.rule.up', 'rules.rule.down',
// 'rules.rule-group.up', 'rules.rule-group.down', 'debugbar',
];
$routes = Route::getRoutes();
/** @var \Illuminate\Routing\Route $route */

View File

@ -113,13 +113,11 @@ class TagController extends Controller
}
/**
* @param Tag $tag
*
* @param TagRepositoryInterface $repository
* @param Tag $tag
*
* @return \Illuminate\View\View
*/
public function edit(Tag $tag, TagRepositoryInterface $repository)
public function edit(Tag $tag)
{
$subTitle = trans('firefly.edit_tag', ['tag' => $tag->tag]);
$subTitleIcon = 'fa-tag';

View File

@ -82,7 +82,6 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function earnedInPeriod(Collection $accounts, Carbon $start, Carbon $end): string
{
Log::debug('earnedinperiod');
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
$sum = bcmul($this->sumInPeriod($accounts, $types, $start, $end), '-1');
@ -438,7 +437,6 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function spentInPeriod(Collection $accounts, Carbon $start, Carbon $end): string
{
Log::debug('spentinperiod');
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
$sum = $this->sumInPeriod($accounts, $types, $start, $end);
@ -757,7 +755,6 @@ class AccountRepository implements AccountRepositoryInterface
$second = strval($query->sum('t.amount'));
$sum = bcadd($first, $second);
Log::debug('SumInPeriodData ', ['accounts' => $accountIds, 'first' => $first, 'second' => $second, 'sum' => $sum]);
return $sum;
}

View File

@ -205,8 +205,6 @@ class BudgetRepository implements BudgetRepositoryInterface
// get them:
$journals = $journalQuery->get(TransactionJournal::queryFields());
//Log::debug('journalsInPeriod journal count is ' . $journals->count());
// then get transactions themselves.
$transactionQuery = $this->user->transactionjournals()
->expanded()

View File

@ -198,9 +198,6 @@ class CategoryRepository implements CategoryRepositoryInterface
);
// create paginator
$offset = ($page - 1) * $pageSize;
Log::debug('Page is ' . $page);
Log::debug('Offset is ' . $offset);
Log::debug('pagesize is ' . $pageSize);
$subSet = $complete->slice($offset, $pageSize)->all();
$paginator = new LengthAwarePaginator($subSet, $complete->count(), $pageSize, $page);
@ -343,7 +340,6 @@ class CategoryRepository implements CategoryRepositoryInterface
/** @var TransactionJournal $first */
$lastJournalQuery = $category->transactionjournals()->orderBy('date', 'DESC');
Log::debug('lastUseDate ' . $category->name . ' (' . $category->id . ')');
if ($accounts->count() > 0) {
// filter journals:
@ -356,7 +352,6 @@ class CategoryRepository implements CategoryRepositoryInterface
if ($lastJournal) {
$last = $lastJournal->date;
Log::debug('last is now ' . $last);
}
// check transactions:
@ -371,8 +366,6 @@ class CategoryRepository implements CategoryRepositoryInterface
}
$lastTransaction = $lastTransactionQuery->first(['transaction_journals.*']);
if (!is_null($lastTransaction)) {
}
if (!is_null($lastTransaction) && ((!is_null($last) && $lastTransaction->date < $last) || is_null($last))) {
$last = new Carbon($lastTransaction->date);
}

View File

@ -122,11 +122,9 @@ class JournalRepository implements JournalRepositoryInterface
$entry = $this->user->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
if (is_null($entry)) {
Log::debug('Could not find first transaction journal.');
return new TransactionJournal;
}
Log::debug('Found first journal: ', ['date' => $entry->date->format('Y-m-d')]);
return $entry;
}
@ -145,8 +143,7 @@ class JournalRepository implements JournalRepositoryInterface
if (count($types) > 0) {
$query->transactionTypes($types);
}
$count = $this->user->transactionJournals()->transactionTypes($types)->count();
Log::debug('getJournals() count: ' . $count);
$count = $this->user->transactionJournals()->transactionTypes($types)->count();
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields());
$journals = new LengthAwarePaginator($set, $count, $pageSize, $page);
@ -205,7 +202,6 @@ class JournalRepository implements JournalRepositoryInterface
* @param TransactionJournal $journal
*
* @return Collection
* @throws FireflyException
*/
public function getTransactions(TransactionJournal $journal): Collection
{
@ -231,8 +227,8 @@ class JournalRepository implements JournalRepositoryInterface
/** @var Collection $transactions */
$transactions = $journal->transactions()
->groupBy('transactions.id')
->orderBy('transactions.id')->get(
->groupBy('transactions.id')
->orderBy('transactions.id')->get(
['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]
);
break;
@ -253,10 +249,6 @@ class JournalRepository implements JournalRepositoryInterface
);
$transactions->push($final);
break;
default:
throw new FireflyException('Cannot handle ' . $journal->transactionType->type);
break;
}
// foreach do balance thing
$transactions->each(
@ -469,27 +461,22 @@ class JournalRepository implements JournalRepositoryInterface
{
$sourceAccount = null;
$destinationAccount = null;
Log::debug('Now in storeAccounts()');
switch ($type->type) {
case TransactionType::WITHDRAWAL:
Log::debug('Now in storeAccounts()::withdrawal');
list($sourceAccount, $destinationAccount) = $this->storeWithdrawalAccounts($data);
break;
case TransactionType::DEPOSIT:
Log::debug('Now in storeAccounts()::deposit');
list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($data);
break;
case TransactionType::TRANSFER:
Log::debug('Now in storeAccounts()::transfer');
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
break;
default:
throw new FireflyException('Did not recognise transaction type.');
}
Log::debug('Now in storeAccounts(), continued.');
if (is_null($destinationAccount)) {
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
@ -540,10 +527,8 @@ class JournalRepository implements JournalRepositoryInterface
private function storeWithdrawalAccounts(array $data): array
{
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
Log::debug('Now in storeWithdrawalAccounts() with ', ['name' => $data['destination_account_name'], 'len' => strlen($data['destination_account_name'])]);
if (strlen($data['destination_account_name']) > 0) {
Log::debug('Now in storeWithdrawalAccounts()');
$destinationType = AccountType::where('type', 'Expense account')->first();
$destinationAccount = Account::firstOrCreateEncrypted(
[
@ -553,7 +538,6 @@ class JournalRepository implements JournalRepositoryInterface
'active' => 1,
]
);
Log::debug('Errors: ', ['err' => $destinationAccount->getErrors()->toArray(), 'id' => $destinationAccount->id]);
return [$sourceAccount, $destinationAccount];
}

View File

@ -72,8 +72,6 @@ class TransactionMatcher
// - the maximum number of transactions to search in have been searched
do {
// Fetch a batch of transactions from the database
//$offset = $page > 0 ? ($page - 1) * $pagesize : 0;
//$set = $this->repository->getCollectionOfTypes($this->transactionTypes, $offset, $pagesize);
$paginator = $this->repository->getJournals($this->transactionTypes, $page, $pagesize);
$set = $paginator->getCollection();

View File

@ -343,7 +343,6 @@ class ExpandedForm
$label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name);
//$value = $this->fillFieldValue($name, $value);
$html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render();
return $html;

View File

@ -1,282 +0,0 @@
<?php
/**
* SplitDataSeeder.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);
/**
* SplitDataSeeder.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.
*/
use Carbon\Carbon;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\Migration\TestData;
use FireflyIII\User;
use Illuminate\Database\Seeder;
/**
* Class SplitDataSeeder
*/
class SplitDataSeeder extends Seeder
{
/**
* TestDataSeeder constructor.
*/
public function __construct()
{
}
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$skipWithdrawal = false;
$skipDeposit = false;
$skipTransfer = true;
// start by creating all users:
// method will return the first user.
$user = TestData::createUsers();
// create all kinds of static data:
$assets = [['name' => 'Checking Account', 'iban' => 'NL11XOLA6707795988', 'meta' => ['accountRole' => 'defaultAsset']],
['name' => 'Alternate Checking Account', 'iban' => 'NL40UKBK3619908726', 'meta' => ['accountRole' => 'defaultAsset']],
['name' => 'Savings Account', 'iban' => 'NL96DZCO4665940223', 'meta' => ['accountRole' => 'savingAsset']],
['name' => 'Shared Checking Account', 'iban' => 'NL81RCQZ7160379858', 'meta' => ['accountRole' => 'sharedAsset']]];
// some asset accounts
TestData::createAssetAccounts($user, $assets);
// budgets, categories and others:
TestData::createBudgets($user);
TestData::createCategories($user);
TestData::createExpenseAccounts($user);
TestData::createRevenueAccounts($user);
TestData::createPiggybanks($user, 'Savings Account');
TestData::createBills($user);
// some bills
/*
* Create splitted expense of 66,-
*/
$today = new Carbon('2012-03-14');
if (!$skipWithdrawal) {
$this->generateWithdrawals($user);
}
// create splitted income of 99,-
$today->addDay();
if (!$skipDeposit) {
$this->generateDeposits($user);
}
// create a splitted transfer of 57,- (19)
// $today->addDay();
if (!$skipTransfer) {
$this->generateTransfers();
}
}
/**
* @param User $user
*/
private function generateDeposits(User $user)
{
/*
* DEPOSIT ONE
*/
$sources = ['Work SixtyFive', 'Work EightyFour'];
$categories = ['Salary', 'Reimbursements'];
$amounts = [50, 50];
$destination = TestData::findAccount($user, 'Alternate Checking Account');
$date = new Carbon('2012-03-12');
$journal = TransactionJournal::create(
['user_id' => $user->id, 'transaction_type_id' => 2, 'transaction_currency_id' => 1, 'description' => 'Split Even Income (journal (50/50))',
'completed' => 1, 'date' => $date->format('Y-m-d'),]
);
foreach ($sources as $index => $source) {
$cat = $categories[$index];
$source = TestData::findAccount($user, $source);
$one = Transaction::create(
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
'description' => 'Split Even Income #' . $index,]
);
$two = Transaction::create(
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
'description' => 'Split Even Income #' . $index,]
);
$one->categories()->save(TestData::findCategory($user, $cat));
$two->categories()->save(TestData::findCategory($user, $cat));
}
/*
* DEPOSIT TWO.
*/
$sources = ['Work SixtyFive', 'Work EightyFour', 'Work Fiftyone'];
$categories = ['Salary', 'Bills', 'Reimbursements'];
$amounts = [15, 34, 51];
$destination = TestData::findAccount($user, 'Checking Account');
$date = new Carbon;
$date->subDays(3);
$journal = TransactionJournal::create(
['user_id' => $user->id, 'transaction_type_id' => 2, 'transaction_currency_id' => 1,
'description' => 'Split Uneven Income (journal (15/34/51=100))', 'completed' => 1, 'date' => $date->format('Y-m-d'),]
);
foreach ($sources as $index => $source) {
$cat = $categories[$index];
$source = TestData::findAccount($user, $source);
$one = Transaction::create(
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
'description' => 'Split Uneven Income #' . $index,]
);
$two = Transaction::create(
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
'description' => 'Split Uneven Income #' . $index,]
);
$one->categories()->save(TestData::findCategory($user, $cat));
$two->categories()->save(TestData::findCategory($user, $cat));
}
}
private function generateTransfers()
{
$journal = TransactionJournal::create(
[
'user_id' => $user->id,
'transaction_type_id' => 3, // transfer
'transaction_currency_id' => 1,
'description' => 'Split Transfer (journal)',
'completed' => 1,
'date' => $today->format('Y-m-d'),
]
);
$source = TestData::findAccount($user, 'Alternate Checking Account');
$destinations = ['Checking Account', 'Savings Account', 'Shared Checking Account'];
$budgets = ['Groceries', 'Groceries', 'Car'];
$categories = ['Bills', 'Bills', 'Car'];
foreach ($destinations as $index => $dest) {
$bud = $budgets[$index];
$cat = $categories[$index];
$destination = TestData::findAccount($user, $dest);
$one = Transaction::create(
[
'account_id' => $source->id,
'transaction_journal_id' => $journal->id,
'amount' => '-19',
]
);
$two = Transaction::create(
[
'account_id' => $destination->id,
'transaction_journal_id' => $journal->id,
'amount' => '19',
]
);
$one->budgets()->save(TestData::findBudget($user, $bud));
$two->budgets()->save(TestData::findBudget($user, $bud));
$one->categories()->save(TestData::findCategory($user, $cat));
$two->categories()->save(TestData::findCategory($user, $cat));
}
}
/**
* @param User $user
*/
private function generateWithdrawals(User $user)
{
/*
* TRANSACTION ONE
*/
$destinations = ['SixtyFive', 'EightyFour'];
$budgets = ['Groceries', 'Car'];
$categories = ['Bills', 'Bills'];
$amounts = [50, 50];
$source = TestData::findAccount($user, 'Alternate Checking Account');
$date = new Carbon('2012-03-15');
$journal = TransactionJournal::create(
['user_id' => $user->id, 'transaction_type_id' => 1, 'transaction_currency_id' => 1, 'description' => 'Split Even Expense (journal (50/50))',
'completed' => 1, 'date' => $date->format('Y-m-d'),]
);
foreach ($destinations as $index => $dest) {
$bud = $budgets[$index];
$cat = $categories[$index];
$destination = TestData::findAccount($user, $dest);
$one = Transaction::create(
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
'description' => 'Split Even Expense #' . $index,]
);
$two = Transaction::create(
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
'description' => 'Split Even Expense #' . $index,]
);
$one->budgets()->save(TestData::findBudget($user, $bud));
$two->budgets()->save(TestData::findBudget($user, $bud));
$one->categories()->save(TestData::findCategory($user, $cat));
$two->categories()->save(TestData::findCategory($user, $cat));
}
/*
* TRANSACTION TWO.
*/
$destinations = ['SixtyFive', 'EightyFour', 'Fiftyone'];
$budgets = ['Groceries', 'Groceries', 'Car'];
$categories = ['Bills', 'Bills', 'Car'];
$amounts = [15, 34, 51];
$source = TestData::findAccount($user, 'Checking Account');
$date = new Carbon;
$journal = TransactionJournal::create(
['user_id' => $user->id, 'transaction_type_id' => 1, 'transaction_currency_id' => 1,
'description' => 'Split Uneven Expense (journal (15/34/51=100))', 'completed' => 1, 'date' => $date->format('Y-m-d'),]
);
foreach ($destinations as $index => $dest) {
$bud = $budgets[$index];
$cat = $categories[$index];
$destination = TestData::findAccount($user, $dest);
$one = Transaction::create(
['account_id' => $source->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index] * -1,
'description' => 'Split Uneven Expense #' . $index,]
);
$two = Transaction::create(
['account_id' => $destination->id, 'transaction_journal_id' => $journal->id, 'amount' => $amounts[$index],
'description' => 'Split Uneven Expense #' . $index,]
);
$one->budgets()->save(TestData::findBudget($user, $bud));
$two->budgets()->save(TestData::findBudget($user, $bud));
$one->categories()->save(TestData::findCategory($user, $cat));
$two->categories()->save(TestData::findCategory($user, $cat));
}
}
}