diff --git a/app/models/Account.php b/app/models/Account.php index 496b14bbed..47e4a0594f 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -7,25 +7,25 @@ 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 { @@ -36,8 +36,11 @@ class Account extends Ardent * @var array */ public static $rules - = ['name' => ['required', 'between:1,100', 'alphabasic'], 'user_id' => 'required|exists:users,id', - 'account_type_id' => 'required|exists:account_types,id', 'active' => 'required|boolean' + = [ + 'name' => ['required', 'between:1,100', 'alphabasic'], + 'user_id' => 'required|exists:users,id', + 'account_type_id' => 'required|exists:account_types,id', + 'active' => 'required|boolean' ]; @@ -56,6 +59,8 @@ class Account extends Ardent /** * Get an accounts current balance. * + * TODO remove this method in favour of something in the FireflyIII libraries. + * * @param \Carbon\Carbon $date * * @return float @@ -82,6 +87,9 @@ class Account extends Ardent } /** + * + * TODO remove this method in favour of something in the FireflyIII libraries. + * * @param TransactionJournal $journal * * @return float @@ -98,6 +106,8 @@ class Account extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * @return Carbon */ public function lastActionDate() @@ -119,6 +129,8 @@ class Account extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * @param \Carbon\Carbon $date * * @return null diff --git a/app/models/AccountMeta.php b/app/models/AccountMeta.php index 73d7f9f973..ada62b614a 100644 --- a/app/models/AccountMeta.php +++ b/app/models/AccountMeta.php @@ -13,7 +13,10 @@ class AccountMeta extends Ardent * @var array */ public static $rules - = ['account_id' => 'numeric|required|exists:accounts,id', 'name' => 'required|between:1,250', 'data' => 'required']; + = [ + 'account_id' => 'numeric|required|exists:accounts,id', + 'name' => 'required|between:1,250', + 'data' => 'required']; /** * @var array diff --git a/app/models/Budget.php b/app/models/Budget.php index 18bf3d069c..59fb3a73f1 100644 --- a/app/models/Budget.php +++ b/app/models/Budget.php @@ -32,12 +32,5 @@ class Budget extends Component return $this->hasMany('Limit', 'component_id'); } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|\TransactionJournal - */ - public function transactionjournals() - { - return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id'); - } } \ No newline at end of file diff --git a/app/models/Category.php b/app/models/Category.php index cadcfdc4c6..f8cda2fa37 100644 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -25,24 +25,5 @@ class Category extends Component { protected $isSubclass = true; - /** - * @return Carbon - */ - public function lastActionDate() - { - $transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first(); - if (is_null($transaction)) { - return null; - } - return $transaction->date; - } - - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function transactionjournals() - { - return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id'); - } -} \ No newline at end of file +} \ No newline at end of file diff --git a/app/models/Component.php b/app/models/Component.php index ea5398035d..1c9d1509e2 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -5,22 +5,22 @@ use FireflyIII\Shared\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 { @@ -33,11 +33,17 @@ class Component extends SingleTableInheritanceEntity protected $table = 'components'; /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * TODO remove this method in favour of something in the FireflyIII libraries. + * @return Carbon */ - public function limits() + public function lastActionDate() { - return $this->hasMany('Limit'); + $transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first(); + if (is_null($transaction)) { + return null; + } + + return $transaction->date; } /** @@ -45,9 +51,10 @@ class Component extends SingleTableInheritanceEntity */ public function transactionjournals() { - return $this->belongsToMany('TransactionJournal'); + return $this->belongsToMany('TransactionJournal','component_transaction_journal','component_id'); } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ diff --git a/app/models/Importentry.php b/app/models/Importentry.php deleted file mode 100644 index c35e831d72..0000000000 --- a/app/models/Importentry.php +++ /dev/null @@ -1,30 +0,0 @@ -belongsTo('Importmap'); - } -} \ No newline at end of file diff --git a/app/models/Importmap.php b/app/models/Importmap.php deleted file mode 100644 index c150c8f89d..0000000000 --- a/app/models/Importmap.php +++ /dev/null @@ -1,49 +0,0 @@ - 'required|exists:users,id', 'file' => 'required', 'totaljobs' => 'numeric|required|min:0', 'jobsdone' => 'numeric|required|min:0', - - ]; - - public function pct() - { - if ($this->jobsdone == 0 || $this->totaljobs == 0) { - return 0; - } else { - return round((($this->jobsdone / $this->totaljobs) * 100), 1); - } - } - - /** - * User - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function user() - { - return $this->belongsTo('User'); - } -} \ No newline at end of file diff --git a/app/models/Limit.php b/app/models/Limit.php index 3855b2f376..2e1f1f604f 100644 --- a/app/models/Limit.php +++ b/app/models/Limit.php @@ -46,14 +46,6 @@ class Limit extends Ardent return $this->belongsTo('Budget', 'component_id'); } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function component() - { - return $this->belongsTo('Component', 'component_id'); - } - /** * Create a new repetition for this limit, starting on * the given date. diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php index 3b8707f4af..61f89ce547 100644 --- a/app/models/LimitRepetition.php +++ b/app/models/LimitRepetition.php @@ -45,6 +45,10 @@ class LimitRepetition extends Ardent } + /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * @return float + */ public function spentInRepetition() { $sum = \DB::table('transactions')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin( @@ -69,6 +73,8 @@ class LimitRepetition extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * Returns a string used to sort this particular repetition * based on the date and period it falls into. Ie. the limit * repeats monthly and the start date is 12 dec 2012, this will @@ -105,6 +111,8 @@ class LimitRepetition extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * Same as above, just with a more natural view. So "March 2012". */ public function periodShow() diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php index 3b1fb614d8..1e35e41081 100644 --- a/app/models/Piggybank.php +++ b/app/models/Piggybank.php @@ -71,16 +71,34 @@ class Piggybank extends Ardent return $this->belongsTo('Account'); } + /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * + * @return int + */ public function amountPerReminder() { return 0; } + /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * + * @return int + */ public function countFutureReminders() { return 0; } + /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * + * @param Carbon $start + * @param Carbon $target + * + * @return PiggybankRepetition + */ public function createRepetition(Carbon $start = null, Carbon $target = null) { $rep = new \PiggybankRepetition; @@ -94,6 +112,8 @@ class Piggybank extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * Grabs the PiggyBankRepetition that's currently relevant / active * * @returns \PiggybankRepetition @@ -167,6 +187,8 @@ class Piggybank extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * Same but for specific date. * * @param Carbon $date diff --git a/app/models/PiggybankRepetition.php b/app/models/PiggybankRepetition.php index 7360fa26ad..a7c15705b0 100644 --- a/app/models/PiggybankRepetition.php +++ b/app/models/PiggybankRepetition.php @@ -34,6 +34,11 @@ class PiggybankRepetition extends Ardent return ['created_at', 'updated_at', 'targetdate', 'startdate']; } + /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * + * @return float|int + */ public function pct() { $total = $this->piggybank->targetamount; diff --git a/app/models/RecurringTransaction.php b/app/models/RecurringTransaction.php index 952a801ffb..f5e9d98bc5 100644 --- a/app/models/RecurringTransaction.php +++ b/app/models/RecurringTransaction.php @@ -72,6 +72,8 @@ class RecurringTransaction extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. + * * Find the next expected match based on the set journals and the date stuff from the recurring * transaction. */ diff --git a/app/models/Reminder.php b/app/models/Reminder.php index 2cf33da6d8..9b6634fc0b 100644 --- a/app/models/Reminder.php +++ b/app/models/Reminder.php @@ -50,19 +50,6 @@ class Reminder extends Ardent return $this->belongsTo('User'); } - /** - * Expected data in this value: - * - * type: Piggybank, Test - * action_uri: where to go when the user wants to do this? - * text: full text to present to user - * amount: any relevant amount. - * model: id of relevant model. - * - * @param $value - * - * @return mixed - */ public function getDataAttribute($value) { return json_decode($value); diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php index 04c6a502a5..1651b4eecd 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -86,6 +86,7 @@ class TransactionJournal extends Ardent } /** + * TODO remove this method in favour of something in the FireflyIII libraries. * @return float */ public function getAmount() diff --git a/app/routes.php b/app/routes.php index daee77ffea..0f39c30440 100644 --- a/app/routes.php +++ b/app/routes.php @@ -221,7 +221,7 @@ Route::group( // user controller Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']); - //Route::post('budgets/amount/{budget}', ['uses' => 'BudgetController@amount']); + Route::post('budgets/amount/{budget}', ['uses' => 'BudgetController@amount']); } diff --git a/bootstrap/start.php b/bootstrap/start.php index 4a78106be2..38c19a0300 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -102,4 +102,5 @@ Event::subscribe('FireflyIII\Event\Piggybank'); // although this not changes the amount in the piggy bank). // TODO check if recurring transactions are being updated when journals are updated (aka no longer fitting, thus removed). // TODO think about reminders. +// TODO an event that triggers and creates a limit + limit repetition when a budget is created, or something? return $app;