mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-30 06:50:49 +00:00 
			
		
		
		
	Update API to match new end points.
This commit is contained in:
		| @@ -129,7 +129,7 @@ class TransactionController extends Controller | ||||
|         $paginator->setPath(route('api.v1.transactions.index') . $this->buildParams()); | ||||
|         $transactions = $paginator->getCollection(); | ||||
|  | ||||
|         $resource = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions'); | ||||
|         $resource = new FractalCollection($transactions, new TransactionTransformer($this->parameters, $this->repository), 'transactions'); | ||||
|         $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); | ||||
|  | ||||
|         return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); | ||||
| @@ -141,21 +141,15 @@ class TransactionController extends Controller | ||||
|      * | ||||
|      * @param Request     $request | ||||
|      * @param Transaction $transaction | ||||
|      * @param string      $include | ||||
|      * | ||||
|      * @return JsonResponse | ||||
|      */ | ||||
|     public function show(Request $request, Transaction $transaction, string $include = null): JsonResponse | ||||
|     public function show(Request $request, Transaction $transaction): JsonResponse | ||||
|     { | ||||
|         $manager = new Manager(); | ||||
|         $baseUrl = $request->getSchemeAndHttpHost() . '/api/v1'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
|  | ||||
|         // add include parameter: | ||||
|         $include = $include ?? ''; | ||||
|         $include = $request->get('include') ?? $include; | ||||
|         $manager->parseIncludes($include); | ||||
|  | ||||
|         // collect transactions using the journal collector | ||||
|         $collector = app(TransactionCollectorInterface::class); | ||||
|         $collector->setUser(auth()->user()); | ||||
| @@ -173,7 +167,7 @@ class TransactionController extends Controller | ||||
|         } | ||||
|  | ||||
|         $transactions = $collector->getTransactions(); | ||||
|         $resource     = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions'); | ||||
|         $resource     = new FractalCollection($transactions, new TransactionTransformer($this->parameters, $this->repository), 'transactions'); | ||||
|  | ||||
|         return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); | ||||
|     } | ||||
| @@ -200,10 +194,6 @@ class TransactionController extends Controller | ||||
|         $baseUrl = $request->getSchemeAndHttpHost() . '/api/v1'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
|  | ||||
|         // add include parameter: | ||||
|         $include = $request->get('include') ?? ''; | ||||
|         $manager->parseIncludes($include); | ||||
|  | ||||
|         // collect transactions using the journal collector | ||||
|         $collector = app(TransactionCollectorInterface::class); | ||||
|         $collector->setUser(auth()->user()); | ||||
| @@ -221,7 +211,7 @@ class TransactionController extends Controller | ||||
|         } | ||||
|  | ||||
|         $transactions = $collector->getTransactions(); | ||||
|         $resource     = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions'); | ||||
|         $resource     = new FractalCollection($transactions, new TransactionTransformer($this->parameters, $this->repository), 'transactions'); | ||||
|  | ||||
|         return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); | ||||
|     } | ||||
| @@ -247,10 +237,6 @@ class TransactionController extends Controller | ||||
|  | ||||
|         event(new UpdatedTransactionJournal($journal)); | ||||
|  | ||||
|         // add include parameter: | ||||
|         $include = $request->get('include') ?? ''; | ||||
|         $manager->parseIncludes($include); | ||||
|  | ||||
|         // needs a lot of extra data to match the journal collector. Or just expand that one. | ||||
|         // collect transactions using the journal collector | ||||
|         $collector = app(TransactionCollectorInterface::class); | ||||
| @@ -269,7 +255,7 @@ class TransactionController extends Controller | ||||
|         } | ||||
|  | ||||
|         $transactions = $collector->getTransactions(); | ||||
|         $resource     = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions'); | ||||
|         $resource     = new FractalCollection($transactions, new TransactionTransformer($this->parameters, $this->repository), 'transactions'); | ||||
|  | ||||
|         return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); | ||||
|  | ||||
|   | ||||
| @@ -134,10 +134,6 @@ class UserController extends Controller | ||||
|         $baseUrl = $request->getSchemeAndHttpHost() . '/api/v1'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
|  | ||||
|         // add include parameter: | ||||
|         $include = $request->get('include') ?? ''; | ||||
|         $manager->parseIncludes($include); | ||||
|  | ||||
|         // make resource | ||||
|         $resource = new Item($user, new UserTransformer($this->parameters), 'users'); | ||||
|  | ||||
| @@ -161,10 +157,6 @@ class UserController extends Controller | ||||
|         $baseUrl = $request->getSchemeAndHttpHost() . '/api/v1'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
|  | ||||
|         // add include parameter: | ||||
|         $include = $request->get('include') ?? ''; | ||||
|         $manager->parseIncludes($include); | ||||
|  | ||||
|         // make resource | ||||
|         $resource = new Item($user, new UserTransformer($this->parameters), 'users'); | ||||
|  | ||||
| @@ -189,10 +181,6 @@ class UserController extends Controller | ||||
|         $baseUrl = $request->getSchemeAndHttpHost() . '/api/v1'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
|  | ||||
|         // add include parameter: | ||||
|         $include = $request->get('include') ?? ''; | ||||
|         $manager->parseIncludes($include); | ||||
|  | ||||
|         // make resource | ||||
|         $resource = new Item($user, new UserTransformer($this->parameters), 'users'); | ||||
|  | ||||
|   | ||||
| @@ -25,6 +25,7 @@ declare(strict_types=1); | ||||
| namespace FireflyIII\Api\V1\Requests; | ||||
|  | ||||
| use FireflyIII\Rules\BelongsUser; | ||||
| use FireflyIII\Rules\IsBoolean; | ||||
| use FireflyIII\Validation\TransactionValidation; | ||||
| use Illuminate\Validation\Validator; | ||||
|  | ||||
| @@ -73,8 +74,21 @@ class TransactionRequest extends Request | ||||
|             'invoice_date'       => $this->date('invoice_date'), | ||||
|             'internal_reference' => $this->string('internal_reference'), | ||||
|             'notes'              => $this->string('notes'), | ||||
|             'original-source'    => sprintf('api-v%s', config('firefly.api_version')), | ||||
|             'original-source'    => sprintf('ff3-v%s|api-v%s', config('firefly.version'),config('firefly.api_version')), | ||||
|             'transactions'       => $this->getTransactionData(), | ||||
|  | ||||
|             // SEPA fields: | ||||
|             'sepa-cc'            => $this->string('sepa_cc'), | ||||
|             'sepa-ct-op'         => $this->string('sepa_ct_op'), | ||||
|             'sepa-db'            => $this->string('sepa_db'), | ||||
|             'sepa-country'       => $this->string('sepa_country'), | ||||
|             'sepa-ep'            => $this->string('sepa_ep'), | ||||
|             'sepa-ci'            => $this->string('sepa_ci'), | ||||
|             'sepa-batch-id'      => $this->string('sepa_batch_id'), | ||||
|  | ||||
|             // others: | ||||
|             'bunq_payment_id'    => $this->string('bunq_payment_id'), | ||||
|             'external_id'        => $this->string('external_id'), | ||||
|         ]; | ||||
|  | ||||
|         return $data; | ||||
| @@ -109,11 +123,20 @@ class TransactionRequest extends Request | ||||
|             'internal_reference'                   => 'min:1,max:255|nullable', | ||||
|             'notes'                                => 'min:1,max:50000|nullable', | ||||
|  | ||||
|             // SEPA fields: | ||||
|             'sepa_cc'                              => 'min:1,max:255|nullable', | ||||
|             'sepa_ct_op'                           => 'min:1,max:255|nullable', | ||||
|             'sepa_db'                              => 'min:1,max:255|nullable', | ||||
|             'sepa_country'                         => 'min:1,max:255|nullable', | ||||
|             'sepa_ep'                              => 'min:1,max:255|nullable', | ||||
|             'sepa_ci'                              => 'min:1,max:255|nullable', | ||||
|             'sepa_batch_id'                        => 'min:1,max:255|nullable', | ||||
|  | ||||
|             // transaction rules (in array for splits): | ||||
|             'transactions.*.description'           => 'nullable|between:1,255', | ||||
|             'transactions.*.amount'                => 'required|numeric|more:0', | ||||
|             'transactions.*.currency_id'           => 'numeric|exists:transaction_currencies,id|required_without:transactions.*.currency_code', | ||||
|             'transactions.*.currency_code'         => 'min:3|max:3|exists:transaction_currencies,code|required_without:transactions.*.currency_id', | ||||
|             'transactions.*.currency_id'           => 'numeric|exists:transaction_currencies,id', | ||||
|             'transactions.*.currency_code'         => 'min:3|max:3|exists:transaction_currencies,code', | ||||
|             'transactions.*.foreign_amount'        => 'numeric|more:0', | ||||
|             'transactions.*.foreign_currency_id'   => 'numeric|exists:transaction_currencies,id', | ||||
|             'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code', | ||||
| @@ -121,7 +144,7 @@ class TransactionRequest extends Request | ||||
|             'transactions.*.budget_name'           => ['between:1,255', 'nullable', new BelongsUser], | ||||
|             'transactions.*.category_id'           => ['mustExist:categories,id', new BelongsUser], | ||||
|             'transactions.*.category_name'         => 'between:1,255|nullable', | ||||
|             'transactions.*.reconciled'            => 'boolean|nullable', | ||||
|             'transactions.*.reconciled'            => [new IsBoolean], | ||||
|             // basic rules will be expanded later. | ||||
|             'transactions.*.source_id'             => ['numeric', 'nullable', new BelongsUser], | ||||
|             'transactions.*.source_name'           => 'between:1,255|nullable', | ||||
|   | ||||
| @@ -40,6 +40,11 @@ use Log; | ||||
|  */ | ||||
| class TransactionFactory | ||||
| { | ||||
|     /** @var User */ | ||||
|     private $user; | ||||
|  | ||||
|     use TransactionServiceTrait; | ||||
|  | ||||
|     /** | ||||
|      * Constructor. | ||||
|      */ | ||||
| @@ -50,11 +55,6 @@ class TransactionFactory | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     use TransactionServiceTrait; | ||||
|  | ||||
|     /** @var User */ | ||||
|     private $user; | ||||
|  | ||||
|     /** | ||||
|      * @param array $data | ||||
|      * | ||||
| @@ -109,8 +109,9 @@ class TransactionFactory | ||||
|         Log::debug('Start of TransactionFactory::createPair()', $data); | ||||
|         // all this data is the same for both transactions: | ||||
|         Log::debug('Searching for currency info.'); | ||||
|         $defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user); | ||||
|         $currency        = $this->findCurrency($data['currency_id'], $data['currency_code']); | ||||
|         //$description = $data['description']; | ||||
|         $currency        = $currency ?? $defaultCurrency; | ||||
|  | ||||
|         // type of source account and destination account depends on journal type: | ||||
|         $sourceType      = $this->accountType($journal, 'source'); | ||||
|   | ||||
| @@ -142,7 +142,7 @@ class MassController extends Controller | ||||
|  | ||||
|         $this->rememberPreviousUri('transactions.mass-edit.uri'); | ||||
|  | ||||
|         $transformer = new TransactionTransformer(new ParameterBag); | ||||
|         $transformer = new TransactionTransformer(new ParameterBag, $this->repository); | ||||
|         /** @var TransactionCollectorInterface $collector */ | ||||
|         $collector = app(TransactionCollectorInterface::class); | ||||
|         $collector->setUser($user); | ||||
|   | ||||
| @@ -253,7 +253,7 @@ class TransactionController extends Controller | ||||
|         $collector->setJournals(new Collection([$journal])); | ||||
|         $set          = $collector->getTransactions(); | ||||
|         $transactions = []; | ||||
|         $transformer  = new TransactionTransformer(new ParameterBag); | ||||
|         $transformer  = new TransactionTransformer(new ParameterBag, $this->repository); | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($set as $transaction) { | ||||
|             $transactions[] = $transformer->transform($transaction); | ||||
|   | ||||
| @@ -474,6 +474,24 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return string value of a meta date (or NULL). | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param string             $field | ||||
|      * | ||||
|      * @return null|string | ||||
|      */ | ||||
|     public function getMetaDateString(TransactionJournal $journal, string $field): ?string | ||||
|     { | ||||
|         $date = $this->getMetaDate($journal, $field); | ||||
|         if (null === $date) { | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         return $date->format('Y-m-d'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return value of a meta field (or NULL) as a string. | ||||
|      * | ||||
|   | ||||
| @@ -38,17 +38,6 @@ use Illuminate\Support\MessageBag; | ||||
|  */ | ||||
| interface JournalRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * Return all attachments for journal. | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function getAttachments(TransactionJournal $journal): Collection; | ||||
|  | ||||
|  | ||||
|     /** @noinspection MoreThanThreeArgumentsInspection */ | ||||
|     /** | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param TransactionType    $type | ||||
| @@ -59,6 +48,9 @@ interface JournalRepositoryInterface | ||||
|      */ | ||||
|     public function convert(TransactionJournal $journal, TransactionType $type, Account $source, Account $destination): MessageBag; | ||||
|  | ||||
|  | ||||
|     /** @noinspection MoreThanThreeArgumentsInspection */ | ||||
|  | ||||
|     /** | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
| @@ -121,6 +113,15 @@ interface JournalRepositoryInterface | ||||
|      */ | ||||
|     public function getAssetTransaction(TransactionJournal $journal): ?Transaction; | ||||
|  | ||||
|     /** | ||||
|      * Return all attachments for journal. | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function getAttachments(TransactionJournal $journal): Collection; | ||||
|  | ||||
|     /** | ||||
|      * Returns the first positive transaction for the journal. Useful when editing journals. | ||||
|      * | ||||
| @@ -196,6 +197,16 @@ interface JournalRepositoryInterface | ||||
|      */ | ||||
|     public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon; | ||||
|  | ||||
|     /** | ||||
|      * Return string value of a meta date (or NULL). | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param string             $field | ||||
|      * | ||||
|      * @return null|string | ||||
|      */ | ||||
|     public function getMetaDateString(TransactionJournal $journal, string $field): ?string; | ||||
|  | ||||
|     /** | ||||
|      * Return value of a meta field (or NULL). | ||||
|      * | ||||
|   | ||||
| @@ -33,6 +33,7 @@ use FireflyIII\Http\Requests\TestRuleFormRequest; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Models\TransactionType; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Support\Binder\AccountList; | ||||
| use FireflyIII\Transformers\TransactionTransformer; | ||||
| use FireflyIII\User; | ||||
| @@ -221,6 +222,7 @@ trait RequestInformation | ||||
|      */ | ||||
|     protected function getTransactionDataFromJournal(TransactionJournal $journal): array // convert object | ||||
|     { | ||||
|         $repository = app(JournalRepositoryInterface::class); | ||||
|         // use collector to collect transactions. | ||||
|         $collector = app(TransactionCollectorInterface::class); | ||||
|         $collector->setUser(auth()->user()); | ||||
| @@ -229,7 +231,7 @@ trait RequestInformation | ||||
|         $collector->setJournals(new Collection([$journal])); | ||||
|         $set          = $collector->getTransactions(); | ||||
|         $transactions = []; | ||||
|         $transformer  = new TransactionTransformer(new ParameterBag); | ||||
|         $transformer  = new TransactionTransformer(new ParameterBag, $repository); | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($set as $transaction) { | ||||
|             $res = []; | ||||
|   | ||||
| @@ -30,6 +30,7 @@ use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use League\Fractal\Resource\Collection as FractalCollection; | ||||
| use League\Fractal\Resource\Item; | ||||
| @@ -118,7 +119,9 @@ class AccountTransformer extends TransformerAbstract | ||||
|         $collector->setLimit($pageSize)->setPage($this->parameters->get('page')); | ||||
|         $transactions = $collector->getTransactions(); | ||||
|  | ||||
|         return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions'); | ||||
|         $journalRepos = app(JournalRepositoryInterface::class); | ||||
|  | ||||
|         return $this->collection($transactions, new TransactionTransformer($this->parameters, $journalRepos), 'transactions'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -25,11 +25,9 @@ namespace FireflyIII\Transformers; | ||||
|  | ||||
|  | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\Note; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionType; | ||||
| use League\Fractal\Resource\Collection as FractalCollection; | ||||
| use League\Fractal\Resource\Item; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use League\Fractal\TransformerAbstract; | ||||
| use Log; | ||||
| use Symfony\Component\HttpFoundation\ParameterBag; | ||||
| @@ -39,111 +37,26 @@ use Symfony\Component\HttpFoundation\ParameterBag; | ||||
|  */ | ||||
| class TransactionTransformer extends TransformerAbstract | ||||
| { | ||||
|     /** | ||||
|      * List of resources possible to include | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $availableIncludes = ['attachments', 'user', 'tags', 'journal_meta', 'piggy_bank_events']; | ||||
|     /** | ||||
|      * List of resources to automatically include | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $defaultIncludes = []; | ||||
|  | ||||
|     /** @var ParameterBag */ | ||||
|     protected $parameters; | ||||
|  | ||||
|     /** @var JournalRepositoryInterface */ | ||||
|     protected $repository; | ||||
|  | ||||
|     /** | ||||
|      * TransactionTransformer constructor. | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param ParameterBag               $parameters | ||||
|      * @param JournalRepositoryInterface $repository | ||||
|      */ | ||||
|     public function __construct(ParameterBag $parameters) | ||||
|     public function __construct(ParameterBag $parameters, JournalRepositoryInterface $repository) | ||||
|     { | ||||
|         $this->parameters = $parameters; | ||||
|         $this->repository = $repository; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Include attachments. | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param Transaction $transaction | ||||
|      * | ||||
|      * @return FractalCollection | ||||
|      */ | ||||
|     public function includeAttachments(Transaction $transaction): FractalCollection | ||||
|     { | ||||
|         return $this->collection($transaction->transactionJournal->attachments, new AttachmentTransformer($this->parameters), 'attachments'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Include meta data | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param Transaction $transaction | ||||
|      * | ||||
|      * @return FractalCollection | ||||
|      */ | ||||
|     public function includeJournalMeta(Transaction $transaction): FractalCollection | ||||
|     { | ||||
|         $meta = $transaction->transactionJournal->transactionJournalMeta()->get(); | ||||
|  | ||||
|         return $this->collection($meta, new JournalMetaTransformer($this->parameters), 'journal_meta'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Include piggy bank events | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param Transaction $transaction | ||||
|      * | ||||
|      * @return FractalCollection | ||||
|      */ | ||||
|     public function includePiggyBankEvents(Transaction $transaction): FractalCollection | ||||
|     { | ||||
|         $events = $transaction->transactionJournal->piggyBankEvents()->get(); | ||||
|  | ||||
|         return $this->collection($events, new PiggyBankEventTransformer($this->parameters), 'piggy_bank_events'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Include tags | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param Transaction $transaction | ||||
|      * | ||||
|      * @return FractalCollection | ||||
|      */ | ||||
|     public function includeTags(Transaction $transaction): FractalCollection | ||||
|     { | ||||
|         $set = $transaction->transactionJournal->tags; | ||||
|  | ||||
|         return $this->collection($set, new TagTransformer($this->parameters), 'tags'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Include the user. | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param Transaction $transaction | ||||
|      * | ||||
|      * @return \League\Fractal\Resource\Item | ||||
|      */ | ||||
|     public function includeUser(Transaction $transaction): Item | ||||
|     { | ||||
|         return $this->item($transaction->transactionJournal->user, new UserTransformer($this->parameters), 'users'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Transform the journal. | ||||
|      * | ||||
| @@ -160,17 +73,15 @@ class TransactionTransformer extends TransformerAbstract | ||||
|         $budgetName   = null; | ||||
|         $categoryId   = $transaction->transaction_category_id ?? $transaction->transaction_journal_category_id; | ||||
|         $categoryName = $transaction->transaction_category_name ?? $transaction->transaction_journal_category_name; | ||||
|  | ||||
|         $journal      = $transaction->transactionJournal; | ||||
|         $notes        = $this->repository->getNoteText($journal); | ||||
|         if ($transaction->transaction_type_type === TransactionType::WITHDRAWAL) { | ||||
|             $budgetId   = $transaction->transaction_budget_id ?? $transaction->transaction_journal_budget_id; | ||||
|             $budgetName = $transaction->transaction_budget_name ?? $transaction->transaction_journal_budget_name; | ||||
|         } | ||||
|         /** @var Note $dbNote */ | ||||
|         $dbNote = $transaction->transactionJournal->notes()->first(); | ||||
|         $notes  = null; | ||||
|         if (null !== $dbNote) { | ||||
|             $notes = $dbNote->text; | ||||
|         } | ||||
|         // get tags: | ||||
|         $tags = implode(',', $journal->tags->pluck('tag')->toArray()); | ||||
|  | ||||
|  | ||||
|         $data = [ | ||||
|             'id'                      => (int)$transaction->id, | ||||
| @@ -200,6 +111,27 @@ class TransactionTransformer extends TransformerAbstract | ||||
|             'budget_id'               => $budgetId, | ||||
|             'budget_name'             => $budgetName, | ||||
|             'notes'                   => $notes, | ||||
|             'sepa_cc'                 => $this->repository->getMetaField($journal, 'sepa-cc'), | ||||
|             'sepa_ct_op'              => $this->repository->getMetaField($journal, 'sepa-ct-op'), | ||||
|             'sepa_ct_id'              => $this->repository->getMetaField($journal, 'sepa-ct-ud'), | ||||
|             'sepa_db'                 => $this->repository->getMetaField($journal, 'sepa-db'), | ||||
|             'sepa_country'            => $this->repository->getMetaField($journal, 'sepa-country'), | ||||
|             'sepa_ep'                 => $this->repository->getMetaField($journal, 'sepa-ep'), | ||||
|             'sepa_ci'                 => $this->repository->getMetaField($journal, 'sepa-ci'), | ||||
|             'sepa_batch_id'           => $this->repository->getMetaField($journal, 'sepa-batch-id'), | ||||
|             'interest_date'           => $this->repository->getMetaDateString($journal, 'interest_date'), | ||||
|             'book_date'               => $this->repository->getMetaDateString($journal, 'book_date'), | ||||
|             'process_date'            => $this->repository->getMetaDateString($journal, 'process_date'), | ||||
|             'due_date'                => $this->repository->getMetaDateString($journal, 'due_date'), | ||||
|             'payment_date'            => $this->repository->getMetaDateString($journal, 'payment_date'), | ||||
|             'invoice_date'            => $this->repository->getMetaDateString($journal, 'invoice_date'), | ||||
|             'internal_reference'      => $this->repository->getMetaField($journal, 'internal_reference'), | ||||
|             'bunq_payment_id'         => $this->repository->getMetaField($journal, 'bunq_payment_id'), | ||||
|             'importHashV2'            => $this->repository->getMetaField($journal, 'importHashV2'), | ||||
|             'recurrence_id'           => (int)$this->repository->getMetaField($journal, 'recurrence_id'), | ||||
|             'external_id'             => $this->repository->getMetaField($journal, 'external_id'), | ||||
|             'original_source'         => $this->repository->getMetaField($journal, 'original-source'), | ||||
|             'tags'                    => '' === $tags ? null : $tags, | ||||
|             'links'                   => [ | ||||
|                 [ | ||||
|                     'rel' => 'self', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user