diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 8844503c13..427a40e561 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -46,8 +46,8 @@ class AccountController extends BaseController public function delete(Account $account) { return View::make('accounts.delete')->with('account', $account)->with( - 'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"' - ); + 'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"' + ); } /** @@ -158,10 +158,10 @@ class AccountController extends BaseController } return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)->with(compact('subTitleIcon'))->with( - 'subTitle', 'Edit ' . strtolower( - $account->accountType->type - ) . ' "' . $account->name . '"' - ); + 'subTitle', 'Edit ' . strtolower( + $account->accountType->type + ) . ' "' . $account->name . '"' + ); } /** @@ -182,21 +182,21 @@ class AccountController extends BaseController case 'asset': $subTitleIcon = 'fa-money'; $subTitle = 'Asset accounts'; - $accounts = $acct->getAssetAccounts(); + $accounts = $acct->getAssetAccounts(); break; case 'expense': $subTitleIcon = 'fa-shopping-cart'; $subTitle = 'Expense accounts'; - $accounts = $acct->getExpenseAccounts(); + $accounts = $acct->getExpenseAccounts(); break; case 'revenue': $subTitleIcon = 'fa-download'; $subTitle = 'Revenue accounts'; - $accounts = $acct->getRevenueAccounts(); + $accounts = $acct->getRevenueAccounts(); break; } - return View::make('accounts.index',compact('what','subTitleIcon','subTitle','accounts')); + return View::make('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts')); } /** @@ -228,9 +228,9 @@ class AccountController extends BaseController //$data = $this->_accounts->show($account, 40); - return View::make('accounts.show',compact('account','subTitleIcon','journals'))->with('account', $account)->with( - 'subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"' - ); + return View::make('accounts.show', compact('account', 'subTitleIcon', 'journals'))->with('account', $account)->with( + 'subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"' + ); } /** @@ -240,7 +240,7 @@ class AccountController extends BaseController public function store() { - $data = Input::all(); + $data = Input::all(); $data['what'] = isset($data['what']) && $data['what'] != '' ? $data['what'] : 'asset'; /** @var \FireflyIII\Database\Account $acct */ $acct = App::make('FireflyIII\Database\Account'); diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 0e7de74c14..c4617ffde5 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -206,13 +206,13 @@ class BudgetController extends BaseController $limits = [$repetition->limit]; // get all transaction journals for this budget and limit repetition. $journals = []; - $subTitle = $budget->name.' in ' . $repetition->startdate->format('F Y'); + $subTitle = $budget->name . ' in ' . $repetition->startdate->format('F Y'); $journals = $repos->getTransactionJournalsInRepetition($budget, $repetition, 50); } $hideBudget = true; - return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals','subTitle','hideBudget')); + return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget')); } /** diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php index ec05e23798..200a2fc2c0 100644 --- a/app/controllers/CategoryController.php +++ b/app/controllers/CategoryController.php @@ -66,9 +66,10 @@ class CategoryController extends BaseController public function index() { /** @var \FireflyIII\Database\Category $repos */ - $repos = App::make('FireflyIII\Database\Category'); + $repos = App::make('FireflyIII\Database\Category'); $categories = $repos->get(); - return View::make('categories.index',compact('categories')); + + return View::make('categories.index', compact('categories')); } /** @@ -85,7 +86,7 @@ class CategoryController extends BaseController $journals = $repos->getTransactionJournals($category, 50); - return View::make('categories.show', compact('category','journals','hideCategory')); + return View::make('categories.show', compact('category', 'journals', 'hideCategory')); } /** @@ -93,7 +94,7 @@ class CategoryController extends BaseController */ public function store() { - $data = Input::all(); + $data = Input::all(); /** @var \FireflyIII\Database\Category $repos */ $repos = App::make('FireflyIII\Database\Category'); diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index 8e9456aa6d..a822f6deca 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -481,12 +481,9 @@ class GoogleChartController extends BaseController $chart->addColumn('Balance', 'number'); $sum = 0; - $set = \DB::table('piggybank_events') - ->where('piggybank_id',$piggybank->id) - ->groupBy('date') - ->get(['date',DB::Raw('SUM(`amount`) AS `sum`')]); + $set = \DB::table('piggybank_events')->where('piggybank_id', $piggybank->id)->groupBy('date')->get(['date', DB::Raw('SUM(`amount`) AS `sum`')]); - foreach($set as $entry) { + foreach ($set as $entry) { $chart->addRow(new Carbon($entry->date), floatval($entry->sum)); } diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index e8460051a2..60f030519d 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -110,7 +110,8 @@ class PiggybankController extends BaseController * Flash some data to fill the form. */ $prefilled = ['name' => $piggybank->name, 'account_id' => $piggybank->account_id, 'targetamount' => $piggybank->targetamount, - 'targetdate' => !is_null($piggybank->targetdate) ? $piggybank->targetdate->format('Y-m-d') : null,'reminder' => $piggybank->reminder, 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false]; + 'targetdate' => !is_null($piggybank->targetdate) ? $piggybank->targetdate->format('Y-m-d') : null, 'reminder' => $piggybank->reminder, + 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false]; Session::flash('prefilled', $prefilled); return View::make('piggybanks.edit', compact('piggybank', 'accounts', 'periods', 'prefilled'))->with('title', 'Piggybanks')->with( @@ -230,7 +231,7 @@ class PiggybankController extends BaseController public function show(Piggybank $piggybank) { - $events = $piggybank->piggybankevents()->orderBy('date', 'DESC')->orderBy('id','DESC')->get(); + $events = $piggybank->piggybankevents()->orderBy('date', 'DESC')->orderBy('id', 'DESC')->get(); /* * Number of reminders: @@ -281,7 +282,7 @@ class PiggybankController extends BaseController /* * Create the relevant repetition per Event. */ - Event::fire('piggybank.storePiggybank',[$piggyBank]); + Event::fire('piggybank.storePiggybank', [$piggyBank]); Session::flash('success', 'New piggy bank stored!'); diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.php index a4027bcb00..1e586146ab 100644 --- a/app/controllers/RecurringController.php +++ b/app/controllers/RecurringController.php @@ -1,5 +1,4 @@ with('recurring', $recurringTransaction)->with( + return View::make('recurring.show', compact('journals', 'hideRecurring', 'finalDate'))->with('recurring', $recurringTransaction)->with( 'subTitle', $recurringTransaction->name ); } diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php index 6b31029726..b4960b41dd 100644 --- a/app/lib/FireflyIII/Database/Account.php +++ b/app/lib/FireflyIII/Database/Account.php @@ -501,8 +501,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface $set = $this->getUser()->transactionJournals()->withRelevantData()->leftJoin( 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id' )->where('transactions.account_id', $account->id)->take($limit)->offset($offset)->before($end)->after($start)->orderBy('date', 'DESC')->get( - ['transaction_journals.*'] - ); + ['transaction_journals.*'] + ); $count = $this->getUser()->transactionJournals()->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->before($end)->after($start)->orderBy('date', 'DESC')->where('transactions.account_id', $account->id)->count(); $items = []; diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php index ef901d29ec..6cb68ae838 100644 --- a/app/lib/FireflyIII/Database/Budget.php +++ b/app/lib/FireflyIII/Database/Budget.php @@ -198,10 +198,12 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface public function getTransactionJournalsInRepetition(\Budget $budget, \LimitRepetition $repetition, $limit = 50) { $start = $repetition->startdate; - $end = $repetition->enddate; + $end = $repetition->enddate; $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; - $set = $budget->transactionJournals()->withRelevantData()->before($end)->after($start)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); + $set = $budget->transactionJournals()->withRelevantData()->before($end)->after($start)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get( + ['transaction_journals.*'] + ); $count = $budget->transactionJournals()->before($end)->after($start)->count(); $items = []; foreach ($set as $entry) { diff --git a/app/lib/FireflyIII/Database/Category.php b/app/lib/FireflyIII/Database/Category.php index 7056754dd8..5857f84326 100644 --- a/app/lib/FireflyIII/Database/Category.php +++ b/app/lib/FireflyIII/Database/Category.php @@ -46,15 +46,16 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface */ public function store(array $data) { - $category = new \Category; - $category->name = $data['name']; + $category = new \Category; + $category->name = $data['name']; $category->class = 'Category'; $category->user()->associate($this->getUser()); - if(!$category->validate()) { + if (!$category->validate()) { var_dump($category->errors()); exit(); } $category->save(); + return $category; } diff --git a/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php b/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php index b820b64776..5ff9a7aabb 100644 --- a/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php +++ b/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php @@ -20,6 +20,14 @@ interface RecurringInterface */ public function getJournalForRecurringInRange(\RecurringTransaction $recurring, Carbon $start, Carbon $end); + /** + * @param \RecurringTransaction $recurring + * @param \TransactionJournal $journal + * + * @return bool + */ + public function scan(\RecurringTransaction $recurring, \TransactionJournal $journal); + /** * @param \RecurringTransaction $recurring * @@ -27,12 +35,4 @@ interface RecurringInterface */ public function scanEverything(\RecurringTransaction $recurring); - /** - * @param \RecurringTransaction $recurring - * @param \TransactionJournal $journal - * - * @return bool - */ - public function scan(\RecurringTransaction $recurring,\TransactionJournal $journal); - } \ No newline at end of file diff --git a/app/lib/FireflyIII/Database/Piggybank.php b/app/lib/FireflyIII/Database/Piggybank.php index 804dcc307c..c4104d07ea 100644 --- a/app/lib/FireflyIII/Database/Piggybank.php +++ b/app/lib/FireflyIII/Database/Piggybank.php @@ -59,6 +59,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface exit; } $piggybank->save(); + return $piggybank; } @@ -197,9 +198,8 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface public function find($id) { return \Piggybank:: - leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id') - ->where('piggybanks.id','=',$id) - ->where('accounts.user_id', $this->getUser()->id)->first(['piggybanks.*']); + leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where('piggybanks.id', '=', $id)->where('accounts.user_id', $this->getUser()->id) + ->first(['piggybanks.*']); } /** diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php index 0f4a145a06..36c22c6116 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal.php @@ -38,6 +38,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData public function destroy(Ardent $model) { $model->delete(); + return true; } @@ -128,19 +129,19 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /* * Store the budget. */ - if(isset($data['budget_id']) && intval($data['budget_id']) > 0) { + if (isset($data['budget_id']) && intval($data['budget_id']) > 0) { /** @var \FireflyIII\Database\Budget $budgetRepository */ $budgetRepository = \App::make('FireflyIII\Database\Budget'); - $budget = $budgetRepository->find(intval($data['budget_id'])); - if($budget) { + $budget = $budgetRepository->find(intval($data['budget_id'])); + if ($budget) { $journal->budgets()->save($budget); } } - if(strlen($data['category']) > 0) { + if (strlen($data['category']) > 0) { /** @var \FireflyIII\Database\Category $categoryRepository */ $categoryRepository = \App::make('FireflyIII\Database\Category'); - $category = $categoryRepository->firstOrCreate($data['category']); - if($category) { + $category = $categoryRepository->firstOrCreate($data['category']); + if ($category) { $journal->categories()->save($category); } } @@ -222,19 +223,19 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /* * Store the budget. */ - if(isset($data['budget_id']) && intval($data['budget_id']) > 0) { + if (isset($data['budget_id']) && intval($data['budget_id']) > 0) { /** @var \FireflyIII\Database\Budget $budgetRepository */ $budgetRepository = \App::make('FireflyIII\Database\Budget'); - $budget = $budgetRepository->find(intval($data['budget_id'])); - if($budget) { + $budget = $budgetRepository->find(intval($data['budget_id'])); + if ($budget) { $model->budgets()->sync([$budget->id]); } } - if(strlen($data['category']) > 0) { + if (strlen($data['category']) > 0) { /** @var \FireflyIII\Database\Category $categoryRepository */ $categoryRepository = \App::make('FireflyIII\Database\Category'); - $category = $categoryRepository->firstOrCreate($data['category']); - if($category) { + $category = $categoryRepository->firstOrCreate($data['category']); + if ($category) { $model->categories()->sync([$category->id]); } } @@ -545,6 +546,22 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $sum; } + public function getDepositsPaginated($limit = 50) + { + $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; + + $set = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->withRelevantData()->take($limit)->offset($offset)->orderBy( + 'date', 'DESC' + )->get(['transaction_journals.*']); + $count = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->count(); + $items = []; + foreach ($set as $entry) { + $items[] = $entry; + } + + return \Paginator::make($items, $count, $limit); + } + /** * @param \Account $account * @param int $count @@ -568,12 +585,15 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $query; } - public function getWithdrawalsPaginated($limit = 50) { + public function getTransfersPaginated($limit = 50) + { $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; - $set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); - $count = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->count(); - $items = []; + $set = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->withRelevantData()->take($limit)->offset($offset)->orderBy( + 'date', 'DESC' + )->get(['transaction_journals.*']); + $count = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->count(); + $items = []; foreach ($set as $entry) { $items[] = $entry; } @@ -581,25 +601,15 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return \Paginator::make($items, $count, $limit); } - public function getDepositsPaginated($limit = 50) { + public function getWithdrawalsPaginated($limit = 50) + { $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; - $set = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); - $count = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->count(); - $items = []; - foreach ($set as $entry) { - $items[] = $entry; - } - - return \Paginator::make($items, $count, $limit); - } - - public function getTransfersPaginated($limit = 50) { - $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; - - $set = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); - $count = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->count(); - $items = []; + $set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->take($limit)->offset($offset)->orderBy( + 'date', 'DESC' + )->get(['transaction_journals.*']); + $count = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->count(); + $items = []; foreach ($set as $entry) { $items[] = $entry; } diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php index d881b0ece2..9a4b0ff845 100644 --- a/app/lib/FireflyIII/Event/Piggybank.php +++ b/app/lib/FireflyIII/Event/Piggybank.php @@ -92,6 +92,18 @@ class Piggybank * */ + public function storePiggybank(\Piggybank $piggybank) + { + if (intval($piggybank->repeats) == 0) { + $repetition = new \PiggybankRepetition; + $repetition->piggybank()->associate($piggybank); + $repetition->startdate = $piggybank->startdate; + $repetition->targetdate = $piggybank->targetdate; + $repetition->currentamount = 0; + $repetition->save(); + } + } + /** * @param \TransactionJournal $journal * @param int $piggybankId @@ -159,17 +171,6 @@ class Piggybank } } - public function storePiggybank(\Piggybank $piggybank) { - if(intval($piggybank->repeats) == 0) { - $repetition = new \PiggybankRepetition; - $repetition->piggybank()->associate($piggybank); - $repetition->startdate = $piggybank->startdate; - $repetition->targetdate = $piggybank->targetdate; - $repetition->currentamount = 0; - $repetition->save(); - } - } - /** * @param Dispatcher $events */ diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php index a5a30fe4f8..82dee3b288 100644 --- a/app/lib/FireflyIII/Form/Form.php +++ b/app/lib/FireflyIII/Form/Form.php @@ -31,67 +31,6 @@ class Form } - /** - * @param $name - * @param null $value - * @param array $options - * - * @return string - * @throws FireflyException - */ - public static function ffBalance($name, $value = null, array $options = []) - { - $options['step'] = 'any'; - - return self::ffInput('amount', $name, $value, $options); - - } - - /** - * @param $name - * @param int $value - * @param null $checked - * @param array $options - * - * @return string - * @throws FireflyException - */ - public static function ffCheckbox($name, $value = 1, $checked = null, $options = []) - { - $options['checked'] = $checked ? true : null; - - return self::ffInput('checkbox', $name, $value, $options); - } - - /** - * @param $name - * @param null $value - * @param array $options - * - * @return string - * @throws FireflyException - */ - public static function ffDate($name, $value = null, array $options = []) - { - return self::ffInput('date', $name, $value, $options); - } - - /** - * @param $name - * @param null $value - * @param array $options - * - * @return string - * @throws FireflyException - */ - public static function ffInteger($name, $value = null, array $options = []) - { - $options['step'] = '1'; - - return self::ffInput('number', $name, $value, $options); - - } - /** * @param $type * @param $name @@ -113,7 +52,6 @@ class Form $label = self::label($name, $options); - /* * Make label and placeholder look nice. */ @@ -272,6 +210,67 @@ class Form } + /** + * @param $name + * @param null $value + * @param array $options + * + * @return string + * @throws FireflyException + */ + public static function ffBalance($name, $value = null, array $options = []) + { + $options['step'] = 'any'; + + return self::ffInput('amount', $name, $value, $options); + + } + + /** + * @param $name + * @param int $value + * @param null $checked + * @param array $options + * + * @return string + * @throws FireflyException + */ + public static function ffCheckbox($name, $value = 1, $checked = null, $options = []) + { + $options['checked'] = $checked ? true : null; + + return self::ffInput('checkbox', $name, $value, $options); + } + + /** + * @param $name + * @param null $value + * @param array $options + * + * @return string + * @throws FireflyException + */ + public static function ffDate($name, $value = null, array $options = []) + { + return self::ffInput('date', $name, $value, $options); + } + + /** + * @param $name + * @param null $value + * @param array $options + * + * @return string + * @throws FireflyException + */ + public static function ffInteger($name, $value = null, array $options = []) + { + $options['step'] = '1'; + + return self::ffInput('number', $name, $value, $options); + + } + /** * Return buttons for update/validate/return. * diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.php index a41f40b5f9..6e01172b8f 100644 --- a/app/lib/FireflyIII/Shared/Toolkit/Date.php +++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php @@ -85,6 +85,7 @@ class Date $currentEnd->addYear()->subDay(); break; } + return $currentEnd; } diff --git a/app/models/Account.php b/app/models/Account.php index b126388ad1..496b14bbed 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -3,28 +3,29 @@ use Carbon\Carbon; use LaravelBook\Ardent\Ardent as Ardent; use LaravelBook\Ardent\Builder; + /** * 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) - * @method static \Account accountTypeIn($types) + * @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) + * @method static \Account accountTypeIn($types) */ class Account extends Ardent { @@ -70,6 +71,16 @@ class Account extends Ardent ); } + /** + * Transactions. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function transactions() + { + return $this->hasMany('Transaction'); + } + /** * @param TransactionJournal $journal * @@ -92,23 +103,13 @@ class Account extends Ardent public function lastActionDate() { $transaction = $this->transactions()->orderBy('updated_at', 'DESC')->first(); - if(is_null($transaction)) { + if (is_null($transaction)) { return null; } return $transaction->updated_at; } - /** - * Transactions. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function transactions() - { - return $this->hasMany('Transaction'); - } - /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/models/AccountMeta.php b/app/models/AccountMeta.php index dc8a8452b9..73d7f9f973 100644 --- a/app/models/AccountMeta.php +++ b/app/models/AccountMeta.php @@ -1,6 +1,7 @@ transactionjournals()->orderBy('updated_at', 'DESC')->first(); + if (is_null($transaction)) { + return null; + } + + return $transaction->date; + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ @@ -31,16 +45,4 @@ class Category extends Component { return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id'); } - /** - * @return Carbon - */ - public function lastActionDate() - { - $transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first(); - if(is_null($transaction)) { - return null; - } - - return $transaction->date; - } } \ No newline at end of file diff --git a/app/models/Component.php b/app/models/Component.php index b70d981ccf..ea5398035d 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -1,25 +1,26 @@ leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin( - 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' - )->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->leftJoin( - 'limits', 'limits.component_id', '=', 'components.id' - )->leftJoin('limit_repetitions', 'limit_repetitions.limit_id', '=', 'limits.id')->where( - 'transaction_journals.date', '>=', $this->startdate->format('Y-m-d') - )->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))->where('transactions.amount', '>', 0)->where( - 'limit_repetitions.id', '=', $this->id - )->sum('transactions.amount'); + 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' + )->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->leftJoin( + 'limits', 'limits.component_id', '=', 'components.id' + )->leftJoin('limit_repetitions', 'limit_repetitions.limit_id', '=', 'limits.id')->where( + 'transaction_journals.date', '>=', $this->startdate->format('Y-m-d') + )->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))->where('transactions.amount', '>', 0)->where( + 'limit_repetitions.id', '=', $this->id + )->sum('transactions.amount'); return floatval($sum); } diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php index 623d82f74d..f949e38e07 100644 --- a/app/models/Piggybank.php +++ b/app/models/Piggybank.php @@ -2,45 +2,46 @@ use Carbon\Carbon; 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 boolean $remind_me - * @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 boolean $remind_me + * @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 whereRemindMe($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) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereRemindMe($value) */ class Piggybank extends Ardent { @@ -70,21 +71,23 @@ class Piggybank extends Ardent return $this->belongsTo('Account'); } - public function countFutureReminders() { + public function countFutureReminders() + { /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */ $dateKit = App::make('FireflyIII\Shared\Toolkit\Date'); - if(is_null($this->reminder)) { + if (is_null($this->reminder)) { return 0; } - $start = new Carbon; - $end = !is_null($this->targetdate) ? clone $this->targetdate : new Carbon; + $start = new Carbon; + $end = !is_null($this->targetdate) ? clone $this->targetdate : new Carbon; $reminders = 0; - while($start <= $end) { + while ($start <= $end) { $reminders++; $start = $dateKit->addPeriod($start, $this->reminder, $this->reminder_skip); } + return $reminders; } diff --git a/app/models/PiggybankEvent.php b/app/models/PiggybankEvent.php index b33a8567cc..d8edc9fa0c 100644 --- a/app/models/PiggybankEvent.php +++ b/app/models/PiggybankEvent.php @@ -2,22 +2,26 @@ 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 integer $transaction_journal_id * @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) + * @property-read \TransactionJournal $transactionJournal + * @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 whereTransactionJournalId($value) */ class PiggybankEvent extends Ardent { diff --git a/app/models/PiggybankRepetition.php b/app/models/PiggybankRepetition.php index 99e0ee85a6..7360fa26ad 100644 --- a/app/models/PiggybankRepetition.php +++ b/app/models/PiggybankRepetition.php @@ -1,24 +1,25 @@ transactionjournals()->orderBy('date','DESC')->first(); - if($last) { + public function lastFoundMatch() + { + $last = $this->transactionjournals()->orderBy('date', 'DESC')->first(); + if ($last) { return $last->date; } + return null; } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function transactionjournals() + { + return $this->hasMany('TransactionJournal'); + } + /** * Find the next expected match based on the set journals and the date stuff from the recurring * transaction. @@ -110,15 +122,8 @@ class RecurringTransaction extends Ardent $start = $dateKit->addPeriod($start, $this->repeat_freq, 0); $counter++; } - return $finalDate; - } - /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function transactionjournals() - { - return $this->hasMany('TransactionJournal'); + return $finalDate; } /** diff --git a/app/models/Reminder.php b/app/models/Reminder.php index e8fb4154cd..fac62d9d48 100644 --- a/app/models/Reminder.php +++ b/app/models/Reminder.php @@ -6,21 +6,25 @@ use LaravelBook\Ardent\Ardent; /** * Reminder * - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $user_id + * @property integer $user_id * @property \Carbon\Carbon $startdate * @property \Carbon\Carbon $enddate - * @property boolean $active - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Reminder whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Reminder whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Reminder whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Reminder whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Reminder whereStartdate($value) - * @method static \Illuminate\Database\Query\Builder|\Reminder whereEnddate($value) - * @method static \Illuminate\Database\Query\Builder|\Reminder whereActive($value) + * @property boolean $active + * @property string $title + * @property string $data + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Reminder whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereStartdate($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereEnddate($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereActive($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereTitle($value) + * @method static \Illuminate\Database\Query\Builder|\Reminder whereData($value) */ class Reminder extends Ardent { diff --git a/app/models/Transaction.php b/app/models/Transaction.php index 6a85e97864..dcdf22871d 100644 --- a/app/models/Transaction.php +++ b/app/models/Transaction.php @@ -1,7 +1,6 @@ hasMany('PiggybankEvent'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -138,14 +148,6 @@ class TransactionJournal extends Ardent return $query->where('date', '>=', $date->format('Y-m-d')); } - /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function piggybankevents() - { - return $this->hasMany('PiggybankEvent'); - } - /** * @param $query * @param Carbon $date @@ -221,7 +223,7 @@ class TransactionJournal extends Ardent $q->orderBy('amount', 'ASC'); }, 'transactiontype', 'components' => function ($q) { $q->orderBy('class'); - }, 'transactions.account.accounttype', 'recurringTransaction','budgets','categories'] + }, 'transactions.account.accounttype', 'recurringTransaction', 'budgets', 'categories'] ); } diff --git a/app/models/TransactionType.php b/app/models/TransactionType.php index 0fea66cadd..9633bc07e1 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 15de4c9168..88b46873c4 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -9,29 +9,29 @@ 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) */ class User extends Ardent implements UserInterface, RemindableInterface { diff --git a/app/start/global.php b/app/start/global.php index 6968b4dfba..5604f492bb 100644 --- a/app/start/global.php +++ b/app/start/global.php @@ -14,10 +14,7 @@ ClassLoader::addDirectories( [ - 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', ] ); diff --git a/bootstrap/paths.php b/bootstrap/paths.php index 289ed916e0..5600950eee 100644 --- a/bootstrap/paths.php +++ b/bootstrap/paths.php @@ -1,6 +1,6 @@ __DIR__ . '/../app/storage', -); +]; diff --git a/bootstrap/start.php b/bootstrap/start.php index 3a43913112..3de22ae845 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -38,10 +38,7 @@ $app = new Illuminate\Foundation\Application; */ $env = $app->detectEnvironment( - [ - 'local' => ['SMJD*'], - 'homestead' => ['homestead'] - ] + ['local' => ['SMJD*'], 'homestead' => ['homestead']] ); @@ -69,8 +66,7 @@ $app->bindInstallPaths(require __DIR__ . '/paths.php'); | */ -$framework = $app['path.base'] . - '/vendor/laravel/framework/src'; +$framework = $app['path.base'] . '/vendor/laravel/framework/src'; require $framework . '/Illuminate/Foundation/start.php';