mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Basic list, no functionalities.
This commit is contained in:
@@ -29,11 +29,16 @@ use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionGroupFactory;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Services\Internal\Update\GroupUpdateService;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -72,16 +77,15 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
$result = [];
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($set as $attachment) {
|
||||
$journalId = (int)$attachment->attachable_id;
|
||||
$result[$journalId] = $result[$journalId] ?? [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['journal_title'] = $attachment->attachable->description;
|
||||
$result[] = $current;
|
||||
$result[$journalId][] = $current;
|
||||
|
||||
}
|
||||
|
||||
//$result = $set->toArray();
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -103,25 +107,34 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
$q->orWhereIn('destination_id', $journals);
|
||||
}
|
||||
)
|
||||
->with(['source', 'destination'])
|
||||
->with(['source', 'destination', 'source.transactions'])
|
||||
->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id')
|
||||
->get(['journal_links.*', 'link_types.inward', 'link_types.outward']);
|
||||
/** @var TransactionJournalLink $entry */
|
||||
foreach ($set as $entry) {
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$return[$journalId] = $return[$journalId] ?? [];
|
||||
|
||||
if ($journalId === $entry->source_id) {
|
||||
$amount = $this->getFormattedAmount($entry->destination);
|
||||
$foreignAmount = $this->getFormattedForeignAmount($entry->destination);
|
||||
$return[$journalId][] = [
|
||||
'link' => $entry->outward,
|
||||
'group' => $entry->destination->transaction_group_id,
|
||||
'description' => $entry->destination->description,
|
||||
'link' => $entry->outward,
|
||||
'group' => $entry->destination->transaction_group_id,
|
||||
'description' => $entry->destination->description,
|
||||
'amount' => $amount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
];
|
||||
}
|
||||
if ($journalId === $entry->destination_id) {
|
||||
$amount = $this->getFormattedAmount($entry->source);
|
||||
$foreignAmount = $this->getFormattedForeignAmount($entry->source);
|
||||
$return[$journalId][] = [
|
||||
'link' => $entry->inward,
|
||||
'group' => $entry->source->transaction_group_id,
|
||||
'description' => $entry->source->description,
|
||||
'link' => $entry->inward,
|
||||
'group' => $entry->source->transaction_group_id,
|
||||
'description' => $entry->source->description,
|
||||
'amount' => $amount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -210,7 +223,37 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
*/
|
||||
public function getPiggyEvents(TransactionGroup $group): array
|
||||
{
|
||||
return [];
|
||||
$return = [];
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$data = PiggyBankEvent
|
||||
::whereIn('transaction_journal_id', $journals)
|
||||
->with('piggyBank', 'piggyBank.account')
|
||||
->get(['piggy_bank_events.*']);
|
||||
/** @var PiggyBankEvent $row */
|
||||
foreach ($data as $row) {
|
||||
// get currency preference.
|
||||
$currencyPreference = AccountMeta
|
||||
::where('account_id', $row->piggyBank->account_id)
|
||||
->where('name', 'currency_id')
|
||||
->first();
|
||||
if (null !== $currencyPreference) {
|
||||
$currency = TransactionCurrency::where('id', $currencyPreference->data)->first();
|
||||
}
|
||||
if (null === $currencyPreference) {
|
||||
$currencyCode = app('preferences')->getForUser($this->user, 'currencyPreference', 'EUR')->data;
|
||||
$currency = TransactionCurrency::where('code', $currencyCode)->first();
|
||||
}
|
||||
$journalId = (int)$row->transaction_journal_id;
|
||||
$return[$journalId] = $return[$journalId] ?? [];
|
||||
|
||||
$return[$journalId][] = [
|
||||
'piggy' => $row->piggyBank->name,
|
||||
'piggy_id' => $row->piggy_bank_id,
|
||||
'amount' => app('amount')->formatAnything($currency, $row->amount),
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,4 +314,54 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
|
||||
return $updatedGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedAmount(TransactionJournal $journal): string
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
$currency = $transaction->transactionCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $type) {
|
||||
$return = app('amount')->formatAnything($currency, $amount);
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedForeignAmount(TransactionJournal $journal): string
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
if (null === $transaction->foreign_amount) {
|
||||
return '';
|
||||
}
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $type) {
|
||||
$return = app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user