| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * RecurrenceTransformer.php | 
					
						
							| 
									
										
										
										
											2020-02-16 13:57:18 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +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. | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +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. | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +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/>. | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Transformers; | 
					
						
							| 
									
										
										
										
											2021-07-18 14:51:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | use Carbon\Carbon; | 
					
						
							|  |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							|  |  |  | use FireflyIII\Factory\CategoryFactory; | 
					
						
							|  |  |  | use FireflyIII\Models\Recurrence; | 
					
						
							|  |  |  | use FireflyIII\Models\RecurrenceRepetition; | 
					
						
							|  |  |  | use FireflyIII\Models\RecurrenceTransaction; | 
					
						
							|  |  |  | use FireflyIII\Models\RecurrenceTransactionMeta; | 
					
						
							| 
									
										
										
										
											2021-07-18 14:51:30 +02:00
										 |  |  | use FireflyIII\Repositories\Bill\BillRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Class RecurringTransactionTransformer | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  | class RecurrenceTransformer extends AbstractTransformer | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     private BillRepositoryInterface      $billRepos; | 
					
						
							| 
									
										
										
										
											2021-03-06 16:15:39 +01:00
										 |  |  |     private BudgetRepositoryInterface    $budgetRepos; | 
					
						
							|  |  |  |     private CategoryFactory              $factory; | 
					
						
							|  |  |  |     private PiggyBankRepositoryInterface $piggyRepos; | 
					
						
							|  |  |  |     private RecurringRepositoryInterface $repository; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * RecurrenceTransformer constructor. | 
					
						
							| 
									
										
										
										
											2018-12-20 20:50:05 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-02-12 07:15:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-12-15 22:03:42 +01:00
										 |  |  |     public function __construct() | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-20 20:50:05 +01:00
										 |  |  |         $this->repository  = app(RecurringRepositoryInterface::class); | 
					
						
							|  |  |  |         $this->piggyRepos  = app(PiggyBankRepositoryInterface::class); | 
					
						
							|  |  |  |         $this->factory     = app(CategoryFactory::class); | 
					
						
							|  |  |  |         $this->budgetRepos = app(BudgetRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2021-07-18 14:51:30 +02:00
										 |  |  |         $this->billRepos   = app(BillRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |      * Transform the recurring transaction. | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param Recurrence $recurrence | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function transform(Recurrence $recurrence): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-06 18:23:32 +02:00
										 |  |  |         app('log')->debug('Now in Recurrence::transform()'); | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |         $this->repository->setUser($recurrence->user); | 
					
						
							| 
									
										
										
										
											2018-12-20 20:50:05 +01:00
										 |  |  |         $this->piggyRepos->setUser($recurrence->user); | 
					
						
							|  |  |  |         $this->factory->setUser($recurrence->user); | 
					
						
							|  |  |  |         $this->budgetRepos->setUser($recurrence->user); | 
					
						
							| 
									
										
										
										
											2023-10-06 18:23:32 +02:00
										 |  |  |         app('log')->debug('Set user.'); | 
					
						
							| 
									
										
										
										
											2018-12-20 20:50:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |         $shortType = (string)config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type)); | 
					
						
							| 
									
										
										
										
											2019-08-27 05:57:58 +02:00
										 |  |  |         $notes     = $this->repository->getNoteText($recurrence); | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |         $reps      = 0 === (int)$recurrence->repetitions ? null : (int)$recurrence->repetitions; | 
					
						
							| 
									
										
										
										
											2023-10-06 18:23:32 +02:00
										 |  |  |         app('log')->debug('Get basic data.'); | 
					
						
							| 
									
										
										
										
											2021-03-06 16:15:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |         // basic data.
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:11:25 +02:00
										 |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |             'id'                => (string)$recurrence->id, | 
					
						
							| 
									
										
										
										
											2019-08-25 16:15:02 +02:00
										 |  |  |             'created_at'        => $recurrence->created_at->toAtomString(), | 
					
						
							|  |  |  |             'updated_at'        => $recurrence->updated_at->toAtomString(), | 
					
						
							|  |  |  |             'type'              => $shortType, | 
					
						
							|  |  |  |             'title'             => $recurrence->title, | 
					
						
							|  |  |  |             'description'       => $recurrence->description, | 
					
						
							| 
									
										
										
										
											2023-05-17 07:02:08 +02:00
										 |  |  |             'first_date'        => $recurrence->first_date->format('Y-m-d'), | 
					
						
							|  |  |  |             'latest_date'       => $recurrence->latest_date?->format('Y-m-d'), | 
					
						
							|  |  |  |             'repeat_until'      => $recurrence->repeat_until?->format('Y-m-d'), | 
					
						
							| 
									
										
										
										
											2019-08-25 16:15:02 +02:00
										 |  |  |             'apply_rules'       => $recurrence->apply_rules, | 
					
						
							|  |  |  |             'active'            => $recurrence->active, | 
					
						
							| 
									
										
										
										
											2019-09-04 21:06:01 +02:00
										 |  |  |             'nr_of_repetitions' => $reps, | 
					
						
							| 
									
										
										
										
											2019-08-27 05:57:58 +02:00
										 |  |  |             'notes'             => '' === $notes ? null : $notes, | 
					
						
							| 
									
										
										
										
											2019-08-25 16:15:02 +02:00
										 |  |  |             'repetitions'       => $this->getRepetitions($recurrence), | 
					
						
							|  |  |  |             'transactions'      => $this->getTransactions($recurrence), | 
					
						
							|  |  |  |             'links'             => [ | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |                 [ | 
					
						
							|  |  |  |                     'rel' => 'self', | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |                     'uri' => '/recurring/' . $recurrence->id, | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |                 ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param Recurrence $recurrence | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function getRepetitions(Recurrence $recurrence): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-06 18:23:32 +02:00
										 |  |  |         app('log')->debug('Now in getRepetitions().'); | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |         $fromDate = $recurrence->latest_date ?? $recurrence->first_date; | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |         $return   = []; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /** @var RecurrenceRepetition $repetition */ | 
					
						
							|  |  |  |         foreach ($recurrence->recurrenceRepetitions as $repetition) { | 
					
						
							|  |  |  |             $repetitionArray = [ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 'id'          => (string)$repetition->id, | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |                 'created_at'  => $repetition->created_at->toAtomString(), | 
					
						
							|  |  |  |                 'updated_at'  => $repetition->updated_at->toAtomString(), | 
					
						
							|  |  |  |                 'type'        => $repetition->repetition_type, | 
					
						
							|  |  |  |                 'moment'      => $repetition->repetition_moment, | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 'skip'        => (int)$repetition->repetition_skip, | 
					
						
							|  |  |  |                 'weekend'     => (int)$repetition->weekend, | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |                 'description' => $this->repository->repetitionDescription($repetition), | 
					
						
							|  |  |  |                 'occurrences' => [], | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |             ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // get the (future) occurrences for this specific type of repetition:
 | 
					
						
							| 
									
										
										
										
											2022-10-30 14:24:37 +01:00
										 |  |  |             $occurrences = $this->repository->getXOccurrencesSince($repetition, $fromDate, new Carbon(), 5); | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |             /** @var Carbon $carbon */ | 
					
						
							|  |  |  |             foreach ($occurrences as $carbon) { | 
					
						
							| 
									
										
										
										
											2021-04-02 06:18:04 +02:00
										 |  |  |                 $repetitionArray['occurrences'][] = $carbon->toAtomString(); | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |             $return[] = $repetitionArray; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-29 13:56:55 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param Recurrence $recurrence | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function getTransactions(Recurrence $recurrence): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-06 18:23:32 +02:00
										 |  |  |         app('log')->debug(sprintf('Now in %s', __METHOD__)); | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |         $return = []; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |         // get all transactions:
 | 
					
						
							|  |  |  |         /** @var RecurrenceTransaction $transaction */ | 
					
						
							| 
									
										
										
										
											2019-08-27 06:08:30 +02:00
										 |  |  |         foreach ($recurrence->recurrenceTransactions()->get() as $transaction) { | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |             $sourceAccount         = $transaction->sourceAccount; | 
					
						
							|  |  |  |             $destinationAccount    = $transaction->destinationAccount; | 
					
						
							|  |  |  |             $foreignCurrencyCode   = null; | 
					
						
							|  |  |  |             $foreignCurrencySymbol = null; | 
					
						
							|  |  |  |             $foreignCurrencyDp     = null; | 
					
						
							| 
									
										
										
										
											2020-07-12 17:54:51 +02:00
										 |  |  |             $foreignCurrencyId     = null; | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |             if (null !== $transaction->foreign_currency_id) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 $foreignCurrencyId     = (int)$transaction->foreign_currency_id; | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |                 $foreignCurrencyCode   = $transaction->foreignCurrency->code; | 
					
						
							|  |  |  |                 $foreignCurrencySymbol = $transaction->foreignCurrency->symbol; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 $foreignCurrencyDp     = (int)$transaction->foreignCurrency->decimal_places; | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-06-16 13:16:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // source info:
 | 
					
						
							|  |  |  |             $sourceName = ''; | 
					
						
							|  |  |  |             $sourceId   = null; | 
					
						
							|  |  |  |             $sourceType = null; | 
					
						
							|  |  |  |             $sourceIban = null; | 
					
						
							|  |  |  |             if (null !== $sourceAccount) { | 
					
						
							|  |  |  |                 $sourceName = $sourceAccount->name; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 $sourceId   = (int)$sourceAccount->id; | 
					
						
							| 
									
										
										
										
											2019-06-16 13:16:04 +02:00
										 |  |  |                 $sourceType = $sourceAccount->accountType->type; | 
					
						
							|  |  |  |                 $sourceIban = $sourceAccount->iban; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $destinationName = ''; | 
					
						
							|  |  |  |             $destinationId   = null; | 
					
						
							|  |  |  |             $destinationType = null; | 
					
						
							|  |  |  |             $destinationIban = null; | 
					
						
							|  |  |  |             if (null !== $destinationAccount) { | 
					
						
							|  |  |  |                 $destinationName = $destinationAccount->name; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 $destinationId   = (int)$destinationAccount->id; | 
					
						
							| 
									
										
										
										
											2019-06-16 13:16:04 +02:00
										 |  |  |                 $destinationType = $destinationAccount->accountType->type; | 
					
						
							|  |  |  |                 $destinationIban = $destinationAccount->iban; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-12-27 21:13:18 +01:00
										 |  |  |             $amount        = app('steam')->bcround($transaction->amount, $transaction->transactionCurrency->decimal_places); | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |             $foreignAmount = null; | 
					
						
							|  |  |  |             if (null !== $transaction->foreign_currency_id && null !== $transaction->foreign_amount) { | 
					
						
							| 
									
										
										
										
											2022-12-27 21:13:18 +01:00
										 |  |  |                 $foreignAmount = app('steam')->bcround($transaction->foreign_amount, $foreignCurrencyDp); | 
					
						
							| 
									
										
										
										
											2018-12-12 20:30:25 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             $transactionArray = [ | 
					
						
							| 
									
										
										
										
											2023-06-03 21:17:49 +02:00
										 |  |  |                 'id'                              => (string)$transaction->id, | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 'currency_id'                     => (string)$transaction->transaction_currency_id, | 
					
						
							| 
									
										
										
										
											2018-12-18 19:57:23 +01:00
										 |  |  |                 'currency_code'                   => $transaction->transactionCurrency->code, | 
					
						
							|  |  |  |                 'currency_symbol'                 => $transaction->transactionCurrency->symbol, | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 'currency_decimal_places'         => (int)$transaction->transactionCurrency->decimal_places, | 
					
						
							|  |  |  |                 'foreign_currency_id'             => null === $foreignCurrencyId ? null : (string)$foreignCurrencyId, | 
					
						
							| 
									
										
										
										
											2018-12-18 19:57:23 +01:00
										 |  |  |                 'foreign_currency_code'           => $foreignCurrencyCode, | 
					
						
							|  |  |  |                 'foreign_currency_symbol'         => $foreignCurrencySymbol, | 
					
						
							|  |  |  |                 'foreign_currency_decimal_places' => $foreignCurrencyDp, | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 'source_id'                       => (string)$sourceId, | 
					
						
							| 
									
										
										
										
											2019-06-16 13:16:04 +02:00
										 |  |  |                 'source_name'                     => $sourceName, | 
					
						
							|  |  |  |                 'source_iban'                     => $sourceIban, | 
					
						
							|  |  |  |                 'source_type'                     => $sourceType, | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:40 +01:00
										 |  |  |                 'destination_id'                  => (string)$destinationId, | 
					
						
							| 
									
										
										
										
											2019-06-16 13:16:04 +02:00
										 |  |  |                 'destination_name'                => $destinationName, | 
					
						
							|  |  |  |                 'destination_iban'                => $destinationIban, | 
					
						
							|  |  |  |                 'destination_type'                => $destinationType, | 
					
						
							| 
									
										
										
										
											2018-12-18 19:57:23 +01:00
										 |  |  |                 'amount'                          => $amount, | 
					
						
							|  |  |  |                 'foreign_amount'                  => $foreignAmount, | 
					
						
							|  |  |  |                 'description'                     => $transaction->description, | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |             ]; | 
					
						
							| 
									
										
										
										
											2019-08-25 16:27:17 +02:00
										 |  |  |             $transactionArray = $this->getTransactionMeta($transaction, $transactionArray); | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |             if (null !== $transaction->foreign_currency_id) { | 
					
						
							| 
									
										
										
										
											2018-12-18 19:57:23 +01:00
										 |  |  |                 $transactionArray['foreign_currency_code']           = $transaction->foreignCurrency->code; | 
					
						
							|  |  |  |                 $transactionArray['foreign_currency_symbol']         = $transaction->foreignCurrency->symbol; | 
					
						
							|  |  |  |                 $transactionArray['foreign_currency_decimal_places'] = $transaction->foreignCurrency->decimal_places; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // store transaction in recurrence array.
 | 
					
						
							| 
									
										
										
										
											2018-07-18 07:28:35 +02:00
										 |  |  |             $return[] = $transactionArray; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param RecurrenceTransaction $transaction | 
					
						
							|  |  |  |      * @param array                 $array | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function getTransactionMeta(RecurrenceTransaction $transaction, array $array): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-06 18:23:32 +02:00
										 |  |  |         app('log')->debug(sprintf('Now in %s', __METHOD__)); | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |         $array['tags']            = []; | 
					
						
							|  |  |  |         $array['category_id']     = null; | 
					
						
							|  |  |  |         $array['category_name']   = null; | 
					
						
							|  |  |  |         $array['budget_id']       = null; | 
					
						
							|  |  |  |         $array['budget_name']     = null; | 
					
						
							|  |  |  |         $array['piggy_bank_id']   = null; | 
					
						
							|  |  |  |         $array['piggy_bank_name'] = null; | 
					
						
							|  |  |  |         $array['bill_id']         = null; | 
					
						
							|  |  |  |         $array['bill_name']       = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var RecurrenceTransactionMeta $transactionMeta */ | 
					
						
							|  |  |  |         foreach ($transaction->recurrenceTransactionMeta as $transactionMeta) { | 
					
						
							|  |  |  |             switch ($transactionMeta->name) { | 
					
						
							|  |  |  |                 default: | 
					
						
							|  |  |  |                     throw new FireflyException(sprintf('Recurrence transformer cant handle field "%s"', $transactionMeta->name)); | 
					
						
							|  |  |  |                 case 'bill_id': | 
					
						
							|  |  |  |                     $bill = $this->billRepos->find((int)$transactionMeta->value); | 
					
						
							|  |  |  |                     if (null !== $bill) { | 
					
						
							|  |  |  |                         $array['bill_id']   = (string)$bill->id; | 
					
						
							|  |  |  |                         $array['bill_name'] = $bill->name; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'tags': | 
					
						
							|  |  |  |                     $array['tags'] = json_decode($transactionMeta->value); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'piggy_bank_id': | 
					
						
							|  |  |  |                     $piggy = $this->piggyRepos->find((int)$transactionMeta->value); | 
					
						
							|  |  |  |                     if (null !== $piggy) { | 
					
						
							|  |  |  |                         $array['piggy_bank_id']   = (string)$piggy->id; | 
					
						
							|  |  |  |                         $array['piggy_bank_name'] = $piggy->name; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'category_id': | 
					
						
							|  |  |  |                     $category = $this->factory->findOrCreate((int)$transactionMeta->value, null); | 
					
						
							|  |  |  |                     if (null !== $category) { | 
					
						
							|  |  |  |                         $array['category_id']   = (string)$category->id; | 
					
						
							|  |  |  |                         $array['category_name'] = $category->name; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'category_name': | 
					
						
							|  |  |  |                     $category = $this->factory->findOrCreate(null, $transactionMeta->value); | 
					
						
							|  |  |  |                     if (null !== $category) { | 
					
						
							|  |  |  |                         $array['category_id']   = (string)$category->id; | 
					
						
							|  |  |  |                         $array['category_name'] = $category->name; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'budget_id': | 
					
						
							|  |  |  |                     $budget = $this->budgetRepos->find((int)$transactionMeta->value); | 
					
						
							|  |  |  |                     if (null !== $budget) { | 
					
						
							|  |  |  |                         $array['budget_id']   = (string)$budget->id; | 
					
						
							|  |  |  |                         $array['budget_name'] = $budget->name; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $array; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-22 20:32:02 +02:00
										 |  |  | } |