mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	🤖 Auto commit for release 'develop' on 2025-06-02
This commit is contained in:
		| @@ -85,7 +85,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
| 
 | ||||
|     public function expandGroup(TransactionGroup $group): array | ||||
|     { | ||||
|         $result = $group->toArray(); | ||||
|         $result                         = $group->toArray(); | ||||
|         $result['transaction_journals'] = []; | ||||
| 
 | ||||
|         /** @var TransactionJournal $journal */ | ||||
| @@ -98,16 +98,16 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
| 
 | ||||
|     private function expandJournal(TransactionJournal $journal): array | ||||
|     { | ||||
|         $array = $journal->toArray(); | ||||
|         $array['transactions'] = []; | ||||
|         $array['meta'] = $journal->transactionJournalMeta->toArray(); | ||||
|         $array['tags'] = $journal->tags->toArray(); | ||||
|         $array['categories'] = $journal->categories->toArray(); | ||||
|         $array['budgets'] = $journal->budgets->toArray(); | ||||
|         $array['notes'] = $journal->notes->toArray(); | ||||
|         $array['locations'] = []; | ||||
|         $array['attachments'] = $journal->attachments->toArray(); | ||||
|         $array['links'] = []; | ||||
|         $array                      = $journal->toArray(); | ||||
|         $array['transactions']      = []; | ||||
|         $array['meta']              = $journal->transactionJournalMeta->toArray(); | ||||
|         $array['tags']              = $journal->tags->toArray(); | ||||
|         $array['categories']        = $journal->categories->toArray(); | ||||
|         $array['budgets']           = $journal->budgets->toArray(); | ||||
|         $array['notes']             = $journal->notes->toArray(); | ||||
|         $array['locations']         = []; | ||||
|         $array['attachments']       = $journal->attachments->toArray(); | ||||
|         $array['links']             = []; | ||||
|         $array['piggy_bank_events'] = $journal->piggyBankEvents->toArray(); | ||||
| 
 | ||||
|         /** @var Transaction $transaction */ | ||||
| @@ -120,9 +120,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
| 
 | ||||
|     private function expandTransaction(Transaction $transaction): array | ||||
|     { | ||||
|         $array = $transaction->toArray(); | ||||
|         $array['account'] = $transaction->account->toArray(); | ||||
|         $array['budgets'] = []; | ||||
|         $array               = $transaction->toArray(); | ||||
|         $array['account']    = $transaction->account->toArray(); | ||||
|         $array['budgets']    = []; | ||||
|         $array['categories'] = []; | ||||
| 
 | ||||
|         foreach ($transaction->categories as $category) { | ||||
| @@ -143,24 +143,25 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|     { | ||||
|         $repository = app(AttachmentRepositoryInterface::class); | ||||
|         $repository->setUser($this->user); | ||||
|         $journals = $group->transactionJournals->pluck('id')->toArray(); | ||||
|         $set = Attachment::whereIn('attachable_id', $journals) | ||||
|         $journals   = $group->transactionJournals->pluck('id')->toArray(); | ||||
|         $set        = Attachment::whereIn('attachable_id', $journals) | ||||
|             ->where('attachable_type', TransactionJournal::class) | ||||
|             ->where('uploaded', true) | ||||
|             ->whereNull('deleted_at')->get(); | ||||
|             ->whereNull('deleted_at')->get() | ||||
|         ; | ||||
| 
 | ||||
|         $result = []; | ||||
|         $result     = []; | ||||
| 
 | ||||
|         /** @var Attachment $attachment */ | ||||
|         foreach ($set as $attachment) { | ||||
|             $journalId = $attachment->attachable_id; | ||||
|             $journalId                = $attachment->attachable_id; | ||||
|             $result[$journalId] ??= []; | ||||
|             $current = $attachment->toArray(); | ||||
|             $current['file_exists'] = true; | ||||
|             $current['notes'] = $repository->getNoteText($attachment); | ||||
|             $current                  = $attachment->toArray(); | ||||
|             $current['file_exists']   = true; | ||||
|             $current['notes']         = $repository->getNoteText($attachment); | ||||
|             // already determined that this attachable is a TransactionJournal.
 | ||||
|             $current['journal_title'] = $attachment->attachable->description; | ||||
|             $result[$journalId][] = $current; | ||||
|             $result[$journalId][]     = $current; | ||||
|         } | ||||
| 
 | ||||
|         return $result; | ||||
| @@ -174,7 +175,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|         /** @var null|Note $note */ | ||||
|         $note = Note::where('noteable_id', $journalId) | ||||
|             ->where('noteable_type', TransactionJournal::class) | ||||
|             ->first(); | ||||
|             ->first() | ||||
|         ; | ||||
|         if (null === $note) { | ||||
|             return null; | ||||
|         } | ||||
| @@ -187,9 +189,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|      */ | ||||
|     public function getLinks(TransactionGroup $group): array | ||||
|     { | ||||
|         $return = []; | ||||
|         $return   = []; | ||||
|         $journals = $group->transactionJournals->pluck('id')->toArray(); | ||||
|         $set = TransactionJournalLink::where( | ||||
|         $set      = TransactionJournalLink::where( | ||||
|             static function (Builder $q) use ($journals): void { | ||||
|                 $q->whereIn('source_id', $journals); | ||||
|                 $q->orWhereIn('destination_id', $journals); | ||||
| @@ -197,7 +199,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|         ) | ||||
|             ->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', 'link_types.editable']); | ||||
|             ->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']) | ||||
|         ; | ||||
| 
 | ||||
|         /** @var TransactionJournalLink $entry */ | ||||
|         foreach ($set as $entry) { | ||||
| @@ -207,28 +210,28 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|             // phpstan: the editable field is provided by the query.
 | ||||
| 
 | ||||
|             if ($journalId === $entry->source_id) { | ||||
|                 $amount = $this->getFormattedAmount($entry->destination); | ||||
|                 $foreignAmount = $this->getFormattedForeignAmount($entry->destination); | ||||
|                 $amount               = $this->getFormattedAmount($entry->destination); | ||||
|                 $foreignAmount        = $this->getFormattedForeignAmount($entry->destination); | ||||
|                 $return[$journalId][] = [ | ||||
|                     'id' => $entry->id, | ||||
|                     'link' => $entry->outward, | ||||
|                     'group' => $entry->destination->transaction_group_id, | ||||
|                     'description' => $entry->destination->description, | ||||
|                     'editable' => 1 === (int)$entry->editable, | ||||
|                     'amount' => $amount, | ||||
|                     'id'             => $entry->id, | ||||
|                     'link'           => $entry->outward, | ||||
|                     'group'          => $entry->destination->transaction_group_id, | ||||
|                     'description'    => $entry->destination->description, | ||||
|                     'editable'       => 1 === (int)$entry->editable, | ||||
|                     'amount'         => $amount, | ||||
|                     'foreign_amount' => $foreignAmount, | ||||
|                 ]; | ||||
|             } | ||||
|             if ($journalId === $entry->destination_id) { | ||||
|                 $amount = $this->getFormattedAmount($entry->source); | ||||
|                 $foreignAmount = $this->getFormattedForeignAmount($entry->source); | ||||
|                 $amount               = $this->getFormattedAmount($entry->source); | ||||
|                 $foreignAmount        = $this->getFormattedForeignAmount($entry->source); | ||||
|                 $return[$journalId][] = [ | ||||
|                     'id' => $entry->id, | ||||
|                     'link' => $entry->inward, | ||||
|                     'group' => $entry->source->transaction_group_id, | ||||
|                     'description' => $entry->source->description, | ||||
|                     'editable' => 1 === (int)$entry->editable, | ||||
|                     'amount' => $amount, | ||||
|                     'id'             => $entry->id, | ||||
|                     'link'           => $entry->inward, | ||||
|                     'group'          => $entry->source->transaction_group_id, | ||||
|                     'description'    => $entry->source->description, | ||||
|                     'editable'       => 1 === (int)$entry->editable, | ||||
|                     'amount'         => $amount, | ||||
|                     'foreign_amount' => $foreignAmount, | ||||
|                 ]; | ||||
|             } | ||||
| @@ -241,9 +244,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|     { | ||||
|         /** @var Transaction $transaction */ | ||||
|         $transaction = $journal->transactions->first(); | ||||
|         $currency = $transaction->transactionCurrency; | ||||
|         $type = $journal->transactionType->type; | ||||
|         $amount = app('steam')->positive($transaction->amount); | ||||
|         $currency    = $transaction->transactionCurrency; | ||||
|         $type        = $journal->transactionType->type; | ||||
|         $amount      = app('steam')->positive($transaction->amount); | ||||
|         if (TransactionTypeEnum::WITHDRAWAL->value === $type) { | ||||
|             return app('amount')->formatAnything($currency, app('steam')->negative($amount)); | ||||
|         } | ||||
| @@ -264,9 +267,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|         if (0 === bccomp('0', (string)$transaction->foreign_amount)) { | ||||
|             return ''; | ||||
|         } | ||||
|         $currency = $transaction->foreignCurrency; | ||||
|         $type = $journal->transactionType->type; | ||||
|         $amount = app('steam')->positive($transaction->foreign_amount); | ||||
|         $currency    = $transaction->foreignCurrency; | ||||
|         $type        = $journal->transactionType->type; | ||||
|         $amount      = app('steam')->positive($transaction->foreign_amount); | ||||
|         if (TransactionTypeEnum::WITHDRAWAL->value === $type) { | ||||
|             return app('amount')->formatAnything($currency, app('steam')->negative($amount)); | ||||
|         } | ||||
| @@ -293,11 +296,12 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|      */ | ||||
|     public function getMetaDateFields(int $journalId, array $fields): NullArrayObject | ||||
|     { | ||||
|         $query = DB::table('journal_meta') | ||||
|         $query  = DB::table('journal_meta') | ||||
|             ->where('transaction_journal_id', $journalId) | ||||
|             ->whereIn('name', $fields) | ||||
|             ->whereNull('deleted_at') | ||||
|             ->get(['name', 'data']); | ||||
|             ->get(['name', 'data']) | ||||
|         ; | ||||
|         $return = []; | ||||
| 
 | ||||
|         foreach ($query as $row) { | ||||
| @@ -312,11 +316,12 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|      */ | ||||
|     public function getMetaFields(int $journalId, array $fields): NullArrayObject | ||||
|     { | ||||
|         $query = DB::table('journal_meta') | ||||
|         $query  = DB::table('journal_meta') | ||||
|             ->where('transaction_journal_id', $journalId) | ||||
|             ->whereIn('name', $fields) | ||||
|             ->whereNull('deleted_at') | ||||
|             ->get(['name', 'data']); | ||||
|             ->get(['name', 'data']) | ||||
|         ; | ||||
|         $return = []; | ||||
| 
 | ||||
|         foreach ($query as $row) { | ||||
| @@ -333,12 +338,13 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|      */ | ||||
|     public function getPiggyEvents(TransactionGroup $group): array | ||||
|     { | ||||
|         $return = []; | ||||
|         $return   = []; | ||||
|         $journals = $group->transactionJournals->pluck('id')->toArray(); | ||||
|         $currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); | ||||
|         $data = PiggyBankEvent::whereIn('transaction_journal_id', $journals) | ||||
|         $data     = PiggyBankEvent::whereIn('transaction_journal_id', $journals) | ||||
|             ->with('piggyBank', 'piggyBank.account') | ||||
|             ->get(['piggy_bank_events.*']); | ||||
|             ->get(['piggy_bank_events.*']) | ||||
|         ; | ||||
| 
 | ||||
|         /** @var PiggyBankEvent $row */ | ||||
|         foreach ($data as $row) { | ||||
| @@ -346,19 +352,20 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|                 continue; | ||||
|             } | ||||
|             // get currency preference.
 | ||||
|             $currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id) | ||||
|             $currencyPreference   = AccountMeta::where('account_id', $row->piggyBank->account_id) | ||||
|                 ->where('name', 'currency_id') | ||||
|                 ->first(); | ||||
|                 ->first() | ||||
|             ; | ||||
|             if (null !== $currencyPreference) { | ||||
|                 $currency = TransactionCurrency::where('id', $currencyPreference->data)->first(); | ||||
|             } | ||||
|             $journalId = $row->transaction_journal_id; | ||||
|             $journalId            = $row->transaction_journal_id; | ||||
|             $return[$journalId] ??= []; | ||||
| 
 | ||||
|             $return[$journalId][] = [ | ||||
|                 'piggy' => $row->piggyBank->name, | ||||
|                 'piggy'    => $row->piggyBank->name, | ||||
|                 'piggy_id' => $row->piggy_bank_id, | ||||
|                 'amount' => app('amount')->formatAnything($currency, $row->amount), | ||||
|                 'amount'   => app('amount')->formatAnything($currency, $row->amount), | ||||
|             ]; | ||||
|         } | ||||
| 
 | ||||
| @@ -382,7 +389,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|             ->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id') | ||||
|             ->where('tag_transaction_journal.transaction_journal_id', $journalId) | ||||
|             ->orderBy('tags.tag', 'ASC') | ||||
|             ->get(['tags.tag']); | ||||
|             ->get(['tags.tag']) | ||||
|         ; | ||||
| 
 | ||||
|         return $result->pluck('tag')->toArray(); | ||||
|     } | ||||
| @@ -427,7 +435,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
| 
 | ||||
|     public function getCompareHash(TransactionGroup $group): string | ||||
|     { | ||||
|         $sum = '0'; | ||||
|         $sum   = '0'; | ||||
|         $names = ''; | ||||
| 
 | ||||
|         /** @var TransactionJournal $journal */ | ||||
| @@ -435,7 +443,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, | ||||
|             /** @var Transaction $transaction */ | ||||
|             foreach ($journal->transactions as $transaction) { | ||||
|                 if (-1 === bccomp('0', (string)$transaction->amount)) { | ||||
|                     $sum = bcadd($sum, $transaction->amount); | ||||
|                     $sum   = bcadd($sum, $transaction->amount); | ||||
|                     $names = sprintf('%s%s', $names, $transaction->account->name); | ||||
|                 } | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user