mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Various code cleanup.
This commit is contained in:
@@ -39,6 +39,13 @@ interface LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function destroy(LinkType $linkType, LinkType $moveTo): bool;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroyLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
@@ -46,20 +53,6 @@ interface LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function find(int $id): LinkType;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroyLink(TransactionJournalLink $link):bool;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* Check if link exists between journals.
|
||||
*
|
||||
@@ -91,6 +84,13 @@ interface LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): LinkType;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param array $data
|
||||
|
||||
@@ -186,6 +186,34 @@ class TagRepository implements TagRepositoryInterface
|
||||
return new Carbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as sum of tag but substracts income instead of adding it as well.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resultOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): string
|
||||
{
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
|
||||
if (!is_null($start) && !is_null($end)) {
|
||||
$collector->setRange($start, $end);
|
||||
}
|
||||
|
||||
$collector->setAllAssetAccounts()->setTag($tag);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = '0';
|
||||
foreach ($journals as $journal) {
|
||||
$sum = bcadd($sum, strval($journal->transaction_amount));
|
||||
}
|
||||
|
||||
return strval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@@ -262,34 +290,6 @@ class TagRepository implements TagRepositoryInterface
|
||||
return strval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as sum of tag but substracts income instead of adding it as well.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resultOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): string
|
||||
{
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
|
||||
if (!is_null($start) && !is_null($end)) {
|
||||
$collector->setRange($start, $end);
|
||||
}
|
||||
|
||||
$collector->setAllAssetAccounts()->setTag($tag);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = '0';
|
||||
foreach ($journals as $journal) {
|
||||
$sum = bcadd($sum, strval($journal->transaction_amount));
|
||||
}
|
||||
|
||||
return strval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a tag cloud.
|
||||
*
|
||||
@@ -380,13 +380,14 @@ class TagRepository implements TagRepositoryInterface
|
||||
Log::debug(sprintf('AmountDiff is %f', $amountDiff));
|
||||
|
||||
// no difference? Every tag same range:
|
||||
if($amountDiff === 0.0) {
|
||||
if ($amountDiff === 0.0) {
|
||||
Log::debug(sprintf('AmountDiff is zero, return %d', $range[0]));
|
||||
|
||||
return $range[0];
|
||||
}
|
||||
|
||||
$diff = $range[1] - $range[0];
|
||||
$step = 1;
|
||||
$diff = $range[1] - $range[0];
|
||||
$step = 1;
|
||||
if ($diff != 0) {
|
||||
$step = $amountDiff / $diff;
|
||||
}
|
||||
|
||||
@@ -103,11 +103,6 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function lastUseDate(Tag $tag): Carbon;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
@@ -117,6 +112,11 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function resultOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): string;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
|
||||
Reference in New Issue
Block a user