Skip to content

Firefly III: a personal finances manager

Lost a lot of stuff along the way.

James Coleb2c1527b1721
diff --git a/app/Models/Account.php b/app/Models/Account.php
new file mode 100644
index 0000000000..2c6c21002e
--- /dev/null
+++ b/app/Models/Account.php
@@ -0,0 +1,105 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Watson\Validating\ValidatingTrait;
+
+/**
+ * Class Account
+ *
+ * @package FireflyIII\Models
+ */
+class Account extends Model
+{
+ use SoftDeletes, ValidatingTrait;
+
+ protected $rules
+ = [
+ 'user_id' => 'required|exists:users,id',
+ 'account_type_id' => 'required|exists:account_types,id',
+ 'name' => 'required|between:1,100|uniqueForUser:accounts,name',
+ 'active' => 'required|boolean'
+ ];
+
+ protected $fillable = ['user_id', 'account_type_id', 'name', 'active'];
+
+ /**
+ * @param $fieldName
+ *
+ * @return string|null
+ */
+ public function getMeta($fieldName)
+ {
+ foreach ($this->accountMeta as $meta) {
+ if ($meta->name == $fieldName) {
+ return $meta->data;
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function accountMeta()
+ {
+ return $this->hasMany('FireflyIII\Models\AccountMeta');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function accountType()
+ {
+ return $this->belongsTo('FireflyIII\Models\AccountType');
+ }
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @param EloquentBuilder $query
+ * @param array $types
+ */
+ public function scopeAccountTypeIn(EloquentBuilder $query, array $types)
+ {
+ if (is_null($this->joinedAccountTypes)) {
+ $query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id');
+ $this->joinedAccountTypes = true;
+ }
+ $query->whereIn('account_types.type', $types);
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function transactions()
+ {
+ return $this->hasMany('FireflyIII\Models\Transaction');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo('FireflyIII\User');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function piggyBanks()
+ {
+ return $this->hasMany('FireflyIII\Models\PiggyBank');
+ }
+
+}
diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php
new file mode 100644
index 0000000000..aee84c7c1e
--- /dev/null
+++ b/app/Models/AccountType.php
@@ -0,0 +1,29 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class AccountType
+ *
+ * @package FireflyIII\Models
+ */
+class AccountType extends Model
+{
+
+ //
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function accounts()
+ {
+ return $this->hasMany('FireflyIII\Models\Account');
+ }
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at'];
+ }
+}
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
new file mode 100644
index 0000000000..7cdcc2e67c
--- /dev/null
+++ b/app/Models/Bill.php
@@ -0,0 +1,40 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Bill
+ *
+ * @package FireflyIII\Models
+ */
+class Bill extends Model
+{
+
+ protected $fillable = ['name', 'match', 'amount_min','user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'date'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function transactionjournals()
+ {
+ return $this->hasMany('FireflyIII\Models\TransactionJournal');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo('FireflyIII\User');
+ }
+
+
+}
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
new file mode 100644
index 0000000000..b07c11b830
--- /dev/null
+++ b/app/Models/Budget.php
@@ -0,0 +1,59 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * Class Budget
+ *
+ * @package FireflyIII\Models
+ */
+class Budget extends Model
+{
+
+ use SoftDeletes;
+
+ protected $fillable = ['user_id', 'name'];
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function budgetlimits()
+ {
+ return $this->hasMany('FireflyIII\Models\BudgetLimit');
+ }
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
+ */
+ public function limitrepetitions()
+ {
+ return $this->hasManyThrough('FireflyIII\Models\LimitRepetition', 'FireflyIII\Models\BudgetLimit', 'budget_id');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function transactionjournals()
+ {
+ return $this->belongsToMany('FireflyIII\Models\TransactionJournal', 'budget_transaction_journal', 'budget_id');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo('FireflyIII\User');
+ }
+
+
+}
diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php
new file mode 100644
index 0000000000..5189d91664
--- /dev/null
+++ b/app/Models/BudgetLimit.php
@@ -0,0 +1,37 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class BudgetLimit
+ *
+ * @package FireflyIII\Models
+ */
+class BudgetLimit extends Model
+{
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function budget()
+ {
+ return $this->belongsTo('FireflyIII\Models\Budget');
+ }
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'startdate'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function limitrepetitions()
+ {
+ return $this->hasMany('FireflyIII\Models\LimitRepetition');
+ }
+
+}
diff --git a/app/Models/Category.php b/app/Models/Category.php
new file mode 100644
index 0000000000..37f12c7ca8
--- /dev/null
+++ b/app/Models/Category.php
@@ -0,0 +1,41 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * Class Category
+ *
+ * @package FireflyIII\Models
+ */
+class Category extends Model
+{
+ use SoftDeletes;
+
+ protected $fillable = ['user_id', 'name'];
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function transactionjournals()
+ {
+ return $this->belongsToMany('FireflyIII\Models\TransactionJournal', 'category_transaction_journal', 'category_id');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo('FireflyIII\User');
+ }
+
+}
diff --git a/app/Models/Component.php b/app/Models/Component.php
new file mode 100644
index 0000000000..0c8e57a45f
--- /dev/null
+++ b/app/Models/Component.php
@@ -0,0 +1,22 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * Class Component
+ *
+ * @package FireflyIII\Models
+ */
+class Component extends Model
+{
+ use SoftDeletes;
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+}
diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php
new file mode 100644
index 0000000000..927d33b1f9
--- /dev/null
+++ b/app/Models/LimitRepetition.php
@@ -0,0 +1,45 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class LimitRepetition
+ *
+ * @package FireflyIII\Models
+ */
+class LimitRepetition extends Model
+{
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function budgetLimit()
+ {
+ return $this->belongsTo('FireflyIII\Models\BudgetLimit');
+ }
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ 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('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id')
+ ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
+ ->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d'))
+ ->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))
+ ->where('transactions.amount', '>', 0)
+ ->where('limit_repetitions.id', '=', $this->id)
+ ->sum('transactions.amount');
+
+ return floatval($sum);
+ }
+
+}
diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php
new file mode 100644
index 0000000000..f9a94a0286
--- /dev/null
+++ b/app/Models/PiggyBankEvent.php
@@ -0,0 +1,37 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class PiggyBankEvent
+ *
+ * @package FireflyIII\Models
+ */
+class PiggyBankEvent extends Model
+{
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'date'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function piggyBank()
+ {
+ return $this->belongsTo('FireflyIII\Models\PiggyBank');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function transactionJournal()
+ {
+ return $this->belongsTo('FireflyIII\Models\TransactionJournal');
+ }
+
+}
diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php
new file mode 100644
index 0000000000..fe4d72a6f2
--- /dev/null
+++ b/app/Models/PiggyBankRepetition.php
@@ -0,0 +1,29 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class PiggyBankRepetition
+ *
+ * @package FireflyIII\Models
+ */
+class PiggyBankRepetition extends Model
+{
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'startdate', 'targetdate'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function piggyBank()
+ {
+ return $this->belongsTo('FireflyIII\Models\PiggyBank');
+ }
+
+}
diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php
new file mode 100644
index 0000000000..98e75a0a4c
--- /dev/null
+++ b/app/Models/Reminder.php
@@ -0,0 +1,37 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Reminder
+ *
+ * @package FireflyIII\Models
+ */
+class Reminder extends Model
+{
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'startdate', 'enddate'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\MorphTo
+ */
+ public function remindersable()
+ {
+ return $this->morphTo();
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo('FireflyIII\User');
+ }
+
+}
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
new file mode 100644
index 0000000000..90af507dae
--- /dev/null
+++ b/app/Models/Transaction.php
@@ -0,0 +1,48 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Watson\Validating\ValidatingTrait;
+
+/**
+ * Class Transaction
+ *
+ * @package FireflyIII\Models
+ */
+class Transaction extends Model
+{
+
+ protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount'];
+ protected $rules
+ = [
+ 'account_id' => 'required|exists:accounts,id',
+ 'transaction_journal_id' => 'required|exists:transaction_journals,id',
+ 'description' => 'between:1,255',
+ 'amount' => 'required|numeric'
+ ];
+ use SoftDeletes, ValidatingTrait;
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function account()
+ {
+ return $this->belongsTo('FireflyIII\Models\Account');
+ }
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function transactionJournal()
+ {
+ return $this->belongsTo('FireflyIII\Models\TransactionJournal');
+ }
+}
diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php
new file mode 100644
index 0000000000..9283709f9e
--- /dev/null
+++ b/app/Models/TransactionCurrency.php
@@ -0,0 +1,33 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * Class TransactionCurrency
+ *
+ * @package FireflyIII\Models
+ */
+class TransactionCurrency extends Model
+{
+ use SoftDeletes;
+
+
+ protected $fillable = ['name', 'code', 'symbol'];
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function transactionJournals()
+ {
+ return $this->hasMany('FireflyIII\Models\TransactionJournal');
+ }
+}
diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php
new file mode 100644
index 0000000000..3afbdba0f4
--- /dev/null
+++ b/app/Models/TransactionGroup.php
@@ -0,0 +1,39 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * Class TransactionGroup
+ *
+ * @package FireflyIII\Models
+ */
+class TransactionGroup extends Model
+{
+ use SoftDeletes;
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function transactionjournals()
+ {
+ return $this->belongsToMany('FireflyIII\Models\TransactionJournal');
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo('FireflyIII\User');
+ }
+
+}
diff --git a/app/Models/TransactionRelation.php b/app/Models/TransactionRelation.php
new file mode 100644
index 0000000000..058f395537
--- /dev/null
+++ b/app/Models/TransactionRelation.php
@@ -0,0 +1,21 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class TransactionRelation
+ *
+ * @package FireflyIII\Models
+ */
+class TransactionRelation extends Model
+{
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at'];
+ }
+
+}
diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php
new file mode 100644
index 0000000000..dbabd104f8
--- /dev/null
+++ b/app/Models/TransactionType.php
@@ -0,0 +1,30 @@
+<?php namespace FireflyIII\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * Class TransactionType
+ *
+ * @package FireflyIII\Models
+ */
+class TransactionType extends Model
+{
+ use SoftDeletes;
+
+ /**
+ * @return array
+ */
+ public function getDates()
+ {
+ return ['created_at', 'updated_at', 'deleted_at'];
+ }
+
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function transactionJournals()
+ {
+ return $this->hasMany('FireflyIII\Models\TransactionJournal');
+ }
+}