-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d64917a
commit 68f31b8
Showing
11 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Traits; | ||
|
||
trait Transactions | ||
{ | ||
public function isIncome() | ||
{ | ||
$type = $this->type ?? $this->transaction->type ?? 'income'; | ||
|
||
return in_array($type, $this->getIncomeTypes()); | ||
} | ||
|
||
public function isExpense() | ||
{ | ||
$type = $this->type ?? $this->transaction->type ?? 'expense'; | ||
|
||
return in_array($type, $this->getExpenseTypes()); | ||
} | ||
|
||
public function getIncomeTypes($return = 'array') | ||
{ | ||
return $this->getTransactionTypes('income', $return); | ||
} | ||
|
||
public function getExpenseTypes($return = 'array') | ||
{ | ||
return $this->getTransactionTypes('expense', $return); | ||
} | ||
|
||
public function getTransactionTypes($index, $return = 'array') | ||
{ | ||
$types = (string) setting('transaction.type.' . $index); | ||
|
||
return ($return == 'array') ? explode(',', $types) : $types; | ||
} | ||
|
||
public function addIncomeType($new_type) | ||
{ | ||
$this->addTransactionType($new_type, 'income'); | ||
} | ||
|
||
public function addExpenseType($new_type) | ||
{ | ||
$this->addTransactionType($new_type, 'expense'); | ||
} | ||
|
||
public function addTransactionType($new_type, $index) | ||
{ | ||
$types = explode(',', setting('transaction.type.' . $index)); | ||
|
||
if (in_array($new_type, $types)) { | ||
return; | ||
} | ||
|
||
$types[] = $new_type; | ||
|
||
setting([ | ||
'transaction.type.' . $index => implode(',', $types), | ||
])->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters