| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * GroupUpdateService.php | 
					
						
							| 
									
										
										
										
											2020-02-16 13:56:35 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Services\Internal\Update; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  | use FireflyIII\Events\TriggeredAuditLog; | 
					
						
							| 
									
										
										
										
											2021-09-18 10:20:19 +02:00
										 |  |  | use FireflyIII\Exceptions\DuplicateTransactionException; | 
					
						
							| 
									
										
										
										
											2019-06-02 16:33:25 +02:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							|  |  |  | use FireflyIII\Factory\TransactionJournalFactory; | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  | use FireflyIII\Models\TransactionGroup; | 
					
						
							|  |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2019-08-12 16:54:48 +02:00
										 |  |  | use FireflyIII\Services\Internal\Destroy\JournalDestroyService; | 
					
						
							| 
									
										
										
										
											2023-05-29 13:56:55 +02:00
										 |  |  | use JsonException; | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class GroupUpdateService | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class GroupUpdateService | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Update a transaction group. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |      * @param TransactionGroup $transactionGroup | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * @param array            $data | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return TransactionGroup | 
					
						
							| 
									
										
										
										
											2022-03-29 15:10:05 +02:00
										 |  |  |      * @throws DuplicateTransactionException | 
					
						
							| 
									
										
										
										
											2019-06-02 16:33:25 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2023-07-04 13:29:19 +02:00
										 |  |  |      * @throws JsonException | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function update(TransactionGroup $transactionGroup, array $data): TransactionGroup | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug(sprintf('Now in %s', __METHOD__)); | 
					
						
							|  |  |  |         app('log')->debug('Now in group update service', $data); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |         /** @var array $transactions */ | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |         $transactions = $data['transactions'] ?? []; | 
					
						
							|  |  |  |         // update group name.
 | 
					
						
							|  |  |  |         if (array_key_exists('group_title', $data)) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |             app('log')->debug(sprintf('Update transaction group #%d title.', $transactionGroup->id)); | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |             $oldTitle                = $transactionGroup->title; | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |             $transactionGroup->title = $data['group_title']; | 
					
						
							|  |  |  |             $transactionGroup->save(); | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |             event( | 
					
						
							|  |  |  |                 new TriggeredAuditLog( | 
					
						
							|  |  |  |                     $transactionGroup->user, | 
					
						
							|  |  |  |                     $transactionGroup, | 
					
						
							|  |  |  |                     'update_group_title', | 
					
						
							|  |  |  |                     $oldTitle, | 
					
						
							|  |  |  |                     $data['group_title'] | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-03-10 06:34:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-13 07:04:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-04 05:11:05 +01:00
										 |  |  |         if (0 === count($transactions)) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |             app('log')->debug('No transactions submitted, do nothing.'); | 
					
						
							| 
									
										
										
										
											2021-03-10 06:34:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return $transactionGroup; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |         if (1 === count($transactions) && 1 === $transactionGroup->transactionJournals()->count()) { | 
					
						
							|  |  |  |             /** @var TransactionJournal $first */ | 
					
						
							|  |  |  |             $first = $transactionGroup->transactionJournals()->first(); | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |             app('log')->debug( | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |                 sprintf('Will now update journal #%d (only journal in group #%d)', $first->id, $transactionGroup->id) | 
					
						
							|  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |             $this->updateTransactionJournal($transactionGroup, $first, reset($transactions)); | 
					
						
							|  |  |  |             $transactionGroup->refresh(); | 
					
						
							| 
									
										
										
										
											2019-06-01 20:38:18 +02:00
										 |  |  |             app('preferences')->mark(); | 
					
						
							| 
									
										
										
										
											2019-06-02 16:33:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |             return $transactionGroup; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-06-02 16:33:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug('Going to update split group.'); | 
					
						
							| 
									
										
										
										
											2019-06-02 16:33:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 16:54:48 +02:00
										 |  |  |         $existing = $transactionGroup->transactionJournals->pluck('id')->toArray(); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |         $updated  = $this->updateTransactions($transactionGroup, $transactions); | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug('Array of updated IDs: ', $updated); | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-28 20:49:37 +01:00
										 |  |  |         if (0 === count($updated)) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:32:00 +01:00
										 |  |  |             app('log')->error('There were no transactions updated or created. Will not delete anything.'); | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  |             $transactionGroup->refresh(); | 
					
						
							|  |  |  |             app('preferences')->mark(); | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  |             return $transactionGroup; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $result = array_diff($existing, $updated); | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug('Result of DIFF: ', $result); | 
					
						
							| 
									
										
										
										
											2019-08-12 16:54:48 +02:00
										 |  |  |         if (count($result) > 0) { | 
					
						
							|  |  |  |             /** @var string $deletedId */ | 
					
						
							|  |  |  |             foreach ($result as $deletedId) { | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |                 /** @var TransactionJournal $journal */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  |                 $journal = $transactionGroup->transactionJournals()->find((int)$deletedId); | 
					
						
							| 
									
										
										
										
											2019-08-12 16:54:48 +02:00
										 |  |  |                 /** @var JournalDestroyService $service */ | 
					
						
							|  |  |  |                 $service = app(JournalDestroyService::class); | 
					
						
							|  |  |  |                 $service->destroy($journal); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         app('preferences')->mark(); | 
					
						
							| 
									
										
										
										
											2020-02-14 07:49:29 +01:00
										 |  |  |         $transactionGroup->refresh(); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 16:33:25 +02:00
										 |  |  |         return $transactionGroup; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Update single journal. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |      * @param TransactionGroup   $transactionGroup | 
					
						
							|  |  |  |      * @param TransactionJournal $journal | 
					
						
							|  |  |  |      * @param array              $data | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |     private function updateTransactionJournal( | 
					
						
							|  |  |  |         TransactionGroup   $transactionGroup, | 
					
						
							|  |  |  |         TransactionJournal $journal, | 
					
						
							|  |  |  |         array              $data | 
					
						
							|  |  |  |     ): void { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug(sprintf('Now in %s', __METHOD__)); | 
					
						
							| 
									
										
										
										
											2022-11-04 05:11:05 +01:00
										 |  |  |         if (0 === count($data)) { | 
					
						
							| 
									
										
										
										
											2021-06-13 07:04:18 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-01-28 20:49:37 +01:00
										 |  |  |         if (1 === count($data) && array_key_exists('transaction_journal_id', $data)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |         /** @var JournalUpdateService $updateService */ | 
					
						
							|  |  |  |         $updateService = app(JournalUpdateService::class); | 
					
						
							|  |  |  |         $updateService->setTransactionGroup($transactionGroup); | 
					
						
							|  |  |  |         $updateService->setTransactionJournal($journal); | 
					
						
							|  |  |  |         $updateService->setData($data); | 
					
						
							|  |  |  |         $updateService->update(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |      * @param TransactionGroup $transactionGroup | 
					
						
							|  |  |  |      * @param array            $transactions | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2021-09-18 10:21:29 +02:00
										 |  |  |      * @throws DuplicateTransactionException | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2023-02-22 18:03:31 +01:00
										 |  |  |      * @throws JsonException | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     private function updateTransactions(TransactionGroup $transactionGroup, array $transactions): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug(sprintf('Now in %s', __METHOD__)); | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  |         // updated or created transaction journals:
 | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |         $updated = []; | 
					
						
							|  |  |  |         /** | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |          * @var int   $index | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |          * @var array $transaction | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         foreach ($transactions as $index => $transaction) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |             app('log')->debug(sprintf('Now at #%d of %d', ($index + 1), count($transactions)), $transaction); | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  |             $journalId = (int)($transaction['transaction_journal_id'] ?? 0); | 
					
						
							| 
									
										
										
										
											2021-04-06 17:00:16 +02:00
										 |  |  |             /** @var TransactionJournal|null $journal */ | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |             $journal = $transactionGroup->transactionJournals()->find($journalId); | 
					
						
							|  |  |  |             if (null === $journal) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                 app('log')->debug('This entry has no existing journal: make a new split.'); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |                 // force the transaction type on the transaction data.
 | 
					
						
							|  |  |  |                 // by plucking it from another journal in the group:
 | 
					
						
							| 
									
										
										
										
											2021-04-06 17:00:16 +02:00
										 |  |  |                 if (!array_key_exists('type', $transaction)) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                     app('log')->debug('No transaction type is indicated.'); | 
					
						
							| 
									
										
										
										
											2021-04-06 17:00:16 +02:00
										 |  |  |                     /** @var TransactionJournal|null $randomJournal */ | 
					
						
							| 
									
										
										
										
											2023-06-21 05:55:57 +02:00
										 |  |  |                     $randomJournal = $transactionGroup->transactionJournals()->inRandomOrder()->with( | 
					
						
							|  |  |  |                         ['transactionType'] | 
					
						
							|  |  |  |                     )->first(); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |                     if (null !== $randomJournal) { | 
					
						
							|  |  |  |                         $transaction['type'] = $randomJournal->transactionType->type; | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                         app('log')->debug(sprintf('Transaction type set to %s.', $transaction['type'])); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                 app('log')->debug('Call createTransactionJournal'); | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  |                 $newJournal = $this->createTransactionJournal($transactionGroup, $transaction); | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                 app('log')->debug('Done calling createTransactionJournal'); | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  |                 if (null !== $newJournal) { | 
					
						
							|  |  |  |                     $updated[] = $newJournal->id; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (null === $newJournal) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:32:00 +01:00
										 |  |  |                     app('log')->error('createTransactionJournal returned NULL, indicating something went wrong.'); | 
					
						
							| 
									
										
										
										
											2022-01-24 07:38:05 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (null !== $journal) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                 app('log')->debug('Call updateTransactionJournal'); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |                 $this->updateTransactionJournal($transactionGroup, $journal, $transaction); | 
					
						
							|  |  |  |                 $updated[] = $journal->id; | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |                 app('log')->debug('Done calling updateTransactionJournal'); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:33:06 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $updated; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param TransactionGroup $transactionGroup | 
					
						
							|  |  |  |      * @param array            $data | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return TransactionJournal|null | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws DuplicateTransactionException | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      * @throws JsonException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function createTransactionJournal(TransactionGroup $transactionGroup, array $data): ?TransactionJournal | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $submission = [ | 
					
						
							|  |  |  |             'transactions' => [ | 
					
						
							|  |  |  |                 $data, | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         /** @var TransactionJournalFactory $factory */ | 
					
						
							|  |  |  |         $factory = app(TransactionJournalFactory::class); | 
					
						
							|  |  |  |         $factory->setUser($transactionGroup->user); | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $collection = $factory->create($submission); | 
					
						
							|  |  |  |         } catch (FireflyException $e) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:32:00 +01:00
										 |  |  |             app('log')->error($e->getMessage()); | 
					
						
							|  |  |  |             app('log')->error($e->getTraceAsString()); | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |             throw new FireflyException( | 
					
						
							|  |  |  |                 sprintf('Could not create new transaction journal: %s', $e->getMessage()), | 
					
						
							|  |  |  |                 0, | 
					
						
							|  |  |  |                 $e | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $collection->each( | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |             static function (TransactionJournal $journal) use ($transactionGroup) { | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |                 $transactionGroup->transactionJournals()->save($journal); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         if (0 === $collection->count()) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $collection->first(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-17 12:09:03 +02:00
										 |  |  | } |