From 7d4006b20597eb8f0f275fe0bd66dcf01c3fbd55 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 07:14:01 +0100
Subject: [PATCH 01/71] Fixed some bugs while registering users.
---
app/controllers/UserController.php | 9 ++++++++-
.../FireflyIII/Shared/Mail/Registration.php | 20 +++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index 82309e2460..2a4af46abb 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -77,7 +77,11 @@ class UserController extends BaseController
$user = $repository->register(Input::all());
if ($user) {
- $email->sendVerificationMail($user);
+ $result = $email->sendVerificationMail($user);
+ if($result === false) {
+ $user->delete();
+ return View::make('error')->with('message','The email message could not be send. See the log files.');
+ }
return View::make('user.verification-pending');
}
@@ -121,6 +125,9 @@ class UserController extends BaseController
*/
public function register()
{
+ if (Config::get('mail.from.address') == '@gmail.com' || Config::get('mail.from.address') == '') {
+ return View::make('error')->with('message', 'Configuration error in app/config/'.App::environment().'/mail.php');
+ }
return View::make('user.register');
}
diff --git a/app/lib/FireflyIII/Shared/Mail/Registration.php b/app/lib/FireflyIII/Shared/Mail/Registration.php
index 4a8367c408..62f98eefe9 100644
--- a/app/lib/FireflyIII/Shared/Mail/Registration.php
+++ b/app/lib/FireflyIII/Shared/Mail/Registration.php
@@ -3,6 +3,8 @@ namespace FireflyIII\Shared\Mail;
use Swift_RfcComplianceException;
use Illuminate\Mail\Message;
+use Swift_TransportException;
+
/**
* Class Registration
*
@@ -57,7 +59,16 @@ class Registration implements RegistrationInterface
}
);
} catch (Swift_RfcComplianceException $e) {
+ \Log::error($e->getMessage());
+ return false;
+ } catch(Swift_TransportException $e) {
+ \Log::error($e->getMessage());
+ return false;
+ } catch(\Exception $e) {
+ \Log::error($e->getMessage());
+ return false;
}
+ return true;
}
@@ -84,7 +95,16 @@ class Registration implements RegistrationInterface
}
);
} catch (Swift_RfcComplianceException $e) {
+ \Log::error($e->getMessage());
+ return false;
+ } catch(Swift_TransportException $e) {
+ \Log::error($e->getMessage());
+ return false;
+ } catch(\Exception $e) {
+ \Log::error($e->getMessage());
+ return false;
}
+ return true;
}
}
From a854b2c17ef512388a7e8109c8c201f247617145 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 07:25:44 +0100
Subject: [PATCH 02/71] Some code cleanup in the account code.
---
app/controllers/GoogleChartController.php | 2 +-
app/controllers/HomeController.php | 4 +-
app/controllers/JsonController.php | 4 +-
app/controllers/PiggybankController.php | 4 +-
app/controllers/PreferencesController.php | 2 +-
app/controllers/RepeatedExpenseController.php | 4 +-
app/controllers/UserController.php | 7 +-
.../FireflyIII/Database/Account/Account.php | 188 +++---------------
.../Database/Account/AccountInterface.php | 46 -----
app/lib/FireflyIII/Report/Report.php | 2 +-
10 files changed, 40 insertions(+), 223 deletions(-)
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index f413c9c5a3..98696a972f 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -88,7 +88,7 @@ class GoogleChartController extends BaseController
/** @var \FireflyIII\Database\Account\Account $acct */
$acct = App::make('FireflyIII\Database\Account\Account');
- $accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAssetAccounts();
+ $accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAccountsByType(['Default account', 'Asset account']);
/** @var Account $account */
foreach ($accounts as $account) {
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php
index 33bd974e5e..485f71cb15 100644
--- a/app/controllers/HomeController.php
+++ b/app/controllers/HomeController.php
@@ -33,7 +33,7 @@ class HomeController extends BaseController
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
- $count = $acct->countAssetAccounts();
+ $count = $acct->countAccountsByType(['Default account', 'Asset account']);
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
@@ -42,7 +42,7 @@ class HomeController extends BaseController
// get the preference for the home accounts to show:
$frontPage = $preferences->get('frontPageAccounts', []);
if ($frontPage->data == []) {
- $accounts = $acct->getAssetAccounts();
+ $accounts = $acct->getAccountsByType(['Default account', 'Asset account']);
} else {
$accounts = $acct->getByIds($frontPage->data);
}
diff --git a/app/controllers/JsonController.php b/app/controllers/JsonController.php
index fedc5768d2..a0e6f08262 100644
--- a/app/controllers/JsonController.php
+++ b/app/controllers/JsonController.php
@@ -36,7 +36,7 @@ class JsonController extends BaseController
{
/** @var \FireflyIII\Database\Account\Account $accounts */
$accounts = App::make('FireflyIII\Database\Account\Account');
- $list = $accounts->getExpenseAccounts();
+ $list = $accounts->getAccountsByType(['Expense account', 'Beneficiary account']);
$return = [];
foreach ($list as $entry) {
$return[] = $entry->name;
@@ -53,7 +53,7 @@ class JsonController extends BaseController
{
/** @var \FireflyIII\Database\Account\Account $accounts */
$accounts = App::make('FireflyIII\Database\Account\Account');
- $list = $accounts->getRevenueAccounts();
+ $list = $accounts->getAccountsByType(['Revenue account']);
$return = [];
foreach ($list as $entry) {
$return[] = $entry->name;
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index 69222f22fa..16089486f2 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -62,7 +62,7 @@ class PiggyBankController extends BaseController
$acct = App::make('FireflyIII\Database\Account\Account');
$periods = Config::get('firefly.piggy_bank_periods');
- $accounts = FFForm::makeSelectList($acct->getAssetAccounts());
+ $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
$subTitle = 'Create new piggy bank';
$subTitleIcon = 'fa-plus';
@@ -107,7 +107,7 @@ class PiggyBankController extends BaseController
$acct = App::make('FireflyIII\Database\Account\Account');
$periods = Config::get('firefly.piggy_bank_periods');
- $accounts = FFForm::makeSelectList($acct->getAssetAccounts());
+ $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
$subTitle = 'Edit piggy bank "' . e($piggyBank->name) . '"';
$subTitleIcon = 'fa-pencil';
diff --git a/app/controllers/PreferencesController.php b/app/controllers/PreferencesController.php
index b1a5ca0fc7..ab4b81f717 100644
--- a/app/controllers/PreferencesController.php
+++ b/app/controllers/PreferencesController.php
@@ -29,7 +29,7 @@ class PreferencesController extends BaseController
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
- $accounts = $acct->getAssetAccounts();
+ $accounts = $acct->getAccountsByType(['Default account', 'Asset account']);
$viewRange = $preferences->get('viewRange', '1M');
$viewRangeValue = $viewRange->data;
$frontPage = $preferences->get('frontPageAccounts', []);
diff --git a/app/controllers/RepeatedExpenseController.php b/app/controllers/RepeatedExpenseController.php
index 652e255578..78272a9453 100644
--- a/app/controllers/RepeatedExpenseController.php
+++ b/app/controllers/RepeatedExpenseController.php
@@ -34,7 +34,7 @@ class RepeatedExpenseController extends BaseController
/** @var \FireflyIII\Database\Account\Account $acct */
$acct = App::make('FireflyIII\Database\Account\Account');
$periods = Config::get('firefly.piggy_bank_periods');
- $accounts = FFForm::makeSelectList($acct->getAssetAccounts());
+ $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
return View::make('repeatedExpense.create', compact('accounts', 'periods'))->with('subTitle', 'Create new repeated expense')->with(
'subTitleIcon', 'fa-plus'
@@ -79,7 +79,7 @@ class RepeatedExpenseController extends BaseController
$acct = App::make('FireflyIII\Database\Account\Account');
$periods = Config::get('firefly.piggy_bank_periods');
- $accounts = FFForm::makeSelectList($acct->getAssetAccounts());
+ $accounts = FFForm::makeSelectList($acct->getAccountsByType(['Default account', 'Asset account']));
$subTitle = 'Edit repeated expense "' . e($repeatedExpense->name) . '"';
$subTitleIcon = 'fa-pencil';
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index 2a4af46abb..74be723b18 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -78,9 +78,10 @@ class UserController extends BaseController
if ($user) {
$result = $email->sendVerificationMail($user);
- if($result === false) {
+ if ($result === false) {
$user->delete();
- return View::make('error')->with('message','The email message could not be send. See the log files.');
+
+ return View::make('error')->with('message', 'The email message could not be send. See the log files.');
}
return View::make('user.verification-pending');
@@ -126,7 +127,7 @@ class UserController extends BaseController
public function register()
{
if (Config::get('mail.from.address') == '@gmail.com' || Config::get('mail.from.address') == '') {
- return View::make('error')->with('message', 'Configuration error in app/config/'.App::environment().'/mail.php');
+ return View::make('error')->with('message', 'Configuration error in app/config/' . App::environment() . '/mail.php');
}
return View::make('user.register');
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php
index 368aeecac6..257ae7b79a 100644
--- a/app/lib/FireflyIII/Database/Account/Account.php
+++ b/app/lib/FireflyIII/Database/Account/Account.php
@@ -41,47 +41,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
return $this->getUser()->accounts()->accountTypeIn($types)->count();
}
- /**
- * @return int
- */
- public function countAssetAccounts()
- {
- return $this->countAccountsByType(['Default account', 'Asset account']);
- }
-
- /**
- * @return int
- */
- public function countExpenseAccounts()
- {
- return $this->countAccountsByType(['Expense account', 'Beneficiary account']);
- }
-
- /**
- * Counts the number of total revenue accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countRevenueAccounts()
- {
- return $this->countAccountsByType(['Revenue account']);
- }
-
- /**
- * @param \Account $account
- *
- * @return \Account|null
- */
- public function findInitialBalanceAccount(\Account $account)
- {
- /** @var \FireflyIII\Database\AccountType\AccountType $acctType */
- $acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
-
- $accountType = $acctType->findByWhat('initial');
-
- return $this->getUser()->accounts()->where('account_type_id', $accountType->id)->where('name', 'LIKE', $account->name . '%')->first();
- }
-
/**
* @param array $types
*
@@ -107,57 +66,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
return $set;
}
- /**
- * Get all asset accounts. Optional JSON based parameters.
- *
- * @param array $metaFilter
- *
- * @return Collection
- */
- public function getAssetAccounts($metaFilter = [])
- {
- $list = $this->getAccountsByType(['Default account', 'Asset account']);
- $list->each(
- function (\Account $account) {
-
- // get accountRole:
-
- /** @var \AccountMeta $entry */
- $accountRole = $account->accountmeta()->whereName('accountRole')->first();
- if (!$accountRole) {
- $accountRole = new \AccountMeta;
- $accountRole->account_id = $account->id;
- $accountRole->name = 'accountRole';
- $accountRole->data = 'defaultExpense';
- $accountRole->save();
-
- }
- $account->accountRole = $accountRole->data;
- }
- );
-
- return $list;
-
- }
-
- /**
- * @return Collection
- */
- public function getExpenseAccounts()
- {
- return $this->getAccountsByType(['Expense account', 'Beneficiary account']);
- }
-
- /**
- * Get all revenue accounts.
- *
- * @return Collection
- */
- public function getRevenueAccounts()
- {
- return $this->getAccountsByType(['Revenue account']);
- }
-
/**
* @param \Account $account
*
@@ -235,6 +143,31 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
+ /**
+ * @param \Account $account
+ *
+ * @return int
+ */
+ public function getLastActivity(\Account $account)
+ {
+ $lastActivityKey = 'account.' . $account->id . '.lastActivityDate';
+ if (\Cache::has($lastActivityKey)) {
+ return \Cache::get($lastActivityKey);
+ }
+
+ $transaction = $account->transactions()
+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ ->orderBy('transaction_journals.date', 'DESC')->first();
+ if ($transaction) {
+ $date = $transaction->transactionJournal->date;
+ } else {
+ $date = 0;
+ }
+ \Cache::forever($lastActivityKey, $date);
+
+ return $date;
+ }
+
/**
* @param Eloquent $model
*
@@ -571,57 +504,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
- /**
- * @param \Account $account
- * @param int $limit
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getAllTransactionJournals(\Account $account, $limit = 50)
- {
- $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
- $set = $this->getUser()->transactionJournals()->withRelevantData()->leftJoin(
- 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
- )->where('transactions.account_id', $account->id)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(
- ['transaction_journals.*']
- );
- $count = $this->getUser()->transactionJournals()->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->orderBy('date', 'DESC')->where('transactions.account_id', $account->id)->count();
- $items = [];
- foreach ($set as $entry) {
- $items[] = $entry;
- }
-
- return \Paginator::make($items, $count, $limit);
-
-
- }
-
- /**
- * @param \Account $account
- *
- * @return int
- */
- public function getLastActivity(\Account $account)
- {
- $lastActivityKey = 'account.' . $account->id . '.lastActivityDate';
- if (\Cache::has($lastActivityKey)) {
- return \Cache::get($lastActivityKey);
- }
-
- $transaction = $account->transactions()
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->orderBy('transaction_journals.date', 'DESC')->first();
- if ($transaction) {
- $date = $transaction->transactionJournal->date;
- } else {
- $date = 0;
- }
- \Cache::forever($lastActivityKey, $date);
-
- return $date;
- }
-
/**
* @param \Account $account
* @param int $limit
@@ -656,24 +538,4 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
- /**
- * @param \Account $account
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getTransactionJournalsInRange(\Account $account, Carbon $start, Carbon $end)
- {
- $set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->leftJoin(
- 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
- )->where('transactions.account_id', $account->id)->before($end)->after($start)->orderBy('date', 'DESC')->get(
- ['transaction_journals.*']
- );
-
- return $set;
-
- }
-
-
}
diff --git a/app/lib/FireflyIII/Database/Account/AccountInterface.php b/app/lib/FireflyIII/Database/Account/AccountInterface.php
index 336df90401..c9d21ba229 100644
--- a/app/lib/FireflyIII/Database/Account/AccountInterface.php
+++ b/app/lib/FireflyIII/Database/Account/AccountInterface.php
@@ -21,34 +21,6 @@ interface AccountInterface
*/
public function countAccountsByType(array $types);
- /**
- * Counts the number of total asset accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countAssetAccounts();
-
- /**
- * Counts the number of total expense accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countExpenseAccounts();
-
- /**
- * Counts the number of total revenue accounts. Useful for DataTables.
- *
- * @return int
- */
- public function countRevenueAccounts();
-
- /**
- * @param \Account $account
- *
- * @return \Account|null
- */
- public function findInitialBalanceAccount(\Account $account);
-
/**
* Get all accounts of the selected types. Is also capable of handling DataTables' parameters.
*
@@ -58,24 +30,6 @@ interface AccountInterface
*/
public function getAccountsByType(array $types);
- /**
- * Get all asset accounts. The parameters are optional and are provided by the DataTables plugin.
- *
- * @return Collection
- */
- public function getAssetAccounts();
-
- /**
- * @return Collection
- */
- public function getExpenseAccounts();
-
- /**
- * Get all revenue accounts.
- *
- * @return Collection
- */
- public function getRevenueAccounts();
/**
* @param \Account $account
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index 56deca08ec..f3040fe30f 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -387,7 +387,7 @@ class Report implements ReportInterface
$sharedAccounts[] = $account->id;
}
- $accounts = $this->_accounts->getAssetAccounts()->filter(
+ $accounts = $this->_accounts->getAccountsByType(['Default account', 'Asset account'])->filter(
function (\Account $account) use ($sharedAccounts) {
if (!in_array($account->id, $sharedAccounts)) {
return $account;
From d9c2df5b0d44c8d00a9c526d5170f098b53ad6a9 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 07:33:43 +0100
Subject: [PATCH 03/71] Removed unused methods.
---
app/lib/FireflyIII/Database/Bill/Bill.php | 13 --
.../Database/Bill/BillInterface.php | 12 --
app/lib/FireflyIII/Database/Budget/Budget.php | 175 +++++++-----------
.../FireflyIII/Database/Category/Category.php | 13 --
4 files changed, 68 insertions(+), 145 deletions(-)
diff --git a/app/lib/FireflyIII/Database/Bill/Bill.php b/app/lib/FireflyIII/Database/Bill/Bill.php
index 6e17ffe827..9c9683b7cf 100644
--- a/app/lib/FireflyIII/Database/Bill/Bill.php
+++ b/app/lib/FireflyIII/Database/Bill/Bill.php
@@ -189,19 +189,6 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
return $this->getUser()->bills()->where('active', 1)->get();
}
- /**
- * @param \Bill $bill
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return \TransactionJournal|null
- */
- public function getJournalForBillInRange(\Bill $bill, Carbon $start, Carbon $end)
- {
- return $this->getUser()->transactionjournals()->where('bill_id', $bill->id)->after($start)->before($end)->first();
-
- }
-
/**
* @param \Bill $bill
*
diff --git a/app/lib/FireflyIII/Database/Bill/BillInterface.php b/app/lib/FireflyIII/Database/Bill/BillInterface.php
index f6dca6325f..ec75dd1167 100644
--- a/app/lib/FireflyIII/Database/Bill/BillInterface.php
+++ b/app/lib/FireflyIII/Database/Bill/BillInterface.php
@@ -11,18 +11,6 @@ use Carbon\Carbon;
*/
interface BillInterface
{
- /**
- * @param \Bill $bill
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return null|\TransactionJournal
- * @internal param Carbon $current
- * @internal param Carbon $currentEnd
- *
- */
- public function getJournalForBillInRange(\Bill $bill, Carbon $start, Carbon $end);
-
/**
* @param \Bill $bill
*
diff --git a/app/lib/FireflyIII/Database/Budget/Budget.php b/app/lib/FireflyIII/Database/Budget/Budget.php
index 05f712a259..aaf6eabe3c 100644
--- a/app/lib/FireflyIII/Database/Budget/Budget.php
+++ b/app/lib/FireflyIII/Database/Budget/Budget.php
@@ -8,9 +8,9 @@ use FireflyIII\Database\SwitchUser;
use FireflyIII\Exception\FireflyException;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Database\Eloquent\Model as Eloquent;
+use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
-use Illuminate\Database\Query\Builder as QueryBuilder;
/**
* Class Budget
@@ -97,6 +97,71 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
}
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function expenseNoBudget(Carbon $start, Carbon $end)
+ {
+ // Add expenses that have no budget:
+ return $this->getUser()
+ ->transactionjournals()
+ ->whereNotIn(
+ 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
+ $query
+ ->select('transaction_journals.id')
+ ->from('transaction_journals')
+ ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
+ ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
+ }
+ )
+ ->before($end)
+ ->after($start)
+ ->lessThan(0)
+ ->transactionTypes(['Withdrawal'])
+ ->get();
+ }
+
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function journalsNoBudget(Carbon $start, Carbon $end)
+ {
+ $set = $this->getUser()
+ ->transactionjournals()
+ ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->whereNull('budget_transaction_journal.id')
+ ->before($end)
+ ->after($start)
+ ->orderBy('transaction_journals.date')
+ ->get(['transaction_journals.*']);
+
+ return $set;
+ }
+
+ /**
+ * This method includes the time because otherwise, SQLite does not understand it.
+ *
+ * @param \Budget $budget
+ * @param Carbon $date
+ *
+ * @return \LimitRepetition|null
+ */
+ public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date)
+ {
+ return \LimitRepetition::
+ leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
+ ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
+ ->where('budget_limits.budget_id', $budget->id)
+ ->first(['limit_repetitions.*']);
+ }
+
/**
* Returns an object with id $id.
*
@@ -210,96 +275,6 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
}
- /**
- * @param \Budget $budget
- * @param \LimitRepetition $repetition
- * @param int $limit
- *
- * @return \Illuminate\Pagination\Paginator
- */
- public function getTransactionJournalsInRepetition(\Budget $budget, \LimitRepetition $repetition, $limit = 50)
- {
- $start = $repetition->startdate;
- $end = $repetition->enddate;
-
- $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
- $set = $budget->transactionJournals()->withRelevantData()->before($end)->after($start)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(
- ['transaction_journals.*']
- );
- $count = $budget->transactionJournals()->before($end)->after($start)->count();
- $items = [];
- foreach ($set as $entry) {
- $items[] = $entry;
- }
-
- return \Paginator::make($items, $count, $limit);
- }
-
- /**
- * This method includes the time because otherwise, SQLite does not understand it.
- *
- * @param \Budget $budget
- * @param Carbon $date
- *
- * @return \LimitRepetition|null
- */
- public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date)
- {
- return \LimitRepetition::
- leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
- ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
- ->where('budget_limits.budget_id', $budget->id)
- ->first(['limit_repetitions.*']);
- }
-
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function expenseNoBudget(Carbon $start, Carbon $end)
- {
- // Add expenses that have no budget:
- return $this->getUser()
- ->transactionjournals()
- ->whereNotIn(
- 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
- $query
- ->select('transaction_journals.id')
- ->from('transaction_journals')
- ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
- ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
- }
- )
- ->before($end)
- ->after($start)
- ->lessThan(0)
- ->transactionTypes(['Withdrawal'])
- ->get();
- }
-
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function journalsNoBudget(Carbon $start, Carbon $end)
- {
- $set = $this->getUser()
- ->transactionjournals()
- ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->whereNull('budget_transaction_journal.id')
- ->before($end)
- ->after($start)
- ->orderBy('transaction_journals.date')
- ->get(['transaction_journals.*']);
-
- return $set;
- }
-
/**
* @param \Budget $budget
* @param Carbon $date
@@ -316,20 +291,6 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
return $sum;
}
- /**
- * @param \Budget $budget
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return float
- */
- public function spentInPeriod(\Budget $budget, Carbon $start, Carbon $end)
- {
- $sum = floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
-
- return $sum;
- }
-
/**
* This method updates the amount (envelope) for the given date and budget. This results in a (new) limit (aka an envelope)
* for that budget. Returned to the user is the new limit repetition.
@@ -343,7 +304,7 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
*/
public function updateLimitAmount(\Budget $budget, Carbon $date, $amount)
{
- /** @var \Limit $limit */
+ /** @var \BudgetLimit $limit */
$limit = $this->limitOnStartingOnDate($budget, $date);
if (!$limit) {
// create one!
@@ -381,7 +342,7 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
* @param \Budget $budget
* @param Carbon $date
*
- * @return \Limit
+ * @return \BudgetLimit
*/
public function limitOnStartingOnDate(\Budget $budget, Carbon $date)
{
diff --git a/app/lib/FireflyIII/Database/Category/Category.php b/app/lib/FireflyIII/Database/Category/Category.php
index 873ac9c312..14d8b64da3 100644
--- a/app/lib/FireflyIII/Database/Category/Category.php
+++ b/app/lib/FireflyIII/Database/Category/Category.php
@@ -195,19 +195,6 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
return $set;
}
- /**
- * @param \Category $category
- * @param Carbon $date
- *
- * @return null
- * @throws NotImplementedException
- * @internal param \Category $budget
- */
- public function repetitionOnStartingOnDate(\Category $category, Carbon $date)
- {
- throw new NotImplementedException;
- }
-
/**
* @param \Category $category
* @param Carbon $date
From fa7a59572a34d61ca394475d365abd74615e254f Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 08:57:55 +0100
Subject: [PATCH 04/71] Code cleanup for all controllers.
---
app/controllers/BillController.php | 23 +-
app/controllers/BudgetController.php | 3 -
app/controllers/CategoryController.php | 1 -
app/controllers/CurrencyController.php | 1 -
app/controllers/GoogleChartController.php | 4 -
app/controllers/HelpController.php | 78 ++-
app/controllers/PiggybankController.php | 3 -
app/controllers/PreferencesController.php | 1 -
app/controllers/ProfileController.php | 42 +-
app/controllers/RelatedController.php | 5 +
app/controllers/RepeatedExpenseController.php | 2 -
app/controllers/TransactionController.php | 5 -
app/database/seeds/DefaultUserSeeder.php | 22 -
app/database/seeds/TestContentSeeder.php | 561 ------------------
14 files changed, 99 insertions(+), 652 deletions(-)
delete mode 100644 app/database/seeds/DefaultUserSeeder.php
delete mode 100644 app/database/seeds/TestContentSeeder.php
diff --git a/app/controllers/BillController.php b/app/controllers/BillController.php
index 521c21736b..0fdd0f7309 100644
--- a/app/controllers/BillController.php
+++ b/app/controllers/BillController.php
@@ -5,8 +5,7 @@ use FireflyIII\Exception\FireflyException;
/**
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
- * @SuppressWarnings("NPathComplexity")
+ *
* Class BillController
*
*/
@@ -120,9 +119,9 @@ class BillController extends BaseController
*/
public function show(Bill $bill)
{
- $journals = $bill->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get();
+ $journals = $bill->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get();
$bill->nextExpectedMatch = $this->_repository->nextExpectedMatch($bill);
- $hideBill = true;
+ $hideBill = true;
return View::make('bills.show', compact('journals', 'hideBill', 'bill'))->with(
@@ -136,7 +135,7 @@ class BillController extends BaseController
*/
public function store()
{
- $data = Input::all();
+ $data = Input::except(['_token', 'post_submit_action']);
$data['user_id'] = Auth::user()->id;
@@ -149,17 +148,19 @@ class BillController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store bill: ' . $messages['errors']->first());
+
+ return Redirect::route('bills.create')->withInput();
}
// return to create screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if (Input::get('post_submit_action') == 'validate_only') {
return Redirect::route('bills.create')->withInput();
}
// store
$this->_repository->store($data);
Session::flash('success', 'Bill "' . e($data['name']) . '" stored.');
- if ($data['post_submit_action'] == 'store') {
+ if (Input::get('post_submit_action') == 'store') {
return Redirect::route('bills.index');
}
@@ -176,8 +177,8 @@ class BillController extends BaseController
public function update(Bill $bill)
{
$data = Input::except('_token');
- $data['active'] = isset($data['active']) ? 1 : 0;
- $data['automatch'] = isset($data['automatch']) ? 1 : 0;
+ $data['active'] = intval(Input::get('active'));
+ $data['automatch'] = intval(Input::get('automatch'));
$data['user_id'] = Auth::user()->id;
// always validate:
@@ -189,10 +190,12 @@ class BillController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update bill: ' . $messages['errors']->first());
+
+ return Redirect::route('bills.edit', $bill->id)->withInput();
}
// return to update screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('bills.edit', $bill->id)->withInput();
}
diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index 500ed85573..9365d67d2c 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -8,9 +8,6 @@ use FireflyIII\Shared\Preferences\PreferencesInterface as Pref;
* Class BudgetController
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("TooManyMethods") // I'm also fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
- * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove.
*
*/
class BudgetController extends BaseController
diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php
index 8459b4c40f..915562cfc2 100644
--- a/app/controllers/CategoryController.php
+++ b/app/controllers/CategoryController.php
@@ -6,7 +6,6 @@ use FireflyIII\Exception\FireflyException;
/**
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
*
* Class CategoryController
*/
diff --git a/app/controllers/CurrencyController.php b/app/controllers/CurrencyController.php
index d8c2d5b5d6..5e79791af3 100644
--- a/app/controllers/CurrencyController.php
+++ b/app/controllers/CurrencyController.php
@@ -4,7 +4,6 @@ use FireflyIII\Database\TransactionCurrency\TransactionCurrency as Repository;
/**
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
*
* Class CurrencyController
*/
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index 98696a972f..f2cfb3a0cf 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -6,10 +6,6 @@ use Grumpydictator\Gchart\GChart as GChart;
/**
* Class GoogleChartController
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("TooManyMethods") // I'm also fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
- * @SuppressWarnings("MethodLength") // There is one with 45 lines and im gonna move it.
- * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove.
*/
class GoogleChartController extends BaseController
{
diff --git a/app/controllers/HelpController.php b/app/controllers/HelpController.php
index 813b8faf5c..356f86b397 100644
--- a/app/controllers/HelpController.php
+++ b/app/controllers/HelpController.php
@@ -1,7 +1,6 @@
There is no help for this route!
';
- $helpTitle = 'Help';
+ $content = [
+ 'text' => 'There is no help for this route!
',
+ 'title' => 'Help',
+ ];
+
if (!Route::has($route)) {
\Log::error('No such route: ' . $route);
- return Response::json(['title' => $helpTitle, 'text' => $helpText]);
- }
- if (Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text')) {
- $helpText = Cache::get('help.' . $route . '.text');
- $helpTitle = Cache::get('help.' . $route . '.title');
-
- return Response::json(['title' => $helpTitle, 'text' => $helpText]);
+ return Response::json($content);
}
- $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md';
- \Log::debug('URL is: ' . $uri);
+ if ($this->_inCache($route)) {
+ $content = [
+ 'text' => Cache::get('help.' . $route . '.text'),
+ 'title' => Cache::get('help.' . $route . '.title'),
+ ];
+
+ return Response::json($content);
+ }
+ $content = $this->_getFromGithub($route);
+
+
+ Cache::put('help.' . $route . '.text', $content['text'], 10080); // a week.
+ Cache::put('help.' . $route . '.title', $content['title'], 10080);
+
+ return Response::json($content);
+
+ }
+
+ /**
+ * @param $route
+ *
+ * @return bool
+ */
+ protected function _inCache($route)
+ {
+ return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
+ }
+
+ /**
+ * @param $route
+ *
+ * @return array
+ */
+ protected function _getFromGithub($route)
+ {
+ $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md';
+ $content = [
+ 'text' => 'There is no help for this route!
',
+ 'title' => $route,
+ ];
try {
- $helpText = file_get_contents($uri);
+ $content['text'] = file_get_contents($uri);
} catch (ErrorException $e) {
\Log::error(trim($e->getMessage()));
}
- \Log::debug('Found help for ' . $route);
- \Log::debug('Help text length for route ' . $route . ' is ' . strlen($helpText));
- \Log::debug('Help text IS: "' . $helpText . '".');
- if (strlen(trim($helpText)) == 0) {
- $helpText = 'There is no help for this route.
';
+ if (strlen(trim($content['text'])) == 0) {
+ $content['text'] = 'There is no help for this route.
';
}
+ $content['text'] = \Michelf\Markdown::defaultTransform($content['text']);
- $helpText = \Michelf\Markdown::defaultTransform($helpText);
- $helpTitle = $route;
+ return $content;
- Cache::put('help.' . $route . '.text', $helpText, 10080); // a week.
- Cache::put('help.' . $route . '.title', $helpTitle, 10080);
-
- return Response::json(['title' => $helpTitle, 'text' => $helpText]);
}
-}
+}
+
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index 16089486f2..1523206116 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -8,9 +8,6 @@ use Illuminate\Support\Collection;
/**
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
- * @SuppressWarnings("TooManyMethods") // I'm also fine with this.
- * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove.
*
*
* Class PiggyBankController
diff --git a/app/controllers/PreferencesController.php b/app/controllers/PreferencesController.php
index ab4b81f717..d0d62d797d 100644
--- a/app/controllers/PreferencesController.php
+++ b/app/controllers/PreferencesController.php
@@ -3,7 +3,6 @@
/**
* Class PreferencesController
*
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
*
*/
class PreferencesController extends BaseController
diff --git a/app/controllers/ProfileController.php b/app/controllers/ProfileController.php
index e9b397833c..a9f9419bea 100644
--- a/app/controllers/ProfileController.php
+++ b/app/controllers/ProfileController.php
@@ -1,7 +1,6 @@
_validatePassword(Input::get('old'), Input::get('new1'), Input::get('new2'));
+ if (!($result === true)) {
+ Session::flash('error', $result);
return View::make('profile.change-password');
}
@@ -66,4 +55,29 @@ class ProfileController extends BaseController
return Redirect::route('profile');
}
+ /**
+ * @param string $old
+ * @param string $new1
+ * @param string $new2
+ *
+ * @return string|bool
+ */
+ protected function _validatePassword($old, $new1, $new2)
+ {
+ if (strlen($new1) == 0 || strlen($new2) == 0) {
+ return 'Do fill in a password!';
+
+ }
+ if ($new1 == $old) {
+ return 'The idea is to change your password.';
+ }
+
+ if ($new1 !== $new2) {
+ return 'New passwords do not match!';
+ }
+
+ return true;
+
+ }
+
}
diff --git a/app/controllers/RelatedController.php b/app/controllers/RelatedController.php
index 747dad5e3f..ec533564bb 100644
--- a/app/controllers/RelatedController.php
+++ b/app/controllers/RelatedController.php
@@ -3,6 +3,8 @@ use FireflyIII\Helper\Related\RelatedInterface;
use Illuminate\Support\Collection;
/**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
* Class RelatedController
*/
class RelatedController extends BaseController
@@ -10,6 +12,9 @@ class RelatedController extends BaseController
protected $_repository;
+ /**
+ * @param RelatedInterface $repository
+ */
public function __construct(RelatedInterface $repository)
{
$this->_repository = $repository;
diff --git a/app/controllers/RepeatedExpenseController.php b/app/controllers/RepeatedExpenseController.php
index 78272a9453..d9bf9f4002 100644
--- a/app/controllers/RepeatedExpenseController.php
+++ b/app/controllers/RepeatedExpenseController.php
@@ -6,8 +6,6 @@ use FireflyIII\Exception\FireflyException;
/**
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
- * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove.
*
* Class RepeatedExpenseController
*/
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index a7c9b12e71..5cef244661 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -9,10 +9,6 @@ use Illuminate\Support\Collection;
/**
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
- * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
- * @SuppressWarnings("CouplingBetweenObjects") // There's only so much I can remove.
- * @SuppressWarnings("TooManyMethods") // I'm also fine with this.
- * @SuppressWarnings("ExcessiveClassComplexity")
*
* Class TransactionController
*
@@ -198,7 +194,6 @@ class TransactionController extends BaseController
}
-
/**
* @param TransactionJournal $journal
*
diff --git a/app/database/seeds/DefaultUserSeeder.php b/app/database/seeds/DefaultUserSeeder.php
deleted file mode 100644
index 1b40e29097..0000000000
--- a/app/database/seeds/DefaultUserSeeder.php
+++ /dev/null
@@ -1,22 +0,0 @@
-delete();
- if (App::environment() == 'testing' || App::environment() == 'homestead') {
-
- User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
- User::create(['email' => 'acceptance@example.com', 'password' => 'acceptance', 'reset' => null, 'remember_token' => null]);
- User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
- User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
-
- }
-
- }
-
-}
diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.php
deleted file mode 100644
index e2cdebf7d7..0000000000
--- a/app/database/seeds/TestContentSeeder.php
+++ /dev/null
@@ -1,561 +0,0 @@
-_startOfMonth = Carbon::now()->startOfMonth();
- $this->som = $this->_startOfMonth->format('Y-m-d');
-
- $this->_endOfMonth = Carbon::now()->endOfMonth();
- $this->eom = $this->_endOfMonth->format('Y-m-d');
-
- $this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();
- $this->nsom = $this->_nextStartOfMonth->format('Y-m-d');
-
- $this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();
- $this->neom = $this->_nextEndOfMonth->format('Y-m-d');
-
- $this->_yearAgoStartOfMonth = Carbon::now()->subYear()->startOfMonth();
- $this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d');
-
- $this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();
- $this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');
-
-
- $this->_today = Carbon::now();
- $this->today = $this->_today->format('Y-m-d');
- }
-
- /**
- * Dates are always this month, the start of this month or earlier.
- */
- public function run()
- {
- if (App::environment() == 'testing' || App::environment() == 'homestead') {
-
- $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
-
- // create initial accounts and various other stuff:
- $this->createAssetAccounts($user);
- $this->createBudgets($user);
- $this->createCategories($user);
- $this->createPiggyBanks($user);
- $this->createReminders($user);
- $this->createRecurringTransactions($user);
- $this->createBills($user);
- $this->createExpenseAccounts($user);
- $this->createRevenueAccounts($user);
-
- // get some objects from the database:
- $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
- $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
- $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
- $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
- $television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
- $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
- $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
-
-
- $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
- $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
-
- $house = Category::whereName('House')->orderBy('id', 'DESC')->first();
-
-
- $withdrawal = TransactionType::whereType('Withdrawal')->first();
- $deposit = TransactionType::whereType('Deposit')->first();
- $transfer = TransactionType::whereType('Transfer')->first();
-
- $euro = TransactionCurrency::whereCode('EUR')->first();
-
- $rentBill = Bill::where('name', 'Rent')->first();
-
-
- $current = clone $this->_yearAgoStartOfMonth;
- while ($current <= $this->_startOfMonth) {
- $cur = $current->format('Y-m-d');
- $formatted = $current->format('F Y');
-
- // create expenses for rent, utilities, TV, phone on the 1st of the month.
- $this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill);
- $this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house);
- $this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house);
- $this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house);
-
- // two transactions. One without a budget, one without a category.
- $this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house);
- $this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null);
-
- // income from job:
- $this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro);
- $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);
-
- $this->createGroceries($current);
- $this->createBigExpense(clone $current);
-
- echo 'Created test-content for ' . $current->format('F Y') . "\n";
- $current->addMonth();
- }
-
-
- // piggy bank event
- // add money to this piggy bank
- // create a piggy bank event to match:
- $piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
- $intoPiggy = $this->createTransaction($checking, $savings, 100, $transfer, 'Money for piggy', $this->yaeom, $euro, $groceries, $house);
- PiggyBankEvent::create(
- [
- 'piggy_bank_id' => $piggyBank->id,
- 'transaction_journal_id' => $intoPiggy->id,
- 'date' => $this->yaeom,
- 'amount' => 100
- ]
- );
- }
- }
-
- /**
- * @param User $user
- */
- public function createAssetAccounts(User $user)
- {
- $assetType = AccountType::whereType('Asset account')->first();
- $ibType = AccountType::whereType('Initial balance account')->first();
- $obType = TransactionType::whereType('Opening balance')->first();
- $euro = TransactionCurrency::whereCode('EUR')->first();
-
-
- $acc_a = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
- $acc_b = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
- $acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
-
- $acc_d = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Checking account initial balance', 'active' => 0]);
- $acc_e = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]);
- $acc_f = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Delete me initial balance', 'active' => 0]);
-
-
- $this->createTransaction($acc_d, $acc_a, 4000, $obType, 'Initial Balance for Checking account', $this->yasom, $euro);
- $this->createTransaction($acc_e, $acc_b, 10000, $obType, 'Initial Balance for Savings account', $this->yasom, $euro);
- $this->createTransaction($acc_f, $acc_c, 100, $obType, 'Initial Balance for Delete me', $this->yasom, $euro);
- }
-
- /**
- * @param Account $from
- * @param Account $to
- * @param $amount
- * @param TransactionType $type
- * @param $description
- * @param $date
- * @param TransactionCurrency $currency
- *
- * @param Budget $budget
- * @param Category $category
- * @param Bill $bill
- *
- * @return TransactionJournal
- */
- public function createTransaction(
- Account $from, Account $to, $amount, TransactionType $type, $description, $date, TransactionCurrency $currency, Budget $budget = null,
- Category $category = null, Bill $bill = null
- ) {
- $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
-
- $billID = is_null($bill) ? null : $bill->id;
-
-
- /** @var TransactionJournal $journal */
- $journal = TransactionJournal::create(
- [
- 'user_id' => $user->id, 'transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'bill_id' => $billID,
- 'description' => $description, 'completed' => 1, 'date' => $date
- ]
- );
-
- Transaction::create(['account_id' => $from->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount * -1]);
- Transaction::create(['account_id' => $to->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount]);
-
- if (!is_null($budget)) {
- $journal->budgets()->save($budget);
- }
- if (!is_null($category)) {
- $journal->categories()->save($category);
- }
-
- return $journal;
- }
-
- /**
- * @param User $user
- */
- public function createBudgets(User $user)
- {
-
- $groceries = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
- $bills = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
- $deleteMe = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']);
- Budget::create(['user_id' => $user->id, 'name' => 'Budget without repetition']);
- $groceriesLimit = BudgetLimit::create(
- ['startdate' => $this->som, 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $groceries->id]
- );
- $billsLimit = BudgetLimit::create(
- ['startdate' => $this->som, 'amount' => 202, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $bills->id]
- );
- $deleteMeLimit = BudgetLimit::create(
- ['startdate' => $this->som, 'amount' => 203, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $deleteMe->id]
- );
-
- // and because we have no filters, some repetitions:
- LimitRepetition::create(['budget_limit_id' => $groceriesLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 201]);
- LimitRepetition::create(['budget_limit_id' => $billsLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 202]);
- LimitRepetition::create(['budget_limit_id' => $deleteMeLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 203]);
- }
-
- /**
- * @param User $user
- */
- public function createCategories(User $user)
- {
- Category::create(['user_id' => $user->id, 'name' => 'DailyGroceries']);
- Category::create(['user_id' => $user->id, 'name' => 'Lunch']);
- Category::create(['user_id' => $user->id, 'name' => 'House']);
- Category::create(['user_id' => $user->id, 'name' => 'Delete me']);
-
- }
-
- /**
- * @param User $user
- */
- public function createPiggyBanks(User $user)
- {
- // account
- $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
-
- // some dates
- $endDate = clone $this->_startOfMonth;
- $nextYear = clone $this->_startOfMonth;
-
- $endDate->addMonths(4);
- $nextYear->addYear()->subDay();
-
- $next = $nextYear->format('Y-m-d');
- $end = $endDate->format('Y-m-d');
-
- // piggy bank
- $newCamera = PiggyBank::create(
- [
- 'account_id' => $savings->id,
- 'name' => 'New camera',
- 'targetamount' => 2000,
- 'startdate' => $this->som,
- 'targetdate' => null,
- 'repeats' => 0,
- 'rep_length' => null,
- 'rep_every' => 0,
- 'rep_times' => null,
- 'reminder' => null,
- 'reminder_skip' => 0,
- 'remind_me' => 0,
- 'order' => 0,
- ]
- );
- // and some events!
- PiggyBankEvent::create(['piggy_bank_id' => $newCamera->id, 'date' => $this->som, 'amount' => 100]);
- PiggyBankRepetition::create(['piggy_bank_id' => $newCamera->id, 'startdate' => $this->som, 'targetdate' => null, 'currentamount' => 100]);
-
-
- $newClothes = PiggyBank::create(
- [
- 'account_id' => $savings->id,
- 'name' => 'New clothes',
- 'targetamount' => 2000,
- 'startdate' => $this->som,
- 'targetdate' => $end,
- 'repeats' => 0,
- 'rep_length' => null,
- 'rep_every' => 0,
- 'rep_times' => null,
- 'reminder' => null,
- 'reminder_skip' => 0,
- 'remind_me' => 0,
- 'order' => 0,
- ]
- );
-
- PiggyBankEvent::create(['piggy_bank_id' => $newClothes->id, 'date' => $this->som, 'amount' => 100]);
- PiggyBankRepetition::create(['piggy_bank_id' => $newClothes->id, 'startdate' => $this->som, 'targetdate' => $end, 'currentamount' => 100]);
-
- // weekly reminder piggy bank
- $weekly = PiggyBank::create(
- [
- 'account_id' => $savings->id,
- 'name' => 'Weekly reminder for clothes',
- 'targetamount' => 2000,
- 'startdate' => $this->som,
- 'targetdate' => $next,
- 'repeats' => 0,
- 'rep_length' => null,
- 'rep_every' => 0,
- 'rep_times' => null,
- 'reminder' => 'week',
- 'reminder_skip' => 0,
- 'remind_me' => 1,
- 'order' => 0,
- ]
- );
- PiggyBankRepetition::create(['piggy_bank_id' => $weekly->id, 'startdate' => $this->som, 'targetdate' => $next, 'currentamount' => 0]);
- }
-
- /**
- * @param User $user
- */
- public function createReminders(User $user)
- {
- // for weekly piggy bank (clothes)
- $nextWeek = clone $this->_startOfMonth;
- $piggyBank = PiggyBank::whereName('New clothes')->orderBy('id', 'DESC')->first();
- $nextWeek->addWeek();
- $week = $nextWeek->format('Y-m-d');
-
- Reminder::create(
- ['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 1, 'notnow' => 0,
- 'remindersable_id' => $piggyBank->id, 'remindersable_type' => 'PiggyBank']
- );
-
- // a fake reminder::
- Reminder::create(
- ['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 0, 'notnow' => 0, 'remindersable_id' => 40,
- 'remindersable_type' => 'Transaction']
- );
- }
-
- /**
- * @param User $user
- */
- public function createRecurringTransactions(User $user)
- {
- // account
- $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
-
- $recurring = PiggyBank::create(
- [
- 'account_id' => $savings->id,
- 'name' => 'Nieuwe spullen',
- 'targetamount' => 1000,
- 'startdate' => $this->som,
- 'targetdate' => $this->eom,
- 'repeats' => 1,
- 'rep_length' => 'month',
- 'rep_every' => 0,
- 'rep_times' => 0,
- 'reminder' => 'month',
- 'reminder_skip' => 0,
- 'remind_me' => 1,
- 'order' => 0,
- ]
- );
- PiggyBankRepetition::create(['piggy_bank_id' => $recurring->id, 'startdate' => $this->som, 'targetdate' => $this->eom, 'currentamount' => 0]);
- PiggyBankRepetition::create(
- ['piggy_bank_id' => $recurring->id, 'startdate' => $this->nsom, 'targetdate' => $this->neom, 'currentamount' => 0]
- );
- Reminder::create(
- ['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $this->neom, 'active' => 1, 'notnow' => 0,
- 'remindersable_id' => $recurring->id, 'remindersable_type' => 'PiggyBank']
- );
- }
-
- /**
- * @param $user
- */
- public function createBills($user)
- {
- // bill
- Bill::create(
- [
- 'user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord',
- 'amount_min' => 700,
- 'amount_max' => 900,
- 'date' => $this->som,
- 'active' => 1,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- ]
- );
-
- // bill
- Bill::create(
- [
- 'user_id' => $user->id,
- 'name' => 'Gas licht',
- 'match' => 'no,match',
- 'amount_min' => 500,
- 'amount_max' => 700,
- 'date' => $this->som,
- 'active' => 1,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- ]
- );
-
- // bill
- Bill::create(
- [
- 'user_id' => $user->id,
- 'name' => 'Something something',
- 'match' => 'mumble,mumble',
- 'amount_min' => 500,
- 'amount_max' => 700,
- 'date' => $this->som,
- 'active' => 0,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- ]
- );
-
- }
-
- /**
- * @param $user
- */
- public function createExpenseAccounts($user)
- {
- //// create expenses for rent, utilities, water, TV, phone on the 1st of the month.
- $expenseType = AccountType::whereType('Expense account')->first();
-
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Land lord', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Utilities company', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Water company', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'TV company', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Phone agency', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Super savers', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Groceries House', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Lunch House', 'active' => 1]);
-
-
- Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Buy More', 'active' => 1]);
-
- }
-
- /**
- * @param $user
- */
- public function createRevenueAccounts($user)
- {
- $revenueType = AccountType::whereType('Revenue account')->first();
-
- Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
- Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Second job employer', 'active' => 1]);
-
- }
-
- /**
- * @param Carbon $date
- */
- public function createGroceries(Carbon $date)
- {
- // variables we need:
- $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
- $shopOne = Account::whereName('Groceries House')->orderBy('id', 'DESC')->first();
- $shopTwo = Account::whereName('Super savers')->orderBy('id', 'DESC')->first();
- $lunchHouse = Account::whereName('Lunch House')->orderBy('id', 'DESC')->first();
- $lunch = Category::whereName('Lunch')->orderBy('id', 'DESC')->first();
- $daily = Category::whereName('DailyGroceries')->orderBy('id', 'DESC')->first();
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $withdrawal = TransactionType::whereType('Withdrawal')->first();
- $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
-
-
- $shops = [$shopOne, $shopTwo];
-
- // create groceries and lunch (daily, between 5 and 10 euro).
- $mStart = clone $date;
- $mEnd = clone $date;
- $mEnd->endOfMonth();
- while ($mStart <= $mEnd) {
- $mFormat = $mStart->format('Y-m-d');
- $shop = $shops[rand(0, 1)];
-
- $this->createTransaction($checking, $shop, (rand(500, 1000) / 100), $withdrawal, 'Groceries', $mFormat, $euro, $groceries, $daily);
- $this->createTransaction($checking, $lunchHouse, (rand(200, 600) / 100), $withdrawal, 'Lunch', $mFormat, $euro, $groceries, $lunch);
-
- $mStart->addDay();
- }
- }
-
- /**
- * @param $date
- */
- public function createBigExpense($date)
- {
- $date->addDays(12);
- $dollar = TransactionCurrency::whereCode('USD')->first();
- $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
- $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
- $buyMore = Account::whereName('Buy More')->orderBy('id', 'DESC')->first();
- $withdrawal = TransactionType::whereType('Withdrawal')->first();
- $transfer = TransactionType::whereType('Transfer')->first();
- $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
-
-
- // create some big expenses, move some money around.
- $amount = rand(500, 2000);
- $one = $this->createTransaction(
- $savings, $checking, $amount, $transfer, 'Money for big expense in ' . $date->format('F Y'), $date->format('Y-m-d'), $dollar
- );
- $two = $this->createTransaction(
- $checking, $buyMore, $amount, $withdrawal, 'Big expense in ' . $date->format('F Y'), $date->format('Y-m-d'), $dollar
- );
- $group = TransactionGroup::create(
- [
- 'user_id' => $user->id,
- 'relation' => 'balance'
- ]
- );
- $group->transactionjournals()->save($one);
- $group->transactionjournals()->save($two);
- }
-}
From a7887f1e25d3ad59a98e34aeddb47c497706323e Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 08:58:19 +0100
Subject: [PATCH 05/71] Added inspections for all migrations.
---
.../migrations/2014_06_27_163032_create_users_table.php | 2 ++
.../2014_06_27_163145_create_account_types_table.php | 2 ++
.../migrations/2014_06_27_163259_create_accounts_table.php | 2 ++
.../migrations/2014_06_27_163817_create_components_table.php | 2 ++
.../migrations/2014_06_27_163818_create_piggybanks_table.php | 2 ++
.../2014_06_27_164042_create_transaction_currencies_table.php | 2 ++
.../2014_06_27_164512_create_transaction_types_table.php | 2 ++
.../2014_06_27_164619_create_recurring_transactions_table.php | 2 ++
.../2014_06_27_164620_create_transaction_journals_table.php | 2 ++
.../migrations/2014_06_27_164836_create_transactions_table.php | 2 ++
.../2014_06_27_165344_create_component_transaction_table.php | 2 ++
...07_05_171326_create_component_transaction_journal_table.php | 2 ++
.../migrations/2014_07_06_123842_create_preferences_table.php | 2 ++
.../migrations/2014_07_09_204843_create_session_table.php | 2 ++
.../migrations/2014_07_17_183717_create_limits_table.php | 3 +++
.../migrations/2014_07_19_055011_create_limit_repeat_table.php | 2 ++
..._06_044416_create_component_recurring_transaction_table.php | 2 ++
.../2014_08_12_173919_create_piggybank_repetitions_table.php | 2 ++
.../2014_08_18_100330_create_piggybank_events_table.php | 2 ++
.../migrations/2014_08_23_113221_create_reminders_table.php | 2 ++
.../migrations/2014_11_10_172053_create_account_meta_table.php | 2 ++
.../2014_11_29_135749_create_transaction_groups_table.php | 2 ++
app/database/migrations/2014_12_13_190730_changes_for_v321.php | 2 ++
app/database/migrations/2014_12_24_191544_changes_for_v322.php | 2 ++
24 files changed, 49 insertions(+)
diff --git a/app/database/migrations/2014_06_27_163032_create_users_table.php b/app/database/migrations/2014_06_27_163032_create_users_table.php
index 3c72c3ab6c..cd554148db 100644
--- a/app/database/migrations/2014_06_27_163032_create_users_table.php
+++ b/app/database/migrations/2014_06_27_163032_create_users_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateUsersTable
*/
class CreateUsersTable extends Migration
diff --git a/app/database/migrations/2014_06_27_163145_create_account_types_table.php b/app/database/migrations/2014_06_27_163145_create_account_types_table.php
index 7d90098389..783ec4d15d 100644
--- a/app/database/migrations/2014_06_27_163145_create_account_types_table.php
+++ b/app/database/migrations/2014_06_27_163145_create_account_types_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateAccountTypesTable
*
*/
diff --git a/app/database/migrations/2014_06_27_163259_create_accounts_table.php b/app/database/migrations/2014_06_27_163259_create_accounts_table.php
index 71d3cd8a37..3fb5541655 100644
--- a/app/database/migrations/2014_06_27_163259_create_accounts_table.php
+++ b/app/database/migrations/2014_06_27_163259_create_accounts_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateAccountsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_163817_create_components_table.php b/app/database/migrations/2014_06_27_163817_create_components_table.php
index 2c4852f02c..465b1ecaff 100644
--- a/app/database/migrations/2014_06_27_163817_create_components_table.php
+++ b/app/database/migrations/2014_06_27_163817_create_components_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php b/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
index 5ac466d43e..67d527a66d 100644
--- a/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
+++ b/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePiggybanksTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php b/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php
index a6444da219..809a837bc9 100644
--- a/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php
+++ b/app/database/migrations/2014_06_27_164042_create_transaction_currencies_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionCurrenciesTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php b/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php
index 77a3d9924c..746f037a84 100644
--- a/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php
+++ b/app/database/migrations/2014_06_27_164512_create_transaction_types_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionTypesTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php b/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php
index c3e9aea81b..724059c859 100644
--- a/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php
+++ b/app/database/migrations/2014_06_27_164619_create_recurring_transactions_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateRecurringTransactionsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php b/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php
index b44af8769c..44ede35eb0 100644
--- a/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php
+++ b/app/database/migrations/2014_06_27_164620_create_transaction_journals_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionJournalsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_164836_create_transactions_table.php b/app/database/migrations/2014_06_27_164836_create_transactions_table.php
index 74765c1910..66b2772534 100644
--- a/app/database/migrations/2014_06_27_164836_create_transactions_table.php
+++ b/app/database/migrations/2014_06_27_164836_create_transactions_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionsTable
*
*/
diff --git a/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php b/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php
index d5f73f8444..6eee751926 100644
--- a/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php
+++ b/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentTransactionTable
*
*/
diff --git a/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php b/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php
index 2069e961a9..e6de376c42 100644
--- a/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php
+++ b/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentTransactionJournalTable
*
*/
diff --git a/app/database/migrations/2014_07_06_123842_create_preferences_table.php b/app/database/migrations/2014_07_06_123842_create_preferences_table.php
index 61f12090a2..7cd7069c8e 100644
--- a/app/database/migrations/2014_07_06_123842_create_preferences_table.php
+++ b/app/database/migrations/2014_07_06_123842_create_preferences_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePreferencesTable
*
*/
diff --git a/app/database/migrations/2014_07_09_204843_create_session_table.php b/app/database/migrations/2014_07_09_204843_create_session_table.php
index e09703979a..240f66ba88 100644
--- a/app/database/migrations/2014_07_09_204843_create_session_table.php
+++ b/app/database/migrations/2014_07_09_204843_create_session_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateSessionTable
*
*/
diff --git a/app/database/migrations/2014_07_17_183717_create_limits_table.php b/app/database/migrations/2014_07_17_183717_create_limits_table.php
index fc39882c7b..f6c507216a 100644
--- a/app/database/migrations/2014_07_17_183717_create_limits_table.php
+++ b/app/database/migrations/2014_07_17_183717_create_limits_table.php
@@ -4,6 +4,9 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)\
+ *
+ *
* Class CreateLimitsTable
*
*/
diff --git a/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php b/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php
index 1240cf3657..46edc87ac9 100644
--- a/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php
+++ b/app/database/migrations/2014_07_19_055011_create_limit_repeat_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateLimitRepeatTable
*
*/
diff --git a/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php b/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php
index 512387e29b..6105817f64 100644
--- a/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php
+++ b/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateComponentRecurringTransactionTable
*
*/
diff --git a/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php b/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php
index d285d99487..341d36a9d8 100644
--- a/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php
+++ b/app/database/migrations/2014_08_12_173919_create_piggybank_repetitions_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePiggyInstance
*
*/
diff --git a/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php b/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php
index 480f09d658..8eebf01388 100644
--- a/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php
+++ b/app/database/migrations/2014_08_18_100330_create_piggybank_events_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreatePiggybankEventsTable
*
*/
diff --git a/app/database/migrations/2014_08_23_113221_create_reminders_table.php b/app/database/migrations/2014_08_23_113221_create_reminders_table.php
index 8d231aac04..1aaa49fb0a 100644
--- a/app/database/migrations/2014_08_23_113221_create_reminders_table.php
+++ b/app/database/migrations/2014_08_23_113221_create_reminders_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateRemindersTable
*
*/
diff --git a/app/database/migrations/2014_11_10_172053_create_account_meta_table.php b/app/database/migrations/2014_11_10_172053_create_account_meta_table.php
index 0cbc84ae4d..1febb05a1b 100644
--- a/app/database/migrations/2014_11_10_172053_create_account_meta_table.php
+++ b/app/database/migrations/2014_11_10_172053_create_account_meta_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateAccountMetaTable
*
*/
diff --git a/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php b/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php
index acba3c84ce..c3d2e3af49 100644
--- a/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php
+++ b/app/database/migrations/2014_11_29_135749_create_transaction_groups_table.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class CreateTransactionGroupsTable
*
*/
diff --git a/app/database/migrations/2014_12_13_190730_changes_for_v321.php b/app/database/migrations/2014_12_13_190730_changes_for_v321.php
index 4a9a743178..546361390b 100644
--- a/app/database/migrations/2014_12_13_190730_changes_for_v321.php
+++ b/app/database/migrations/2014_12_13_190730_changes_for_v321.php
@@ -5,6 +5,8 @@ use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Down:
* 1. Create new Components based on Budgets.
* 2. Create new Components based on Categories
diff --git a/app/database/migrations/2014_12_24_191544_changes_for_v322.php b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
index 0714ea25fe..5e11626130 100644
--- a/app/database/migrations/2014_12_24_191544_changes_for_v322.php
+++ b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
@@ -4,6 +4,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
+ * @SuppressWarnings(PHPMD.ShortMethodName)
+ *
* Class ChangesForV322
*/
class ChangesForV322 extends Migration
From 33c830a4320c4b70ce90c570faff2e11692db926 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 08:58:30 +0100
Subject: [PATCH 06/71] Cleaned up seeders.
---
app/database/seeds/AccountTypeSeeder.php | 33 ++++++------------------
app/database/seeds/DatabaseSeeder.php | 2 --
2 files changed, 8 insertions(+), 27 deletions(-)
diff --git a/app/database/seeds/AccountTypeSeeder.php b/app/database/seeds/AccountTypeSeeder.php
index f0fd27b341..93523755ac 100644
--- a/app/database/seeds/AccountTypeSeeder.php
+++ b/app/database/seeds/AccountTypeSeeder.php
@@ -10,31 +10,14 @@ class AccountTypeSeeder extends Seeder
{
DB::table('account_types')->delete();
- AccountType::create(
- ['type' => 'Default account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Cash account', 'editable' => false]
- );
- AccountType::create(
- ['type' => 'Asset account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Expense account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Revenue account', 'editable' => true]
- );
- AccountType::create(
- ['type' => 'Initial balance account', 'editable' => false]
- );
- AccountType::create(
- ['type' => 'Beneficiary account', 'editable' => true]
- );
-
- AccountType::create(
- ['type' => 'Import account', 'editable' => false]
- );
+ AccountType::create(['type' => 'Default account', 'editable' => true]);
+ AccountType::create(['type' => 'Cash account', 'editable' => false]);
+ AccountType::create(['type' => 'Asset account', 'editable' => true]);
+ AccountType::create(['type' => 'Expense account', 'editable' => true]);
+ AccountType::create(['type' => 'Revenue account', 'editable' => true]);
+ AccountType::create(['type' => 'Initial balance account', 'editable' => false]);
+ AccountType::create(['type' => 'Beneficiary account', 'editable' => true]);
+ AccountType::create(['type' => 'Import account', 'editable' => false]);
}
diff --git a/app/database/seeds/DatabaseSeeder.php b/app/database/seeds/DatabaseSeeder.php
index 29319ca38c..ec034ef5f7 100644
--- a/app/database/seeds/DatabaseSeeder.php
+++ b/app/database/seeds/DatabaseSeeder.php
@@ -18,8 +18,6 @@ class DatabaseSeeder extends Seeder
$this->call('AccountTypeSeeder');
$this->call('TransactionCurrencySeeder');
$this->call('TransactionTypeSeeder');
- $this->call('DefaultUserSeeder');
- $this->call('TestContentSeeder');
}
}
From 027b954b50a122d3cd61daa68280c10b418dccc2 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 08:58:49 +0100
Subject: [PATCH 07/71] Cleanup various factories and libraries.
---
.../FireflyIII/Database/Account/Account.php | 49 ++---
.../Database/PiggyBank/PiggyBank.php | 5 +-
.../TransactionJournal/TransactionJournal.php | 178 ++++++++++--------
.../TransactionType/TransactionType.php | 3 +-
.../Helper/TransactionJournal/Helper.php | 21 ++-
app/lib/FireflyIII/Report/Report.php | 3 +-
app/lib/FireflyIII/Report/ReportQuery.php | 9 +-
app/lib/FireflyIII/Shared/Toolkit/Date.php | 124 ++++++------
app/lib/FireflyIII/Shared/Toolkit/Filter.php | 49 +++--
app/lib/FireflyIII/Shared/Toolkit/Form.php | 2 +-
app/tests/factories/PiggyBank.php | 8 +-
app/tests/factories/Transaction.php | 4 +-
12 files changed, 227 insertions(+), 228 deletions(-)
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php
index 257ae7b79a..1faa84c220 100644
--- a/app/lib/FireflyIII/Database/Account/Account.php
+++ b/app/lib/FireflyIII/Database/Account/Account.php
@@ -88,51 +88,31 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
{
$opposingData = ['name' => $account->name . ' Initial Balance', 'active' => 0, 'what' => 'initial'];
$opposingAccount = $this->store($opposingData);
-
- /*
- * Create a journal from opposing to account or vice versa.
- */
- $balance = floatval($data['openingbalance']);
- $date = new Carbon($data['openingbalancedate']);
- /** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $tj */
- $tj = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
+ $balance = floatval($data['openingbalance']);
+ $date = new Carbon($data['openingbalancedate']);
+ /** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journals */
+ $journals = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
+ $fromAccount = $opposingAccount;
+ $toAccount = $account;
if ($balance < 0) {
- // first transaction draws money from the new account to the opposing
- $from = $account;
- $to = $opposingAccount;
- } else {
- // first transaction puts money into account
- $from = $opposingAccount;
- $to = $account;
+ $fromAccount = $account;
+ $toAccount = $opposingAccount;
}
-
// data for transaction journal:
$balance = $balance < 0 ? $balance * -1 : $balance;
- // find the account type:
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
$type = $typeRepository->findByWhat('opening');
+ $currency = \Amount::getDefaultCurrency();
- // find the currency.
- $currency = \Amount::getDefaultCurrency();
+ $opening = ['transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'amount' => $balance, 'from' => $fromAccount,
+ 'completed' => 0, 'currency' => 'EUR', 'what' => 'opening', 'to' => $toAccount, 'date' => $date,
+ 'description' => 'Opening balance for new account ' . $account->name,];
- $opening = [
- 'transaction_type_id' => $type->id,
- 'transaction_currency_id' => $currency->id,
- 'amount' => $balance,
- 'from' => $from,
- 'completed' => 0,
- 'currency' => 'EUR',
- 'what' => 'opening',
- 'to' => $to,
- 'date' => $date,
- 'description' => 'Opening balance for new account ' . $account->name,];
-
-
- $validation = $tj->validate($opening);
+ $validation = $journals->validate($opening);
if ($validation['errors']->count() == 0) {
- $tj->store($opening);
+ $journals->store($opening);
return true;
} else {
@@ -141,6 +121,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
\App::abort(500);
}
+ return false;
}
/**
diff --git a/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php b/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
index b77f9246bb..5de40005e9 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
@@ -30,13 +30,10 @@ class PiggyBank extends PiggyBankShared implements CUDInterface, CommonDatabaseC
if ($reps->count() == 1) {
return $reps->first();
}
- if ($reps->count() == 0) {
- throw new FireflyException('Should always find a piggy bank repetition.');
- }
// should filter the one we need:
$repetitions = $reps->filter(
function (\PiggyBankRepetition $rep) use ($date) {
- if ($date >= $rep->startdate && $date <= $rep->targetdate) {
+ if ($date->between($rep->startdate, $rep->targetdate)) {
return $rep;
}
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index beb7b13df2..60f74c1415 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -117,9 +117,6 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$this->storeBudget($data, $model);
$this->storeCategory($data, $model);
- /*
- * Now we can update the transactions related to this journal.
- */
$amount = floatval($data['amount']);
/** @var \Transaction $transaction */
foreach ($model->transactions()->get() as $transaction) {
@@ -161,91 +158,37 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$journal->isValid();
$errors = $journal->getErrors();
+ /*
+ * Is not in rules.
+ */
if (!isset($model['what'])) {
$errors->add('description', 'Internal error: need to know type of transaction!');
}
/*
- * Amount
+ * Is not in rules.
*/
- if (isset($model['amount']) && floatval($model['amount']) < 0.01) {
- $errors->add('amount', 'Amount must be > 0.01');
- } else {
- if (!isset($model['amount'])) {
- $errors->add('amount', 'Amount must be set!');
- } else {
- $successes->add('amount', 'OK');
- }
- }
-
- /*
- * Budget
- */
- if (isset($model['budget_id']) && !ctype_digit($model['budget_id'])) {
- $errors->add('budget_id', 'Invalid budget');
- } else {
- $successes->add('budget_id', 'OK');
- }
-
- $successes->add('category', 'OK');
-
- /*
- * Many checks to catch invalid or not-existing accounts.
- */
- switch (true) {
- // this combination is often seen in withdrawals.
- case (isset($model['account_id']) && isset($model['expense_account'])):
- if (intval($model['account_id']) < 1) {
- $errors->add('account_id', 'Invalid account.');
- } else {
- $successes->add('account_id', 'OK');
- }
- $successes->add('expense_account', 'OK');
- break;
- case (isset($model['account_id']) && isset($model['revenue_account'])):
- if (intval($model['account_id']) < 1) {
- $errors->add('account_id', 'Invalid account.');
- } else {
- $successes->add('account_id', 'OK');
- }
- $successes->add('revenue_account', 'OK');
- break;
- case (isset($model['account_from_id']) && isset($model['account_to_id'])):
- if (intval($model['account_from_id']) < 1 || intval($model['account_from_id']) < 1) {
- $errors->add('account_from_id', 'Invalid account selected.');
- $errors->add('account_to_id', 'Invalid account selected.');
-
- } else {
- if (intval($model['account_from_id']) == intval($model['account_to_id'])) {
- $errors->add('account_to_id', 'Cannot be the same as "from" account.');
- $errors->add('account_from_id', 'Cannot be the same as "to" account.');
- } else {
- $successes->add('account_from_id', 'OK');
- $successes->add('account_to_id', 'OK');
- }
- }
- break;
-
- case (isset($model['to']) && isset($model['from'])):
- if (is_object($model['to']) && is_object($model['from'])) {
- $successes->add('from', 'OK');
- $successes->add('to', 'OK');
- }
- break;
-
- default:
- throw new FireflyException('Cannot validate accounts for transaction journal.');
- break;
- }
+ $errors = $errors->merge($this->_validateAmount($model));
+ $errors = $errors->merge($this->_validateBudget($model));
+ $errors = $errors->merge($this->_validateAccount($model));
/*
* Add "OK"
*/
- if (!$errors->has('description')) {
- $successes->add('description', 'OK');
- }
- if (!$errors->has('date')) {
- $successes->add('date', 'OK');
+
+ /**
+ * else {
+ * $successes->add('account_from_id', 'OK');
+ * $successes->add('account_to_id', 'OK');
+ * }
+ * else {
+ */
+ $list = ['date', 'description', 'amount', 'budget_id', 'from', 'to', 'account_from_id', 'account_to_id', 'category', 'account_id', 'expense_account',
+ 'revenue_account'];
+ foreach ($list as $entry) {
+ if (!$errors->has($entry)) {
+ $successes->add($entry, 'OK');
+ }
}
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
@@ -377,6 +320,85 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
return $typeRepository->findByWhat($type);
}
+ /**
+ * @param array $model
+ *
+ * @return MessageBag
+ */
+ protected function _validateAmount(array $model)
+ {
+ $errors = new MessageBag;
+ if (isset($model['amount']) && floatval($model['amount']) < 0.01) {
+ $errors->add('amount', 'Amount must be > 0.01');
+ } else {
+ if (!isset($model['amount'])) {
+ $errors->add('amount', 'Amount must be set!');
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @param array $model
+ *
+ * @return MessageBag
+ */
+ protected function _validateBudget(array $model)
+ {
+ /*
+ * Budget (is not in rules)
+ */
+ $errors = new MessageBag;
+ if (isset($model['budget_id']) && !ctype_digit($model['budget_id'])) {
+ $errors->add('budget_id', 'Invalid budget');
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @param array $model
+ *
+ * @return MessageBag
+ * @throws FireflyException
+ */
+ protected function _validateAccount(array $model)
+ {
+ $errors = new MessageBag;
+ switch (true) {
+ // this combination is often seen in withdrawals.
+ case (isset($model['account_id']) && isset($model['expense_account'])):
+ if (intval($model['account_id']) < 1) {
+ $errors->add('account_id', 'Invalid account.');
+ }
+ break;
+ case (isset($model['account_id']) && isset($model['revenue_account'])):
+ if (intval($model['account_id']) < 1) {
+ $errors->add('account_id', 'Invalid account.');
+ }
+ break;
+ case (isset($model['account_from_id']) && isset($model['account_to_id'])):
+ if (intval($model['account_from_id']) < 1 || intval($model['account_from_id']) < 1) {
+ $errors->add('account_from_id', 'Invalid account selected.');
+ $errors->add('account_to_id', 'Invalid account selected.');
+
+ } else {
+ if (intval($model['account_from_id']) == intval($model['account_to_id'])) {
+ $errors->add('account_to_id', 'Cannot be the same as "from" account.');
+ $errors->add('account_from_id', 'Cannot be the same as "to" account.');
+ }
+ }
+ break;
+
+ default:
+ throw new FireflyException('Cannot validate accounts for transaction journal.');
+ break;
+ }
+
+ return $errors;
+ }
+
/**
* Returns an object with id $id.
*
diff --git a/app/lib/FireflyIII/Database/TransactionType/TransactionType.php b/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
index b3b5191de4..2159e5d62a 100644
--- a/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
+++ b/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
@@ -96,9 +96,10 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
'withdrawal' => 'Withdrawal',
'deposit' => 'Deposit',
];
- if(!isset($translation[$what])) {
+ if (!isset($translation[$what])) {
throw new FireflyException('Cannot find transaction type described as "' . e($what) . '".');
}
+
return \TransactionType::whereType($translation[$what])->first();
}
diff --git a/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php b/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
index 304cef0c5d..f2f9b0f313 100644
--- a/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
+++ b/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
@@ -12,15 +12,6 @@ use Illuminate\Support\Collection;
class Helper implements HelperInterface
{
- /**
- * @param $what
- *
- * @return int
- */
- public function getTransactionTypeIdByWhat($what) {
-
- }
-
/**
*
* Get the account_id, which is the asset account that paid for the transaction.
@@ -49,7 +40,7 @@ class Helper implements HelperInterface
/** @var \FireflyIII\Database\Account\Account $accountRepository */
$accountRepository = \App::make('FireflyIII\Database\Account\Account');
- return $accountRepository->getAssetAccounts();
+ return $accountRepository->getAccountsByType(['Default account', 'Asset account']);
}
/**
@@ -90,4 +81,14 @@ class Helper implements HelperInterface
}
+ /**
+ * @param $what
+ *
+ * @return int
+ */
+ public function getTransactionTypeIdByWhat($what)
+ {
+
+ }
+
}
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index f3040fe30f..748b2f5f49 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -11,8 +11,9 @@ use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
/**
- * Class Report
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
*
+ * Class Report
*
* @package FireflyIII\Report
*/
diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php
index 1a143cbb44..a53618adcd 100644
--- a/app/lib/FireflyIII/Report/ReportQuery.php
+++ b/app/lib/FireflyIII/Report/ReportQuery.php
@@ -68,16 +68,13 @@ class ReportQuery implements ReportQueryInterface
}
)
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'otherJournals.id')
- ->before($end)
- ->after($start)
+ ->before($end)->after($start)
->where('transaction_types.type', 'Withdrawal')
->where('transaction_journals.user_id', \Auth::user()->id)
- ->whereNull('budget_transaction_journal.budget_id')
- ->whereNull('transaction_journals.deleted_at')
+ ->whereNull('budget_transaction_journal.budget_id')->whereNull('transaction_journals.deleted_at')
->whereNull('otherJournals.deleted_at')
->where('transactions.account_id', $account->id)
- ->whereNotNull('transaction_group_transaction_journal.transaction_group_id')
- ->groupBy('transaction_journals.id')
+ ->whereNotNull('transaction_group_transaction_journal.transaction_group_id')->groupBy('transaction_journals.id')
->get(
[
'transaction_journals.id as transferId',
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.php
index 3f7b321216..7b41d9d273 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Date.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php
@@ -13,7 +13,7 @@ use FireflyIII\Exception\FireflyException;
class Date
{
/**
- * @param Carbon $theDate
+ * @param Carbon $theDate
* @param $repeatFreq
* @param $skip
*
@@ -25,41 +25,37 @@ class Date
$date = clone $theDate;
$add = ($skip + 1);
- switch ($repeatFreq) {
- default:
- throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"');
- break;
- case 'daily':
- $date->addDays($add);
- break;
- case 'week':
- case 'weekly':
- $date->addWeeks($add);
- break;
- case 'month':
- case 'monthly':
- $date->addMonths($add);
- break;
- case 'quarter':
- case 'quarterly':
- $months = $add * 3;
- $date->addMonths($months);
- break;
- case 'half-year':
- $months = $add * 6;
- $date->addMonths($months);
- break;
- case 'year':
- case 'yearly':
- $date->addYears($add);
- break;
+ $functionMap = [
+ 'daily' => 'addDays',
+ 'weekly' => 'addWeeks',
+ 'week' => 'addWeeks',
+ 'month' => 'addMonths',
+ 'monthly' => 'addMonths',
+ 'quarter' => 'addMonths',
+ 'quarterly' => 'addMonths',
+ 'half-year' => 'addMonths',
+ 'year' => 'addYears',
+ 'yearly' => 'addYears',
+ ];
+ $modifierMap = [
+ 'quarter' => 3,
+ 'quarterly' => 3,
+ 'half-year' => 6,
+ ];
+ if (!isset($functionMap[$repeatFreq])) {
+ throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"');
}
+ if (isset($modifierMap[$repeatFreq])) {
+ $add = $add * $modifierMap[$repeatFreq];
+ }
+ $function = $functionMap[$repeatFreq];
+ $date->$function($add);
return $date;
}
/**
- * @param Carbon $theCurrentEnd
+ * @param Carbon $theCurrentEnd
* @param $repeatFreq
*
* @return Carbon
@@ -68,41 +64,47 @@ class Date
public function endOfPeriod(Carbon $theCurrentEnd, $repeatFreq)
{
$currentEnd = clone $theCurrentEnd;
- switch ($repeatFreq) {
- default:
- throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
- break;
- case 'daily':
- $currentEnd->addDay();
- break;
- case 'week':
- case 'weekly':
- $currentEnd->addWeek()->subDay();
- break;
- case 'month':
- case 'monthly':
- $currentEnd->addMonth()->subDay();
- break;
- case 'quarter':
- case 'quarterly':
- $currentEnd->addMonths(3)->subDay();
- break;
- case 'half-year':
- $currentEnd->addMonths(6)->subDay();
- break;
- case 'year':
- case 'yearly':
- $currentEnd->addYear()->subDay();
- break;
+
+ $functionMap = [
+ 'daily' => 'addDay',
+ 'week' => 'addWeek',
+ 'weekly' => 'addWeek',
+ 'month' => 'addMonth',
+ 'monthly' => 'addMonth',
+ 'quarter' => 'addMonths',
+ 'quarterly' => 'addMonths',
+ 'half-year' => 'addMonths',
+ 'year' => 'addYear',
+ 'yearly' => 'addYear',
+ ];
+ $modifierMap = [
+ 'quarter' => 3,
+ 'quarterly' => 3,
+ 'half-year' => 6,
+ ];
+
+ $subDay = ['week', 'weekly', 'month', 'monthly', 'quarter', 'quarterly', 'half-year', 'year', 'yearly'];
+
+ if (!isset($functionMap[$repeatFreq])) {
+ throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
+ }
+ $function = $functionMap[$repeatFreq];
+ if (isset($modifierMap[$repeatFreq])) {
+ $currentEnd->$function($modifierMap[$repeatFreq]);
+ } else {
+ $currentEnd->$function();
+ }
+ if (in_array($repeatFreq, $subDay)) {
+ $currentEnd->subDay();
}
return $currentEnd;
}
/**
- * @param Carbon $theCurrentEnd
+ * @param Carbon $theCurrentEnd
* @param $repeatFreq
- * @param Carbon $maxDate
+ * @param Carbon $maxDate
*
* @return Carbon
* @throws FireflyException
@@ -149,7 +151,7 @@ class Date
}
/**
- * @param Carbon $date
+ * @param Carbon $date
* @param $repeatFrequency
*
* @return string
@@ -183,7 +185,7 @@ class Date
}
/**
- * @param Carbon $theDate
+ * @param Carbon $theDate
* @param $repeatFreq
*
* @return Carbon
@@ -228,7 +230,7 @@ class Date
}
/**
- * @param Carbon $theDate
+ * @param Carbon $theDate
* @param $repeatFreq
* @param int $subtract
*
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Filter.php b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
index 9be82e313a..f8fdf42037 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Filter.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
@@ -69,36 +69,29 @@ class Filter
*/
protected function updateStartDate($range, Carbon $start)
{
- switch ($range) {
- default:
- throw new FireflyException('updateStartDate cannot handle $range ' . $range);
- break;
- case '1D':
- $start->startOfDay();
- break;
- case '1W':
- $start->startOfWeek();
- break;
- case '1M':
- $start->startOfMonth();
- break;
- case '3M':
- $start->firstOfQuarter();
- break;
- case '6M':
- if (intval($start->format('m')) >= 7) {
- $start->startOfYear()->addMonths(6);
- } else {
- $start->startOfYear();
- }
- break;
- case '1Y':
- $start->startOfYear();
- break;
+ $functionMap = [
+ '1D' => 'startOfDay',
+ '1W' => 'startOfWeek',
+ '1M' => 'startOfMonth',
+ '3M' => 'firstOfQuarter',
+ '1Y' => 'startOfYear',
+ ];
+ if (isset($functionMap[$range])) {
+ $function = $functionMap[$range];
+ $start->$function();
+
+ return $start;
}
+ if ($range == '6M') {
+ if (intval($start->format('m')) >= 7) {
+ $start->startOfYear()->addMonths(6);
+ } else {
+ $start->startOfYear();
+ }
- return $start;
-
+ return $start;
+ }
+ throw new FireflyException('updateStartDate cannot handle $range ' . $range);
}
/**
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Form.php b/app/lib/FireflyIII/Shared/Toolkit/Form.php
index 55457dc7d5..a5475a0456 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Form.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Form.php
@@ -32,7 +32,7 @@ class Form
$title = null;
foreach ($fields as $field) {
- if (is_null($title) && isset($entry->$field)) {
+ if (isset($entry->$field)) {
$title = $entry->$field;
}
}
diff --git a/app/tests/factories/PiggyBank.php b/app/tests/factories/PiggyBank.php
index 36f89debf8..aaab88cd71 100644
--- a/app/tests/factories/PiggyBank.php
+++ b/app/tests/factories/PiggyBank.php
@@ -15,8 +15,12 @@ League\FactoryMuffin\Facade::define(
return $set[rand(0, count($set) - 1)];
},
- 'rep_every' => function() {return rand(0,3);},
- 'rep_times' => function() {return rand(0,3);},
+ 'rep_every' => function () {
+ return rand(0, 3);
+ },
+ 'rep_times' => function () {
+ return rand(0, 3);
+ },
'reminder' => function () {
$set = ['day', 'week', 'quarter', 'month', 'year'];
diff --git a/app/tests/factories/Transaction.php b/app/tests/factories/Transaction.php
index 9f812b8ce0..39f50f7ca5 100644
--- a/app/tests/factories/Transaction.php
+++ b/app/tests/factories/Transaction.php
@@ -5,8 +5,8 @@ League\FactoryMuffin\Facade::define(
'account_id' => 'factory|Account',
'transaction_journal_id' => 'factory|TransactionJournal',
'description' => 'sentence',
- 'amount' => function() {
- return round(rand(100,10000) / 100,2);
+ 'amount' => function () {
+ return round(rand(100, 10000) / 100, 2);
}
]
);
From fc0ef4b79de59803871fab228c936422c41834bd Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 10:05:43 +0100
Subject: [PATCH 08/71] Small optimizations.
---
app/controllers/BudgetController.php | 8 ++++++--
app/controllers/CategoryController.php | 8 ++++++--
app/controllers/CurrencyController.php | 5 ++++-
app/controllers/GoogleChartController.php | 2 +-
app/controllers/HelpController.php | 2 ++
app/controllers/PiggybankController.php | 2 ++
app/controllers/ProfileController.php | 4 +++-
app/controllers/RelatedController.php | 4 ++++
app/controllers/RepeatedExpenseController.php | 3 ++-
9 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index 9365d67d2c..53ae58aef2 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -145,6 +145,8 @@ class BudgetController extends BaseController
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param Budget $budget
* @param LimitRepetition $repetition
*
@@ -181,10 +183,11 @@ class BudgetController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not validate budget: ' . $messages['errors']->first());
+ return Redirect::route('budgets.create')->withInput();
}
// return to create screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('budgets.create')->withInput();
}
@@ -219,10 +222,11 @@ class BudgetController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update budget: ' . $messages['errors']->first());
+ return Redirect::route('budgets.edit', $budget->id)->withInput();
}
// return to update screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('budgets.edit', $budget->id)->withInput();
}
diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php
index 915562cfc2..bc5d0846f1 100644
--- a/app/controllers/CategoryController.php
+++ b/app/controllers/CategoryController.php
@@ -105,6 +105,7 @@ class CategoryController extends BaseController
}
/**
+ *
* @return $this
* @throws FireflyException
*/
@@ -122,10 +123,11 @@ class CategoryController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store category: ' . $messages['errors']->first());
+ return Redirect::route('categories.create')->withInput();
}
// return to create screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('categories.create')->withInput();
}
@@ -140,6 +142,7 @@ class CategoryController extends BaseController
}
/**
+ *
* @param Category $category
*
* @return $this
@@ -159,10 +162,11 @@ class CategoryController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update category: ' . $messages['errors']->first());
+ return Redirect::route('categories.edit', $category->id)->withInput();
}
// return to update screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('categories.edit', $category->id)->withInput();
}
diff --git a/app/controllers/CurrencyController.php b/app/controllers/CurrencyController.php
index 5e79791af3..9b55132333 100644
--- a/app/controllers/CurrencyController.php
+++ b/app/controllers/CurrencyController.php
@@ -122,6 +122,8 @@ class CurrencyController extends BaseController
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function store()
@@ -173,10 +175,11 @@ class CurrencyController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update currency: ' . $messages['errors']->first());
+ return Redirect::route('currency.edit', $currency->id)->withInput();
}
// return to update screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('currency.edit', $currency->id)->withInput();
}
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index f2cfb3a0cf..99d5662b12 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -72,7 +72,7 @@ class GoogleChartController extends BaseController
}
/**
- * This method renders the b
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
*/
public function allAccountsBalanceChart()
{
diff --git a/app/controllers/HelpController.php b/app/controllers/HelpController.php
index 356f86b397..dbb9f7a2aa 100644
--- a/app/controllers/HelpController.php
+++ b/app/controllers/HelpController.php
@@ -1,8 +1,10 @@
count() > 0) {
Session::flash('error', 'Could not store repeated expense: ' . $messages['errors']->first());
+ return Redirect::route('repeated.create')->withInput();
}
// return to create screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('repeated.create')->withInput();
}
From 0faebc290fe5f6e197c4902b53d389b0ee809deb Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 10:05:51 +0100
Subject: [PATCH 09/71] Suppress warnings.
---
app/database/migrations/2014_12_13_190730_changes_for_v321.php | 3 ++-
app/database/migrations/2014_12_24_191544_changes_for_v322.php | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/app/database/migrations/2014_12_13_190730_changes_for_v321.php b/app/database/migrations/2014_12_13_190730_changes_for_v321.php
index 546361390b..9d5242189d 100644
--- a/app/database/migrations/2014_12_13_190730_changes_for_v321.php
+++ b/app/database/migrations/2014_12_13_190730_changes_for_v321.php
@@ -5,7 +5,8 @@ use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
- * @SuppressWarnings(PHPMD.ShortMethodName)
+ * @SuppressWarnings(PHPMD.ShortMethodName) // method names are mandated by laravel.
+ * @SuppressWarnings("TooManyMethods") // I'm fine with this
*
* Down:
* 1. Create new Components based on Budgets.
diff --git a/app/database/migrations/2014_12_24_191544_changes_for_v322.php b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
index 5e11626130..5b5e7abff2 100644
--- a/app/database/migrations/2014_12_24_191544_changes_for_v322.php
+++ b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
@@ -5,6 +5,8 @@ use Illuminate\Database\Schema\Blueprint;
/**
* @SuppressWarnings(PHPMD.ShortMethodName)
+ * @SuppressWarnings("MethodLength") // I don't mind this in case of migrations.
+
*
* Class ChangesForV322
*/
From 9e2b34bc12dc57560e9d5ad8b6e7889e52bb0245 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 10:06:12 +0100
Subject: [PATCH 10/71] Various cleanup.
---
.../FireflyIII/Database/Account/Account.php | 16 ++++----
.../Database/AccountType/AccountType.php | 41 ++++++++++---------
app/lib/FireflyIII/Database/Bill/Bill.php | 14 +++----
app/lib/FireflyIII/Database/Budget/Budget.php | 4 ++
.../FireflyIII/Database/Category/Category.php | 8 ++++
.../Database/PiggyBank/PiggyBankShared.php | 4 ++
.../Database/PiggyBank/RepeatedExpense.php | 2 +
.../Database/Transaction/Transaction.php | 9 ++++
.../TransactionCurrency.php | 6 +++
.../TransactionJournal/TransactionJournal.php | 10 +++++
.../TransactionType/TransactionType.php | 14 +++++++
app/lib/FireflyIII/Event/Piggybank.php | 4 ++
.../Helper/TransactionJournal/Helper.php | 9 ----
.../TransactionJournal/HelperInterface.php | 7 ----
app/lib/FireflyIII/Report/Report.php | 4 ++
app/lib/FireflyIII/Search/Search.php | 2 +
.../FireflyIII/Shared/Toolkit/Reminders.php | 5 +++
.../Shared/Validation/FireflyValidator.php | 2 +
app/models/Bill.php | 1 -
app/models/BudgetLimit.php | 3 --
app/models/LimitRepetition.php | 1 -
app/tests/TestCase.php | 2 +
22 files changed, 113 insertions(+), 55 deletions(-)
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php
index 1faa84c220..9fe77ea498 100644
--- a/app/lib/FireflyIII/Database/Account/Account.php
+++ b/app/lib/FireflyIII/Database/Account/Account.php
@@ -406,6 +406,8 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param $what
*
* @throws NotImplementedException
@@ -445,14 +447,14 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*/
public function firstExpenseAccountOrCreate($name)
{
- /** @var \FireflyIII\Database\AccountType\AccountType $accountTypeRepository */
- $accountTypeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
+ /** @var \FireflyIII\Database\AccountType\AccountType $typeRepository */
+ $typeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
- $accountType = $accountTypeRepository->findByWhat('expense');
+ $accountType = $typeRepository->findByWhat('expense');
// if name is "", find cash account:
if (strlen($name) == 0) {
- $cashAccountType = $accountTypeRepository->findByWhat('cash');
+ $cashAccountType = $typeRepository->findByWhat('cash');
// find or create cash account:
return \Account::firstOrCreate(
@@ -474,10 +476,10 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*/
public function firstRevenueAccountOrCreate($name)
{
- /** @var \FireflyIII\Database\AccountType\AccountType $accountTypeRepository */
- $accountTypeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
+ /** @var \FireflyIII\Database\AccountType\AccountType $typeRepository */
+ $typeRepository = \App::make('FireflyIII\Database\AccountType\AccountType');
- $accountType = $accountTypeRepository->findByWhat('revenue');
+ $accountType = $typeRepository->findByWhat('revenue');
$data = ['user_id' => $this->getUser()->id, 'account_type_id' => $accountType->id, 'name' => $name, 'active' => 1];
diff --git a/app/lib/FireflyIII/Database/AccountType/AccountType.php b/app/lib/FireflyIII/Database/AccountType/AccountType.php
index 58f6cebb13..30a9c2bcc6 100644
--- a/app/lib/FireflyIII/Database/AccountType/AccountType.php
+++ b/app/lib/FireflyIII/Database/AccountType/AccountType.php
@@ -19,6 +19,7 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param Eloquent $model
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
* @throws NotImplementedException
@@ -30,6 +31,7 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param array $data
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return \Eloquent
* @throws NotImplementedException
@@ -42,6 +44,7 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param Eloquent $model
* @param array $data
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
* @throws NotImplementedException
@@ -52,6 +55,8 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Validates an array. Returns an array containing MessageBags
* errors/warnings/successes.
*
@@ -66,6 +71,8 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
@@ -88,30 +95,22 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
*/
public function findByWhat($what)
{
- switch ($what) {
- case 'expense':
- return \AccountType::whereType('Expense account')->first();
- break;
- case 'asset':
- return \AccountType::whereType('Asset account')->first();
- break;
- case 'revenue':
- return \AccountType::whereType('Revenue account')->first();
- break;
- case 'cash':
- return \AccountType::whereType('Cash account')->first();
- break;
- case 'initial':
- return \AccountType::whereType('Initial balance account')->first();
- break;
- default:
- throw new FireflyException('Cannot find account type described as "' . e($what) . '".');
- break;
-
+ $typeMap = [
+ 'expense' => 'Expense account',
+ 'asset' => 'Asset account',
+ 'revenue' => 'Revenue account',
+ 'cash' => 'Cash account',
+ 'initial' => 'Initial balance account',
+ ];
+ if (isset($typeMap[$what])) {
+ return \AccountType::whereType($typeMap[$what])->first();
}
+ throw new FireflyException('Cannot find account type described as "' . e($what) . '".');
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns all objects.
*
* @return Collection
@@ -123,6 +122,8 @@ class AccountType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
diff --git a/app/lib/FireflyIII/Database/Bill/Bill.php b/app/lib/FireflyIII/Database/Bill/Bill.php
index 9c9683b7cf..e987d4abc7 100644
--- a/app/lib/FireflyIII/Database/Bill/Bill.php
+++ b/app/lib/FireflyIII/Database/Bill/Bill.php
@@ -133,6 +133,8 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
@@ -146,6 +148,8 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
@@ -169,6 +173,7 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param array $ids
*
* @return Collection
@@ -205,15 +210,14 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \Bill $bill
*
* @return Carbon|null
*/
public function nextExpectedMatch(\Bill $bill)
{
- /*
- * The date Firefly tries to find. If this stays null, it's "unknown".
- */
$finalDate = null;
if ($bill->active == 0) {
return $finalDate;
@@ -225,10 +229,6 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
*/
$today = \DateKit::addPeriod(new Carbon, $bill->repeat_freq, 0);
- /*
- * FF3 loops from the $start of the bill, and to make sure
- * $skip works, it adds one (for modulo).
- */
$skip = $bill->skip + 1;
$start = \DateKit::startOfPeriod(new Carbon, $bill->repeat_freq);
/*
diff --git a/app/lib/FireflyIII/Database/Budget/Budget.php b/app/lib/FireflyIII/Database/Budget/Budget.php
index aaf6eabe3c..f437879e87 100644
--- a/app/lib/FireflyIII/Database/Budget/Budget.php
+++ b/app/lib/FireflyIII/Database/Budget/Budget.php
@@ -175,6 +175,8 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
@@ -200,6 +202,8 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
diff --git a/app/lib/FireflyIII/Database/Category/Category.php b/app/lib/FireflyIII/Database/Category/Category.php
index 14d8b64da3..a4a8dc0137 100644
--- a/app/lib/FireflyIII/Database/Category/Category.php
+++ b/app/lib/FireflyIII/Database/Category/Category.php
@@ -99,6 +99,8 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
@@ -112,6 +114,8 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
@@ -125,6 +129,8 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns all objects.
*
* @return Collection
@@ -135,6 +141,8 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
diff --git a/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php b/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php
index 5a878e37f4..1d5fa492aa 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/PiggyBankShared.php
@@ -58,6 +58,8 @@ class PiggyBankShared
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
@@ -123,6 +125,8 @@ class PiggyBankShared
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param Eloquent $model
* @param array $data
*
diff --git a/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php b/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php
index 171b4c7a88..bf22ca509c 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/RepeatedExpense.php
@@ -17,6 +17,8 @@ class RepeatedExpense extends PiggyBankShared implements CUDInterface, CommonDat
{
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* Based on the piggy bank, the reminder-setting and
* other variables this method tries to divide the piggy bank into equal parts. Each is
* accommodated by a reminder (if everything goes to plan).
diff --git a/app/lib/FireflyIII/Database/Transaction/Transaction.php b/app/lib/FireflyIII/Database/Transaction/Transaction.php
index a92f110d2e..6880999fb7 100644
--- a/app/lib/FireflyIII/Database/Transaction/Transaction.php
+++ b/app/lib/FireflyIII/Database/Transaction/Transaction.php
@@ -22,6 +22,7 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
/**
* @param Eloquent $model
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
* @throws NotImplementedException
@@ -59,6 +60,8 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Eloquent $model
* @param array $data
*
@@ -92,6 +95,8 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
@@ -105,6 +110,8 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
@@ -129,6 +136,8 @@ class Transaction implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
diff --git a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php
index 55b7c5f502..fc72379da4 100644
--- a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php
+++ b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php
@@ -89,6 +89,8 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
@@ -102,6 +104,8 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
@@ -125,6 +129,8 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $objectIds
* @throws NotImplementedException
*
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index 60f74c1415..10015a1afb 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -210,6 +210,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param array $data
*
* @return array
@@ -321,6 +323,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
}
/**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
* @param array $model
*
* @return MessageBag
@@ -340,6 +344,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
}
/**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
* @param array $model
*
* @return MessageBag
@@ -358,6 +364,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
}
/**
+ * @SuppressWarnings("CamelCase") // I'm fine with this.
+ *
* @param array $model
*
* @return MessageBag
@@ -412,6 +420,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
* @param $what
diff --git a/app/lib/FireflyIII/Database/TransactionType/TransactionType.php b/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
index 2159e5d62a..ca5b678587 100644
--- a/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
+++ b/app/lib/FireflyIII/Database/TransactionType/TransactionType.php
@@ -20,6 +20,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
{
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Eloquent $model
*
* @return bool
@@ -31,6 +33,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $data
*
* @return \Eloquent
@@ -42,6 +46,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Eloquent $model
* @param array $data
*
@@ -54,6 +60,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Validates an array. Returns an array containing MessageBags
* errors/warnings/successes.
*
@@ -68,6 +76,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns an object with id $id.
*
* @param int $objectId
@@ -104,6 +114,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* Returns all objects.
*
* @return Collection
@@ -115,6 +127,8 @@ class TransactionType implements CUDInterface, CommonDatabaseCallsInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $ids
*
* @return Collection
diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php
index 5c1960a170..645f48432b 100644
--- a/app/lib/FireflyIII/Event/Piggybank.php
+++ b/app/lib/FireflyIII/Event/Piggybank.php
@@ -34,6 +34,8 @@ class PiggyBank
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \TransactionJournal $journal
*
* @throws \FireflyIII\Exception\FireflyException
@@ -109,6 +111,8 @@ class PiggyBank
*/
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \TransactionJournal $journal
* @param int $piggyBankId
*/
diff --git a/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php b/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
index f2f9b0f313..90ef11060d 100644
--- a/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
+++ b/app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
@@ -81,14 +81,5 @@ class Helper implements HelperInterface
}
- /**
- * @param $what
- *
- * @return int
- */
- public function getTransactionTypeIdByWhat($what)
- {
-
- }
}
diff --git a/app/lib/FireflyIII/Helper/TransactionJournal/HelperInterface.php b/app/lib/FireflyIII/Helper/TransactionJournal/HelperInterface.php
index f49046a42a..06bcac0de7 100644
--- a/app/lib/FireflyIII/Helper/TransactionJournal/HelperInterface.php
+++ b/app/lib/FireflyIII/Helper/TransactionJournal/HelperInterface.php
@@ -22,13 +22,6 @@ interface HelperInterface
*/
public function getAssetAccount($what, Collection $transactions);
- /**
- * @param $what
- *
- * @return int
- */
- public function getTransactionTypeIdByWhat($what);
-
/**
* @return Collection
*/
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index 748b2f5f49..91a3caae95 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -227,6 +227,8 @@ class Report implements ReportInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Carbon $date
* @param bool $shared
*
@@ -354,6 +356,8 @@ class Report implements ReportInterface
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param Carbon $start
* @param Carbon $end
* @param int $limit
diff --git a/app/lib/FireflyIII/Search/Search.php b/app/lib/FireflyIII/Search/Search.php
index 859d83b7b4..4a5d429634 100644
--- a/app/lib/FireflyIII/Search/Search.php
+++ b/app/lib/FireflyIII/Search/Search.php
@@ -80,6 +80,8 @@ class Search
}
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param array $words
*
* @return Collection
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Reminders.php b/app/lib/FireflyIII/Shared/Toolkit/Reminders.php
index fe3b40ed9b..11b75259e1 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Reminders.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Reminders.php
@@ -15,6 +15,8 @@ class Reminders
{
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param \Reminder $reminder
*
* @return int
@@ -62,6 +64,9 @@ class Reminders
return $reminders;
}
+ /**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ */
public function updateReminders()
{
/** @var Collection $set */
diff --git a/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php b/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php
index 544174a1c5..33795d563b 100644
--- a/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php
+++ b/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php
@@ -11,6 +11,8 @@ use Illuminate\Validation\Validator;
class FireflyValidator extends Validator
{
/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ *
* @param $attribute
* @param $value
* @param $parameters
diff --git a/app/models/Bill.php b/app/models/Bill.php
index 00d7d2c1e4..bc5500ebe2 100644
--- a/app/models/Bill.php
+++ b/app/models/Bill.php
@@ -1,5 +1,4 @@
Date: Sat, 17 Jan 2015 10:41:29 +0100
Subject: [PATCH 11/71] Reinstated test data seeder, fixed the tests.
---
app/controllers/UserController.php | 6 +-
app/database/seeds/DatabaseSeeder.php | 4 +
app/database/seeds/TestDataSeeder.php | 562 ++++++++++++++++++++++++++
3 files changed, 570 insertions(+), 2 deletions(-)
create mode 100644 app/database/seeds/TestDataSeeder.php
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index 74be723b18..702ffe991b 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -78,7 +78,7 @@ class UserController extends BaseController
if ($user) {
$result = $email->sendVerificationMail($user);
- if ($result === false) {
+ if ($result === false && Config::get('mail.pretend') === false) {
$user->delete();
return View::make('error')->with('message', 'The email message could not be send. See the log files.');
@@ -126,7 +126,9 @@ class UserController extends BaseController
*/
public function register()
{
- if (Config::get('mail.from.address') == '@gmail.com' || Config::get('mail.from.address') == '') {
+ if ((Config::get('mail.from.address') == '@gmail.com' || Config::get('mail.from.address') == '')
+ && Config::get('mail.pretend') === false
+ ) {
return View::make('error')->with('message', 'Configuration error in app/config/' . App::environment() . '/mail.php');
}
diff --git a/app/database/seeds/DatabaseSeeder.php b/app/database/seeds/DatabaseSeeder.php
index ec034ef5f7..f357dfd6ec 100644
--- a/app/database/seeds/DatabaseSeeder.php
+++ b/app/database/seeds/DatabaseSeeder.php
@@ -18,6 +18,10 @@ class DatabaseSeeder extends Seeder
$this->call('AccountTypeSeeder');
$this->call('TransactionCurrencySeeder');
$this->call('TransactionTypeSeeder');
+
+ if (App::environment() == 'testing') {
+ $this->call('TestDataSeeder');
+ }
}
}
diff --git a/app/database/seeds/TestDataSeeder.php b/app/database/seeds/TestDataSeeder.php
new file mode 100644
index 0000000000..bfa8e63de1
--- /dev/null
+++ b/app/database/seeds/TestDataSeeder.php
@@ -0,0 +1,562 @@
+_startOfMonth = Carbon::now()->startOfMonth();
+ $this->som = $this->_startOfMonth->format('Y-m-d');
+
+ $this->_endOfMonth = Carbon::now()->endOfMonth();
+ $this->eom = $this->_endOfMonth->format('Y-m-d');
+
+ $this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();
+ $this->nsom = $this->_nextStartOfMonth->format('Y-m-d');
+
+ $this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();
+ $this->neom = $this->_nextEndOfMonth->format('Y-m-d');
+
+ $this->_yearAgoStartOfMonth = Carbon::now()->subYear()->startOfMonth();
+ $this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d');
+
+ $this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();
+ $this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');
+
+
+ $this->_today = Carbon::now();
+ $this->today = $this->_today->format('Y-m-d');
+ }
+
+ /**
+ * Dates are always this month, the start of this month or earlier.
+ */
+ public function run()
+ {
+ User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
+ User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
+
+
+ $user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
+
+ // create initial accounts and various other stuff:
+ $this->createAssetAccounts($user);
+ $this->createBudgets($user);
+ $this->createCategories($user);
+ $this->createPiggyBanks($user);
+ $this->createReminders($user);
+ $this->createRecurringTransactions($user);
+ $this->createBills($user);
+ $this->createExpenseAccounts($user);
+ $this->createRevenueAccounts($user);
+
+ // get some objects from the database:
+ $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
+ $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
+ $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
+ $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
+ $television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
+ $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
+ $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
+
+
+ $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
+ $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
+
+ $house = Category::whereName('House')->orderBy('id', 'DESC')->first();
+
+
+ $withdrawal = TransactionType::whereType('Withdrawal')->first();
+ $deposit = TransactionType::whereType('Deposit')->first();
+ $transfer = TransactionType::whereType('Transfer')->first();
+
+ $euro = TransactionCurrency::whereCode('EUR')->first();
+
+ $rentBill = Bill::where('name', 'Rent')->first();
+
+
+ $current = clone $this->_yearAgoStartOfMonth;
+ while ($current <= $this->_startOfMonth) {
+ $cur = $current->format('Y-m-d');
+ $formatted = $current->format('F Y');
+
+ // create expenses for rent, utilities, TV, phone on the 1st of the month.
+ $this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill);
+ $this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house);
+ $this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house);
+ $this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house);
+
+ // two transactions. One without a budget, one without a category.
+ $this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house);
+ $this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null);
+
+ // income from job:
+ $this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro);
+ $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);
+
+ $this->createGroceries($current);
+ $this->createBigExpense(clone $current);
+
+ echo 'Created test-content for ' . $current->format('F Y') . "\n";
+ $current->addMonth();
+ }
+
+
+ // piggy bank event
+ // add money to this piggy bank
+ // create a piggy bank event to match:
+ $piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
+ $intoPiggy = $this->createTransaction($checking, $savings, 100, $transfer, 'Money for piggy', $this->yaeom, $euro, $groceries, $house);
+ PiggyBankEvent::create(
+ [
+ 'piggy_bank_id' => $piggyBank->id,
+ 'transaction_journal_id' => $intoPiggy->id,
+ 'date' => $this->yaeom,
+ 'amount' => 100
+ ]
+ );
+ }
+
+ /**
+ * @param User $user
+ */
+ public function createAssetAccounts(User $user)
+ {
+ $assetType = AccountType::whereType('Asset account')->first();
+ $ibType = AccountType::whereType('Initial balance account')->first();
+ $obType = TransactionType::whereType('Opening balance')->first();
+ $euro = TransactionCurrency::whereCode('EUR')->first();
+
+
+ $acc_a = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
+ $acc_b = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
+ $acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
+
+ $acc_d = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Checking account initial balance', 'active' => 0]);
+ $acc_e = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]);
+ $acc_f = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Delete me initial balance', 'active' => 0]);
+
+
+ $this->createTransaction($acc_d, $acc_a, 4000, $obType, 'Initial Balance for Checking account', $this->yasom, $euro);
+ $this->createTransaction($acc_e, $acc_b, 10000, $obType, 'Initial Balance for Savings account', $this->yasom, $euro);
+ $this->createTransaction($acc_f, $acc_c, 100, $obType, 'Initial Balance for Delete me', $this->yasom, $euro);
+ }
+
+ /**
+ * @param Account $from
+ * @param Account $to
+ * @param $amount
+ * @param TransactionType $type
+ * @param $description
+ * @param $date
+ * @param TransactionCurrency $currency
+ *
+ * @param Budget $budget
+ * @param Category $category
+ * @param Bill $bill
+ *
+ * @return TransactionJournal
+ */
+ public function createTransaction(
+ Account $from, Account $to, $amount, TransactionType $type, $description, $date, TransactionCurrency $currency, Budget $budget = null,
+ Category $category = null, Bill $bill = null
+ ) {
+ $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
+
+ $billID = is_null($bill) ? null : $bill->id;
+
+
+ /** @var TransactionJournal $journal */
+ $journal = TransactionJournal::create(
+ [
+ 'user_id' => $user->id, 'transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'bill_id' => $billID,
+ 'description' => $description, 'completed' => 1, 'date' => $date
+ ]
+ );
+
+ Transaction::create(['account_id' => $from->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount * -1]);
+ Transaction::create(['account_id' => $to->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount]);
+
+ if (!is_null($budget)) {
+ $journal->budgets()->save($budget);
+ }
+ if (!is_null($category)) {
+ $journal->categories()->save($category);
+ }
+
+ return $journal;
+ }
+
+ /**
+ * @param User $user
+ */
+ public function createBudgets(User $user)
+ {
+
+ $groceries = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
+ $bills = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
+ $deleteMe = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']);
+ Budget::create(['user_id' => $user->id, 'name' => 'Budget without repetition']);
+ $groceriesLimit = BudgetLimit::create(
+ ['startdate' => $this->som, 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $groceries->id]
+ );
+ $billsLimit = BudgetLimit::create(
+ ['startdate' => $this->som, 'amount' => 202, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $bills->id]
+ );
+ $deleteMeLimit = BudgetLimit::create(
+ ['startdate' => $this->som, 'amount' => 203, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $deleteMe->id]
+ );
+
+ // and because we have no filters, some repetitions:
+ LimitRepetition::create(['budget_limit_id' => $groceriesLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 201]);
+ LimitRepetition::create(['budget_limit_id' => $billsLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 202]);
+ LimitRepetition::create(['budget_limit_id' => $deleteMeLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 203]);
+ }
+
+ /**
+ * @param User $user
+ */
+ public function createCategories(User $user)
+ {
+ Category::create(['user_id' => $user->id, 'name' => 'DailyGroceries']);
+ Category::create(['user_id' => $user->id, 'name' => 'Lunch']);
+ Category::create(['user_id' => $user->id, 'name' => 'House']);
+ Category::create(['user_id' => $user->id, 'name' => 'Delete me']);
+
+ }
+
+ /**
+ * @param User $user
+ */
+ public function createPiggyBanks(User $user)
+ {
+ // account
+ $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
+
+ // some dates
+ $endDate = clone $this->_startOfMonth;
+ $nextYear = clone $this->_startOfMonth;
+
+ $endDate->addMonths(4);
+ $nextYear->addYear()->subDay();
+
+ $next = $nextYear->format('Y-m-d');
+ $end = $endDate->format('Y-m-d');
+
+ // piggy bank
+ $newCamera = PiggyBank::create(
+ [
+ 'account_id' => $savings->id,
+ 'name' => 'New camera',
+ 'targetamount' => 2000,
+ 'startdate' => $this->som,
+ 'targetdate' => null,
+ 'repeats' => 0,
+ 'rep_length' => null,
+ 'rep_every' => 0,
+ 'rep_times' => null,
+ 'reminder' => null,
+ 'reminder_skip' => 0,
+ 'remind_me' => 0,
+ 'order' => 0,
+ ]
+ );
+ // and some events!
+ PiggyBankEvent::create(['piggy_bank_id' => $newCamera->id, 'date' => $this->som, 'amount' => 100]);
+ PiggyBankRepetition::create(['piggy_bank_id' => $newCamera->id, 'startdate' => $this->som, 'targetdate' => null, 'currentamount' => 100]);
+
+
+ $newClothes = PiggyBank::create(
+ [
+ 'account_id' => $savings->id,
+ 'name' => 'New clothes',
+ 'targetamount' => 2000,
+ 'startdate' => $this->som,
+ 'targetdate' => $end,
+ 'repeats' => 0,
+ 'rep_length' => null,
+ 'rep_every' => 0,
+ 'rep_times' => null,
+ 'reminder' => null,
+ 'reminder_skip' => 0,
+ 'remind_me' => 0,
+ 'order' => 0,
+ ]
+ );
+
+ PiggyBankEvent::create(['piggy_bank_id' => $newClothes->id, 'date' => $this->som, 'amount' => 100]);
+ PiggyBankRepetition::create(['piggy_bank_id' => $newClothes->id, 'startdate' => $this->som, 'targetdate' => $end, 'currentamount' => 100]);
+
+ // weekly reminder piggy bank
+ $weekly = PiggyBank::create(
+ [
+ 'account_id' => $savings->id,
+ 'name' => 'Weekly reminder for clothes',
+ 'targetamount' => 2000,
+ 'startdate' => $this->som,
+ 'targetdate' => $next,
+ 'repeats' => 0,
+ 'rep_length' => null,
+ 'rep_every' => 0,
+ 'rep_times' => null,
+ 'reminder' => 'week',
+ 'reminder_skip' => 0,
+ 'remind_me' => 1,
+ 'order' => 0,
+ ]
+ );
+ PiggyBankRepetition::create(['piggy_bank_id' => $weekly->id, 'startdate' => $this->som, 'targetdate' => $next, 'currentamount' => 0]);
+ }
+
+ /**
+ * @param User $user
+ */
+ public function createReminders(User $user)
+ {
+ // for weekly piggy bank (clothes)
+ $nextWeek = clone $this->_startOfMonth;
+ $piggyBank = PiggyBank::whereName('New clothes')->orderBy('id', 'DESC')->first();
+ $nextWeek->addWeek();
+ $week = $nextWeek->format('Y-m-d');
+
+ Reminder::create(
+ ['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 1, 'notnow' => 0,
+ 'remindersable_id' => $piggyBank->id, 'remindersable_type' => 'PiggyBank']
+ );
+
+ // a fake reminder::
+ Reminder::create(
+ ['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 0, 'notnow' => 0, 'remindersable_id' => 40,
+ 'remindersable_type' => 'Transaction']
+ );
+ }
+
+ /**
+ * @param User $user
+ */
+ public function createRecurringTransactions(User $user)
+ {
+ // account
+ $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
+
+ $recurring = PiggyBank::create(
+ [
+ 'account_id' => $savings->id,
+ 'name' => 'Nieuwe spullen',
+ 'targetamount' => 1000,
+ 'startdate' => $this->som,
+ 'targetdate' => $this->eom,
+ 'repeats' => 1,
+ 'rep_length' => 'month',
+ 'rep_every' => 0,
+ 'rep_times' => 0,
+ 'reminder' => 'month',
+ 'reminder_skip' => 0,
+ 'remind_me' => 1,
+ 'order' => 0,
+ ]
+ );
+ PiggyBankRepetition::create(['piggy_bank_id' => $recurring->id, 'startdate' => $this->som, 'targetdate' => $this->eom, 'currentamount' => 0]);
+ PiggyBankRepetition::create(
+ ['piggy_bank_id' => $recurring->id, 'startdate' => $this->nsom, 'targetdate' => $this->neom, 'currentamount' => 0]
+ );
+ Reminder::create(
+ ['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $this->neom, 'active' => 1, 'notnow' => 0,
+ 'remindersable_id' => $recurring->id, 'remindersable_type' => 'PiggyBank']
+ );
+ }
+
+ /**
+ * @param $user
+ */
+ public function createBills($user)
+ {
+ // bill
+ Bill::create(
+ [
+ 'user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord',
+ 'amount_min' => 700,
+ 'amount_max' => 900,
+ 'date' => $this->som,
+ 'active' => 1,
+ 'automatch' => 1,
+ 'repeat_freq' => 'monthly',
+ 'skip' => 0,
+ ]
+ );
+
+ // bill
+ Bill::create(
+ [
+ 'user_id' => $user->id,
+ 'name' => 'Gas licht',
+ 'match' => 'no,match',
+ 'amount_min' => 500,
+ 'amount_max' => 700,
+ 'date' => $this->som,
+ 'active' => 1,
+ 'automatch' => 1,
+ 'repeat_freq' => 'monthly',
+ 'skip' => 0,
+ ]
+ );
+
+ // bill
+ Bill::create(
+ [
+ 'user_id' => $user->id,
+ 'name' => 'Something something',
+ 'match' => 'mumble,mumble',
+ 'amount_min' => 500,
+ 'amount_max' => 700,
+ 'date' => $this->som,
+ 'active' => 0,
+ 'automatch' => 1,
+ 'repeat_freq' => 'monthly',
+ 'skip' => 0,
+ ]
+ );
+
+ }
+
+ /**
+ * @param $user
+ */
+ public function createExpenseAccounts($user)
+ {
+ //// create expenses for rent, utilities, water, TV, phone on the 1st of the month.
+ $expenseType = AccountType::whereType('Expense account')->first();
+
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Land lord', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Utilities company', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Water company', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'TV company', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Phone agency', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Super savers', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Groceries House', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Lunch House', 'active' => 1]);
+
+
+ Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Buy More', 'active' => 1]);
+
+ }
+
+ /**
+ * @param $user
+ */
+ public function createRevenueAccounts($user)
+ {
+ $revenueType = AccountType::whereType('Revenue account')->first();
+
+ Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
+ Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Second job employer', 'active' => 1]);
+
+ }
+
+ /**
+ * @param Carbon $date
+ */
+ public function createGroceries(Carbon $date)
+ {
+ // variables we need:
+ $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
+ $shopOne = Account::whereName('Groceries House')->orderBy('id', 'DESC')->first();
+ $shopTwo = Account::whereName('Super savers')->orderBy('id', 'DESC')->first();
+ $lunchHouse = Account::whereName('Lunch House')->orderBy('id', 'DESC')->first();
+ $lunch = Category::whereName('Lunch')->orderBy('id', 'DESC')->first();
+ $daily = Category::whereName('DailyGroceries')->orderBy('id', 'DESC')->first();
+ $euro = TransactionCurrency::whereCode('EUR')->first();
+ $withdrawal = TransactionType::whereType('Withdrawal')->first();
+ $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
+
+
+ $shops = [$shopOne, $shopTwo];
+
+ // create groceries and lunch (daily, between 5 and 10 euro).
+ $mStart = clone $date;
+ $mEnd = clone $date;
+ $mEnd->endOfMonth();
+ while ($mStart <= $mEnd) {
+ $mFormat = $mStart->format('Y-m-d');
+ $shop = $shops[rand(0, 1)];
+
+ $this->createTransaction($checking, $shop, (rand(500, 1000) / 100), $withdrawal, 'Groceries', $mFormat, $euro, $groceries, $daily);
+ $this->createTransaction($checking, $lunchHouse, (rand(200, 600) / 100), $withdrawal, 'Lunch', $mFormat, $euro, $groceries, $lunch);
+
+ $mStart->addDay();
+ }
+ }
+
+ /**
+ * @param $date
+ */
+ public function createBigExpense($date)
+ {
+ $date->addDays(12);
+ $dollar = TransactionCurrency::whereCode('USD')->first();
+ $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
+ $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
+ $buyMore = Account::whereName('Buy More')->orderBy('id', 'DESC')->first();
+ $withdrawal = TransactionType::whereType('Withdrawal')->first();
+ $transfer = TransactionType::whereType('Transfer')->first();
+ $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
+
+
+ // create some big expenses, move some money around.
+ $amount = rand(500, 2000);
+ $one = $this->createTransaction(
+ $savings, $checking, $amount, $transfer, 'Money for big expense in ' . $date->format('F Y'), $date->format('Y-m-d'), $dollar
+ );
+ $two = $this->createTransaction(
+ $checking, $buyMore, $amount, $withdrawal, 'Big expense in ' . $date->format('F Y'), $date->format('Y-m-d'), $dollar
+ );
+ $group = TransactionGroup::create(
+ [
+ 'user_id' => $user->id,
+ 'relation' => 'balance'
+ ]
+ );
+ $group->transactionjournals()->save($one);
+ $group->transactionjournals()->save($two);
+ }
+
+
+}
\ No newline at end of file
From 21e89c3b6479cabd59bfc31303023e1028263193 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sat, 17 Jan 2015 11:31:12 +0100
Subject: [PATCH 12/71] Remove composer.lock when running Travis.
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index 1f82f07b02..3da09d1ad1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ php:
- 5.6
install:
+ - rm composer.lock
- composer install
script:
From 037135e764b5578e84215c9dde3e908decc8d02a Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 00:10:57 +0100
Subject: [PATCH 13/71] A complete gamble on my side to fix a bug where
transfers FROM shared accounts were not counted as income.
---
app/lib/FireflyIII/Report/Report.php | 1 +
app/lib/FireflyIII/Report/ReportQuery.php | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index 91a3caae95..d704cfb31a 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -46,6 +46,7 @@ class Report implements ReportInterface
}
/**
+ * This methods fails to take in account transfers FROM shared accounts.
* @param Carbon $start
* @param Carbon $end
* @param int $limit
diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php
index a53618adcd..a83a544d95 100644
--- a/app/lib/FireflyIII/Report/ReportQuery.php
+++ b/app/lib/FireflyIII/Report/ReportQuery.php
@@ -306,8 +306,23 @@ class ReportQuery implements ReportQueryInterface
}
)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->where('transaction_types.type', 'Withdrawal')
- ->where('acm_from.data', '!=', '"sharedExpense"')
+ // not shared, withdrawal
+ ->where(
+ function ($q) {
+ $q->where(
+ function ($q) {
+ $q->where('transaction_types.type', 'Withdrawal');
+ $q->where('acm_from.data', '!=', '"sharedExpense"');
+ }
+ )->orWhere(
+ function ($q) {
+ $q->where('transaction_types.type', 'Transfer');
+ $q->where('acm_from.data', '=', '"sharedExpense"');
+ }
+ );
+ }
+ )
+ // shared, transfer?
->before($end)
->after($start)
->where('transaction_journals.user_id', \Auth::user()->id)
From 8a0f76ab6875a56823f385fe78075f21b78dc44d Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:48:24 +0100
Subject: [PATCH 14/71] Code cleanup.
---
app/controllers/GoogleChartController.php | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index 99d5662b12..af1400bfb1 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -117,8 +117,6 @@ class GoogleChartController extends BaseController
$this->_chart->addColumn('Budgeted', 'number');
$this->_chart->addColumn('Spent', 'number');
- Log::debug('Now in allBudgetsHomeChart()');
-
/** @var \FireflyIII\Database\Budget\Budget $bdt */
$bdt = App::make('FireflyIII\Database\Budget\Budget');
$budgets = $bdt->get();
@@ -126,18 +124,13 @@ class GoogleChartController extends BaseController
/** @var Budget $budget */
foreach ($budgets as $budget) {
- Log::debug('Now working budget #' . $budget->id . ', ' . $budget->name);
-
/** @var \LimitRepetition $repetition */
$repetition = $bdt->repetitionOnStartingOnDate($budget, $this->_start);
- if (is_null($repetition)) {
- \Log::debug('Budget #' . $budget->id . ' has no repetition on ' . $this->_start->format('Y-m-d'));
- // use the session start and end for our search query
+ if (is_null($repetition)) { // use the session start and end for our search query
$searchStart = $this->_start;
$searchEnd = $this->_end;
$limit = 0; // the limit is zero:
} else {
- \Log::debug('Budget #' . $budget->id . ' has a repetition on ' . $this->_start->format('Y-m-d') . '!');
// use the limit's start and end for our search query
$searchStart = $repetition->startdate;
$searchEnd = $repetition->enddate;
@@ -145,7 +138,6 @@ class GoogleChartController extends BaseController
}
$expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;
- \Log::debug('Expenses in budget ' . $budget->name . ' before ' . $searchEnd->format('Y-m-d') . ' and after ' . $searchStart . ' are: ' . $expenses);
if ($expenses > 0) {
$this->_chart->addRow($budget->name, $limit, $expenses);
}
@@ -314,18 +306,15 @@ class GoogleChartController extends BaseController
if ($repetition) {
$budgeted = floatval($repetition->amount);
- \Log::debug('Found a repetition on ' . $start->format('Y-m-d'). ' for budget ' . $budget->name.'!');
+ \Log::debug('Found a repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name . '!');
} else {
- \Log::debug('No repetition on ' . $start->format('Y-m-d'). ' for budget ' . $budget->name);
+ \Log::debug('No repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name);
$budgeted = null;
}
-
$this->_chart->addRow(clone $start, $budgeted, $spent);
-
$start->addMonth();
}
-
$this->_chart->generate();
return Response::json($this->_chart->getData());
From 45447646fa01794913d76a62dd95ee7caecc4410 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:48:29 +0100
Subject: [PATCH 15/71] Code cleanup.
---
app/controllers/PiggybankController.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index 051a5d2ca5..9f279598c1 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -334,10 +334,11 @@ class PiggyBankController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update piggy bank: ' . $messages['errors']->first());
+ return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput();
}
// return to update screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('piggy_banks.edit', $piggyBank->id)->withInput();
}
From a36cab969fcf5b1f6cabd899e6f8578d822faf7a Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:48:36 +0100
Subject: [PATCH 16/71] Code cleanup.
---
app/controllers/RepeatedExpenseController.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/app/controllers/RepeatedExpenseController.php b/app/controllers/RepeatedExpenseController.php
index 61abf4a133..32dbc7c0ce 100644
--- a/app/controllers/RepeatedExpenseController.php
+++ b/app/controllers/RepeatedExpenseController.php
@@ -135,7 +135,7 @@ class RepeatedExpenseController extends BaseController
}
/**
- *
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
*/
public function store()
{
@@ -150,7 +150,6 @@ class RepeatedExpenseController extends BaseController
$data['remind_me'] = isset($data['remind_me']) ? 1 : 0;
$data['order'] = 0;
- // always validate:
$messages = $this->_repository->validate($data);
Session::flash('warnings', $messages['warnings']);
From 79ff67852fc3bb741cedc8738118e2cd5d4550e8 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:48:48 +0100
Subject: [PATCH 17/71] Deleted an old unique index.
---
.../2015_01_18_082406_changes_for_325.php | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 app/database/migrations/2015_01_18_082406_changes_for_325.php
diff --git a/app/database/migrations/2015_01_18_082406_changes_for_325.php b/app/database/migrations/2015_01_18_082406_changes_for_325.php
new file mode 100644
index 0000000000..7c86443bb9
--- /dev/null
+++ b/app/database/migrations/2015_01_18_082406_changes_for_325.php
@@ -0,0 +1,43 @@
+dropIndex('unique_ci_combo');
+ $table->dropUnique('unique_ci_combi');
+ });
+
+ }
+
+}
From 10a93df6539749679122cc37354b571eb749a547 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:48:58 +0100
Subject: [PATCH 18/71] Clean up test data seeder
---
app/database/seeds/TestDataSeeder.php | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/app/database/seeds/TestDataSeeder.php b/app/database/seeds/TestDataSeeder.php
index bfa8e63de1..13028277d4 100644
--- a/app/database/seeds/TestDataSeeder.php
+++ b/app/database/seeds/TestDataSeeder.php
@@ -3,6 +3,10 @@ use Carbon\Carbon;
/**
* @SuppressWarnings("CamelCase") // I'm fine with this.
+ * @SuppressWarnings("TooManyMethods") // I'm fine with this
+ * @SuppressWarnings("CouplingBetweenObjects") // I'm fine with this
+ * @SuppressWarnings("MethodLength") // I'm fine with this
+
*
* Class TestDataSeeder
*/
@@ -410,16 +414,8 @@ class TestDataSeeder extends Seeder
{
// bill
Bill::create(
- [
- 'user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord',
- 'amount_min' => 700,
- 'amount_max' => 900,
- 'date' => $this->som,
- 'active' => 1,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- ]
+ ['user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord', 'amount_min' => 700, 'amount_max' => 900, 'date' => $this->som,
+ 'active' => 1, 'automatch' => 1, 'repeat_freq' => 'monthly', 'skip' => 0,]
);
// bill
@@ -428,13 +424,10 @@ class TestDataSeeder extends Seeder
'user_id' => $user->id,
'name' => 'Gas licht',
'match' => 'no,match',
- 'amount_min' => 500,
- 'amount_max' => 700,
+ 'amount_min' => 500, 'amount_max' => 700,
'date' => $this->som,
- 'active' => 1,
- 'automatch' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
+ 'active' => 1, 'automatch' => 1,
+ 'repeat_freq' => 'monthly', 'skip' => 0,
]
);
From 1068dcb8a437efb243e404c750b62dd8cc2bc427 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:49:32 +0100
Subject: [PATCH 19/71] Cleanup and refactor
---
.../FireflyIII/Database/Account/Account.php | 16 +--
app/lib/FireflyIII/Database/Bill/Bill.php | 2 +-
.../TransactionJournal/TransactionJournal.php | 18 ----
app/lib/FireflyIII/Event/Piggybank.php | 4 -
app/lib/FireflyIII/Report/Report.php | 5 +-
app/lib/FireflyIII/Shared/Toolkit/Date.php | 93 +++++++---------
app/lib/FireflyIII/Shared/Toolkit/Filter.php | 101 ++++++++----------
app/lib/FireflyIII/Shared/Toolkit/Form.php | 2 +
8 files changed, 91 insertions(+), 150 deletions(-)
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php
index 9fe77ea498..cb921b0baa 100644
--- a/app/lib/FireflyIII/Database/Account/Account.php
+++ b/app/lib/FireflyIII/Database/Account/Account.php
@@ -156,10 +156,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*/
public function destroy(Eloquent $model)
{
-
- // delete piggy banks
- // delete journals:
- $journals = \TransactionJournal::whereIn(
+ $journals = \TransactionJournal::whereIn(
'id', function (QueryBuilder $query) use ($model) {
$query->select('transaction_journal_id')
->from('transactions')->whereIn(
@@ -183,9 +180,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
)->get();
}
)->get();
- /*
- * Get all transactions.
- */
$transactions = [];
/** @var \TransactionJournal $journal */
foreach ($journals as $journal) {
@@ -195,18 +189,10 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
$journal->delete();
}
- // also delete transactions.
if (count($transactions) > 0) {
\Transaction::whereIn('id', $transactions)->delete();
}
-
-
- /*
- * Trigger deletion:
- */
\Event::fire('account.destroy', [$model]);
-
- // delete accounts:
\Account::where(
function (EloquentBuilder $q) use ($model) {
$q->where('id', $model->id);
diff --git a/app/lib/FireflyIII/Database/Bill/Bill.php b/app/lib/FireflyIII/Database/Bill/Bill.php
index e987d4abc7..2110180426 100644
--- a/app/lib/FireflyIII/Database/Bill/Bill.php
+++ b/app/lib/FireflyIII/Database/Bill/Bill.php
@@ -114,7 +114,7 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
$warnings = new MessageBag;
$successes = new MessageBag;
$errors = new MessageBag;
- if (isset($model['amount_min']) && isset($model['amount_max']) && floatval($model['amount_min']) > floatval($model['amount_max'])) {
+ if (floatval($model['amount_min']) > floatval($model['amount_max'])) {
$errors->add('amount_max', 'Maximum amount can not be less than minimum amount.');
$errors->add('amount_min', 'Minimum amount can not be more than maximum amount.');
}
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index 10015a1afb..ba0b70bf27 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -158,31 +158,13 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$journal->isValid();
$errors = $journal->getErrors();
- /*
- * Is not in rules.
- */
if (!isset($model['what'])) {
$errors->add('description', 'Internal error: need to know type of transaction!');
}
- /*
- * Is not in rules.
- */
$errors = $errors->merge($this->_validateAmount($model));
$errors = $errors->merge($this->_validateBudget($model));
$errors = $errors->merge($this->_validateAccount($model));
-
- /*
- * Add "OK"
- */
-
- /**
- * else {
- * $successes->add('account_from_id', 'OK');
- * $successes->add('account_to_id', 'OK');
- * }
- * else {
- */
$list = ['date', 'description', 'amount', 'budget_id', 'from', 'to', 'account_from_id', 'account_to_id', 'category', 'account_id', 'expense_account',
'revenue_account'];
foreach ($list as $entry) {
diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php
index 645f48432b..1e0b62c053 100644
--- a/app/lib/FireflyIII/Event/Piggybank.php
+++ b/app/lib/FireflyIII/Event/Piggybank.php
@@ -197,7 +197,6 @@ class PiggyBank
foreach ($list as $entry) {
$start = $entry->startdate;
$target = $entry->targetdate;
- // find a repetition on this date:
$count = $entry->piggyBankrepetitions()->starts($start)->targets($target)->count();
if ($count == 0) {
$repetition = new \PiggyBankRepetition;
@@ -207,14 +206,11 @@ class PiggyBank
$repetition->currentamount = 0;
$repetition->save();
}
- // then continue and do something in the current relevant time frame.
-
$currentTarget = clone $target;
$currentStart = null;
while ($currentTarget < $today) {
$currentStart = \DateKit::subtractPeriod($currentTarget, $entry->rep_length, 0);
$currentTarget = \DateKit::addPeriod($currentTarget, $entry->rep_length, 0);
- // create if not exists:
$count = $entry->piggyBankRepetitions()->starts($currentStart)->targets($currentTarget)->count();
if ($count == 0) {
$repetition = new \PiggyBankRepetition;
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index d704cfb31a..b926e6662c 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -228,6 +228,8 @@ class Report implements ReportInterface
}
/**
+ * This method gets all incomes (journals) in a list.
+ *
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param Carbon $date
@@ -357,7 +359,6 @@ class Report implements ReportInterface
}
/**
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param Carbon $start
* @param Carbon $end
@@ -367,7 +368,7 @@ class Report implements ReportInterface
*/
public function revenueGroupedByAccount(Carbon $start, Carbon $end, $limit = 15)
{
- return $this->_queries->journalsByRevenueAccount($start, $end);
+ return $this->_queries->journalsByRevenueAccount($start, $end, $limit);
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.php
index 7b41d9d273..443e343654 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Date.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php
@@ -102,6 +102,8 @@ class Date
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param Carbon $theCurrentEnd
* @param $repeatFreq
* @param Carbon $maxDate
@@ -111,37 +113,32 @@ class Date
*/
public function endOfX(Carbon $theCurrentEnd, $repeatFreq, Carbon $maxDate)
{
+ $functionMap = [
+ 'daily' => 'endOfDay',
+ 'week' => 'endOfWeek',
+ 'weekly' => 'endOfWeek',
+ 'month' => 'endOfMonth',
+ 'monthly' => 'endOfMonth',
+ 'quarter' => 'lastOfQuarter',
+ 'quarterly' => 'lastOfQuarter',
+ 'year' => 'endOfYear',
+ 'yearly' => 'endOfYear',
+ ];
+ $specials = ['mont', 'monthly'];
+
$currentEnd = clone $theCurrentEnd;
- switch ($repeatFreq) {
- default:
- throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
- break;
- case 'daily':
- $currentEnd->endOfDay();
- break;
- case 'week':
- case 'weekly':
- $currentEnd->endOfWeek();
- break;
- case 'month':
- case 'monthly':
- $currentEnd->endOfMonth();
- break;
- case 'quarter':
- case 'quarterly':
- $currentEnd->lastOfQuarter();
- break;
- case 'half-year':
- $month = intval($theCurrentEnd->format('m'));
- $currentEnd->endOfYear();
- if ($month <= 6) {
- $currentEnd->subMonths(6);
- }
- break;
- case 'year':
- case 'yearly':
- $currentEnd->endOfYear();
- break;
+
+ if (isset($functionMap[$repeatFreq])) {
+ $function = $functionMap[$repeatFreq];
+ $currentEnd->$function();
+
+ }
+ if (isset($specials[$repeatFreq])) {
+ $month = intval($theCurrentEnd->format('m'));
+ $currentEnd->endOfYear();
+ if ($month <= 6) {
+ $currentEnd->subMonths(6);
+ }
}
if ($currentEnd > $maxDate) {
return clone $maxDate;
@@ -159,29 +156,21 @@ class Date
*/
public function periodShow(Carbon $date, $repeatFrequency)
{
- switch ($repeatFrequency) {
- default:
- throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
- break;
- case 'daily':
- return $date->format('j F Y');
- break;
- case 'week':
- case 'weekly':
- return $date->format('\W\e\e\k W, Y');
- break;
- case 'quarter':
- return $date->format('F Y');
- break;
- case 'monthly':
- case 'month':
- return $date->format('F Y');
- break;
- case 'year':
- case 'yearly':
- return $date->format('Y');
- break;
+ $formatMap = [
+ 'daily' => 'j F Y',
+ 'week' => '\W\e\e\k W, Y',
+ 'weekly' => '\W\e\e\k W, Y',
+ 'quarter' => 'F Y',
+ 'month' => 'F Y',
+ 'monthly' => 'F Y',
+ 'year' => 'Y',
+ 'yearly' => 'Y',
+
+ ];
+ if (isset($formatMap[$repeatFrequency])) {
+ return $date->format($formatMap[$repeatFrequency]);
}
+ throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
}
/**
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Filter.php b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
index f8fdf42037..ae04ae6062 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Filter.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
@@ -103,37 +103,31 @@ class Filter
*/
protected function updateEndDate($range, Carbon $start)
{
- $end = clone $start;
- switch ($range) {
- default:
- throw new FireflyException('updateEndDate cannot handle $range ' . $range);
- break;
- case '1D':
- $end->endOfDay();
- break;
- case '1W':
- $end->endOfWeek();
- break;
- case '1M':
- $end->endOfMonth();
- break;
- case '3M':
- $end->lastOfQuarter();
- break;
- case '6M':
- if (intval($start->format('m')) >= 7) {
- $end->endOfYear();
- } else {
- $end->startOfYear()->addMonths(6);
- }
- break;
- case '1Y':
- $end->endOfYear();
- break;
+ $functionMap = [
+ '1D' => 'endOfDay',
+ '1W' => 'endOfWeek',
+ '1M' => 'endOfMonth',
+ '3M' => 'lastOfQuarter',
+ '1Y' => 'endOfYear',
+ ];
+ $end = clone $start;
+ if (isset($functionMap[$range])) {
+ $function = $functionMap[$range];
+ $end->$function();
+
+ return $end;
}
+ if ($range == '6M') {
+ if (intval($start->format('m')) >= 7) {
+ $end->endOfYear();
+ } else {
+ $end->startOfYear()->addMonths(6);
+ }
- return $end;
+ return $end;
+ }
+ throw new FireflyException('updateEndDate cannot handle $range ' . $range);
}
/**
@@ -145,37 +139,28 @@ class Filter
*/
protected function periodName($range, Carbon $date)
{
- switch ($range) {
- default:
- throw new FireflyException('No _periodName() for range "' . $range . '"');
- break;
- case '1D':
- return $date->format('jS F Y');
- break;
- case '1W':
- return 'week ' . $date->format('W, Y');
- break;
- case '1M':
- return $date->format('F Y');
- break;
- case '3M':
- $month = intval($date->format('m'));
-
- return 'Q' . ceil(($month / 12) * 4) . ' ' . $date->format('Y');
- break;
- case '6M':
- $month = intval($date->format('m'));
- $half = ceil(($month / 12) * 2);
- $halfName = $half == 1 ? 'first' : 'second';
-
- return $halfName . ' half of ' . $date->format('d-m-Y');
- break;
- case '1Y':
- return $date->format('Y');
- break;
-
-
+ $formatMap = [
+ '1D' => 'jS F Y',
+ '1W' => '\w\e\ek W, Y',
+ '1M' => 'F Y',
+ '1Y' => 'Y',
+ ];
+ if (isset($formatMap[$range])) {
+ return $date->format($formatMap[$range]);
}
+ if ($range == '3M') {
+ $month = intval($date->format('m'));
+
+ return 'Q' . ceil(($month / 12) * 4) . ' ' . $date->format('Y');
+ }
+ if ($range == '6M') {
+ $month = intval($date->format('m'));
+ $half = ceil(($month / 12) * 2);
+ $halfName = $half == 1 ? 'first' : 'second';
+
+ return $halfName . ' half of ' . $date->format('d-m-Y');
+ }
+ throw new FireflyException('No _periodName() for range "' . $range . '"');
}
/**
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Form.php b/app/lib/FireflyIII/Shared/Toolkit/Form.php
index a5475a0456..1f51fe357a 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Form.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Form.php
@@ -12,6 +12,8 @@ use Illuminate\Support\Collection;
class Form
{
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* Takes any collection and tries to make a sensible select list compatible array of it.
*
* @param Collection $set
From 03e0510c4f9942d8198ad6c5984cb3581685a229 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:49:53 +0100
Subject: [PATCH 20/71] Fixed a bug where certain reports would not show
incomes from shared accounts.
---
app/controllers/TransactionController.php | 3 +-
app/lib/FireflyIII/Report/ReportQuery.php | 42 ++++++++++++-----------
app/views/list/journals-small.blade.php | 20 ++++++-----
3 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index 5cef244661..c56d7ae08a 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -254,10 +254,11 @@ class TransactionController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store transaction: ' . $messages['errors']->first());
+ return Redirect::route('transactions.create', $data['what'])->withInput();
}
// return to create screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('transactions.create', $data['what'])->withInput();
}
diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php
index a83a544d95..7ac2cd18bd 100644
--- a/app/lib/FireflyIII/Report/ReportQuery.php
+++ b/app/lib/FireflyIII/Report/ReportQuery.php
@@ -306,23 +306,8 @@ class ReportQuery implements ReportQueryInterface
}
)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- // not shared, withdrawal
- ->where(
- function ($q) {
- $q->where(
- function ($q) {
- $q->where('transaction_types.type', 'Withdrawal');
- $q->where('acm_from.data', '!=', '"sharedExpense"');
- }
- )->orWhere(
- function ($q) {
- $q->where('transaction_types.type', 'Transfer');
- $q->where('acm_from.data', '=', '"sharedExpense"');
- }
- );
- }
- )
- // shared, transfer?
+ ->where('transaction_types.type', 'Withdrawal')
+ ->where('acm_from.data', '!=', '"sharedExpense"')
->before($end)
->after($start)
->where('transaction_journals.user_id', \Auth::user()->id)
@@ -336,10 +321,11 @@ class ReportQuery implements ReportQueryInterface
*
* @param Carbon $start
* @param Carbon $end
+ * @param int $limit
*
* @return Collection
*/
- public function journalsByRevenueAccount(Carbon $start, Carbon $end)
+ public function journalsByRevenueAccount(Carbon $start, Carbon $end, $limit = 15)
{
return \TransactionJournal::
leftJoin(
@@ -365,8 +351,24 @@ class ReportQuery implements ReportQueryInterface
}
)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->where('transaction_types.type', 'Deposit')
- ->where('acm_to.data', '!=', '"sharedExpense"')
+ ->where(
+ function ($query) {
+ $query->where(
+ function ($q) {
+ $q->where('transaction_types.type', 'Deposit');
+ $q->where('acm_to.data', '!=', '"sharedExpense"');
+ }
+ );
+ $query->orWhere(
+ function ($q) {
+ $q->where('transaction_types.type', 'Transfer');
+ $q->where('acm_from.data', '=', '"sharedExpense"');
+ }
+ );
+ }
+ )
+ // ->where('transaction_types.type', 'Deposit')
+ // ->where('acm_to.data', '!=', '"sharedExpense"')
->before($end)->after($start)
->where('transaction_journals.user_id', \Auth::user()->id)
->groupBy('t_from.account_id')->orderBy('amount')
diff --git a/app/views/list/journals-small.blade.php b/app/views/list/journals-small.blade.php
index 9bf33f4b0b..b1ba57dacf 100644
--- a/app/views/list/journals-small.blade.php
+++ b/app/views/list/journals-small.blade.php
@@ -9,24 +9,28 @@
transactions[1]->amount);?>
@if($journal->transactiontype->type == 'Withdrawal')
- {{Amount::formatTransaction($journal->transactions[1],false)}}
+ {{Amount::formatTransaction($journal->transactions[1],false)}}
@endif
@if($journal->transactiontype->type == 'Deposit')
- {{Amount::formatTransaction($journal->transactions[1],false)}}
+ {{Amount::formatTransaction($journal->transactions[1],false)}}
@endif
@if($journal->transactiontype->type == 'Transfer')
- {{Amount::formatTransaction($journal->transactions[1],false)}}
+ {{Amount::formatTransaction($journal->transactions[1],false)}}
@endif
|
{{$journal->date->format('j F Y')}}
|
- @if($journal->transactions[1]->account->accounttype->description == 'Cash account')
- (cash)
- @else
- {{{$journal->transactions[1]->account->name}}}
- @endif
+ @foreach($journal->transactions as $t)
+ @if(floatval($t->amount < 0))
+ @if($t->account->accounttype->description == 'Cash account')
+ (cash)
+ @else
+ {{{$t->account->name}}}
+ @endif
+ @endif
+ @endforeach
|
@endforeach
From 0afe2a680e98d67195f8879cd8549bb9d0287ade Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 09:50:51 +0100
Subject: [PATCH 21/71] Gave report a subtitle.
---
app/controllers/ReportController.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php
index 29be01240f..e88f69279c 100644
--- a/app/controllers/ReportController.php
+++ b/app/controllers/ReportController.php
@@ -50,11 +50,13 @@ class ReportController extends BaseController
}
$date = new Carbon($year . '-' . $month . '-01');
$dayEarly = clone $date;
+ $subTitle = 'Budget report for ' . $date->format('F Y');
+ $subTitleIcon = 'fa-calendar';
$dayEarly = $dayEarly->subDay();
$accounts = $this->_repository->getAccountListBudgetOverview($date);
$budgets = $this->_repository->getBudgetsForMonth($date);
- return View::make('reports.budget', compact('date', 'accounts', 'budgets', 'dayEarly'));
+ return View::make('reports.budget', compact('subTitle','subTitleIcon','date', 'accounts', 'budgets', 'dayEarly'));
}
From c5a3de09cdf096d209ac07e9d3999cf32b4d3e0b Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 10:33:01 +0100
Subject: [PATCH 22/71] Catch a sqlite error.
---
.../migrations/2015_01_18_082406_changes_for_325.php | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/app/database/migrations/2015_01_18_082406_changes_for_325.php b/app/database/migrations/2015_01_18_082406_changes_for_325.php
index 7c86443bb9..5db32ba627 100644
--- a/app/database/migrations/2015_01_18_082406_changes_for_325.php
+++ b/app/database/migrations/2015_01_18_082406_changes_for_325.php
@@ -1,6 +1,7 @@
dropIndex('unique_ci_combo');
- $table->dropUnique('unique_ci_combi');
- });
+ try {
+ $table->dropUnique('unique_ci_combi');
+ } catch (QueryException $e) {
+ // don't care.
+ }
+ }
+ );
}
From 02b6191d47e5f383665fbb97e311970d7a010d95 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 11:12:17 +0100
Subject: [PATCH 23/71] Another attempt at catching the sqlite error.
---
app/database/migrations/2015_01_18_082406_changes_for_325.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/app/database/migrations/2015_01_18_082406_changes_for_325.php b/app/database/migrations/2015_01_18_082406_changes_for_325.php
index 5db32ba627..a00985b8bf 100644
--- a/app/database/migrations/2015_01_18_082406_changes_for_325.php
+++ b/app/database/migrations/2015_01_18_082406_changes_for_325.php
@@ -40,6 +40,8 @@ class ChangesFor325 extends Migration
$table->dropUnique('unique_ci_combi');
} catch (QueryException $e) {
// don't care.
+ } catch (\Exception $e) {
+ // don't care either.
}
}
);
From bba1ee12646cbca103a773c2b2c0aea8d73bb09d Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 11:18:06 +0100
Subject: [PATCH 24/71] Last attempt.
---
.../2015_01_18_082406_changes_for_325.php | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/app/database/migrations/2015_01_18_082406_changes_for_325.php b/app/database/migrations/2015_01_18_082406_changes_for_325.php
index a00985b8bf..55abb999c5 100644
--- a/app/database/migrations/2015_01_18_082406_changes_for_325.php
+++ b/app/database/migrations/2015_01_18_082406_changes_for_325.php
@@ -33,18 +33,21 @@ class ChangesFor325 extends Migration
//
// delete an old index:
- Schema::table(
- 'budget_limits', function (Blueprint $table) {
- //$table->dropIndex('unique_ci_combo');
- try {
+ try {
+ Schema::table(
+ 'budget_limits', function (Blueprint $table) {
+ //$table->dropIndex('unique_ci_combo');
$table->dropUnique('unique_ci_combi');
- } catch (QueryException $e) {
- // don't care.
- } catch (\Exception $e) {
- // don't care either.
+
}
+ );
+ } catch (QueryException $e) {
+ // don't care.
+ } catch (PDOException $e) {
+ // don't care.
+ } catch (\Exception $e) {
+ // don't care either.
}
- );
}
From 406b658801b75b37e9e86a920bb9c42ede78578c Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 21:07:40 +0100
Subject: [PATCH 25/71] Code cleanup.
---
app/controllers/PiggybankController.php | 3 +-
app/controllers/RepeatedExpenseController.php | 6 +-
app/controllers/ReportController.php | 12 +-
app/controllers/TransactionController.php | 13 +-
app/database/seeds/TestDataSeeder.php | 3 +
.../FireflyIII/Database/Account/Account.php | 43 +++----
.../TransactionJournal/TransactionJournal.php | 2 +
app/lib/FireflyIII/Event/Piggybank.php | 13 +-
app/lib/FireflyIII/Report/Report.php | 3 +-
app/lib/FireflyIII/Report/ReportQuery.php | 2 -
app/lib/FireflyIII/Shared/Toolkit/Date.php | 116 ++++++++----------
app/lib/FireflyIII/Shared/Toolkit/Filter.php | 2 +
12 files changed, 105 insertions(+), 113 deletions(-)
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index 9f279598c1..673a2c31f0 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -290,11 +290,12 @@ class PiggyBankController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store piggy bank: ' . $messages['errors']->first());
+ return Redirect::route('piggy_banks.create')->withInput();
}
// return to create screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('piggy_banks.create')->withInput();
}
diff --git a/app/controllers/RepeatedExpenseController.php b/app/controllers/RepeatedExpenseController.php
index 32dbc7c0ce..73494b0377 100644
--- a/app/controllers/RepeatedExpenseController.php
+++ b/app/controllers/RepeatedExpenseController.php
@@ -178,6 +178,8 @@ class RepeatedExpenseController extends BaseController
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param PiggyBank $repeatedExpense
*
* @return $this
@@ -194,7 +196,6 @@ class RepeatedExpenseController extends BaseController
$data['remind_me'] = isset($data['remind_me']) ? 1 : 0;
$data['user_id'] = Auth::user()->id;
- // always validate:
$messages = $this->_repository->validate($data);
Session::flash('warnings', $messages['warnings']);
@@ -202,10 +203,11 @@ class RepeatedExpenseController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update repeated expense: ' . $messages['errors']->first());
+ return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput();
}
// return to update screen:
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('repeated.edit', $repeatedExpense->id)->withInput();
}
diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php
index e88f69279c..9d2f730003 100644
--- a/app/controllers/ReportController.php
+++ b/app/controllers/ReportController.php
@@ -48,15 +48,15 @@ class ReportController extends BaseController
} catch (Exception $e) {
return View::make('error')->with('message', 'Invalid date');
}
- $date = new Carbon($year . '-' . $month . '-01');
- $dayEarly = clone $date;
+ $date = new Carbon($year . '-' . $month . '-01');
+ $dayEarly = clone $date;
$subTitle = 'Budget report for ' . $date->format('F Y');
$subTitleIcon = 'fa-calendar';
- $dayEarly = $dayEarly->subDay();
- $accounts = $this->_repository->getAccountListBudgetOverview($date);
- $budgets = $this->_repository->getBudgetsForMonth($date);
+ $dayEarly = $dayEarly->subDay();
+ $accounts = $this->_repository->getAccountListBudgetOverview($date);
+ $budgets = $this->_repository->getBudgetsForMonth($date);
- return View::make('reports.budget', compact('subTitle','subTitleIcon','date', 'accounts', 'budgets', 'dayEarly'));
+ return View::make('reports.budget', compact('subTitle', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
}
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index c56d7ae08a..b987272c45 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -230,6 +230,8 @@ class TransactionController extends BaseController
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param $what
*
* @return $this|\Illuminate\Http\RedirectResponse
@@ -245,8 +247,6 @@ class TransactionController extends BaseController
$data['completed'] = 0;
$data['what'] = $what;
$data['currency'] = 'EUR';
-
- // always validate:
$messages = $this->_repository->validate($data);
Session::flash('warnings', $messages['warnings']);
@@ -257,17 +257,13 @@ class TransactionController extends BaseController
return Redirect::route('transactions.create', $data['what'])->withInput();
}
- // return to create screen:
if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('transactions.create', $data['what'])->withInput();
}
- // store
$journal = $this->_repository->store($data);
Event::fire('transactionJournal.store', [$journal, Input::get('piggy_bank_id')]); // new and used.
- /*
- * Also trigger on both transactions.
- */
+
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
Event::fire('transaction.store', [$transaction]);
@@ -303,8 +299,9 @@ class TransactionController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update transaction: ' . $messages['errors']->first());
+ return Redirect::route('transactions.edit', $journal->id)->withInput();
}
- if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ if ($data['post_submit_action'] == 'validate_only') {
return Redirect::route('transactions.edit', $journal->id)->withInput();
}
$this->_repository->update($journal, $data);
diff --git a/app/database/seeds/TestDataSeeder.php b/app/database/seeds/TestDataSeeder.php
index 13028277d4..fa6cb958d0 100644
--- a/app/database/seeds/TestDataSeeder.php
+++ b/app/database/seeds/TestDataSeeder.php
@@ -184,6 +184,9 @@ class TestDataSeeder extends Seeder
}
/**
+ * @SuppressWarnings(PHPMD.ShortVariable)
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
+ *
* @param Account $from
* @param Account $to
* @param $amount
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php
index cb921b0baa..33a8c85ace 100644
--- a/app/lib/FireflyIII/Database/Account/Account.php
+++ b/app/lib/FireflyIII/Database/Account/Account.php
@@ -150,6 +150,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
/**
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot make it shorter because of query.
* @param Eloquent $model
*
* @return bool
@@ -159,25 +160,25 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
$journals = \TransactionJournal::whereIn(
'id', function (QueryBuilder $query) use ($model) {
$query->select('transaction_journal_id')
- ->from('transactions')->whereIn(
- 'account_id', function (QueryBuilder $query) use ($model) {
- $query
- ->select('id')
- ->from('accounts')
- ->where(
- function (QueryBuilder $q) use ($model) {
- $q->where('id', $model->id);
- $q->orWhere(
- function (QueryBuilder $q) use ($model) {
- $q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
- $q->where('accounts.account_type_id', 3);
- $q->where('accounts.active', 0);
- }
- );
- }
- )->where('accounts.user_id', $this->getUser()->id);
- }
- )->get();
+ ->from('transactions')
+ ->whereIn(
+ 'account_id', function (QueryBuilder $query) use ($model) {
+ $query
+ ->select('id')->from('accounts')
+ ->where(
+ function (QueryBuilder $q) use ($model) {
+ $q->where('id', $model->id);
+ $q->orWhere(
+ function (QueryBuilder $q) use ($model) {
+ $q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
+ $q->where('accounts.account_type_id', 3);
+ $q->where('accounts.active', 0);
+ }
+ );
+ }
+ )->where('accounts.user_id', $this->getUser()->id);
+ }
+ )->get();
}
)->get();
$transactions = [];
@@ -218,9 +219,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
public function store(array $data)
{
- /*
- * Find account type.
- */
/** @var \FireflyIII\Database\AccountType\AccountType $acctType */
$acctType = \App::make('FireflyIII\Database\AccountType\AccountType');
@@ -230,7 +228,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
$data['account_type_id'] = $accountType->id;
$data['active'] = isset($data['active']) && $data['active'] === '1' ? 1 : 0;
-
$data = array_except($data, ['_token', 'what']);
$account = new \Account($data);
if (!$account->isValid()) {
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index ba0b70bf27..ce0cfbafcc 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -363,11 +363,13 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$errors->add('account_id', 'Invalid account.');
}
break;
+ // often seen in deposits
case (isset($model['account_id']) && isset($model['revenue_account'])):
if (intval($model['account_id']) < 1) {
$errors->add('account_id', 'Invalid account.');
}
break;
+ // often seen in transfers
case (isset($model['account_from_id']) && isset($model['account_to_id'])):
if (intval($model['account_from_id']) < 1 || intval($model['account_from_id']) < 1) {
$errors->add('account_from_id', 'Invalid account selected.');
diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php
index 1e0b62c053..5188658a2a 100644
--- a/app/lib/FireflyIII/Event/Piggybank.php
+++ b/app/lib/FireflyIII/Event/Piggybank.php
@@ -180,6 +180,7 @@ class PiggyBank
}
/**
+ *
* Validates the presence of repetitions for all repeated expenses!
*/
public function validateRepeatedExpenses()
@@ -189,24 +190,20 @@ class PiggyBank
}
/** @var \FireflyIII\Database\PiggyBank\RepeatedExpense $repository */
$repository = \App::make('FireflyIII\Database\PiggyBank\RepeatedExpense');
-
$list = $repository->get();
$today = Carbon::now();
-
/** @var \PiggyBank $entry */
foreach ($list as $entry) {
- $start = $entry->startdate;
- $target = $entry->targetdate;
- $count = $entry->piggyBankrepetitions()->starts($start)->targets($target)->count();
+ $count = $entry->piggyBankrepetitions()->starts($entry->startdate)->targets($entry->targetdate)->count();
if ($count == 0) {
$repetition = new \PiggyBankRepetition;
$repetition->piggyBank()->associate($entry);
- $repetition->startdate = $start;
- $repetition->targetdate = $target;
+ $repetition->startdate = $entry->startdate;
+ $repetition->targetdate = $entry->targetdate;
$repetition->currentamount = 0;
$repetition->save();
}
- $currentTarget = clone $target;
+ $currentTarget = clone $entry->startdate;
$currentStart = null;
while ($currentTarget < $today) {
$currentStart = \DateKit::subtractPeriod($currentTarget, $entry->rep_length, 0);
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index b926e6662c..70b651eb74 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -232,6 +232,8 @@ class Report implements ReportInterface
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
+ * TODO: This method runs two queries which are only marginally different. Try and combine these.
+ *
* @param Carbon $date
* @param bool $shared
*
@@ -245,7 +247,6 @@ class Report implements ReportInterface
$end->endOfMonth();
$userId = $this->_accounts->getUser()->id;
-
$list = \TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
->leftJoin(
diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php
index 7ac2cd18bd..4f8fd1a663 100644
--- a/app/lib/FireflyIII/Report/ReportQuery.php
+++ b/app/lib/FireflyIII/Report/ReportQuery.php
@@ -367,8 +367,6 @@ class ReportQuery implements ReportQueryInterface
);
}
)
- // ->where('transaction_types.type', 'Deposit')
- // ->where('acm_to.data', '!=', '"sharedExpense"')
->before($end)->after($start)
->where('transaction_journals.user_id', \Auth::user()->id)
->groupBy('t_from.account_id')->orderBy('amount')
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.php
index 443e343654..65d1d49ab9 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Date.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php
@@ -183,39 +183,34 @@ class Date
public function startOfPeriod(Carbon $theDate, $repeatFreq)
{
$date = clone $theDate;
- switch ($repeatFreq) {
- default:
- throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
- break;
- case 'daily':
- $date->startOfDay();
- break;
- case 'week':
- case 'weekly':
- $date->startOfWeek();
- break;
- case 'month':
- case 'monthly':
- $date->startOfMonth();
- break;
- case 'quarter':
- case 'quarterly':
- $date->firstOfQuarter();
- break;
- case 'half-year':
- $month = intval($date->format('m'));
- $date->startOfYear();
- if ($month >= 7) {
- $date->addMonths(6);
- }
- break;
- case 'year':
- case 'yearly':
- $date->startOfYear();
- break;
- }
- return $date;
+ $functionMap = [
+ 'daily' => 'startOfDay',
+ 'week' => 'startOfWeek',
+ 'weekly' => 'startOfWeek',
+ 'month' => 'startOfMonth',
+ 'monthly' => 'startOfMonth',
+ 'quarter' => 'firstOfQuarter',
+ 'quartly' => 'firstOfQuarter',
+ 'year' => 'startOfYear',
+ 'yearly' => 'startOfYear',
+ ];
+ if (isset($functionMap[$repeatFreq])) {
+ $function = $functionMap[$repeatFreq];
+ $date->$function();
+
+ return $date;
+ }
+ if ($repeatFreq == 'half-year') {
+ $month = intval($date->format('m'));
+ $date->startOfYear();
+ if ($month >= 7) {
+ $date->addMonths(6);
+ }
+
+ return $date;
+ }
+ throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
}
/**
@@ -229,38 +224,35 @@ class Date
public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1)
{
$date = clone $theDate;
- switch ($repeatFreq) {
- default:
- throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq);
- break;
- case 'day':
- case 'daily':
- $date->subDays($subtract);
- break;
- case 'week':
- case 'weekly':
- $date->subWeeks($subtract);
- break;
- case 'month':
- case 'monthly':
- $date->subMonths($subtract);
- break;
- case 'quarter':
- case 'quarterly':
- $months = $subtract * 3;
- $date->subMonths($months);
- break;
- case 'half-year':
- $months = $subtract * 6;
- $date->subMonths($months);
- break;
- case 'year':
- case 'yearly':
- $date->subYears($subtract);
- break;
+
+ $functionMap = [
+ 'daily' => 'subDays',
+ 'week' => 'subWeeks',
+ 'weekly' => 'subWeeks',
+ 'month' => 'subMonths',
+ 'monthly' => 'subMonths',
+ 'year' => 'subYears',
+ 'yearly' => 'subYears',
+ ];
+ $modifierMap = [
+ 'quarter' => 3,
+ 'quarterly' => 3,
+ 'half-year' => 6,
+ ];
+ if (isset($functionMap[$repeatFreq])) {
+ $function = $functionMap[$repeatFreq];
+ $date->$function($subtract);
+
+ return $date;
+ }
+ if (isset($modifierMap[$repeatFreq])) {
+ $subtract = $subtract * $modifierMap[$repeatFreq];
+ $date->subMonths($subtract);
+
+ return $date;
}
- return $date;
+ throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq);
}
}
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Filter.php b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
index ae04ae6062..73ca317790 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Filter.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
@@ -131,6 +131,8 @@ class Filter
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
+ *
* @param $range
* @param Carbon $date
*
From 1b685da3e3900a1c9a7465a171422e8940756437 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Sun, 18 Jan 2015 21:40:00 +0100
Subject: [PATCH 26/71] Code cleanup and query optimisation.
---
app/controllers/TransactionController.php | 2 +
app/lib/FireflyIII/Event/Piggybank.php | 1 +
app/lib/FireflyIII/Report/Report.php | 114 +++++++++---------
app/lib/FireflyIII/Report/ReportQuery.php | 64 ++++++++++
.../Report/ReportQueryInterface.php | 12 ++
app/lib/FireflyIII/Shared/Toolkit/Filter.php | 54 ++++-----
app/views/reports/month.blade.php | 36 +++++-
7 files changed, 197 insertions(+), 86 deletions(-)
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index b987272c45..5be29c9855 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -162,6 +162,8 @@ class TransactionController extends BaseController
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's 7. More than 5 but alright.
+ *
* @param $what
*
* @return $this
diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php
index 5188658a2a..9273f5c600 100644
--- a/app/lib/FireflyIII/Event/Piggybank.php
+++ b/app/lib/FireflyIII/Event/Piggybank.php
@@ -180,6 +180,7 @@ class PiggyBank
}
/**
+ * @SuppressWarnings("CyclomaticComplexity") // It's 6. More than 5 but alright.
*
* Validates the presence of repetitions for all repeated expenses!
*/
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index 70b651eb74..0dfce025fc 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -7,7 +7,6 @@ use FireflyIII\Database\Account\Account as AccountRepository;
use FireflyIII\Database\SwitchUser;
use FireflyIII\Database\TransactionJournal\TransactionJournal as JournalRepository;
use Illuminate\Database\Query\Builder;
-use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
/**
@@ -47,6 +46,7 @@ class Report implements ReportInterface
/**
* This methods fails to take in account transfers FROM shared accounts.
+ *
* @param Carbon $start
* @param Carbon $end
* @param int $limit
@@ -117,7 +117,7 @@ class Report implements ReportInterface
$accounts = [];
/** @var \Account $account */
foreach ($list as $account) {
- $id = intval($account->id);
+ $id = intval($account->id);
/** @noinspection PhpParamsInspection */
$accounts[$id] = [
'name' => $account->name,
@@ -232,8 +232,6 @@ class Report implements ReportInterface
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
- * TODO: This method runs two queries which are only marginally different. Try and combine these.
- *
* @param Carbon $date
* @param bool $shared
*
@@ -247,45 +245,48 @@ class Report implements ReportInterface
$end->endOfMonth();
$userId = $this->_accounts->getUser()->id;
- $list = \TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
- ->leftJoin(
- 'account_meta', function (JoinClause $join) {
- $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
- }
- )
- ->transactionTypes(['Deposit'])
- ->where('transaction_journals.user_id', $userId)
- ->where('transactions.amount', '>', 0)
- ->where('transaction_journals.user_id', \Auth::user()->id)
- ->where('account_meta.data', '!=', '"sharedExpense"')
- ->orderBy('date', 'ASC')
- ->before($end)->after($start)->get(['transaction_journals.*']);
+ return $this->_queries->incomeByPeriod($start, $end);
- // incoming from a shared account: it's profit (income):
- $transfers = \TransactionJournal::withRelevantData()
- ->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
- ->leftJoin(
- 'account_meta', function (JoinClause $join) {
- $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
- }
- )
- ->transactionTypes(['Transfer'])
- ->where('transaction_journals.user_id', $userId)
- ->where('transactions.amount', '<', 0)
- ->where('account_meta.data', '=', '"sharedExpense"')
- ->orderBy('date', 'ASC')
- ->before($end)->after($start)->get(['transaction_journals.*']);
+ // $list = \TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ // ->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
+ // ->leftJoin(
+ // 'account_meta', function (JoinClause $join) {
+ // $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
+ // }
+ // )
+ // ->transactionTypes(['Deposit'])
+ // ->where('transaction_journals.user_id', $userId)
+ // ->where('transactions.amount', '>', 0)
+ // ->where('transaction_journals.user_id', \Auth::user()->id)
+ // ->where('account_meta.data', '!=', '"sharedExpense"')
+ // ->orderBy('date', 'ASC')
+ // ->before($end)->after($start)->get(['transaction_journals.*']);
+ //
+ // // incoming from a shared account: it's profit (income):
+ // $transfers = \TransactionJournal::withRelevantData()
+ // ->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ // ->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
+ // ->leftJoin(
+ // 'account_meta', function (JoinClause $join) {
+ // $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
+ // }
+ // )
+ // ->transactionTypes(['Transfer'])
+ // ->where('transaction_journals.user_id', $userId)
+ // ->where('transactions.amount', '<', 0)
+ // ->where('account_meta.data', '=', '"sharedExpense"')
+ // ->orderBy('date', 'ASC')
+ // ->before($end)->after($start)->get(['transaction_journals.*']);
+ //
+ // $list = $list->merge($transfers);
+ // $list->sort(
+ // function (\TransactionJournal $journal) {
+ // return $journal->date->format('U');
+ // }
+ // );
+ //
+ // return $list;
- $list = $list->merge($transfers);
- $list->sort(
- function (\TransactionJournal $journal) {
- return $journal->date->format('U');
- }
- );
-
- return $list;
}
/**
@@ -302,21 +303,21 @@ class Report implements ReportInterface
\PiggyBank::
leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
- ->where('accounts.user_id', \Auth::user()->id)
- ->where('repeats', 0)
- ->where(
- function (Builder $query) use ($start, $end) {
- $query->whereNull('piggy_banks.deleted_at');
- $query->orWhere(
- function (Builder $query) use ($start, $end) {
- $query->whereNotNull('piggy_banks.deleted_at');
- $query->where('piggy_banks.deleted_at', '>=', $start->format('Y-m-d 00:00:00'));
- $query->where('piggy_banks.deleted_at', '<=', $end->format('Y-m-d 00:00:00'));
- }
- );
- }
- )
- ->get(['piggy_banks.*']);
+ ->where('accounts.user_id', \Auth::user()->id)
+ ->where('repeats', 0)
+ ->where(
+ function (Builder $query) use ($start, $end) {
+ $query->whereNull('piggy_banks.deleted_at');
+ $query->orWhere(
+ function (Builder $query) use ($start, $end) {
+ $query->whereNotNull('piggy_banks.deleted_at');
+ $query->where('piggy_banks.deleted_at', '>=', $start->format('Y-m-d 00:00:00'));
+ $query->where('piggy_banks.deleted_at', '<=', $end->format('Y-m-d 00:00:00'));
+ }
+ );
+ }
+ )
+ ->get(['piggy_banks.*']);
}
@@ -372,7 +373,6 @@ class Report implements ReportInterface
return $this->_queries->journalsByRevenueAccount($start, $end, $limit);
-
}
/**
diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php
index 4f8fd1a663..2591b858a6 100644
--- a/app/lib/FireflyIII/Report/ReportQuery.php
+++ b/app/lib/FireflyIII/Report/ReportQuery.php
@@ -199,6 +199,70 @@ class ReportQuery implements ReportQueryInterface
}
+ /**
+ * This method returns all "income" journals in a certain period, which are both transfers from a shared account
+ * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does
+ * not group and returns different fields.
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function incomeByPeriod(Carbon $start, Carbon $end)
+ {
+ return \TransactionJournal::
+ leftJoin(
+ 'transactions as t_from', function (JoinClause $join) {
+ $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
+ }
+ )
+ ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
+ ->leftJoin(
+ 'account_meta as acm_from', function (JoinClause $join) {
+ $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
+ }
+ )
+ ->leftJoin(
+ 'transactions as t_to', function (JoinClause $join) {
+ $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
+ }
+ )
+ ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
+ ->leftJoin(
+ 'account_meta as acm_to', function (JoinClause $join) {
+ $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
+ }
+ )
+ ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
+ ->where(
+ function ($query) {
+ $query->where(
+ function ($q) {
+ $q->where('transaction_types.type', 'Deposit');
+ $q->where('acm_to.data', '!=', '"sharedExpense"');
+ }
+ );
+ $query->orWhere(
+ function ($q) {
+ $q->where('transaction_types.type', 'Transfer');
+ $q->where('acm_from.data', '=', '"sharedExpense"');
+ }
+ );
+ }
+ )
+ ->before($end)->after($start)
+ ->where('transaction_journals.user_id', \Auth::user()->id)
+ ->groupBy('t_from.account_id')->orderBy('transaction_journals.date')
+ ->get(
+ ['transaction_journals.id',
+ 'transaction_journals.description',
+ 'transaction_types.type',
+ 't_to.amount', 'transaction_journals.date', 't_from.account_id as account_id',
+ 'ac_from.name as name']
+ );
+ }
+
/**
* Gets a list of expenses grouped by the budget they were filed under.
*
diff --git a/app/lib/FireflyIII/Report/ReportQueryInterface.php b/app/lib/FireflyIII/Report/ReportQueryInterface.php
index a2097c6635..046835b843 100644
--- a/app/lib/FireflyIII/Report/ReportQueryInterface.php
+++ b/app/lib/FireflyIII/Report/ReportQueryInterface.php
@@ -117,6 +117,18 @@ interface ReportQueryInterface
*/
public function journalsByRevenueAccount(Carbon $start, Carbon $end);
+ /**
+ * This method returns all "income" journals in a certain period, which are both transfers from a shared account
+ * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does
+ * not group and returns different fields.
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function incomeByPeriod(Carbon $start, Carbon $end);
+
/**
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
* expenses.
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Filter.php b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
index 73ca317790..70f0aef677 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Filter.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Filter.php
@@ -174,37 +174,35 @@ class Filter
*/
public function previous($range, Carbon $date)
{
- switch ($range) {
- default:
- throw new FireflyException('Cannot do _previous() on ' . $range);
- break;
- case '1D':
- $date->startOfDay()->subDay();
- break;
- case '1W':
- $date->startOfWeek()->subWeek();
- break;
- case '1M':
- $date->startOfMonth()->subMonth();
- break;
- case '3M':
- $date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
- break;
- case '6M':
- $month = intval($date->format('m'));
- if ($month <= 6) {
- $date->startOfYear()->subMonths(6);
- } else {
- $date->startOfYear();
- }
- break;
- case '1Y':
- $date->startOfYear()->subYear();
- break;
+ $functionMap = [
+ '1D' => 'Day',
+ '1W' => 'Week',
+ '1M' => 'Month',
+ '1Y' => 'Year'
+ ];
+ if (isset($functionMap[$range])) {
+ $startFunction = 'startOf' . $functionMap[$range];
+ $subFunction = 'sub' . $functionMap[$range];
+ $date->$startFunction()->$subFunction();
+
+ return $date;
}
+ if ($range == '3M') {
+ $date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
- return $date;
+ return $date;
+ }
+ if ($range == '6M') {
+ $month = intval($date->format('m'));
+ $date->startOfYear();
+ if ($month <= 6) {
+ $date->subMonths(6);
+ }
+
+ return $date;
+ }
+ throw new FireflyException('Cannot do _previous() on ' . $range);
}
/**
diff --git a/app/views/reports/month.blade.php b/app/views/reports/month.blade.php
index c60d473d62..6943a09ba8 100644
--- a/app/views/reports/month.blade.php
+++ b/app/views/reports/month.blade.php
@@ -5,7 +5,41 @@
Income
- @include('list.journals-small',['journals' => $income])
+
+
+ @foreach($income as $entry)
+
+ |
+ {{{$entry->description}}}
+ |
+
+ amount);?>
+ @if($entry->type == 'Withdrawal')
+ {{Amount::format($entry->amount,false)}}
+ @endif
+ @if($entry->type == 'Deposit')
+ {{Amount::format($entry->amount,false)}}
+ @endif
+ @if($entry->type == 'Transfer')
+ {{Amount::format($entry->amount,false)}}
+ @endif
+ |
+
+ {{$entry->date->format('j F Y')}}
+ |
+
+ {{{$entry->name}}}
+ |
+
+ @endforeach
+ @if(isset($displaySum) && $displaySum === true)
+
+ | Sum |
+ {{Amount::format($tableSum)}} |
+
+
+ @endif
+
From 8eb84acf4fe0deeae2b373a0b961181ab3cdb7e0 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Mon, 19 Jan 2015 06:33:30 +0100
Subject: [PATCH 27/71] Show the view for transactions without a category.
---
app/routes.php | 2 +-
app/views/list/categories.blade.php | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/app/routes.php b/app/routes.php
index 94f89f51b5..2bc973242b 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -204,7 +204,7 @@ Route::group(
Route::get('/categories/edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'categories.edit']);
Route::get('/categories/delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'categories.delete']);
Route::get('/categories/show/{category}', ['uses' => 'CategoryController@show', 'as' => 'categories.show']);
- Route::get('/categories/list/noCategory', ['uses' => 'CategoryController@noCategory', 'as' => 'categories.noBudget']);
+ Route::get('/categories/list/noCategory', ['uses' => 'CategoryController@noCategory', 'as' => 'categories.noCategory']);
// currency controller
Route::get('/currency', ['uses' => 'CurrencyController@index', 'as' => 'currency.index']);
diff --git a/app/views/list/categories.blade.php b/app/views/list/categories.blade.php
index 29e6d7e27f..c12a88762c 100644
--- a/app/views/list/categories.blade.php
+++ b/app/views/list/categories.blade.php
@@ -4,6 +4,11 @@
Name |
Last activity |
+
+ | |
+ Without a category |
+ |
+
@foreach($categories as $category)
|
From 1887977b929c99adf6477ec746109975b3204cb5 Mon Sep 17 00:00:00 2001
From: James Cole
Date: Mon, 19 Jan 2015 07:21:44 +0100
Subject: [PATCH 28/71] Small experimental cleaning up.
---
app/controllers/TransactionController.php | 5 +--
.../TransactionJournal/TransactionJournal.php | 32 +++++++++----------
app/lib/FireflyIII/Form/Form.php | 20 ++++++++++--
app/views/partials/menu.blade.php | 2 +-
4 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index 5be29c9855..91cd99c644 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -248,14 +248,14 @@ class TransactionController extends BaseController
$data['transaction_currency_id'] = $transactionCurrency->id;
$data['completed'] = 0;
$data['what'] = $what;
- $data['currency'] = 'EUR';
- $messages = $this->_repository->validate($data);
+ $messages = $this->_repository->validate($data);
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store transaction: ' . $messages['errors']->first());
+
return Redirect::route('transactions.create', $data['what'])->withInput();
}
@@ -301,6 +301,7 @@ class TransactionController extends BaseController
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update transaction: ' . $messages['errors']->first());
+
return Redirect::route('transactions.edit', $journal->id)->withInput();
}
if ($data['post_submit_action'] == 'validate_only') {
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index ce0cfbafcc..65b842871d 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -63,11 +63,11 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
*/
public function store(array $data)
{
- $currency = $this->getJournalCurrency($data['currency']);
- $journal = new \TransactionJournal(
+ $journal = new \TransactionJournal(
[
'transaction_type_id' => $data['transaction_type_id'],
- 'transaction_currency_id' => $currency->id, 'user_id' => $this->getUser()->id,
+ 'transaction_currency_id' => $data['transaction_currency_id'],
+ 'user_id' => $this->getUser()->id,
'description' => $data['description'], 'date' => $data['date'], 'completed' => 0]
);
$journal->save();
@@ -178,19 +178,6 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
}
- /**
- * @param $currency
- *
- * @return null|\TransactionCurrency
- */
- public function getJournalCurrency($currency)
- {
- /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
- $currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
-
- return $currencyRepository->findByCode($currency);
- }
-
/**
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
*
@@ -304,6 +291,19 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
return $typeRepository->findByWhat($type);
}
+ /**
+ * @param $currency
+ *
+ * @return null|\TransactionCurrency
+ */
+ public function getJournalCurrency($currency)
+ {
+ /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
+ $currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
+
+ return $currencyRepository->findByCode($currency);
+ }
+
/**
* @SuppressWarnings("CamelCase") // I'm fine with this.
*
diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php
index 68409ab2df..2548b2d511 100644
--- a/app/lib/FireflyIII/Form/Form.php
+++ b/app/lib/FireflyIII/Form/Form.php
@@ -54,7 +54,7 @@ class Form
/*
* Make label and placeholder look nice.
*/
- $options['placeholder'] = ucfirst($name);
+ $options['placeholder'] = ucfirst($label);
/*
* Get pre filled value:
@@ -123,7 +123,19 @@ class Form
$html .= \Form::input('text', $name, $value, $options);
break;
case 'amount':
- $html .= ' |