From 71d174d765893f012d5ceb1b34a3f59a31efa47b Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 12 Nov 2014 22:37:44 +0100 Subject: [PATCH] Code clean up and reformat. --- app/models/Account.php | 126 +++++++++++------------- app/models/AccountMeta.php | 6 +- app/models/AccountType.php | 24 +++-- app/models/Budget.php | 30 +++--- app/models/Category.php | 30 +++--- app/models/Component.php | 44 ++++----- app/models/Importentry.php | 28 +++--- app/models/Importmap.php | 50 +++++----- app/models/Limit.php | 66 ++++++------- app/models/LimitRepetition.php | 58 +++++------ app/models/Piggybank.php | 147 ++++++++++++---------------- app/models/PiggybankEvent.php | 30 +++--- app/models/PiggybankRepetition.php | 35 +++---- app/models/Preference.php | 60 ++++++------ app/models/RecurringTransaction.php | 67 ++++++------- app/models/Reminder.php | 23 +++-- app/models/Transaction.php | 136 ++++++++++++------------- app/models/TransactionCurrency.php | 16 +-- app/models/TransactionJournal.php | 125 +++++++++++------------ app/models/TransactionType.php | 16 +-- app/models/User.php | 74 +++++++------- 21 files changed, 551 insertions(+), 640 deletions(-) diff --git a/app/models/Account.php b/app/models/Account.php index 2346f5501d..ce207b98d9 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -5,25 +5,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 { @@ -34,16 +34,23 @@ 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' ]; protected $fillable = ['name', 'user_id', 'account_type_id', 'active']; + /** + * Account type. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function accountType() + { + return $this->belongsTo('AccountType'); + } + /** * Get an accounts current balance. * @@ -56,43 +63,12 @@ class Account extends Ardent $date = is_null($date) ? new \Carbon\Carbon : $date; return floatval( - $this->transactions() - ->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' - ) - ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount') + $this->transactions()->leftJoin( + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' + )->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount') ); } - /** - * @param TransactionJournal $journal - * - * @return float - */ - public function balanceBeforeJournal(TransactionJournal $journal) - { - return floatval( - $this->transactions() - ->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' - ) - ->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d')) - ->where('transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s')) - ->where('transaction_journals.id', '!=', $journal->id) - ->sum('transactions.amount') - ); - } - - /** - * Account type. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function accountType() - { - return $this->belongsTo('AccountType'); - } - /** * Transactions. * @@ -103,6 +79,22 @@ class Account extends Ardent return $this->hasMany('Transaction'); } + /** + * @param TransactionJournal $journal + * + * @return float + */ + public function balanceBeforeJournal(TransactionJournal $journal) + { + return floatval( + $this->transactions()->leftJoin( + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' + )->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where( + 'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s') + )->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount') + ); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -123,16 +115,6 @@ class Account extends Ardent return null; } - /** - * User - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function user() - { - return $this->belongsTo('User'); - } - /** * @param Builder $query * @param array $types @@ -146,5 +128,15 @@ class Account extends Ardent $query->whereIn('account_types.type', $types); } + /** + * 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/AccountMeta.php b/app/models/AccountMeta.php index 12b09102b9..dc8a8452b9 100644 --- a/app/models/AccountMeta.php +++ b/app/models/AccountMeta.php @@ -12,11 +12,7 @@ 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/AccountType.php b/app/models/AccountType.php index 77a4ec8585..63deaee28a 100644 --- a/app/models/AccountType.php +++ b/app/models/AccountType.php @@ -5,24 +5,22 @@ use Illuminate\Database\Eloquent\Model as Eloquent; /** * AccountType * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $type - * @property boolean $editable + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $type + * @property boolean $editable * @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 whereType($value) - * @method static \Illuminate\Database\Query\Builder|\AccountType whereEditable($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 whereType($value) + * @method static \Illuminate\Database\Query\Builder|\AccountType whereEditable($value) */ class AccountType extends Eloquent { public static $rules - = [ - 'type' => ['required', 'between:1,50', 'alphabasic'], - 'editable' => 'required|boolean', + = ['type' => ['required', 'between:1,50', 'alphabasic'], 'editable' => 'required|boolean', ]; diff --git a/app/models/Budget.php b/app/models/Budget.php index 18bf3d069c..e00793396a 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 f0905fcb84..b70d981ccf 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -4,36 +4,32 @@ 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 { public static $rules - = [ - 'user_id' => 'exists:users,id|required', - 'name' => ['required', 'between:1,100','min:1', 'alphabasic'], - 'class' => 'required', - ]; - protected $table = 'components'; - protected $subclassField = 'class'; - protected $fillable = ['name','user_id']; - + = ['user_id' => 'exists:users,id|required', 'name' => ['required', 'between:1,100', 'min:1', 'alphabasic'], + 'class' => 'required',]; + protected $fillable = ['name', 'user_id']; + protected $subclassField = 'class'; + protected $table = 'components'; /** * @return \Illuminate\Database\Eloquent\Relations\HasMany diff --git a/app/models/Importentry.php b/app/models/Importentry.php index 9bf832b31a..790f64ff6a 100644 --- a/app/models/Importentry.php +++ b/app/models/Importentry.php @@ -4,21 +4,21 @@ use Illuminate\Database\Eloquent\Model as Eloquent; /** * Importentry * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $class - * @property integer $importmap_id - * @property integer $old - * @property integer $new + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $class + * @property integer $importmap_id + * @property integer $old + * @property integer $new * @property-read \Importmap $importmap - * @method static \Illuminate\Database\Query\Builder|\Importentry whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Importentry whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Importentry whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Importentry whereClass($value) - * @method static \Illuminate\Database\Query\Builder|\Importentry whereImportmapId($value) - * @method static \Illuminate\Database\Query\Builder|\Importentry whereOld($value) - * @method static \Illuminate\Database\Query\Builder|\Importentry whereNew($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereClass($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereImportmapId($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereOld($value) + * @method static \Illuminate\Database\Query\Builder|\Importentry whereNew($value) */ class Importentry extends Eloquent { diff --git a/app/models/Importmap.php b/app/models/Importmap.php index ab81ed683a..7dc54ca6ea 100644 --- a/app/models/Importmap.php +++ b/app/models/Importmap.php @@ -4,33 +4,38 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * Importmap * - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property string $file - * @property integer $totaljobs - * @property integer $jobsdone - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\Importmap whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Importmap whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Importmap whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Importmap whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\Importmap whereFile($value) - * @method static \Illuminate\Database\Query\Builder|\Importmap whereTotaljobs($value) - * @method static \Illuminate\Database\Query\Builder|\Importmap whereJobsdone($value) + * @property integer $user_id + * @property string $file + * @property integer $totaljobs + * @property integer $jobsdone + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\Importmap whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Importmap whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Importmap whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Importmap whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\Importmap whereFile($value) + * @method static \Illuminate\Database\Query\Builder|\Importmap whereTotaljobs($value) + * @method static \Illuminate\Database\Query\Builder|\Importmap whereJobsdone($value) */ class Importmap extends Ardent { public static $rules - = [ - 'user_id' => 'required|exists:users,id', - 'file' => 'required', - 'totaljobs' => 'numeric|required|min:0', - 'jobsdone' => 'numeric|required|min:0', + = ['user_id' => '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 * @@ -40,13 +45,4 @@ class Importmap extends Ardent { return $this->belongsTo('User'); } - - public function pct() - { - if ($this->jobsdone == 0 || $this->totaljobs == 0) { - return 0; - } else { - return round((($this->jobsdone / $this->totaljobs) * 100), 1); - } - } } \ No newline at end of file diff --git a/app/models/Limit.php b/app/models/Limit.php index 23f893ed1e..d53d1c04f1 100644 --- a/app/models/Limit.php +++ b/app/models/Limit.php @@ -7,36 +7,32 @@ 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 { public static $rules - = [ - 'component_id' => 'required|exists:components,id', - 'startdate' => 'required|date', - 'amount' => 'numeric|required|min:0.01', - 'repeats' => 'required|boolean', - 'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly' + = ['component_id' => 'required|exists:components,id', 'startdate' => 'required|date', 'amount' => 'numeric|required|min:0.01', + 'repeats' => 'required|boolean', 'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly' ]; @@ -90,15 +86,15 @@ class Limit extends Ardent } $end->subDay(); $count = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->count(); - \Log::debug('All: '.$this->limitrepetitions()->count().' (#'.$this->id.')'); - \Log::debug('Found ' . $count.' limit-reps for limit #' . $this->id.' with start '.$start->format('Y-m-d') .' and end ' . $end->format('Y-m-d')); + \Log::debug('All: ' . $this->limitrepetitions()->count() . ' (#' . $this->id . ')'); + \Log::debug('Found ' . $count . ' limit-reps for limit #' . $this->id . ' with start ' . $start->format('Y-m-d') . ' and end ' . $end->format('Y-m-d')); if ($count == 0) { - $repetition = new \LimitRepetition(); + $repetition = new \LimitRepetition(); $repetition->startdate = $start; - $repetition->enddate = $end; - $repetition->amount = $this->amount; + $repetition->enddate = $end; + $repetition->amount = $this->amount; $repetition->limit()->associate($this); try { @@ -113,12 +109,14 @@ class Limit extends Ardent if (isset($repetition->id)) { \Event::fire('limits.repetition', [$repetition]); } - } else if($count == 1) { - // update this one: - $repetition = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->first(); - $repetition->amount = $this->amount; - $repetition->save(); + } else { + if ($count == 1) { + // update this one: + $repetition = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->first(); + $repetition->amount = $this->amount; + $repetition->save(); + } } } diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php index 06613afb59..ec7fefbe53 100644 --- a/app/models/LimitRepetition.php +++ b/app/models/LimitRepetition.php @@ -6,31 +6,26 @@ 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 { public static $rules - = [ - 'limit_id' => 'required|exists:limits,id', - 'startdate' => 'required|date', - 'enddate' => 'required|date', - 'amount' => 'numeric|required|min:0.01', - ]; + = ['limit_id' => 'required|exists:limits,id', 'startdate' => 'required|date', 'enddate' => 'required|date', 'amount' => 'numeric|required|min:0.01',]; /** * @return array @@ -40,20 +35,6 @@ class LimitRepetition extends Ardent return ['created_at', 'updated_at', 'startdate', 'enddate']; } - public function spentInRepetition() { - $sum = \DB::table('transactions') - ->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'); - return floatval($sum); - } - /** * How much money is left in this? */ @@ -63,6 +44,21 @@ class LimitRepetition extends Ardent } + public function spentInRepetition() + { + $sum = \DB::table('transactions')->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'); + + return floatval($sum); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php index c364bcf0d2..03ec278c47 100644 --- a/app/models/Piggybank.php +++ b/app/models/Piggybank.php @@ -5,77 +5,62 @@ 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 boolean $remind_me + * @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 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 whereRemindMe($value) + * @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value) */ class Piggybank extends Ardent { public static $rules - = [ - 'account_id' => 'required|exists:accounts,id', // link to Account - 'name' => 'required|between:1,255', // name - 'targetamount' => 'required|min:0', // amount you want to save - 'startdate' => 'date', // when you started - 'targetdate' => 'date', // when its due - 'repeats' => 'required|boolean', // does it repeat? - 'rep_length' => 'in:day,week,month,year', // how long is the period? - 'rep_every' => 'required|min:1|max:100', // how often does it repeat? every 3 years. - 'rep_times' => 'min:1|max:100', // how many times do you want to save this amount? eg. 3 times - 'reminder' => 'in:day,week,month,year', // want a reminder to put money in this? - 'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months? - 'remind_me' => 'required|boolean', - 'order' => 'required:min:1', // not yet used. - ]; - public $fillable - = [ - 'account_id', - 'name', - 'targetamount', - 'startdate', - 'targetdate', - 'repeats', - 'rep_length', - 'rep_every', - 'rep_times', - 'reminder', - 'reminder_skip', - 'remind_me', - 'order' + = ['account_id' => 'required|exists:accounts,id', // link to Account + 'name' => 'required|between:1,255', // name + 'targetamount' => 'required|min:0', // amount you want to save + 'startdate' => 'date', // when you started + 'targetdate' => 'date', // when its due + 'repeats' => 'required|boolean', // does it repeat? + 'rep_length' => 'in:day,week,month,year', // how long is the period? + 'rep_every' => 'required|min:1|max:100', // how often does it repeat? every 3 years. + 'rep_times' => 'min:1|max:100', // how many times do you want to save this amount? eg. 3 times + 'reminder' => 'in:day,week,month,year', // want a reminder to put money in this? + 'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months? + 'remind_me' => 'required|boolean', 'order' => 'required:min:1', // not yet used. ]; + public $fillable + = ['account_id', 'name', 'targetamount', 'startdate', 'targetdate', 'repeats', 'rep_length', 'rep_every', 'rep_times', 'reminder', 'reminder_skip', + 'remind_me', 'order']; /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo @@ -89,8 +74,8 @@ class Piggybank extends Ardent { $rep = new \PiggybankRepetition; $rep->piggybank()->associate($this); - $rep->startdate = $start; - $rep->targetdate = $target; + $rep->startdate = $start; + $rep->targetdate = $target; $rep->currentamount = 0; $rep->save(); \Event::fire('piggybanks.repetition', [$rep]); @@ -98,14 +83,6 @@ class Piggybank extends Ardent return $rep; } - /** - * @return array - */ - public function getDates() - { - return ['created_at', 'updated_at', 'targetdate', 'startdate']; - } - /** * Grabs the PiggyBankRepetition that's currently relevant / active * @@ -113,8 +90,7 @@ class Piggybank extends Ardent */ public function currentRelevantRep() { - $query = $this->piggybankrepetitions() - ->where( + $query = $this->piggybankrepetitions()->where( function ($q) { $q->where( @@ -123,8 +99,7 @@ class Piggybank extends Ardent $q->whereNull('startdate'); $q->orWhere('startdate', '<=', $today->format('Y-m-d')); } - ) - ->where( + )->where( function ($q) { $today = new Carbon; $q->whereNull('targetdate'); @@ -154,6 +129,14 @@ class Piggybank extends Ardent return $this->hasMany('PiggybankRepetition'); } + /** + * @return array + */ + public function getDates() + { + return ['created_at', 'updated_at', 'targetdate', 'startdate']; + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -171,8 +154,7 @@ class Piggybank extends Ardent */ public function repetitionForDate(Carbon $date) { - $query = $this->piggybankrepetitions() - ->where( + $query = $this->piggybankrepetitions()->where( function ($q) use ($date) { $q->where( @@ -180,8 +162,7 @@ class Piggybank extends Ardent $q->whereNull('startdate'); $q->orWhere('startdate', '<=', $date->format('Y-m-d')); } - ) - ->where( + )->where( function ($q) use ($date) { $q->whereNull('targetdate'); $q->orWhere('targetdate', '>=', $date->format('Y-m-d')); diff --git a/app/models/PiggybankEvent.php b/app/models/PiggybankEvent.php index 5c6cc88fb7..ceb3c1bf91 100644 --- a/app/models/PiggybankEvent.php +++ b/app/models/PiggybankEvent.php @@ -5,29 +5,25 @@ 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 { public static $rules - = [ - 'piggybank_id' => 'required|exists:piggybanks,id', - 'date' => 'required|date', - 'amount' => 'required|numeric' - ]; + = ['piggybank_id' => 'required|exists:piggybanks,id', 'date' => 'required|date', 'amount' => 'required|numeric']; /** * @return array diff --git a/app/models/PiggybankRepetition.php b/app/models/PiggybankRepetition.php index 9f66ef2820..99e0ee85a6 100644 --- a/app/models/PiggybankRepetition.php +++ b/app/models/PiggybankRepetition.php @@ -4,31 +4,26 @@ 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 { public static $rules - = [ - 'piggybank_id' => 'required|exists:piggybanks,id', - 'targetdate' => 'date', - 'startdate' => 'date', - 'currentamount' => 'required|numeric' - ]; + = ['piggybank_id' => 'required|exists:piggybanks,id', 'targetdate' => 'date', 'startdate' => 'date', 'currentamount' => 'required|numeric']; /** * @return array diff --git a/app/models/Preference.php b/app/models/Preference.php index ba8ac43bf9..5f28bd6a17 100644 --- a/app/models/Preference.php +++ b/app/models/Preference.php @@ -5,44 +5,24 @@ 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 { public static $rules - = [ - 'user_id' => 'required|exists:users,id', - 'name' => 'required|between:1,255', - 'data' => 'required' - ]; - - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function user() - { - return $this->belongsTo('User'); - } - - /** - * @param $value - */ - public function setDataAttribute($value) - { - $this->attributes['data'] = json_encode($value); - } + = ['user_id' => 'required|exists:users,id', 'name' => 'required|between:1,255', 'data' => 'required']; /** * @param $value @@ -54,4 +34,20 @@ class Preference extends Ardent return json_decode($value); } + /** + * @param $value + */ + public function setDataAttribute($value) + { + $this->attributes['data'] = json_encode($value); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user() + { + return $this->belongsTo('User'); + } + } \ No newline at end of file diff --git a/app/models/RecurringTransaction.php b/app/models/RecurringTransaction.php index c2781e1252..c2c45a8ac2 100644 --- a/app/models/RecurringTransaction.php +++ b/app/models/RecurringTransaction.php @@ -5,52 +5,43 @@ 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) */ class RecurringTransaction extends Ardent { public static $rules - = [ - 'user_id' => 'required|exists:users,id', - 'name' => 'required|between:1,255', - 'match' => 'required', - 'amount_max' => 'required|between:0,65536', - 'amount_min' => 'required|between:0,65536', - 'date' => 'required|date', - 'active' => 'required|between:0,1', - 'automatch' => 'required|between:0,1', - 'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly', - 'skip' => 'required|between:0,31', - ]; + = ['user_id' => 'required|exists:users,id', 'name' => 'required|between:1,255', 'match' => 'required', 'amount_max' => 'required|between:0,65536', + 'amount_min' => 'required|between:0,65536', 'date' => 'required|date', 'active' => 'required|between:0,1', 'automatch' => 'required|between:0,1', + 'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly', 'skip' => 'required|between:0,31',]; - protected $fillable = ['user_id','name','match','amount_min','amount_max','date','repeat_freq','skip','active','automatch']; + protected $fillable = ['user_id', 'name', 'match', 'amount_min', 'amount_max', 'date', 'repeat_freq', 'skip', 'active', 'automatch']; /** * @return array @@ -68,7 +59,7 @@ class RecurringTransaction extends Ardent { $today = new Carbon; $start = clone $this->date; - $skip = $this->skip == 0 ? 1 : $this->skip; + $skip = $this->skip == 0 ? 1 : $this->skip; if ($today < $start) { return $start; } diff --git a/app/models/Reminder.php b/app/models/Reminder.php index 0d11a174f5..e8fb4154cd 100644 --- a/app/models/Reminder.php +++ b/app/models/Reminder.php @@ -1,27 +1,26 @@ 'numeric|required|exists:accounts,id', - 'piggybank_id' => 'numeric|exists:piggybanks,id', - 'transaction_journal_id' => 'numeric|required|exists:transaction_journals,id', - 'description' => 'between:1,255', - 'amount' => 'required|between:-65536,65536|not_in:0,0.00', - ]; + = ['account_id' => 'numeric|required|exists:accounts,id', 'piggybank_id' => 'numeric|exists:piggybanks,id', + 'transaction_journal_id' => 'numeric|required|exists:transaction_journals,id', 'description' => 'between:1,255', + 'amount' => 'required|between:-65536,65536|not_in:0,0.00',]; /** @@ -58,36 +54,6 @@ class Transaction extends Ardent return $this->belongsTo('Account'); } - /** - * @param Piggybank $piggybank - * - * @return bool - */ - public function connectPiggybank(\Piggybank $piggybank = null) - { - throw new NotImplementedException; -// if (is_null($piggybank)) { -// return true; -// } -// /** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */ -// $piggyRepository = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface'); -// if ($this->account_id == $piggybank->account_id) { -// $this->piggybank()->associate($piggybank); -// $this->save(); -// \Event::fire('piggybanks.createRelatedTransfer', [$piggybank, $this->transactionJournal, $this]); -// return true; -// } -// return false; - } - - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function piggybank() - { - return $this->belongsTo('Piggybank'); - } - /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ @@ -112,6 +78,36 @@ class Transaction extends Ardent return $this->belongsToMany('Component'); } + /** + * @param Piggybank $piggybank + * + * @return bool + */ + public function connectPiggybank(\Piggybank $piggybank = null) + { + throw new NotImplementedException; + // if (is_null($piggybank)) { + // return true; + // } + // /** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */ + // $piggyRepository = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface'); + // if ($this->account_id == $piggybank->account_id) { + // $this->piggybank()->associate($piggybank); + // $this->save(); + // \Event::fire('piggybanks.createRelatedTransfer', [$piggybank, $this->transactionJournal, $this]); + // return true; + // } + // return false; + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function piggybank() + { + return $this->belongsTo('Piggybank'); + } + public function scopeAccountIs(Builder $query, Account $account) { $query->where('transactions.account_id', $account->id); @@ -121,8 +117,7 @@ class Transaction extends Ardent { if (is_null($this->joinedJournals)) { $query->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', - 'transactions.transaction_journal_id' + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' ); $this->joinedJournals = true; } @@ -133,8 +128,7 @@ class Transaction extends Ardent { if (is_null($this->joinedJournals)) { $query->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', - 'transactions.transaction_journal_id' + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' ); $this->joinedJournals = true; } @@ -155,15 +149,13 @@ class Transaction extends Ardent { if (is_null($this->joinedJournals)) { $query->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', - 'transactions.transaction_journal_id' + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' ); $this->joinedJournals = true; } if (is_null($this->joinedTransactionTypes)) { $query->leftJoin( - 'transaction_types', 'transaction_types.id', '=', - 'transaction_journals.transaction_type_id' + 'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id' ); $this->joinedTransactionTypes = true; } diff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.php index 23ee95ad1f..bac3143feb 100644 --- a/app/models/TransactionCurrency.php +++ b/app/models/TransactionCurrency.php @@ -4,15 +4,15 @@ use Illuminate\Database\Eloquent\Model as Eloquent; /** * 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 89513a0d46..fdc0ae6dab 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -7,57 +7,52 @@ use LaravelBook\Ardent\Builder; /** * TransactionJournal * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property integer $transaction_type_id - * @property integer $recurring_transaction_id - * @property integer $transaction_currency_id - * @property string $description - * @property boolean $completed - * @property \Carbon\Carbon $date + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $user_id + * @property integer $transaction_type_id + * @property integer $recurring_transaction_id + * @property integer $transaction_currency_id + * @property string $description + * @property boolean $completed + * @property \Carbon\Carbon $date * @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 \RecurringTransaction $recurringTransaction - * @property-read \TransactionCurrency $transactionCurrency - * @property-read \TransactionType $transactionType + * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components + * @property-read \RecurringTransaction $recurringTransaction + * @property-read \TransactionCurrency $transactionCurrency + * @property-read \TransactionType $transactionType * @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions - * @property-read \User $user - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereUserId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereTransactionTypeId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereRecurringTransactionId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereTransactionCurrencyId($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereDescription($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereCompleted($value) - * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereDate($value) - * @method static \TransactionJournal accountIs($account) - * @method static \TransactionJournal after($date) - * @method static \TransactionJournal before($date) - * @method static \TransactionJournal defaultSorting() - * @method static \TransactionJournal moreThan($amount) - * @method static \TransactionJournal lessThan($amount) - * @method static \TransactionJournal onDate($date) - * @method static \TransactionJournal transactionTypes($types) - * @method static \TransactionJournal withRelevantData() + * @property-read \User $user + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereUserId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereTransactionTypeId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereRecurringTransactionId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereTransactionCurrencyId($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereCompleted($value) + * @method static \Illuminate\Database\Query\Builder|\TransactionJournal whereDate($value) + * @method static \TransactionJournal accountIs($account) + * @method static \TransactionJournal after($date) + * @method static \TransactionJournal before($date) + * @method static \TransactionJournal defaultSorting() + * @method static \TransactionJournal moreThan($amount) + * @method static \TransactionJournal lessThan($amount) + * @method static \TransactionJournal onDate($date) + * @method static \TransactionJournal transactionTypes($types) + * @method static \TransactionJournal withRelevantData() */ class TransactionJournal extends Ardent { public static $rules - = [ - 'transaction_type_id' => 'required|exists:transaction_types,id', - 'transaction_currency_id' => 'required|exists:transaction_currencies,id', - 'description' => 'required|between:1,255', - 'date' => 'required|date', - 'completed' => 'required|between:0,1' - ]; + = ['transaction_type_id' => 'required|exists:transaction_types,id', 'transaction_currency_id' => 'required|exists:transaction_currencies,id', + 'description' => 'required|between:1,255', 'date' => 'required|date', 'completed' => 'required|between:0,1']; /** @@ -99,15 +94,8 @@ class TransactionJournal extends Ardent return floatval($t->amount); } } - return -0.01; - } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function recurringTransaction() - { - return $this->belongsTo('RecurringTransaction'); + return -0.01; } /** @@ -118,6 +106,14 @@ class TransactionJournal extends Ardent return ['created_at', 'updated_at', 'date']; } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function recurringTransaction() + { + return $this->belongsTo('RecurringTransaction'); + } + /** * @param Builder $query * @param Account $account @@ -158,25 +154,11 @@ class TransactionJournal extends Ardent $query->orderBy('date', 'DESC')->orderBy('transaction_journals.id', 'DESC'); } - public function scopeMoreThan(Builder $query, $amount) - { - if (is_null($this->joinedTransactions)) { - $query->leftJoin( - 'transactions', 'transactions.transaction_journal_id', '=', - 'transaction_journals.id' - ); - $this->joinedTransactions = true; - } - - $query->where('transactions.amount', '>=', $amount); - } - public function scopeLessThan(Builder $query, $amount) { if (is_null($this->joinedTransactions)) { $query->leftJoin( - 'transactions', 'transactions.transaction_journal_id', '=', - 'transaction_journals.id' + 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id' ); $this->joinedTransactions = true; } @@ -184,6 +166,18 @@ class TransactionJournal extends Ardent $query->where('transactions.amount', '<=', $amount); } + public function scopeMoreThan(Builder $query, $amount) + { + if (is_null($this->joinedTransactions)) { + $query->leftJoin( + 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id' + ); + $this->joinedTransactions = true; + } + + $query->where('transactions.amount', '>=', $amount); + } + /** * @param $query * @param Carbon $date @@ -199,8 +193,7 @@ class TransactionJournal extends Ardent { if (is_null($this->joinedTransactionTypes)) { $query->leftJoin( - 'transaction_types', 'transaction_types.id', '=', - 'transaction_journals.transaction_type_id' + 'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id' ); $this->joinedTransactionTypes = true; } 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 6f665beaf7..15de4c9168 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 { @@ -40,24 +40,20 @@ class User extends Ardent implements UserInterface, RemindableInterface public static $rules - = [ - 'email' => 'required|email|unique:users,email', - 'migrated' => 'required|boolean', - 'password' => 'required|between:60,60', - 'reset' => 'between:32,32', - ]; - /** - * The database table used by the model. - * - * @var string - */ - protected $table = 'users'; + = ['email' => 'required|email|unique:users,email', 'migrated' => 'required|boolean', 'password' => 'required|between:60,60', + 'reset' => 'between:32,32',]; /** * The attributes excluded from the model's JSON form. * * @var array */ protected $hidden = ['remember_token']; + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'users'; /** * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -91,6 +87,11 @@ class User extends Ardent implements UserInterface, RemindableInterface return $this->hasMany('Component'); } + public function piggybanks() + { + return $this->hasManyThrough('Piggybank', 'Account'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -115,11 +116,6 @@ class User extends Ardent implements UserInterface, RemindableInterface $this->attributes['password'] = Hash::make($value); } - public function piggybanks() - { - return $this->hasManyThrough('Piggybank', 'Account'); - } - /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */