Skip to content

Firefly III: a personal finances manager

References

James Cole804a97cad7ca
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 93ea3f5284..086a812704 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -26,5 +26,4 @@ class Account extends Model
}
-
}
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index 9c8a5044e6..b1226a1a1d 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -5,6 +5,15 @@ use Illuminate\Database\Eloquent\Model;
class Bill extends Model
{
- //
+ public function transactionjournals()
+ {
+ return $this->hasMany('TransactionJournal');
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
+
}
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index 393a2bfca5..e8c7ac829a 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -5,6 +5,26 @@ use Illuminate\Database\Eloquent\Model;
class Budget extends Model
{
- //
+
+ public function budgetlimits()
+ {
+ return $this->hasMany('BudgetLimit');
+ }
+
+ public function limitrepetitions()
+ {
+ return $this->hasManyThrough('LimitRepetition', 'BudgetLimit', 'budget_id');
+ }
+
+ public function transactionjournals()
+ {
+ return $this->belongsToMany('TransactionJournal', 'budget_transaction_journal', 'budget_id');
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
+
}
diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php
index 31b1e1b050..61fdc17962 100644
--- a/app/Models/BudgetLimit.php
+++ b/app/Models/BudgetLimit.php
@@ -5,6 +5,14 @@ use Illuminate\Database\Eloquent\Model;
class BudgetLimit extends Model
{
- //
+ public function budget()
+ {
+ return $this->belongsTo('Budget');
+ }
+
+ public function limitrepetitions()
+ {
+ return $this->hasMany('LimitRepetition');
+ }
}
diff --git a/app/Models/Category.php b/app/Models/Category.php
index e014779288..912242f176 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -5,6 +5,14 @@ use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
- //
+ public function transactionjournals()
+ {
+ return $this->belongsToMany('TransactionJournal', 'category_transaction_journal', 'category_id');
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
}
diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php
index 26913777ba..039aa5f941 100644
--- a/app/Models/LimitRepetition.php
+++ b/app/Models/LimitRepetition.php
@@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Model;
class LimitRepetition extends Model
{
- //
+ public function budgetLimit()
+ {
+ return $this->belongsTo('BudgetLimit');
+ }
}
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index 0eafb632b3..fbd728bbde 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -5,6 +5,23 @@ use Illuminate\Database\Eloquent\Model;
class PiggyBank extends Model
{
- //
+ public function account()
+ {
+ return $this->belongsTo('Account');
+ }
+ public function piggyBankEvents()
+ {
+ return $this->hasMany('PiggyBankEvent');
+ }
+
+ public function piggyBankRepetitions()
+ {
+ return $this->hasMany('PiggyBankRepetition');
+ }
+
+ public function reminders()
+ {
+ return $this->morphMany('Reminder', 'remindersable');
+ }
}
diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php
index f4a317f7ff..85242c29f8 100644
--- a/app/Models/PiggyBankEvent.php
+++ b/app/Models/PiggyBankEvent.php
@@ -5,6 +5,14 @@ use Illuminate\Database\Eloquent\Model;
class PiggyBankEvent extends Model
{
- //
+ public function piggyBank()
+ {
+ return $this->belongsTo('PiggyBank');
+ }
+
+ public function transactionJournal()
+ {
+ return $this->belongsTo('TransactionJournal');
+ }
}
diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php
index 416d71173a..b17a2547b6 100644
--- a/app/Models/PiggyBankRepetition.php
+++ b/app/Models/PiggyBankRepetition.php
@@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Model;
class PiggyBankRepetition extends Model
{
- //
+ public function piggyBank()
+ {
+ return $this->belongsTo('PiggyBank');
+ }
}
diff --git a/app/Models/Preference.php b/app/Models/Preference.php
index 1014fae8f9..26fba678e0 100644
--- a/app/Models/Preference.php
+++ b/app/Models/Preference.php
@@ -5,6 +5,19 @@ use Illuminate\Database\Eloquent\Model;
class Preference extends Model
{
- //
+ public function getDataAttribute($value)
+ {
+ return json_decode($value);
+ }
+
+ public function setDataAttribute($value)
+ {
+ $this->attributes['data'] = json_encode($value);
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
}
diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php
index 429d6ad335..9ea434e14b 100644
--- a/app/Models/Reminder.php
+++ b/app/Models/Reminder.php
@@ -5,6 +5,15 @@ use Illuminate\Database\Eloquent\Model;
class Reminder extends Model
{
- //
+ public function remindersable()
+ {
+ return $this->morphTo();
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
+
}
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
index 4fdd6c2eaa..84672db4ff 100644
--- a/app/Models/Transaction.php
+++ b/app/Models/Transaction.php
@@ -5,6 +5,14 @@ use Illuminate\Database\Eloquent\Model;
class Transaction extends Model
{
- //
+ public function account()
+ {
+ return $this->belongsTo('Account');
+ }
+
+ public function transactionJournal()
+ {
+ return $this->belongsTo('TransactionJournal');
+ }
}
diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php
index 5481e372df..a14db72e4c 100644
--- a/app/Models/TransactionCurrency.php
+++ b/app/Models/TransactionCurrency.php
@@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Model;
class TransactionCurrency extends Model
{
- //
+ public function transactionJournals()
+ {
+ return $this->hasMany('TransactionJournal');
+ }
}
diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php
index 6996c03dd9..c65f6a7ccd 100644
--- a/app/Models/TransactionGroup.php
+++ b/app/Models/TransactionGroup.php
@@ -5,6 +5,15 @@ use Illuminate\Database\Eloquent\Model;
class TransactionGroup extends Model
{
- //
+ public function transactionjournals()
+ {
+ return $this->belongsToMany('TransactionJournal');
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
+
}
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index 2806db956e..973eef46b3 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -5,6 +5,67 @@ use Illuminate\Database\Eloquent\Model;
class TransactionJournal extends Model
{
- //
+ public function bill()
+ {
+ return $this->belongsTo('Bill');
+ }
+
+ public function budgets()
+ {
+ return $this->belongsToMany('Budget');
+ }
+
+ public function categories()
+ {
+ return $this->belongsToMany('Category');
+ }
+
+ public function getDescriptionAttribute($value)
+ {
+ if ($this->encrypted) {
+ return Crypt::decrypt($value);
+ }
+
+ // @codeCoverageIgnoreStart
+ return $value;
+ // @codeCoverageIgnoreEnd
+ }
+
+ public function piggyBankEvents()
+ {
+ return $this->hasMany('PiggyBankEvent');
+ }
+
+ public function setDescriptionAttribute($value)
+ {
+ $this->attributes['description'] = Crypt::encrypt($value);
+ $this->attributes['encrypted'] = true;
+ }
+
+ public function transactionCurrency()
+ {
+ return $this->belongsTo('TransactionCurrency');
+ }
+
+ public function transactionType()
+ {
+ return $this->belongsTo('TransactionType');
+ }
+
+ public function transactiongroups()
+ {
+ return $this->belongsToMany('TransactionGroup');
+ }
+
+ public function transactions()
+ {
+ return $this->hasMany('Transaction');
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('User');
+ }
+
}
diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php
index 13a518284c..d587b027d5 100644
--- a/app/Models/TransactionType.php
+++ b/app/Models/TransactionType.php
@@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Model;
class TransactionType extends Model
{
- //
+ public function transactionJournals()
+ {
+ return $this->hasMany('TransactionJournal');
+ }
}
diff --git a/app/Models/User.php b/app/Models/User.php
index 65e809c75a..e606e579d0 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -11,31 +11,68 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
use Authenticatable, CanResetPassword;
- /**
- * The database table used by the model.
- *
- * @var string
- */
- protected $table = 'users';
-
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
-
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
-
+ /**
+ * The database table used by the model.
+ *
+ * @var string
+ */
+ protected $table = 'users';
public function accounts()
{
return $this->hasMany('Account');
}
+ public function bills()
+ {
+ return $this->hasMany('Bill');
+ }
+
+ public function budgets()
+ {
+ return $this->hasMany('Budget');
+ }
+
+ public function categories()
+ {
+ return $this->hasMany('Category');
+ }
+
+ public function piggyBanks()
+ {
+ return $this->hasManyThrough('PiggyBank', 'Account');
+ }
+
+ public function preferences()
+ {
+ return $this->hasMany('Preference');
+ }
+
+ public function reminders()
+ {
+ return $this->hasMany('Reminder');
+ }
+
+ public function transactionjournals()
+ {
+ return $this->hasMany('TransactionJournal');
+ }
+
+ public function setPasswordAttribute($value)
+ {
+ $this->attributes['password'] = Hash::make($value);
+ }
+
}