From c4f42a604fa29a1b552faf35cd2d43dfb6fd94f8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 28 Aug 2014 07:53:54 +0200 Subject: [PATCH] This will be the first release! --- app/controllers/AccountController.php | 22 ++- app/controllers/BaseController.php | 4 +- app/controllers/BudgetController.php | 10 +- app/controllers/HomeController.php | 27 ++-- app/controllers/JsonController.php | 1 - app/controllers/LimitController.php | 8 +- app/controllers/PiggybankController.php | 12 +- app/controllers/RecurringController.php | 3 + app/controllers/TransactionController.php | 5 +- .../2014_08_18_100330_create_piggy_events.php | 64 ++++----- ...14_08_23_113221_create_reminders_table.php | 34 +++-- app/lib/Firefly/Helper/Controllers/Budget.php | 4 +- .../Helper/Controllers/BudgetInterface.php | 3 +- app/lib/Firefly/Helper/Controllers/Chart.php | 4 +- app/lib/Firefly/Helper/Toolkit/Toolkit.php | 45 ++++--- .../Account/EloquentAccountRepository.php | 10 +- .../Budget/EloquentBudgetRepository.php | 2 +- .../Category/EloquentCategoryRepository.php | 2 +- .../Storage/Limit/EloquentLimitRepository.php | 18 +-- .../Limit/LimitRepositoryInterface.php | 3 +- .../Piggybank/EloquentPiggybankRepository.php | 1 - ...EloquentRecurringTransactionRepository.php | 6 +- ...ecurringTransactionRepositoryInterface.php | 3 +- .../Reminder/EloquentReminderRepository.php | 13 ++ .../Reminder/ReminderRepositoryInterface.php | 6 +- .../EloquentTransactionJournalRepository.php | 6 +- .../Recurring/EloquentRecurringTrigger.php | 127 ++++++++++++++++++ app/models/Account.php | 34 ++--- app/models/AccountType.php | 16 +-- app/models/Budget.php | 30 ++--- app/models/Category.php | 30 ++--- app/models/Component.php | 30 ++--- app/models/Limit.php | 38 +++--- app/models/LimitRepetition.php | 22 +-- app/models/Piggybank.php | 67 ++++----- app/models/PiggybankEvent.php | 24 ++-- app/models/PiggybankReminder.php | 26 ++++ app/models/PiggybankRepetition.php | 28 ++-- app/models/Preference.php | 22 +-- app/models/RecurringTransaction.php | 63 +++++---- app/models/RecurringTransactionReminder.php | 37 +++++ app/models/Reminder.php | 52 ++++++- app/models/Transaction.php | 42 +++--- app/models/TransactionCurrency.php | 16 +-- app/models/TransactionJournal.php | 5 + app/models/TransactionType.php | 16 +-- app/models/User.php | 46 ++++--- app/start/global.php | 36 ++--- .../controllers/AccountControllerTest.php | 24 ++-- .../controllers/BudgetControllerTest.php | 12 +- .../controllers/CategoryControllerTest.php | 2 +- app/tests/controllers/ChartControllerTest.php | 2 +- app/tests/controllers/HomeControllerTest.php | 23 +++- app/tests/controllers/LimitControllerTest.php | 2 +- .../controllers/PiggybankControllerTest.php | 117 ++++++++-------- .../controllers/ProfileControllerTest.php | 2 +- .../controllers/RecurringControllerTest.php | 13 +- .../controllers/TransactionControllerTest.php | 2 +- app/tests/controllers/UserControllerTest.php | 2 +- app/tests/factories/AccountType.php | 5 +- app/tests/factories/Limit.php | 24 ++-- app/tests/factories/LimitRepetition.php | 24 ++-- app/tests/factories/Piggybank.php | 40 +++--- app/tests/factories/PiggybankRepetition.php | 24 ++-- app/tests/factories/Preference.php | 1 - app/tests/factories/RecurringTransaction.php | 18 +-- app/tests/factories/Transaction.php | 1 - app/tests/factories/TransactionCurrency.php | 1 - app/tests/factories/TransactionType.php | 10 +- app/tests/models/ModelTest.php | 2 +- app/views/index.blade.php | 61 ++++++++- app/views/piggybanks/show.blade.php | 20 ++- bootstrap/autoload.php | 12 +- bootstrap/paths.php | 88 ++++++------ bootstrap/start.php | 6 +- 75 files changed, 1043 insertions(+), 618 deletions(-) create mode 100644 app/lib/Firefly/Trigger/Recurring/EloquentRecurringTrigger.php create mode 100644 app/models/RecurringTransactionReminder.php diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 5d04d4693d..cf6a6458f3 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -14,7 +14,7 @@ class AccountController extends \BaseController /** * @param ARI $repository - * @param AI $accounts + * @param AI $accounts */ public function __construct(ARI $repository, AI $accounts) { @@ -40,7 +40,9 @@ class AccountController extends \BaseController $accountType = $account->accountType()->first(); if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') { - return \View::make('error')->with('message', 'Cannot edit this account type (' . $accountType->description . ').'); + return \View::make('error')->with( + 'message', 'Cannot edit this account type (' . $accountType->description . ').' + ); } return View::make('accounts.delete')->with('account', $account); @@ -56,7 +58,9 @@ class AccountController extends \BaseController $accountType = $account->accountType()->first(); if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') { - return View::make('error')->with('message', 'Cannot edit this account type (' . $accountType->description . ').'); + return View::make('error')->with( + 'message', 'Cannot edit this account type (' . $accountType->description . ').' + ); } $result = $this->_repository->destroy($account); if ($result === true) { @@ -79,7 +83,9 @@ class AccountController extends \BaseController $accountType = $account->accountType()->first(); if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') { - return View::make('error')->with('message', 'Cannot edit this account type (' . $accountType->description . ').'); + return View::make('error')->with( + 'message', 'Cannot edit this account type (' . $accountType->description . ').' + ); } $openingBalance = $this->_accounts->openingBalanceTransaction($account); @@ -106,7 +112,9 @@ class AccountController extends \BaseController { $accountType = $account->accountType()->first(); if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') { - return View::make('error')->with('message', 'Cannot show this account type (' . $accountType->description . ').'); + return View::make('error')->with( + 'message', 'Cannot show this account type (' . $accountType->description . ').' + ); } $show = $this->_accounts->show($account, 40); @@ -148,7 +156,9 @@ class AccountController extends \BaseController { $accountType = $account->accountType()->first(); if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') { - return View::make('error')->with('message', 'Cannot show this account type (' . $accountType->description . ').'); + return View::make('error')->with( + 'message', 'Cannot show this account type (' . $accountType->description . ').' + ); } $account = $this->_repository->update($account, Input::all()); if ($account->validate()) { diff --git a/app/controllers/BaseController.php b/app/controllers/BaseController.php index 418082a7d6..8d59afad2d 100644 --- a/app/controllers/BaseController.php +++ b/app/controllers/BaseController.php @@ -9,10 +9,12 @@ class BaseController extends Controller /** * */ - public function __construct() { + public function __construct() + { \Event::fire('limits.check'); \Event::fire('piggybanks.check'); } + /** * Setup the layout used by the controller. * diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 67db159b77..9536b74b6f 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -50,7 +50,7 @@ class BudgetController extends BaseController */ public function destroy(Budget $budget) { - Event::fire('budgets.destroy',[$budget]); // just before deletion. + Event::fire('budgets.destroy', [$budget]); // just before deletion. $result = $this->_repository->destroy($budget); if ($result === true) { Session::flash('success', 'The budget was deleted.'); @@ -133,13 +133,13 @@ class BudgetController extends BaseController $filters[] = 'no_envelope'; } else { // grab all limit repetitions, order them, show them: - $repetitions = $this->_budgets->organizeRepetitions($budget,$useSessionDates); + $repetitions = $this->_budgets->organizeRepetitions($budget, $useSessionDates); } } return View::make('budgets.show')->with('budget', $budget)->with('repetitions', $repetitions)->with( 'filters', $filters - )->with('highlight', Input::get('highlight'))->with('useSessionDates',$useSessionDates); + )->with('highlight', Input::get('highlight'))->with('useSessionDates', $useSessionDates); } /** @@ -150,7 +150,7 @@ class BudgetController extends BaseController $budget = $this->_repository->store(Input::all()); if ($budget->validate()) { - Event::fire('budgets.store',[$budget]); + Event::fire('budgets.store', [$budget]); Session::flash('success', 'Budget created!'); if (Input::get('create') == '1') { @@ -179,7 +179,7 @@ class BudgetController extends BaseController { $budget = $this->_repository->update($budget, Input::all()); if ($budget->validate()) { - Event::fire('budgets.update',[$budget]); + Event::fire('budgets.update', [$budget]); Session::flash('success', 'Budget "' . $budget->name . '" updated.'); if (Input::get('from') == 'date') { diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 3763a1a268..2e06ff1924 100644 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -2,7 +2,7 @@ use Carbon\Carbon; use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI; use Firefly\Storage\Account\AccountRepositoryInterface as ARI; -use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI; +use Firefly\Storage\Reminder\ReminderRepositoryInterface as RRI; use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI; /** @@ -13,20 +13,14 @@ class HomeController extends BaseController protected $_accounts; protected $_preferences; protected $_journal; - protected $_budgets; + protected $_reminders; - /** - * @param ARI $accounts - * @param PHI $preferences - * @param TJRI $journal - * @param BRI $budgets - */ - public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, BRI $budgets) + public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, RRI $reminders) { $this->_accounts = $accounts; $this->_preferences = $preferences; $this->_journal = $journal; - $this->_budgets = $budgets; + $this->_reminders = $reminders; } /** @@ -47,7 +41,7 @@ class HomeController extends BaseController \Event::fire('limits.check'); \Event::fire('piggybanks.check'); - + \Event::fire('recurring.check'); // count, maybe we need some introducing text to show: @@ -64,10 +58,9 @@ class HomeController extends BaseController $accounts = $this->_accounts->getByIds($frontpage->data); } - $transactions = []; foreach ($accounts as $account) { - $set = $this->_journal->getByAccountInDateRange($account, 15, $start, $end); + $set = $this->_journal->getByAccountInDateRange($account, 10, $start, $end); if (count($set) > 0) { $transactions[] = [$set, $account]; } @@ -81,7 +74,13 @@ class HomeController extends BaseController $transactions = array_chunk($transactions, 3); } + // get the users reminders: + + $reminders = $this->_reminders->getCurrentRecurringReminders(); + // build the home screen: - return View::make('index')->with('count', $count)->with('transactions', $transactions); + return View::make('index')->with('count', $count)->with('transactions', $transactions)->with( + 'reminders', $reminders + ); } } \ No newline at end of file diff --git a/app/controllers/JsonController.php b/app/controllers/JsonController.php index db30268efa..6e35c1b0f8 100644 --- a/app/controllers/JsonController.php +++ b/app/controllers/JsonController.php @@ -1,6 +1,5 @@ _limits->destroy($limit); if ($success) { @@ -102,7 +102,7 @@ class LimitController extends BaseController $limit = $this->_limits->store(Input::all()); if ($limit->validate()) { Session::flash('success', 'Envelope created!'); - Event::fire('limits.store',[$limit]); + Event::fire('limits.store', [$limit]); if (Input::get('from') == 'date') { return Redirect::route('budgets.index'); } else { @@ -127,10 +127,10 @@ class LimitController extends BaseController { - $limit = $this->_limits->update($limit,Input::all()); + $limit = $this->_limits->update($limit, Input::all()); if ($limit->validate()) { - Event::fire('limits.update',[$limit]); + Event::fire('limits.update', [$limit]); Session::flash('success', 'Limit saved!'); if (Input::get('from') == 'date') { return Redirect::route('budgets.index'); diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index 59a288d43d..fccc08542b 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -192,7 +192,11 @@ class PiggybankController extends BaseController */ public function show(Piggybank $piggyBank) { - return View::make('piggybanks.show')->with('piggyBank', $piggyBank); + $leftOnAccount = $this->_repository->leftOnAccount($piggyBank->account); + $balance = $piggyBank->account->balance(); + + return View::make('piggybanks.show')->with('piggyBank', $piggyBank)->with('leftOnAccount', $leftOnAccount) + ->with('balance', $balance); } /** @@ -212,7 +216,7 @@ class PiggybankController extends BaseController $piggyBank = $this->_repository->store($data); if (!is_null($piggyBank->id)) { Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!'); - Event::fire('piggybanks.store',[$piggyBank]); + Event::fire('piggybanks.store', [$piggyBank]); return Redirect::route('piggybanks.index'); @@ -241,7 +245,7 @@ class PiggybankController extends BaseController $piggyBank = $this->_repository->store($data); if ($piggyBank->id) { Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!'); - Event::fire('piggybanks.store',[$piggyBank]); + Event::fire('piggybanks.store', [$piggyBank]); return Redirect::route('piggybanks.index'); @@ -261,7 +265,7 @@ class PiggybankController extends BaseController $piggyBank = $this->_repository->update($piggyBank, Input::all()); if ($piggyBank->validate()) { Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.'); - Event::fire('piggybanks.update',[$piggyBank]); + Event::fire('piggybanks.update', [$piggyBank]); return Redirect::route('piggybanks.index'); } else { diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.php index 75761d7929..a32cfde904 100644 --- a/app/controllers/RecurringController.php +++ b/app/controllers/RecurringController.php @@ -44,6 +44,7 @@ class RecurringController extends BaseController */ public function destroy(RecurringTransaction $recurringTransaction) { + Event::fire('recurring.destroy', [$recurringTransaction]); $result = $this->_repository->destroy($recurringTransaction); if ($result === true) { Session::flash('success', 'The recurring transaction was deleted.'); @@ -96,6 +97,7 @@ class RecurringController extends BaseController $recurringTransaction = $this->_repository->store(Input::all()); if ($recurringTransaction->validate()) { Session::flash('success', 'Recurring transaction "' . $recurringTransaction->name . '" saved!'); + Event::fire('recurring.store', [$recurringTransaction]); if (Input::get('create') == '1') { return Redirect::route('recurring.create')->withInput(); } else { @@ -119,6 +121,7 @@ class RecurringController extends BaseController $recurringTransaction = $this->_repository->update($recurringTransaction, Input::all()); if ($recurringTransaction->errors()->count() == 0) { Session::flash('success', 'The recurring transaction has been updated.'); + Event::fire('recurring.update', [$recurringTransaction]); return Redirect::route('recurring.index'); } else { diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index 684b9667fd..c57e733326 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -189,14 +189,15 @@ class TransactionController extends BaseController Session::flash('success', 'Transaction "' . $journal->description . '" saved!'); // if reminder present, deactivate it: - if(Input::get('reminder')) { + if (Input::get('reminder')) { /** @var \Firefly\Storage\Reminder\ReminderRepositoryInterface $reminders */ $reminders = App::make('Firefly\Storage\Reminder\ReminderRepositoryInterface'); $reminder = $reminders->find(Input::get('reminder')); $reminders->deactivate($reminder); - } + // trigger the creation for recurring transactions. + if (Input::get('create') == '1') { return Redirect::route('transactions.create', [$what])->withInput(); } else { diff --git a/app/database/migrations/2014_08_18_100330_create_piggy_events.php b/app/database/migrations/2014_08_18_100330_create_piggy_events.php index c9193738fc..3551a6b0d9 100644 --- a/app/database/migrations/2014_08_18_100330_create_piggy_events.php +++ b/app/database/migrations/2014_08_18_100330_create_piggy_events.php @@ -1,40 +1,42 @@ increments('id'); - $table->timestamps(); - $table->integer('piggybank_id')->unsigned(); - $table->date('date'); - $table->decimal('amount', 10, 2); + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create( + 'piggybank_events', function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('piggybank_id')->unsigned(); + $table->date('date'); + $table->decimal('amount', 10, 2); - // connect instance to piggybank. - $table->foreign('piggybank_id') - ->references('id')->on('piggybanks') - ->onDelete('cascade'); - }); - } + // connect instance to piggybank. + $table->foreign('piggybank_id') + ->references('id')->on('piggybanks') + ->onDelete('cascade'); + } + ); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('piggybank_events'); - } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('piggybank_events'); + } } 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 808b11b857..ba001753a4 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 @@ -1,9 +1,20 @@ increments('id'); $table->timestamps(); - $table->string('class', 30); + $table->string('class', 40); $table->integer('piggybank_id')->unsigned()->nullable(); + $table->integer('recurring_transaction_id')->unsigned()->nullable(); $table->integer('user_id')->unsigned(); $table->date('startdate'); $table->date('enddate'); @@ -29,6 +41,12 @@ class CreateRemindersTable extends Migration { ->references('id')->on('piggybanks') ->onDelete('set null'); + // connect reminders to recurring transactions. + $table->foreign('recurring_transaction_id') + ->references('id')->on('recurring_transactions') + ->onDelete('set null'); + + // connect reminders to users $table->foreign('user_id') ->references('id')->on('users') @@ -37,14 +55,4 @@ class CreateRemindersTable extends Migration { ); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('reminders'); - } - } diff --git a/app/lib/Firefly/Helper/Controllers/Budget.php b/app/lib/Firefly/Helper/Controllers/Budget.php index d234721933..b46190d44f 100644 --- a/app/lib/Firefly/Helper/Controllers/Budget.php +++ b/app/lib/Firefly/Helper/Controllers/Budget.php @@ -110,8 +110,8 @@ class Budget implements BudgetInterface // get the limits: if ($useSessionDates) { $limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->where( - 'startdate', '<=', $sessionEnd->format('Y-m-d') - )->get(); + 'startdate', '<=', $sessionEnd->format('Y-m-d') + )->get(); } else { $limits = $budget->limits; } diff --git a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php index 380f89f98c..ab3639ef20 100644 --- a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php +++ b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php @@ -28,7 +28,8 @@ interface BudgetInterface /** * @param \Budget $budget - * @param bool $useSessionDates + * @param bool $useSessionDates + * * @return mixed */ public function organizeRepetitions(\Budget $budget, $useSessionDates = false); diff --git a/app/lib/Firefly/Helper/Controllers/Chart.php b/app/lib/Firefly/Helper/Controllers/Chart.php index 161fa23325..45b8cac004 100644 --- a/app/lib/Firefly/Helper/Controllers/Chart.php +++ b/app/lib/Firefly/Helper/Controllers/Chart.php @@ -169,8 +169,8 @@ class Chart implements ChartInterface $amount = floatval($rep->amount); $spent = $rep->spent; $color = $spent > $amount ? '#FF0000' : null; - $data['series'][0]['data'][] = ['y' => $amount, 'id' => 'def']; - $data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'abc']; + $data['series'][0]['data'][] = ['y' => $amount, 'id' => 'amount-' . $rep->id]; + $data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'spent-' . $rep->id]; } } diff --git a/app/lib/Firefly/Helper/Toolkit/Toolkit.php b/app/lib/Firefly/Helper/Toolkit/Toolkit.php index 64cc7f0f1f..c968bf0ca3 100644 --- a/app/lib/Firefly/Helper/Toolkit/Toolkit.php +++ b/app/lib/Firefly/Helper/Toolkit/Toolkit.php @@ -64,6 +64,29 @@ class Toolkit implements ToolkitInterface return [\Session::get('start'), \Session::get('end')]; } + /** + * @return mixed + */ + public function getReminders() + { + // get reminders, for menu, mumble mumble: + $today = new Carbon; + $reminders = \Auth::user()->reminders()->where('class', 'PiggybankReminder')->validOn($today)->get(); + + /** @var \Reminder $reminder */ + foreach ($reminders as $index => $reminder) { + if (\Session::has('dismissal-' . $reminder->id)) { + $time = \Session::get('dismissal-' . $reminder->id); + if ($time >= $today) { + unset($reminders[$index]); + } + + } + } + \Session::put('reminderCount', count($reminders)); + + } + /** * @return mixed */ @@ -302,26 +325,4 @@ class Toolkit implements ToolkitInterface return $end; } - /** - * @return mixed - */ - public function getReminders() { - // get reminders, for menu, mumble mumble: - $today = new Carbon; - $reminders = \Auth::user()->reminders()->validOn($today)->get(); - - /** @var \Reminder $reminder */ - foreach($reminders as $index => $reminder) { - if(\Session::has('dismissal-' . $reminder->id)) { - $time = \Session::get('dismissal-' . $reminder->id); - if($time >= $today) { - unset($reminders[$index]); - } - - } - } - \Session::put('reminderCount',count($reminders)); - - } - } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php index 3fe48d154c..78115ce1a3 100644 --- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php +++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php @@ -40,7 +40,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface $account = $this->findByName($name, $type); if (!$account) { $data = [ - 'name' => $name, + 'name' => $name, 'account_type' => $type ]; @@ -76,7 +76,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface { // find the oldest transaction which also is a "Opening balance" $first = \Transaction:: - leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->where('transaction_journals.user_id', \Auth::user()->id) ->where('transaction_types.type', 'Opening balance') @@ -101,7 +101,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface $journal->delete(); } - if(!is_null($initialbalanceAccount)) { + if (!is_null($initialbalanceAccount)) { $initialbalanceAccount->delete(); } @@ -306,8 +306,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface /** * @param \Account $account - * @param int $amount - * @param Carbon $date + * @param int $amount + * @param Carbon $date * * @return bool * @SuppressWarnings(PHPMD.CamelCaseMethodName) diff --git a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php index ec211dcffc..144c3656cf 100644 --- a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php +++ b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php @@ -121,7 +121,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface $limit->repeat_freq = $data['repeat_freq']; if ($limit->validate()) { $limit->save(); - \Event::fire('limits.store',[$limit]); + \Event::fire('limits.store', [$limit]); } } if ($budget->validate()) { diff --git a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php index f18369abc4..8e8b972e37 100644 --- a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php +++ b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php @@ -16,7 +16,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface */ public function createOrFind($name) { - if(strlen($name) == 0) { + if (strlen($name) == 0) { return null; } $category = $this->findByName($name); diff --git a/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php b/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php index fbdf99fdbf..612799d70a 100644 --- a/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php +++ b/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php @@ -28,7 +28,8 @@ class EloquentLimitRepository implements LimitRepositoryInterface /** * @param \Limit $limit - * @param $data + * @param $data + * * @return mixed|void */ public function update(\Limit $limit, $data) @@ -39,6 +40,7 @@ class EloquentLimitRepository implements LimitRepositoryInterface $limit->amount = floatval($data['amount']); $limit->save(); + return $limit; } @@ -57,8 +59,8 @@ class EloquentLimitRepository implements LimitRepositoryInterface /** * @param \Budget $budget - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return mixed */ @@ -113,11 +115,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface } // find existing: $count = \Limit:: - leftJoin('components', 'components.id', '=', 'limits.component_id')->where( - 'components.user_id', \Auth::user()->id - )->where('startdate', $date->format('Y-m-d'))->where('component_id', $data['budget_id'])->where( - 'repeat_freq', $data['period'] - )->count(); + leftJoin('components', 'components.id', '=', 'limits.component_id')->where( + 'components.user_id', \Auth::user()->id + )->where('startdate', $date->format('Y-m-d'))->where('component_id', $data['budget_id'])->where( + 'repeat_freq', $data['period'] + )->count(); if ($count > 0) { \Session::flash('error', 'There already is an entry for these parameters.'); diff --git a/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php b/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php index dc8b03647a..76b683c8a1 100644 --- a/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php +++ b/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php @@ -21,7 +21,8 @@ interface LimitRepositoryInterface /** * @param \Limit $limit - * @param $data + * @param $data + * * @return mixed */ public function update(\Limit $limit, $data); diff --git a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php index 3610ff532c..c8245d80b9 100644 --- a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php +++ b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php @@ -225,7 +225,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface = isset($data['startdate']) && strlen($data['startdate']) > 0 ? new Carbon($data['startdate']) : null; - foreach ($piggy->piggybankrepetitions()->get() as $rep) { $rep->delete(); } diff --git a/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php b/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php index b8d840c501..a04a59bc2c 100644 --- a/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php +++ b/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php @@ -68,10 +68,12 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo /** * @param \RecurringTransaction $recurringTransaction - * @param $data + * @param $data + * * @return mixed|void */ - public function update(\RecurringTransaction $recurringTransaction, $data) { + public function update(\RecurringTransaction $recurringTransaction, $data) + { $recurringTransaction->name = $data['name']; $recurringTransaction->match = join(' ', explode(',', $data['match'])); $recurringTransaction->amount_max = floatval($data['amount_max']); diff --git a/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php b/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php index dc296f28c4..240e8ac47a 100644 --- a/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php +++ b/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php @@ -32,7 +32,8 @@ interface RecurringTransactionRepositoryInterface /** * @param \RecurringTransaction $recurringTransaction - * @param $data + * @param $data + * * @return mixed */ public function update(\RecurringTransaction $recurringTransaction, $data); diff --git a/app/lib/Firefly/Storage/Reminder/EloquentReminderRepository.php b/app/lib/Firefly/Storage/Reminder/EloquentReminderRepository.php index 2edd255c8e..6581b4d6f5 100644 --- a/app/lib/Firefly/Storage/Reminder/EloquentReminderRepository.php +++ b/app/lib/Firefly/Storage/Reminder/EloquentReminderRepository.php @@ -45,4 +45,17 @@ class EloquentReminderRepository implements ReminderRepositoryInterface return \Auth::user()->reminders()->validOn($today)->get(); } + /** + * + */ + public function getCurrentRecurringReminders() + { + $today = new Carbon; + + return \Auth::user()->reminders()->with('recurringtransaction')->validOn($today)->where( + 'class', 'RecurringTransactionReminder' + )->get(); + + } + } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/Reminder/ReminderRepositoryInterface.php b/app/lib/Firefly/Storage/Reminder/ReminderRepositoryInterface.php index 36b0ee3048..ed8c855f66 100644 --- a/app/lib/Firefly/Storage/Reminder/ReminderRepositoryInterface.php +++ b/app/lib/Firefly/Storage/Reminder/ReminderRepositoryInterface.php @@ -14,7 +14,8 @@ namespace Firefly\Storage\Reminder; * * @package Firefly\Storage\Reminder */ -interface ReminderRepositoryInterface { +interface ReminderRepositoryInterface +{ /** * @param \Reminder $reminder @@ -35,4 +36,7 @@ interface ReminderRepositoryInterface { */ public function find($id); + + public function getCurrentRecurringReminders(); + } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php index 3715e43315..af1116c383 100644 --- a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php +++ b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php @@ -34,8 +34,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito * A gains 200 (200). * -1 * B loses 200 (-200). * 1 * - * @param \Account $from - * @param \Account $toAccount + * @param \Account $from + * @param \Account $toAccount * @param $description * @param $amount * @param \Carbon\Carbon $date @@ -122,7 +122,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito $fromTransaction->amount = $amountFrom; if (!$fromTransaction->validate()) { throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first( - )); + )); } $fromTransaction->save(); diff --git a/app/lib/Firefly/Trigger/Recurring/EloquentRecurringTrigger.php b/app/lib/Firefly/Trigger/Recurring/EloquentRecurringTrigger.php new file mode 100644 index 0000000000..a71f7cb69a --- /dev/null +++ b/app/lib/Firefly/Trigger/Recurring/EloquentRecurringTrigger.php @@ -0,0 +1,127 @@ +recurringtransactionreminders()->get(); + /** @var \RecurringTransactionReminder $reminder */ + foreach ($reminders as $reminder) { + $reminder->delete(); + } + + return true; + + } + + /** + * @param \RecurringTransaction $recurring + */ + public function store(\RecurringTransaction $recurring) + { + $this->createReminders(); + + } + + public function createReminders() + { + $entries = \Auth::user()->recurringtransactions()->where('active', 1)->get(); + + // for each entry, check for existing reminders during their period: + /** @var \RecurringTransaction $entry */ + foreach ($entries as $entry) { + + $start = clone $entry->date; + $end = clone $entry->date; + switch ($entry->repeat_freq) { + case 'weekly': + $start->startOfWeek(); + $end->endOfWeek(); + break; + case 'monthly': + $start->startOfMonth(); + $end->endOfMonth(); + break; + case 'quarterly': + $start->firstOfQuarter(); + $end->lastOfQuarter(); + break; + case 'half-year': + // start of half-year: + if (intval($start->format('m')) >= 7) { + $start->startOfYear(); + $start->addMonths(6); + } else { + $start->startOfYear(); + } + $end = clone $start; + $end->addMonths(6); + break; + case 'yearly': + $start->startOfYear(); + $end->endOfYear(); + break; + } + // check if exists. + $count = $entry->reminders()->where('startdate', $start->format('Y-m-d'))->where( + 'enddate', $end->format('Y-m-d') + )->count(); + if ($count == 0) { + // create reminder: + $reminder = new \RecurringTransactionReminder; + $reminder->recurringtransaction()->associate($entry); + $reminder->startdate = $start; + $reminder->enddate = $end; + $reminder->active = 1; + $reminder->user()->associate(\Auth::user()); + $reminder->save(); + } + + + } + + } + + /** + * Trigger! + * + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + $events->listen('recurring.destroy', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@destroy'); + $events->listen('recurring.store', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@store'); + $events->listen('recurring.update', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@update'); + $events->listen('recurring.check', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@createReminders'); + } + + /** + * @param \RecurringTransaction $recurring + */ + public function update(\RecurringTransaction $recurring) + { + // remove old active reminders + $reminders = $recurring->reminders()->validOnOrAfter(new Carbon)->get(); + foreach ($reminders as $r) { + $r->delete(); + } + $this->createReminders(); + // create new reminder for the current period. + + // and now create new one(s)! + } +} \ No newline at end of file diff --git a/app/models/Account.php b/app/models/Account.php index a417f9bdae..c497916677 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -4,24 +4,24 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * Account * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property integer $account_type_id - * @property string $name - * @property boolean $active - * @property-read \AccountType $accountType + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $user_id + * @property integer $account_type_id + * @property string $name + * @property boolean $active + * @property-read \AccountType $accountType * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions - * @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Account whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Account whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Account whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Account whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Account whereAccountTypeId($value) - * @method static \Illuminate\Database\Query\Builder|\Account whereName($value) - * @method static \Illuminate\Database\Query\Builder|\Account whereActive($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Account whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Account whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Account whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Account whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Account whereAccountTypeId($value) + * @method static \Illuminate\Database\Query\Builder|\Account whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Account whereActive($value) */ class Account extends Ardent { diff --git a/app/models/AccountType.php b/app/models/AccountType.php index 16a4f9a9b7..c761dcb956 100644 --- a/app/models/AccountType.php +++ b/app/models/AccountType.php @@ -4,15 +4,15 @@ /** * AccountType * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $description + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $description * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts - * @method static \Illuminate\Database\Query\Builder|\AccountType whereId($value) - * @method static \Illuminate\Database\Query\Builder|\AccountType whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\AccountType whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\AccountType whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\AccountType whereId($value) + * @method static \Illuminate\Database\Query\Builder|\AccountType whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\AccountType whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\AccountType whereDescription($value) */ class AccountType extends Eloquent { diff --git a/app/models/Budget.php b/app/models/Budget.php index 94508a4fb6..fa2c4ee518 100644 --- a/app/models/Budget.php +++ b/app/models/Budget.php @@ -3,22 +3,22 @@ /** * Budget * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $name - * @property integer $user_id - * @property string $class - * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $name + * @property integer $user_id + * @property string $class + * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals - * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Budget whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Budget whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Budget whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Budget whereName($value) - * @method static \Illuminate\Database\Query\Builder|\Budget whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Budget whereClass($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Budget whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Budget whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Budget whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Budget whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Budget whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Budget whereClass($value) */ class Budget extends Component { diff --git a/app/models/Category.php b/app/models/Category.php index 2469907cdc..c39e0642f6 100644 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -3,22 +3,22 @@ /** * Category * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $name - * @property integer $user_id - * @property string $class + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $name + * @property integer $user_id + * @property string $class * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals - * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits - * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Category whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Category whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Category whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Category whereName($value) - * @method static \Illuminate\Database\Query\Builder|\Category whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Category whereClass($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits + * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Category whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Category whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Category whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Category whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Category whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Category whereClass($value) */ class Category extends Component { diff --git a/app/models/Component.php b/app/models/Component.php index b034bf41a5..e1391bbcef 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -4,22 +4,22 @@ use Firefly\Database\SingleTableInheritanceEntity; /** * Component * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $name - * @property integer $user_id - * @property string $class - * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $name + * @property integer $user_id + * @property string $class + * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals - * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Component whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Component whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Component whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Component whereName($value) - * @method static \Illuminate\Database\Query\Builder|\Component whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Component whereClass($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Component whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Component whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Component whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Component whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Component whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Component whereClass($value) */ class Component extends SingleTableInheritanceEntity { diff --git a/app/models/Limit.php b/app/models/Limit.php index ebdc2fa156..44236d815f 100644 --- a/app/models/Limit.php +++ b/app/models/Limit.php @@ -7,25 +7,25 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * Limit * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $component_id - * @property \Carbon\Carbon $startdate - * @property float $amount - * @property boolean $repeats - * @property string $repeat_freq - * @property-read \Budget $budget - * @property-read \Component $component + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $component_id + * @property \Carbon\Carbon $startdate + * @property float $amount + * @property boolean $repeats + * @property string $repeat_freq + * @property-read \Budget $budget + * @property-read \Component $component * @property-read \Illuminate\Database\Eloquent\Collection|\LimitRepetition[] $limitrepetitions - * @method static \Illuminate\Database\Query\Builder|\Limit whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereComponentId($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereStartdate($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereAmount($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereRepeats($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereRepeatFreq($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereComponentId($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereStartdate($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereAmount($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereRepeats($value) + * @method static \Illuminate\Database\Query\Builder|\Limit whereRepeatFreq($value) */ class Limit extends Ardent { @@ -112,7 +112,7 @@ class Limit extends Ardent \Log::error($e->getMessage()); } // @codeCoverageIgnoreEnd - if(isset($repetition->id)) { + if (isset($repetition->id)) { \Event::fire('limits.repetition', [$repetition]); } } diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php index c22bf06567..3ce5871432 100644 --- a/app/models/LimitRepetition.php +++ b/app/models/LimitRepetition.php @@ -5,21 +5,21 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * LimitRepetition * - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $limit_id + * @property integer $limit_id * @property \Carbon\Carbon $startdate * @property \Carbon\Carbon $enddate - * @property float $amount - * @property-read \Limit $limit - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereId($value) - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereLimitId($value) - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereStartdate($value) - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereEnddate($value) - * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereAmount($value) + * @property float $amount + * @property-read \Limit $limit + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereId($value) + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereLimitId($value) + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereStartdate($value) + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereEnddate($value) + * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereAmount($value) */ class LimitRepetition extends Ardent { diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php index 9dfbd8b149..aa59363ba9 100644 --- a/app/models/Piggybank.php +++ b/app/models/Piggybank.php @@ -5,40 +5,41 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * Piggybank * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $account_id - * @property string $name - * @property float $targetamount - * @property \Carbon\Carbon $startdate - * @property \Carbon\Carbon $targetdate - * @property boolean $repeats - * @property string $rep_length - * @property integer $rep_every - * @property integer $rep_times - * @property string $reminder - * @property integer $reminder_skip - * @property integer $order - * @property-read \Account $account + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $account_id + * @property string $name + * @property float $targetamount + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $targetdate + * @property boolean $repeats + * @property string $rep_length + * @property integer $rep_every + * @property integer $rep_times + * @property string $reminder + * @property integer $reminder_skip + * @property integer $order + * @property-read \Account $account * @property-read \Illuminate\Database\Eloquent\Collection|\PiggybankRepetition[] $piggybankrepetitions - * @property-read \Illuminate\Database\Eloquent\Collection|\PiggybankEvent[] $piggybankevents - * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereAccountId($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereName($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetamount($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereStartdate($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetdate($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepeats($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepLength($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepEvery($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepTimes($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminder($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminderSkip($value) - * @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\PiggybankEvent[] $piggybankevents + * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereAccountId($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetamount($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereStartdate($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetdate($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepeats($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepLength($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepEvery($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepTimes($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminder($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminderSkip($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\PiggybankReminder[] $piggybankreminders */ class Piggybank extends Ardent { diff --git a/app/models/PiggybankEvent.php b/app/models/PiggybankEvent.php index 5c6cc88fb7..244b1b4032 100644 --- a/app/models/PiggybankEvent.php +++ b/app/models/PiggybankEvent.php @@ -5,19 +5,19 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * PiggybankEvent * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $piggybank_id - * @property \Carbon\Carbon $date - * @property float $amount + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $piggybank_id + * @property \Carbon\Carbon $date + * @property float $amount * @property-read \Piggybank $piggybank - * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereId($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent wherePiggybankId($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereDate($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereAmount($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent wherePiggybankId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereDate($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankEvent whereAmount($value) */ class PiggybankEvent extends Ardent { diff --git a/app/models/PiggybankReminder.php b/app/models/PiggybankReminder.php index 698fbaa5af..f72918ae0a 100644 --- a/app/models/PiggybankReminder.php +++ b/app/models/PiggybankReminder.php @@ -3,6 +3,32 @@ use Carbon\Carbon; /** * Class PiggybankReminder + * + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $class + * @property integer $piggybank_id + * @property integer $recurring_transaction_id + * @property integer $user_id + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $enddate + * @property boolean $active + * @property-read \Piggybank $piggybank + * @property-read \RecurringTransaction $recurringTransaction + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereClass($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder wherePiggybankId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereRecurringTransactionId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereStartdate($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereEnddate($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankReminder whereActive($value) + * @method static \Reminder validOn($date) + * @method static \Reminder validOnOrAfter($date) */ class PiggybankReminder extends Reminder { diff --git a/app/models/PiggybankRepetition.php b/app/models/PiggybankRepetition.php index da47840bc9..ead16ef84a 100644 --- a/app/models/PiggybankRepetition.php +++ b/app/models/PiggybankRepetition.php @@ -5,21 +5,21 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * PiggybankRepetition * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $piggybank_id - * @property \Carbon\Carbon $startdate - * @property \Carbon\Carbon $targetdate - * @property float $currentamount + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $piggybank_id + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $targetdate + * @property float $currentamount * @property-read \Piggybank $piggybank - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereId($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition wherePiggybankId($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereStartdate($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereTargetdate($value) - * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereCurrentamount($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition wherePiggybankId($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereStartdate($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereTargetdate($value) + * @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereCurrentamount($value) */ class PiggybankRepetition extends Ardent { diff --git a/app/models/Preference.php b/app/models/Preference.php index 24a11a1118..abeeb15f7b 100644 --- a/app/models/Preference.php +++ b/app/models/Preference.php @@ -6,19 +6,19 @@ use LaravelBook\Ardent\Ardent; /** * Preference * - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property string $name - * @property string $data - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Preference whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Preference whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Preference whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Preference whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Preference whereName($value) - * @method static \Illuminate\Database\Query\Builder|\Preference whereData($value) + * @property integer $user_id + * @property string $name + * @property string $data + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Preference whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Preference whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Preference whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Preference whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Preference whereName($value) + * @method static \Illuminate\Database\Query\Builder|\Preference whereData($value) */ class Preference extends Ardent { diff --git a/app/models/RecurringTransaction.php b/app/models/RecurringTransaction.php index bef740cd0a..208f693784 100644 --- a/app/models/RecurringTransaction.php +++ b/app/models/RecurringTransaction.php @@ -5,33 +5,34 @@ use LaravelBook\Ardent\Ardent; /** * RecurringTransaction * - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property string $name - * @property string $match - * @property float $amount_max - * @property float $amount_min + * @property integer $user_id + * @property string $name + * @property string $match + * @property float $amount_max + * @property float $amount_min * @property \Carbon\Carbon $date - * @property boolean $active - * @property boolean $automatch - * @property string $repeat_freq - * @property integer $skip - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereId($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereName($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereMatch($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMax($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMin($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereDate($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereActive($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAutomatch($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereRepeatFreq($value) - * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereSkip($value) + * @property boolean $active + * @property boolean $automatch + * @property string $repeat_freq + * @property integer $skip + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereId($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereName($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereMatch($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMax($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMin($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereDate($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereActive($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAutomatch($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereRepeatFreq($value) + * @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereSkip($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\RecurringTransactionReminder[] $reminders */ class RecurringTransaction extends Ardent { @@ -59,13 +60,27 @@ class RecurringTransaction extends Ardent return ['created_at', 'updated_at', 'date']; } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function reminders() + { + return $this->hasMany('RecurringTransactionReminder'); + + } + /** * @return Carbon */ public function next() { + $today = new Carbon; $start = clone $this->date; $skip = $this->skip == 0 ? 1 : $this->skip; + if ($today < $start) { + return $start; + } while ($start <= $this->date) { switch ($this->repeat_freq) { diff --git a/app/models/RecurringTransactionReminder.php b/app/models/RecurringTransactionReminder.php new file mode 100644 index 0000000000..6b87d54dc7 --- /dev/null +++ b/app/models/RecurringTransactionReminder.php @@ -0,0 +1,37 @@ +belongsTo('Piggybank'); } - public function render() { - return ''; + public function recurringTransaction() + { + return $this->belongsTo('RecurringTransaction'); + } + public function render() + { + return ''; } @@ -44,6 +75,23 @@ class Reminder extends SingleTableInheritanceEntity ->where('active', 1); } + public function scopeValidOnOrAfter($query, Carbon $date) + { + return $query->where( + function ($q) use ($date) { + $q->where('startdate', '<=', $date->format('Y-m-d'))->where( + 'enddate', '>=', $date->format('Y-m-d') + ); + $q->orWhere( + function ($q) use ($date) { + $q->where('startdate', '>=', $date); + $q->where('enddate', '>=', $date); + } + ); + } + )->where('active', 1); + } + /** * User * diff --git a/app/models/Transaction.php b/app/models/Transaction.php index 7093b2f6b9..5d5b00752f 100644 --- a/app/models/Transaction.php +++ b/app/models/Transaction.php @@ -6,28 +6,28 @@ use LaravelBook\Ardent\Ardent; /** * Transaction * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $account_id - * @property integer $piggybank_id - * @property integer $transaction_journal_id - * @property string $description - * @property float $amount - * @property-read \Account $account - * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets - * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $account_id + * @property integer $piggybank_id + * @property integer $transaction_journal_id + * @property string $description + * @property float $amount + * @property-read \Account $account + * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets + * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components - * @property-read \Piggybank $piggybank - * @property-read \TransactionJournal $transactionJournal - * @method static \Illuminate\Database\Query\Builder|\Transaction whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction whereAccountId($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction wherePiggybankId($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction whereTransactionJournalId($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction whereDescription($value) - * @method static \Illuminate\Database\Query\Builder|\Transaction whereAmount($value) + * @property-read \Piggybank $piggybank + * @property-read \TransactionJournal $transactionJournal + * @method static \Illuminate\Database\Query\Builder|\Transaction whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction whereAccountId($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction wherePiggybankId($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction whereTransactionJournalId($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\Transaction whereAmount($value) */ class Transaction extends Ardent { diff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.php index dfc7ce8ed7..1e8648c46d 100644 --- a/app/models/TransactionCurrency.php +++ b/app/models/TransactionCurrency.php @@ -3,15 +3,15 @@ /** * TransactionCurrency * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $code + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $code * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals - * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereCode($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereCode($value) */ class TransactionCurrency extends Eloquent { diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php index 53d648790f..35ab91cfa8 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -36,6 +36,11 @@ use LaravelBook\Ardent\Ardent; * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereDate($value) * @method static \TransactionJournal after($date) * @method static \TransactionJournal before($date) + * @property-read \Illuminate\Database\Eloquent\Collection|\ + * 'Budget[] $budgets + * @property-read \Illuminate\Database\Eloquent\Collection|\ + * 'Category[] $categories + * @method static \TransactionJournal onDate($date) */ class TransactionJournal extends Ardent { diff --git a/app/models/TransactionType.php b/app/models/TransactionType.php index 9633bc07e1..0fea66cadd 100644 --- a/app/models/TransactionType.php +++ b/app/models/TransactionType.php @@ -5,15 +5,15 @@ use LaravelBook\Ardent\Ardent; /** * TransactionType * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $type + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $type * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionJournals - * @method static \Illuminate\Database\Query\Builder|\TransactionType whereId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionType whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionType whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionType whereType($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionType whereId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionType whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionType whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionType whereType($value) */ class TransactionType extends Ardent { diff --git a/app/models/User.php b/app/models/User.php index 92b5b87962..70c7f7ee12 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -10,29 +10,31 @@ use LaravelBook\Ardent\Ardent; /** * User * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $email - * @property string $password - * @property string $reset - * @property string $remember_token - * @property boolean $migrated - * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts - * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets - * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories - * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components - * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $email + * @property string $password + * @property string $reset + * @property string $remember_token + * @property boolean $migrated + * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts + * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets + * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories + * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components + * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences * @property-read \Illuminate\Database\Eloquent\Collection|\RecurringTransaction[] $recurringtransactions - * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals - * @method static \Illuminate\Database\Query\Builder|\User whereId($value) - * @method static \Illuminate\Database\Query\Builder|\User whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\User whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\User whereEmail($value) - * @method static \Illuminate\Database\Query\Builder|\User wherePassword($value) - * @method static \Illuminate\Database\Query\Builder|\User whereReset($value) - * @method static \Illuminate\Database\Query\Builder|\User whereRememberToken($value) - * @method static \Illuminate\Database\Query\Builder|\User whereMigrated($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals + * @method static \Illuminate\Database\Query\Builder|\User whereId($value) + * @method static \Illuminate\Database\Query\Builder|\User whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\User whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\User whereEmail($value) + * @method static \Illuminate\Database\Query\Builder|\User wherePassword($value) + * @method static \Illuminate\Database\Query\Builder|\User whereReset($value) + * @method static \Illuminate\Database\Query\Builder|\User whereRememberToken($value) + * @method static \Illuminate\Database\Query\Builder|\User whereMigrated($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\Reminder[] $reminders + * @property-read \Illuminate\Database\Eloquent\Collection|\PiggybankReminder[] $piggybankreminders */ class User extends Ardent implements UserInterface, RemindableInterface { diff --git a/app/start/global.php b/app/start/global.php index 82ab9ba451..8339a3c7c0 100644 --- a/app/start/global.php +++ b/app/start/global.php @@ -11,14 +11,16 @@ | */ -ClassLoader::addDirectories(array( +ClassLoader::addDirectories( + array( - app_path().'/commands', - app_path().'/controllers', - app_path().'/models', - app_path().'/database/seeds', + app_path() . '/commands', + app_path() . '/controllers', + app_path() . '/models', + app_path() . '/database/seeds', -)); + ) +); /* |-------------------------------------------------------------------------- @@ -31,7 +33,7 @@ ClassLoader::addDirectories(array( | */ -Log::useFiles(storage_path().'/logs/laravel.log'); +Log::useFiles(storage_path() . '/logs/laravel.log'); /* |-------------------------------------------------------------------------- @@ -46,10 +48,11 @@ Log::useFiles(storage_path().'/logs/laravel.log'); | */ -App::error(function(Exception $exception, $code) -{ - Log::error($exception); -}); +App::error( + function (Exception $exception, $code) { + Log::error($exception); + } +); /* |-------------------------------------------------------------------------- @@ -62,10 +65,11 @@ App::error(function(Exception $exception, $code) | */ -App::down(function() -{ - return Response::make("Be right back!", 503); -}); +App::down( + function () { + return Response::make("Be right back!", 503); + } +); /* |-------------------------------------------------------------------------- @@ -78,4 +82,4 @@ App::down(function() | */ -require app_path().'/filters.php'; +require app_path() . '/filters.php'; diff --git a/app/tests/controllers/AccountControllerTest.php b/app/tests/controllers/AccountControllerTest.php index bbb9c34a0c..d336f68837 100644 --- a/app/tests/controllers/AccountControllerTest.php +++ b/app/tests/controllers/AccountControllerTest.php @@ -247,10 +247,10 @@ class AccountControllerTest extends TestCase $collection->add($account); $list = [ - 'personal' => [], + 'personal' => [], 'beneficiaries' => [], - 'initial' => [], - 'cash' => [] + 'initial' => [], + 'cash' => [] ]; $this->_repository->shouldReceive('get')->once()->andReturn($collection); @@ -283,19 +283,19 @@ class AccountControllerTest extends TestCase $data = [ 'statistics' => [ - 'period' => [ - 'in' => 0, - 'out' => 0, - 'diff' => 0, - 't_in' => 0, - 't_out' => 0, + 'period' => [ + 'in' => 0, + 'out' => 0, + 'diff' => 0, + 't_in' => 0, + 't_out' => 0, 't_diff' => 0 ], 'categories' => [], - 'budgets' => [], - 'accounts' => [] + 'budgets' => [], + 'accounts' => [] ], - 'journals' => $paginator, + 'journals' => $paginator, ]; $this->_accounts->shouldReceive('show')->once()->andReturn($data); diff --git a/app/tests/controllers/BudgetControllerTest.php b/app/tests/controllers/BudgetControllerTest.php index 6fc751bdb5..8ba9fe47c1 100644 --- a/app/tests/controllers/BudgetControllerTest.php +++ b/app/tests/controllers/BudgetControllerTest.php @@ -2,8 +2,8 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; -use Mockery as m; use League\FactoryMuffin\Facade as f; +use Mockery as m; /** * Class BudgetControllerTest @@ -65,7 +65,7 @@ class BudgetControllerTest extends TestCase Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id); - Event::shouldReceive('fire')->once()->with('budgets.destroy',[$budget]); + Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]); $this->_repository->shouldReceive('destroy')->once()->andReturn(true); $this->action('POST', 'BudgetController@destroy', $budget->id); @@ -81,7 +81,7 @@ class BudgetControllerTest extends TestCase Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id); - Event::shouldReceive('fire')->once()->with('budgets.destroy',[$budget]); + Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]); $this->_repository->shouldReceive('destroy')->once()->andReturn(true); $this->action('POST', 'BudgetController@destroy', [$budget->id, 'from' => 'date']); @@ -97,7 +97,7 @@ class BudgetControllerTest extends TestCase Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id); - Event::shouldReceive('fire')->once()->with('budgets.destroy',[$budget]); + Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]); $this->_repository->shouldReceive('destroy')->once()->andReturn(false); @@ -233,7 +233,7 @@ class BudgetControllerTest extends TestCase Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id); $this->_repository->shouldReceive('update')->andReturn($budget); - Event::shouldReceive('fire')->with('budgets.update',[$budget]); + Event::shouldReceive('fire')->with('budgets.update', [$budget]); $this->action('POST', 'BudgetController@update', $budget->id); $this->assertRedirectedToRoute('budgets.index.budget'); @@ -248,7 +248,7 @@ class BudgetControllerTest extends TestCase Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id); $this->_repository->shouldReceive('update')->andReturn($budget); - Event::shouldReceive('fire')->with('budgets.update',[$budget]); + Event::shouldReceive('fire')->with('budgets.update', [$budget]); //$this->_user->shouldReceive('budgets')->andReturn([]); // trigger $this->action('POST', 'BudgetController@update', [$budget->id, 'from' => 'date']); diff --git a/app/tests/controllers/CategoryControllerTest.php b/app/tests/controllers/CategoryControllerTest.php index 5d04d3b433..cdfdeb82e0 100644 --- a/app/tests/controllers/CategoryControllerTest.php +++ b/app/tests/controllers/CategoryControllerTest.php @@ -2,8 +2,8 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; -use Mockery as m; use League\FactoryMuffin\Facade as f; +use Mockery as m; /** * Class CategoryControllerTest diff --git a/app/tests/controllers/ChartControllerTest.php b/app/tests/controllers/ChartControllerTest.php index 261b7ea248..18ac0f1980 100644 --- a/app/tests/controllers/ChartControllerTest.php +++ b/app/tests/controllers/ChartControllerTest.php @@ -2,8 +2,8 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; -use Mockery as m; use League\FactoryMuffin\Facade as f; +use Mockery as m; /** diff --git a/app/tests/controllers/HomeControllerTest.php b/app/tests/controllers/HomeControllerTest.php index 07f812459c..8238570470 100644 --- a/app/tests/controllers/HomeControllerTest.php +++ b/app/tests/controllers/HomeControllerTest.php @@ -1,7 +1,7 @@ _repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); $this->_preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); $this->_journals = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); + $this->_reminders = $this->mock('Firefly\Storage\Reminder\ReminderRepositoryInterface'); } @@ -47,6 +49,11 @@ class HomeControllerTest extends TestCase $preference = $this->mock('Preference'); $preference->shouldReceive('getAttribute')->with('data')->andReturn([]); + Event::shouldReceive('fire')->with('limits.check'); + Event::shouldReceive('fire')->with('piggybanks.check'); + Event::shouldReceive('fire')->with('recurring.check'); + + $this->_reminders->shouldReceive('getCurrentRecurringReminders')->once()->andReturn([]); // mock accounts: $this->_repository->shouldReceive('count')->once()->andReturn(0); @@ -71,6 +78,12 @@ class HomeControllerTest extends TestCase $preference = $this->mock('Preference'); $preference->shouldReceive('getAttribute')->with('data')->andReturn([$account->id]); + Event::shouldReceive('fire')->with('limits.check'); + Event::shouldReceive('fire')->with('piggybanks.check'); + Event::shouldReceive('fire')->with('recurring.check'); + + $this->_reminders->shouldReceive('getCurrentRecurringReminders')->once()->andReturn([]); + // mock accounts: $this->_repository->shouldReceive('count')->once()->andReturn(0); @@ -80,7 +93,7 @@ class HomeControllerTest extends TestCase $this->_preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($preference); // mock journals: - $this->_journals->shouldReceive('getByAccountInDateRange')->once()->with($account, 15, $start, $end)->andReturn( + $this->_journals->shouldReceive('getByAccountInDateRange')->once()->with($account, 10, $start, $end)->andReturn( [1, 2] ); @@ -104,6 +117,12 @@ class HomeControllerTest extends TestCase $preference = $this->mock('Preference'); $preference->shouldReceive('getAttribute')->with('data')->andReturn($ids); + Event::shouldReceive('fire')->with('limits.check'); + Event::shouldReceive('fire')->with('piggybanks.check'); + Event::shouldReceive('fire')->with('recurring.check'); + + $this->_reminders->shouldReceive('getCurrentRecurringReminders')->once()->andReturn([]); + // mock accounts: $this->_repository->shouldReceive('count')->once()->andReturn(0); diff --git a/app/tests/controllers/LimitControllerTest.php b/app/tests/controllers/LimitControllerTest.php index 9e81a2b17c..a003d0014f 100644 --- a/app/tests/controllers/LimitControllerTest.php +++ b/app/tests/controllers/LimitControllerTest.php @@ -1,6 +1,6 @@ id, 'amount' => 10.0, - 'what' => 'add' + 'what' => 'add' ]; // for binding @@ -181,7 +181,7 @@ class PiggybankControllerTest extends TestCase $piggyBank->account()->first()->user_id ); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); - Event::shouldReceive('fire');//->with('piggybanks.modifyAmountAdd', [$piggyBank, 10.0]); + Event::shouldReceive('fire'); //->with('piggybanks.modifyAmountAdd', [$piggyBank, 10.0]); $this->_piggybanks->shouldReceive('modifyAmount')->once(); $this->_piggybanks->shouldReceive('leftOnAccount')->once()->andReturn(200); @@ -201,7 +201,7 @@ class PiggybankControllerTest extends TestCase $input = [ $piggyBank->id, 'amount' => 10.0, - 'what' => 'add' + 'what' => 'add' ]; // for binding @@ -230,7 +230,7 @@ class PiggybankControllerTest extends TestCase $input = [ $piggyBank->id, 'amount' => 10.0, - 'what' => 'yomoma' + 'what' => 'yomoma' ]; // for binding @@ -269,7 +269,7 @@ class PiggybankControllerTest extends TestCase $input = [ $rep->piggybank()->first()->id, 'amount' => 10.0, - 'what' => 'remove' + 'what' => 'remove' ]; $this->action('POST', 'PiggybankController@modMoney', $input); @@ -299,7 +299,7 @@ class PiggybankControllerTest extends TestCase $input = [ $rep->piggybank()->first()->id, 'amount' => 10.0, - 'what' => 'remove' + 'what' => 'remove' ]; $this->action('POST', 'PiggybankController@modMoney', $input); @@ -308,48 +308,6 @@ class PiggybankControllerTest extends TestCase } - public function teststorePiggybank() - { - $piggy = f::create('Piggybank'); - $piggy->repeats = 0; - $piggy->save(); - Event::shouldReceive('fire')->with('piggybanks.store',[$piggy])->once(); - - - $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); - $this->action('POST', 'PiggybankController@storePiggybank'); - $this->assertResponseStatus(302); - } - - public function testStoreRepeated() - { - $piggy = f::create('Piggybank'); - $piggy->repeats = 1; - $piggy->save(); - Event::shouldReceive('fire')->with('piggybanks.store',[$piggy])->once(); - $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); - $this->action('POST', 'PiggybankController@storeRepeated'); - $this->assertResponseStatus(302); - } - - public function teststorePiggybankFails() - { - $piggy = f::create('Piggybank'); - unset($piggy->id); - $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); - $this->action('POST', 'PiggybankController@storePiggybank'); - $this->assertResponseStatus(302); - } - - public function testStoreRepeatedFails() - { - $piggy = f::create('Piggybank'); - unset($piggy->id); - $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); - $this->action('POST', 'PiggybankController@storeRepeated'); - $this->assertResponseStatus(302); - } - public function testRemoveMoneyGET() { $pig = $this->mock('Piggybank'); @@ -375,19 +333,48 @@ class PiggybankControllerTest extends TestCase public function testShow() { - $piggyBank = f::create('Piggybank'); - // for binding + $pig = $this->mock('Piggybank'); + $piggybank = f::create('Piggybank'); + $rep = f::create('PiggybankRepetition'); + $rep->piggybank_id = $piggybank->id; + $rep->save(); + Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn( - $piggyBank->account()->first()->user_id + $piggybank->account()->first()->user_id ); $this->_user->shouldReceive('getAttribute')->andReturn('some@email'); - $this->action('GET', 'PiggybankController@show', $piggyBank->id); + $pig->shouldReceive('currentRelevantRep')->andReturn($rep); + + // repos: + $this->_piggybanks->shouldReceive('leftOnAccount'); + + $this->action('GET', 'PiggybankController@show', $piggybank->id); $this->assertResponseOk(); } + public function testStoreRepeated() + { + $piggy = f::create('Piggybank'); + $piggy->repeats = 1; + $piggy->save(); + Event::shouldReceive('fire')->with('piggybanks.store', [$piggy])->once(); + $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); + $this->action('POST', 'PiggybankController@storeRepeated'); + $this->assertResponseStatus(302); + } + + public function testStoreRepeatedFails() + { + $piggy = f::create('Piggybank'); + unset($piggy->id); + $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); + $this->action('POST', 'PiggybankController@storeRepeated'); + $this->assertResponseStatus(302); + } + public function testUpdate() { $piggyBank = f::create('Piggybank'); @@ -401,7 +388,7 @@ class PiggybankControllerTest extends TestCase $piggyBank->account()->first()->user_id ); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); - Event::shouldReceive('fire')->with('piggybanks.update',[$piggyBank]); + Event::shouldReceive('fire')->with('piggybanks.update', [$piggyBank]); $this->action('POST', 'PiggybankController@update', $piggyBank->id); $this->assertResponseStatus(302); @@ -427,5 +414,27 @@ class PiggybankControllerTest extends TestCase $this->assertResponseStatus(302); } + public function teststorePiggybank() + { + $piggy = f::create('Piggybank'); + $piggy->repeats = 0; + $piggy->save(); + Event::shouldReceive('fire')->with('piggybanks.store', [$piggy])->once(); + + + $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); + $this->action('POST', 'PiggybankController@storePiggybank'); + $this->assertResponseStatus(302); + } + + public function teststorePiggybankFails() + { + $piggy = f::create('Piggybank'); + unset($piggy->id); + $this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy); + $this->action('POST', 'PiggybankController@storePiggybank'); + $this->assertResponseStatus(302); + } + } \ No newline at end of file diff --git a/app/tests/controllers/ProfileControllerTest.php b/app/tests/controllers/ProfileControllerTest.php index b293c4300a..9eb6fd95d7 100644 --- a/app/tests/controllers/ProfileControllerTest.php +++ b/app/tests/controllers/ProfileControllerTest.php @@ -1,6 +1,6 @@ andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); @@ -55,6 +57,8 @@ class RecurringControllerTest extends TestCase { $recurringTransaction = f::create('RecurringTransaction'); + Event::shouldReceive('fire')->with('recurring.destroy',m::any()); + // for binding Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); @@ -73,6 +77,7 @@ class RecurringControllerTest extends TestCase // for binding Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('check')->andReturn(true); + Event::shouldReceive('fire')->with('recurring.destroy',m::any()); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); $this->_repository->shouldReceive('destroy')->andReturn(false); @@ -123,6 +128,8 @@ class RecurringControllerTest extends TestCase { $recurringTransaction = f::create('RecurringTransaction'); + Event::shouldReceive('fire')->with('recurring.store',m::any()); + $this->_repository->shouldReceive('store')->andReturn($recurringTransaction); $this->action('POST', 'RecurringController@store'); $this->assertResponseStatus(302); @@ -132,6 +139,8 @@ class RecurringControllerTest extends TestCase { $recurringTransaction = f::create('RecurringTransaction'); + Event::shouldReceive('fire')->with('recurring.store',m::any()); + $this->_repository->shouldReceive('store')->andReturn($recurringTransaction); $this->action('POST', 'RecurringController@store', ['create' => '1']); $this->assertResponseStatus(302); @@ -158,6 +167,8 @@ class RecurringControllerTest extends TestCase $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); + Event::shouldReceive('fire')->with('recurring.update',m::any()); + $this->_repository->shouldReceive('update')->andReturn($recurringTransaction); diff --git a/app/tests/controllers/TransactionControllerTest.php b/app/tests/controllers/TransactionControllerTest.php index 11556e4350..565bb066da 100644 --- a/app/tests/controllers/TransactionControllerTest.php +++ b/app/tests/controllers/TransactionControllerTest.php @@ -1,7 +1,7 @@ function() { + 'description' => function () { $types = [ 'Default account', 'Cash account', 'Initial balance account', 'Beneficiary account' ]; - return $types[rand(0,3)]; + + return $types[rand(0, 3)]; } ] ); \ No newline at end of file diff --git a/app/tests/factories/Limit.php b/app/tests/factories/Limit.php index 7c3c36780a..0add2057c8 100644 --- a/app/tests/factories/Limit.php +++ b/app/tests/factories/Limit.php @@ -7,17 +7,19 @@ Facade::define( [ 'component_id' => 'factory|Budget', - 'startdate' => function () { - $start = new Carbon; - $start->startOfMonth(); - return $start; - }, - 'amount' => 100, - 'repeats' => 'boolean', - 'repeat_freq' => function(){ - $frequencies = ['daily','weekly','monthly','quarterly','half-year','yearly']; - return $frequencies[rand(0,5)]; - } + 'startdate' => function () { + $start = new Carbon; + $start->startOfMonth(); + + return $start; + }, + 'amount' => 100, + 'repeats' => 'boolean', + 'repeat_freq' => function () { + $frequencies = ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly']; + + return $frequencies[rand(0, 5)]; + } ] diff --git a/app/tests/factories/LimitRepetition.php b/app/tests/factories/LimitRepetition.php index 61370085a6..3ff9e40824 100644 --- a/app/tests/factories/LimitRepetition.php +++ b/app/tests/factories/LimitRepetition.php @@ -6,20 +6,22 @@ Facade::define( 'LimitRepetition', [ - 'limit_id' => 'factory|Limit', + 'limit_id' => 'factory|Limit', 'startdate' => function () { - $start = new Carbon; - $start->startOfMonth(); - return $start; + $start = new Carbon; + $start->startOfMonth(); - }, - 'enddate' => function () { - $end = new Carbon; - $end->endOfMonth(); - return $end; + return $start; - }, - 'amount' => 100 + }, + 'enddate' => function () { + $end = new Carbon; + $end->endOfMonth(); + + return $end; + + }, + 'amount' => 100 ] diff --git a/app/tests/factories/Piggybank.php b/app/tests/factories/Piggybank.php index 48b665d49b..f514e7ceee 100644 --- a/app/tests/factories/Piggybank.php +++ b/app/tests/factories/Piggybank.php @@ -6,25 +6,27 @@ Facade::define( 'Piggybank', [ - 'account_id' => 'factory|Account', - 'name' => 'string', - 'targetamount' => 'integer', - 'startdate' => function () { - $start = new Carbon; - $start->startOfMonth(); - return $start; - }, - 'targetdate' => function () { - $end = new Carbon; - $end->endOfMonth(); - return $end; - }, - 'repeats' => 0, - 'rep_length' => null, - 'rep_times' => 0, - 'rep_every' => 0, - 'reminder' => null, + 'account_id' => 'factory|Account', + 'name' => 'string', + 'targetamount' => 'integer', + 'startdate' => function () { + $start = new Carbon; + $start->startOfMonth(); + + return $start; + }, + 'targetdate' => function () { + $end = new Carbon; + $end->endOfMonth(); + + return $end; + }, + 'repeats' => 0, + 'rep_length' => null, + 'rep_times' => 0, + 'rep_every' => 0, + 'reminder' => null, 'reminder_skip' => 0, - 'order' => 1, + 'order' => 1, ] ); \ No newline at end of file diff --git a/app/tests/factories/PiggybankRepetition.php b/app/tests/factories/PiggybankRepetition.php index 5589ae294a..9fcef23652 100644 --- a/app/tests/factories/PiggybankRepetition.php +++ b/app/tests/factories/PiggybankRepetition.php @@ -7,17 +7,19 @@ Facade::define( [ - 'piggybank_id' => 'factory|Piggybank', - 'startdate' => function () { - $start = new Carbon; - $start->startOfMonth(); - return $start; - }, - 'targetdate' => function () { - $end = new Carbon; - $end->endOfMonth(); - return $end; - }, + 'piggybank_id' => 'factory|Piggybank', + 'startdate' => function () { + $start = new Carbon; + $start->startOfMonth(); + + return $start; + }, + 'targetdate' => function () { + $end = new Carbon; + $end->endOfMonth(); + + return $end; + }, 'currentamount' => 200 ] ); \ No newline at end of file diff --git a/app/tests/factories/Preference.php b/app/tests/factories/Preference.php index 1f228025fe..84b77f1ded 100644 --- a/app/tests/factories/Preference.php +++ b/app/tests/factories/Preference.php @@ -1,5 +1,4 @@ 'factory|User', - 'name' => 'string', - 'match' => 'string', - 'amount_max' => 100, - 'amount_min' => 50, - 'date' => new Carbon, - 'active' => 'boolean', - 'automatch' => 'boolean', + 'user_id' => 'factory|User', + 'name' => 'string', + 'match' => 'string', + 'amount_max' => 100, + 'amount_min' => 50, + 'date' => new Carbon, + 'active' => 'boolean', + 'automatch' => 'boolean', 'repeat_freq' => 'monthly', - 'skip' => 'boolean', + 'skip' => 'boolean', ] ); \ No newline at end of file diff --git a/app/tests/factories/Transaction.php b/app/tests/factories/Transaction.php index 0afece342e..7401368d06 100644 --- a/app/tests/factories/Transaction.php +++ b/app/tests/factories/Transaction.php @@ -1,7 +1,6 @@ function() { - $types = ['Withdrawal','Deposit','Transfer','Opening balance']; - return $types[rand(0,3)]; - } + 'type' => function () { + $types = ['Withdrawal', 'Deposit', 'Transfer', 'Opening balance']; + + return $types[rand(0, 3)]; + } ] ); \ No newline at end of file diff --git a/app/tests/models/ModelTest.php b/app/tests/models/ModelTest.php index ef39946fa1..d35416364a 100644 --- a/app/tests/models/ModelTest.php +++ b/app/tests/models/ModelTest.php @@ -264,7 +264,7 @@ class ModelTest extends TestCase $transaction->piggybank()->associate($piggy); $transaction->save(); $this->assertEquals($transaction->piggybank_id, $piggy->id); - $this->assertEquals($piggy->transactions()->first()->id,$transaction->id); + $this->assertEquals($piggy->transactions()->first()->id, $transaction->id); $repetition->pct(); diff --git a/app/views/index.blade.php b/app/views/index.blade.php index 1f1dd15917..56d2f6c2c3 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -71,11 +71,68 @@ @endforeach @endif + @if(count($reminders) > 0) +
+
+

Recurring transactions

+

These transactions are set to be expected between + {{Session::get('start')->format('j F Y')}} and {{Session::get('end')->format('j F Y')}}.

+ + + + + + + + + @foreach($reminders as $reminder) + recurringtransaction->amount_max; + $min += $reminder->recurringtransaction->amount_min; + ?> + + + + + + + + + + @endforeach + + + + + +
NameTagsAmountRepeats
+ + {{{$reminder->recurringtransaction->name}}} + + + @foreach(explode(' ',$reminder->recurringtransaction->match) as $word) + {{{$word}}} + @endforeach + + {{mf($reminder->recurringtransaction->amount_min)}} + + {{mf($reminder->recurringtransaction->amount_max)}} + + {{$reminder->recurringtransaction->repeat_freq}} + + +
Sum{{mf($max)}}{{mf($min)}}
+
+
+ @endif +
-

Budgets

-
diff --git a/app/views/piggybanks/show.blade.php b/app/views/piggybanks/show.blade.php index 84b2484361..673024203d 100644 --- a/app/views/piggybanks/show.blade.php +++ b/app/views/piggybanks/show.blade.php @@ -7,9 +7,21 @@

{{{$piggyBank->account->name}}} has - a balance of {{mf($piggyBank->account->balance())}}. - Of that {{mf($piggyBank->account->balance())}}, you have {{mf(0)}} not yet locked up in other piggy banks. - You can add {{mf(max(0,1))}} to this piggy bank. + a balance of {{mf($balance)}}. + Of that {{mf($balance)}}, you have {{mf($leftOnAccount)}} not yet locked up in other piggy banks. + You can add {{mf(min(max($balance,$leftOnAccount),$piggyBank->targetamount))}} to this piggy bank. +

+

+ Edit + Delete + + @if(min(max($balance,$leftOnAccount),$piggyBank->targetamount) > 0) + Add money + @endif + @if($piggyBank->currentRelevantRep()->currentamount > 0) + Remove money + @endif +

@@ -105,7 +117,7 @@ Current amount - {{mf($rep->currentamount)}} + {{mf($rep->currentamount)}} of {{mf($piggyBank->targetamount)}} Start date diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 6b329312a6..bd114c3156 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -14,7 +14,7 @@ define('LARAVEL_START', microtime(true)); | */ -require __DIR__.'/../vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- @@ -27,9 +27,8 @@ require __DIR__.'/../vendor/autoload.php'; | */ -if (file_exists($compiled = __DIR__.'/compiled.php')) -{ - require $compiled; +if (file_exists($compiled = __DIR__ . '/compiled.php')) { + require $compiled; } /* @@ -69,7 +68,6 @@ Illuminate\Support\ClassLoader::register(); | */ -if (is_dir($workbench = __DIR__.'/../workbench')) -{ - Illuminate\Workbench\Starter::start($workbench); +if (is_dir($workbench = __DIR__ . '/../workbench')) { + Illuminate\Workbench\Starter::start($workbench); } diff --git a/bootstrap/paths.php b/bootstrap/paths.php index 5a1f640ba4..289ed916e0 100644 --- a/bootstrap/paths.php +++ b/bootstrap/paths.php @@ -2,56 +2,56 @@ return array( - /* - |-------------------------------------------------------------------------- - | Application Path - |-------------------------------------------------------------------------- - | - | Here we just defined the path to the application directory. Most likely - | you will never need to change this value as the default setup should - | work perfectly fine for the vast majority of all our applications. - | - */ + /* + |-------------------------------------------------------------------------- + | Application Path + |-------------------------------------------------------------------------- + | + | Here we just defined the path to the application directory. Most likely + | you will never need to change this value as the default setup should + | work perfectly fine for the vast majority of all our applications. + | + */ - 'app' => __DIR__.'/../app', + 'app' => __DIR__ . '/../app', - /* - |-------------------------------------------------------------------------- - | Public Path - |-------------------------------------------------------------------------- - | - | The public path contains the assets for your web application, such as - | your JavaScript and CSS files, and also contains the primary entry - | point for web requests into these applications from the outside. - | - */ + /* + |-------------------------------------------------------------------------- + | Public Path + |-------------------------------------------------------------------------- + | + | The public path contains the assets for your web application, such as + | your JavaScript and CSS files, and also contains the primary entry + | point for web requests into these applications from the outside. + | + */ - 'public' => __DIR__.'/../public', + 'public' => __DIR__ . '/../public', - /* - |-------------------------------------------------------------------------- - | Base Path - |-------------------------------------------------------------------------- - | - | The base path is the root of the Laravel installation. Most likely you - | will not need to change this value. But, if for some wild reason it - | is necessary you will do so here, just proceed with some caution. - | - */ + /* + |-------------------------------------------------------------------------- + | Base Path + |-------------------------------------------------------------------------- + | + | The base path is the root of the Laravel installation. Most likely you + | will not need to change this value. But, if for some wild reason it + | is necessary you will do so here, just proceed with some caution. + | + */ - 'base' => __DIR__.'/..', + 'base' => __DIR__ . '/..', - /* - |-------------------------------------------------------------------------- - | Storage Path - |-------------------------------------------------------------------------- - | - | The storage path is used by Laravel to store cached Blade views, logs - | and other pieces of information. You may modify the path here when - | you want to change the location of this directory for your apps. - | - */ + /* + |-------------------------------------------------------------------------- + | Storage Path + |-------------------------------------------------------------------------- + | + | The storage path is used by Laravel to store cached Blade views, logs + | and other pieces of information. You may modify the path here when + | you want to change the location of this directory for your apps. + | + */ - 'storage' => __DIR__.'/../app/storage', + 'storage' => __DIR__ . '/../app/storage', ); diff --git a/bootstrap/start.php b/bootstrap/start.php index 4a79de419b..1ea0c94653 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -1,8 +1,5 @@