added custom transaction types

This commit is contained in:
Denis Duliçi
2020-08-26 15:14:16 +03:00
parent d64917a3e0
commit 68f31b895f
11 changed files with 115 additions and 23 deletions

View File

@ -8,11 +8,13 @@ use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Media;
use App\Traits\Recurring;
use App\Traits\Transactions;
use Bkwld\Cloner\Cloneable;
use Illuminate\Support\Str;
class Transaction extends Model
{
use Cloneable, Currencies, DateTime, Media, Recurring;
use Cloneable, Currencies, DateTime, Media, Recurring, Transactions;
protected $table = 'transactions';
@ -103,7 +105,7 @@ class Transaction extends Model
*/
public function scopeIncome($query)
{
return $query->where($this->table . '.type', '=', 'income');
return $query->whereIn($this->table . '.type', (array) $this->getIncomeTypes());
}
/**
@ -114,7 +116,7 @@ class Transaction extends Model
*/
public function scopeExpense($query)
{
return $query->where($this->table . '.type', '=', 'expense');
return $query->whereIn($this->table . '.type', (array) $this->getExpenseTypes());
}
/**
@ -279,4 +281,14 @@ class Transaction extends Model
return $this->getMedia('attachment')->last();
}
/**
* Get the title of type.
*
* @return string
*/
public function getTypeTitleAttribute($value)
{
return $value ?? trans_choice('general.' . Str::plural($this->type), 1);
}
}