Piggy banks

This commit is contained in:
James Cole
2015-02-25 19:32:33 +01:00
parent f2eae2fc98
commit c0f96aa948
14 changed files with 542 additions and 160 deletions

View File

@@ -14,6 +14,8 @@ class PiggyBank extends Model
{
use SoftDeletes;
protected $fillable = ['repeats', 'name', 'account_id', 'targetamount','startdate', 'targetdate', 'reminder',];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
@@ -22,38 +24,6 @@ class PiggyBank extends Model
return $this->belongsTo('FireflyIII\Models\Account');
}
/**
* @return array
*/
public function getDates()
{
return ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankEvents()
{
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankRepetitions()
{
return $this->hasMany('FireflyIII\Models\PiggyBankRepetition');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function reminders()
{
return $this->morphMany('FireflyIII\Models\Reminder', 'remindersable');
}
/**
* Grabs the PiggyBankRepetition that's currently relevant / active
*
@@ -70,7 +40,7 @@ class PiggyBank extends Model
return $rep;
} else {
$query = $this->piggyBankRepetitions()->where(
$query = $this->piggyBankRepetitions()->where(
function (EloquentBuilder $q) {
$q->where(
@@ -100,7 +70,7 @@ class PiggyBank extends Model
}
)->orderBy('startdate', 'ASC');
$result = $query->first(['piggy_bank_repetitions.*']);
$result = $query->first(['piggy_bank_repetitions.*']);
$this->currentRep = $result;
return $result;
@@ -108,4 +78,36 @@ class PiggyBank extends Model
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankRepetitions()
{
return $this->hasMany('FireflyIII\Models\PiggyBankRepetition');
}
/**
* @return array
*/
public function getDates()
{
return ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankEvents()
{
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function reminders()
{
return $this->morphMany('FireflyIII\Models\Reminder', 'remindersable');
}
}