Skip to content

Firefly III: a personal finances manager

Clean up lots of models.

James Cole5b5acba81625
diff --git a/app/Models/Account.php b/app/Models/Account.php
index bc06e9b665..2d07b89f37 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -36,12 +36,25 @@ class Account extends Model
{
use SoftDeletes, ValidatingTrait;
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'active' => 'boolean',
+ 'encrypted' => 'boolean',
+ ];
/** @var array */
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/** @var array */
protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
/** @var array */
- protected $hidden = ['virtual_balance_encrypted', 'encrypted'];
+ protected $hidden = ['encrypted'];
protected $rules
= [
'user_id' => 'required|exists:users,id',
@@ -184,7 +197,7 @@ class Account extends Model
public function getNameAttribute($value): string
{
- if (intval($this->encrypted) == 1) {
+ if ($this->encrypted) {
return Crypt::decrypt($value);
}
diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php
index d8c08233a5..797058c122 100644
--- a/app/Models/AccountMeta.php
+++ b/app/Models/AccountMeta.php
@@ -24,7 +24,18 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AccountMeta extends Model
{
- protected $dates = ['created_at', 'updated_at'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at'];
protected $fillable = ['account_id', 'name', 'data'];
protected $table = 'account_meta';
diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php
index 0bf346f471..3efa588ada 100644
--- a/app/Models/AccountType.php
+++ b/app/Models/AccountType.php
@@ -33,6 +33,18 @@ class AccountType extends Model
const IMPORT = 'Import account';
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
+
+ /** @var array */
protected $dates = ['created_at', 'updated_at'];
//
diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php
index eff2095f78..84dfbfc106 100644
--- a/app/Models/Attachment.php
+++ b/app/Models/Attachment.php
@@ -29,6 +29,21 @@ class Attachment extends Model
{
use SoftDeletes;
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'uploaded' => 'boolean',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+ /** @var array */
protected $fillable = ['attachable_id', 'attachable_type', 'user_id', 'md5', 'filename', 'mime', 'title', 'notes', 'description', 'size', 'uploaded'];
/**
diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php
index 330cc0821f..c96893fbb9 100644
--- a/app/Models/AvailableBudget.php
+++ b/app/Models/AvailableBudget.php
@@ -27,10 +27,24 @@ class AvailableBudget extends Model
{
use SoftDeletes;
/** @var array */
- protected $dates = ['created_at', 'updated_at', 'deleted_at', 'start_date', 'end_date'];
- /** @var array */
protected $fillable = ['user_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date'];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'start_date' => 'date',
+ 'end_date' => 'date',
+ ];
+
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index 7c6ca35924..a536caa18e 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -29,8 +29,26 @@ class Bill extends Model
{
use ValidatingTrait;
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
- protected $dates = ['created_at', 'updated_at', 'date'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'date' => 'date',
+ 'skip' => 'int',
+ 'automatch' => 'boolean',
+ 'active' => 'boolean',
+ 'name_encrypted' => 'boolean',
+ 'match_encrypted' => 'boolean',
+ ];
protected $fillable
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
'automatch', 'active',];
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index 8d073fa561..6bca976677 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -30,7 +30,23 @@ class Budget extends Model
use SoftDeletes, ValidatingTrait;
- protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'enddate'];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'active' => 'boolean',
+ 'encrypted' => 'boolean',
+ ];
+
protected $fillable = ['user_id', 'name', 'active'];
protected $hidden = ['encrypted'];
protected $rules = ['name' => 'required|between:1,200',];
@@ -95,7 +111,7 @@ class Budget extends Model
public function getNameAttribute($value)
{
- if (intval($this->encrypted) == 1) {
+ if ($this->encrypted) {
return Crypt::decrypt($value);
}
@@ -115,8 +131,8 @@ class Budget extends Model
*/
public function setNameAttribute($value)
{
- $this->attributes['name'] = Crypt::encrypt($value);
- $this->attributes['encrypted'] = true;
+ $this->attributes['name'] = $value;
+ $this->attributes['encrypted'] = false;
}
/**
diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php
index 86322743bd..622ad9bbc7 100644
--- a/app/Models/BudgetLimit.php
+++ b/app/Models/BudgetLimit.php
@@ -23,7 +23,20 @@ use Illuminate\Database\Eloquent\Model;
class BudgetLimit extends Model
{
- protected $dates = ['created_at', 'updated_at', 'startdate'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'startdate' => 'date',
+ 'repeats' => 'boolean',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at'];
protected $hidden = ['amount_encrypted'];
/**
diff --git a/app/Models/Category.php b/app/Models/Category.php
index b80e03d1b7..c0db1259b8 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -29,10 +29,26 @@ class Category extends Model
{
use SoftDeletes, ValidatingTrait;
- protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'encrypted' => 'boolean',
+ ];
+ /** @var array */
protected $fillable = ['user_id', 'name'];
+ /** @var array */
protected $hidden = ['encrypted'];
+ /** @var array */
protected $rules = ['name' => 'required|between:1,200',];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
* @param array $fields
@@ -86,7 +102,7 @@ class Category extends Model
public function getNameAttribute($value)
{
- if (intval($this->encrypted) == 1) {
+ if ($this->encrypted) {
return Crypt::decrypt($value);
}
@@ -99,8 +115,8 @@ class Category extends Model
*/
public function setNameAttribute($value)
{
- $this->attributes['name'] = Crypt::encrypt($value);
- $this->attributes['encrypted'] = true;
+ $this->attributes['name'] = $value;
+ $this->attributes['encrypted'] = false;
}
/**
diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php
index 9bbee9e894..b5edf6aced 100644
--- a/app/Models/Configuration.php
+++ b/app/Models/Configuration.php
@@ -25,6 +25,17 @@ class Configuration extends Model
{
use SoftDeletes;
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
+ /** @var array */
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $table = 'configuration';
diff --git a/app/Models/ExportJob.php b/app/Models/ExportJob.php
index 9a3807c728..a0eb58cfed 100644
--- a/app/Models/ExportJob.php
+++ b/app/Models/ExportJob.php
@@ -23,6 +23,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*/
class ExportJob extends Model
{
+ /** @var array */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at'];
+
/**
* @param $value
*
diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.php
index 01094638e4..b8a7bd27c3 100644
--- a/app/Models/ImportJob.php
+++ b/app/Models/ImportJob.php
@@ -27,6 +27,19 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ImportJob extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at'];
+
protected $validStatus
= [
'import_status_never_started', // initial state
diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php
index be87b5accf..9c76eab93f 100644
--- a/app/Models/LimitRepetition.php
+++ b/app/Models/LimitRepetition.php
@@ -26,6 +26,18 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class LimitRepetition extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'startdate' => 'date',
+ 'enddate' => 'date',
+ ];
protected $dates = ['created_at', 'updated_at', 'startdate', 'enddate'];
protected $hidden = ['amount_encrypted'];
@@ -38,10 +50,10 @@ class LimitRepetition extends Model
{
if (auth()->check()) {
$object = self::where('limit_repetitions.id', $value)
- ->leftJoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
- ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
- ->where('budgets.user_id', auth()->user()->id)
- ->first(['limit_repetitions.*']);
+ ->leftJoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
+ ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
+ ->where('budgets.user_id', auth()->user()->id)
+ ->first(['limit_repetitions.*']);
if ($object) {
return $object;
}
diff --git a/app/Models/Note.php b/app/Models/Note.php
index 1465008ecf..58600a8073 100644
--- a/app/Models/Note.php
+++ b/app/Models/Note.php
@@ -23,10 +23,20 @@ use League\CommonMark\CommonMarkConverter;
*/
class Note extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ ];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['title', 'text'];
-
/**
* @return string
*/
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index 2e3f1f01b0..e9b6b4a980 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -29,10 +29,25 @@ class PiggyBank extends Model
{
use SoftDeletes;
- protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
- protected $fillable
- = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate'];
- protected $hidden = ['targetamount_encrypted', 'encrypted'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'startdate' => 'date',
+ 'targetdate' => 'date',
+ 'order' => 'int',
+ 'active' => 'boolean',
+ 'encrypted' => 'boolean',
+ ];
+ protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
+ protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate'];
+ protected $hidden = ['targetamount_encrypted', 'encrypted'];
/**
* @param PiggyBank $value
@@ -86,7 +101,7 @@ class PiggyBank extends Model
public function getNameAttribute($value)
{
- if (intval($this->encrypted) == 1) {
+ if ($this->encrypted) {
return Crypt::decrypt($value);
}
@@ -144,8 +159,8 @@ class PiggyBank extends Model
*/
public function setNameAttribute($value)
{
- $this->attributes['name'] = Crypt::encrypt($value);
- $this->attributes['encrypted'] = true;
+ $this->attributes['name'] = $value;
+ $this->attributes['encrypted'] = false;
}
/**
diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php
index ac11ec0d70..be731402ab 100644
--- a/app/Models/PiggyBankEvent.php
+++ b/app/Models/PiggyBankEvent.php
@@ -23,6 +23,17 @@ use Illuminate\Database\Eloquent\Model;
class PiggyBankEvent extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'date' => 'date',
+ ];
protected $dates = ['created_at', 'updated_at', 'date'];
protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'amount'];
protected $hidden = ['amount_encrypted'];
diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php
index cc1432e31b..8b048879df 100644
--- a/app/Models/PiggyBankRepetition.php
+++ b/app/Models/PiggyBankRepetition.php
@@ -25,9 +25,21 @@ use Illuminate\Database\Eloquent\Model;
class PiggyBankRepetition extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'startdate' => 'date',
+ 'targetdate' => 'date',
+ ];
protected $dates = ['created_at', 'updated_at', 'startdate', 'targetdate'];
protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount'];
- protected $hidden = ['currentamount_encrypted'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
diff --git a/app/Models/Preference.php b/app/Models/Preference.php
index 10f38ddd2d..5ec7b943ad 100644
--- a/app/Models/Preference.php
+++ b/app/Models/Preference.php
@@ -27,6 +27,16 @@ use Log;
class Preference extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
protected $dates = ['created_at', 'updated_at'];
protected $fillable = ['user_id', 'data', 'name', 'data'];
diff --git a/app/Models/Role.php b/app/Models/Role.php
index 23584fd274..5f1a7c33e9 100644
--- a/app/Models/Role.php
+++ b/app/Models/Role.php
@@ -23,6 +23,17 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
*/
class Role extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ ];
+ protected $dates = ['created_at', 'updated_at'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
diff --git a/app/Models/Rule.php b/app/Models/Rule.php
index 09f8897326..ad3db4309c 100644
--- a/app/Models/Rule.php
+++ b/app/Models/Rule.php
@@ -26,6 +26,23 @@ class Rule extends Model
{
use SoftDeletes;
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'active' => 'boolean',
+ 'order' => 'int',
+ 'stop_processing' => 'boolean',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+
/**
* @param Rule $value
*
diff --git a/app/Models/RuleAction.php b/app/Models/RuleAction.php
index 6a5cc3a45b..8817a108dc 100644
--- a/app/Models/RuleAction.php
+++ b/app/Models/RuleAction.php
@@ -22,6 +22,22 @@ use Illuminate\Database\Eloquent\Model;
*/
class RuleAction extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'active' => 'boolean',
+ 'order' => 'int',
+ 'stop_processing' => 'boolean',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at'];
+
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.php
index f3dc6abd20..b4be42a160 100644
--- a/app/Models/RuleGroup.php
+++ b/app/Models/RuleGroup.php
@@ -25,6 +25,22 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class RuleGroup extends Model
{
use SoftDeletes;
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'active' => 'boolean',
+ 'order' => 'int',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+
protected $fillable = ['user_id', 'order', 'title', 'description', 'active'];
diff --git a/app/Models/RuleTrigger.php b/app/Models/RuleTrigger.php
index 72fe0f76a4..048d1c94fc 100644
--- a/app/Models/RuleTrigger.php
+++ b/app/Models/RuleTrigger.php
@@ -22,6 +22,22 @@ use Illuminate\Database\Eloquent\Model;
*/
class RuleTrigger extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'active' => 'boolean',
+ 'order' => 'int',
+ 'stop_processing' => 'boolean',
+ ];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at'];
+
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index 6912a47582..769ea2c5af 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -15,6 +15,7 @@ namespace FireflyIII\Models;
use Crypt;
use FireflyIII\Support\Models\TagSupport;
+use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
@@ -25,11 +26,25 @@ use Watson\Validating\ValidatingTrait;
*/
class Tag extends TagSupport
{
- protected $dates = ['created_at', 'updated_at', 'date'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'date' => 'date',
+ 'zoomLevel' => 'int',
+
+ ];
+ protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at'];
protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode'];
protected $rules = ['tag' => 'required|between:1,200',];
- use ValidatingTrait;
+ use ValidatingTrait, SoftDeletes;
/**
* @param array $fields
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
index 6a93196cfb..cf6a061c74 100644
--- a/app/Models/Transaction.php
+++ b/app/Models/Transaction.php
@@ -27,6 +27,18 @@ use Watson\Validating\ValidatingTrait;
class Transaction extends Model
{
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'identifier' => 'int',
+ ];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount', 'identifier'];
protected $hidden = ['encrypted'];
@@ -37,7 +49,6 @@ class Transaction extends Model
'description' => 'between:0,1024',
'amount' => 'required|numeric',
];
-
use SoftDeletes, ValidatingTrait;
/**
diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php
index 3e48b6c1d4..aded707d80 100644
--- a/app/Models/TransactionCurrency.php
+++ b/app/Models/TransactionCurrency.php
@@ -27,11 +27,20 @@ class TransactionCurrency extends Model
{
use SoftDeletes, ValidatingTrait;
-
- protected $dates = ['created_at', 'updated_at', 'deleted_at'];
+ protected $dates = ['created_at', 'updated_at', 'deleted_at','date'];
protected $fillable = ['name', 'code', 'symbol'];
protected $rules = ['name' => 'required|between:1,200', 'code' => 'required|between:3,3', 'symbol' => 'required|between:1,12'];
-
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ ];
/**
* @param TransactionCurrency $currency
*
diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php
deleted file mode 100644
index 46ff2d6e2c..0000000000
--- a/app/Models/TransactionGroup.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * TransactionGroup.php
- * Copyright (C) 2016 [email protected]
- *
- * This software may be modified and distributed under the terms of the
- * Creative Commons Attribution-ShareAlike 4.0 International License.
- *
- * See the LICENSE file for details.
- */
-
-declare(strict_types = 1);
-
-namespace FireflyIII\Models;
-
-use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\SoftDeletes;
-
-/**
- * Class TransactionGroup
- *
- * @package FireflyIII\Models
- */
-class TransactionGroup extends Model
-{
- use SoftDeletes;
-
- protected $dates = ['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/TransactionJournal.php b/app/Models/TransactionJournal.php
index 56773f7b5c..1cf5faf17f 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -34,6 +34,25 @@ class TransactionJournal extends TransactionJournalSupport
{
use SoftDeletes, ValidatingTrait;
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ 'date' => 'date',
+ 'interest_date' => 'date',
+ 'book_date' => 'date',
+ 'process_date' => 'date',
+ 'order' => 'int',
+ 'tag_count' => 'int',
+ 'encrypted' => 'boolean',
+ 'completed' => 'boolean',
+ ];
/** @var array */
protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at', 'interest_date', 'book_date', 'process_date'];
/** @var array */
@@ -65,9 +84,9 @@ class TransactionJournal extends TransactionJournalSupport
{
if (auth()->check()) {
$object = self::where('transaction_journals.id', $value)
- ->with('transactionType')
- ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
+ ->with('transactionType')
+ ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
+ ->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
if (!is_null($object)) {
return $object;
}
@@ -352,8 +371,8 @@ class TransactionJournal extends TransactionJournalSupport
*/
public function setDescriptionAttribute($value)
{
- $this->attributes['description'] = Crypt::encrypt($value);
- $this->attributes['encrypted'] = true;
+ $this->attributes['description'] = $value;
+ $this->attributes['encrypted'] = false;
}
/**
diff --git a/app/Models/TransactionJournalMeta.php b/app/Models/TransactionJournalMeta.php
index 2f57d9ad27..6d54430a47 100644
--- a/app/Models/TransactionJournalMeta.php
+++ b/app/Models/TransactionJournalMeta.php
@@ -26,7 +26,18 @@ class TransactionJournalMeta extends Model
{
use SoftDeletes;
- protected $dates = ['created_at', 'updated_at'];
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ ];
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['transaction_journal_id', 'name', 'data', 'hash'];
protected $table = 'journal_meta';
diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php
index 9d0e6af288..aceffbd8fb 100644
--- a/app/Models/TransactionType.php
+++ b/app/Models/TransactionType.php
@@ -31,6 +31,18 @@ class TransactionType extends Model
const TRANSFER = 'Transfer';
const OPENING_BALANCE = 'Opening balance';
+ /**
+ * The attributes that should be casted to native types.
+ *
+ * @var array
+ */
+ protected $casts
+ = [
+ 'created_at' => 'date',
+ 'updated_at' => 'date',
+ 'deleted_at' => 'date',
+ ];
+
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index b3c916e49b..ab2cc761bd 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -343,7 +343,9 @@ class AccountRepository implements AccountRepositoryInterface
$account->save();
$this->updateMetadata($account, $data);
- $this->updateInitialBalance($account, $data);
+ if ($this->validOpeningBalanceData($data)) {
+ $this->updateInitialBalance($account, $data);
+ }
return $account;
}
@@ -448,7 +450,6 @@ class AccountRepository implements AccountRepositoryInterface
'description' => 'Initial balance for "' . $account->name . '"',
'completed' => true,
'date' => $data['openingBalanceDate'],
- 'encrypted' => true,
]
);
Log::debug(sprintf('Created new opening balance journal: #%d', $journal->id));