mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Some code cleanup.
This commit is contained in:
@@ -143,6 +143,79 @@ class TagRepository implements TagRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Can a tag become an advance payment?
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function tagAllowAdvance(Tag $tag)
|
||||
{
|
||||
/*
|
||||
* If this tag is a balancing act, and it contains transfers, it cannot be
|
||||
* changes to an advancePayment.
|
||||
*/
|
||||
|
||||
if ($tag->tagMode == 'balancingAct' || $tag->tagMode == 'nothing') {
|
||||
foreach ($tag->transactionjournals as $journal) {
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If this tag contains more than one expenses, it cannot become an advance payment.
|
||||
*/
|
||||
$count = 0;
|
||||
foreach ($tag->transactionjournals as $journal) {
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($count > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Can a tag become a balancing act?
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function tagAllowBalancing(Tag $tag)
|
||||
{
|
||||
/*
|
||||
* If has more than two transactions already, cannot become a balancing act:
|
||||
*/
|
||||
if ($tag->transactionjournals->count() > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If any transaction is a deposit, cannot become a balancing act.
|
||||
*/
|
||||
$count = 0;
|
||||
foreach ($tag->transactionjournals as $journal) {
|
||||
if ($journal->transactionType->type == 'Deposit') {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($count > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
|
@@ -18,6 +18,14 @@ interface TagRepositoryInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function connect(TransactionJournal $journal, Tag $tag);
|
||||
|
||||
/**
|
||||
* This method scans the transaction journals from or to the given asset account
|
||||
* and checks if these are part of a balancing act. If so, it will sum up the amounts
|
||||
@@ -34,6 +42,18 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function destroy(Tag $tag);
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
@@ -42,9 +62,22 @@ interface TagRepositoryInterface
|
||||
public function store(array $data);
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* Can a tag become an advance payment?
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get();
|
||||
public function tagAllowAdvance(Tag $tag);
|
||||
|
||||
/**
|
||||
* Can a tag become a balancing act?
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function tagAllowBalancing(Tag $tag);
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
@@ -53,19 +86,4 @@ interface TagRepositoryInterface
|
||||
* @return Tag
|
||||
*/
|
||||
public function update(Tag $tag, array $data);
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function destroy(Tag $tag);
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function connect(TransactionJournal $journal, Tag $tag);
|
||||
}
|
||||
|
Reference in New Issue
Block a user