mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Add new tests for transformers.
This commit is contained in:
@@ -308,6 +308,24 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return (int)$this->user->piggyBanks()->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return note for piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNoteText(PiggyBank $piggyBank): string
|
||||
{
|
||||
/** @var Note $note */
|
||||
$note = $piggyBank->notes()->first();
|
||||
if (null === $note) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -381,6 +399,31 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return $savePerMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBankEvent $event
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTransactionWithEvent(PiggyBankEvent $event): ?int
|
||||
{
|
||||
$journal = $event->transactionJournal;
|
||||
if (null === $journal) {
|
||||
return null;
|
||||
}
|
||||
if ((float)$event->amount < 0) {
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
|
||||
return $transaction->id ?? null;
|
||||
}
|
||||
if ((float)$event->amount > 0) {
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
|
||||
return $transaction->id ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get for piggy account what is left to put in piggies.
|
||||
*
|
||||
|
Reference in New Issue
Block a user