Add strict types, add debug info

This commit is contained in:
James Cole
2022-07-16 09:25:10 +02:00
parent 5c3b4d1663
commit 9493046212
38 changed files with 222 additions and 86 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
class AccountController extends Controller class AccountController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* Controller.php * Controller.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -82,6 +83,11 @@ class Controller extends BaseController
$manager->setSerializer(new JsonApiSerializer($baseUrl)); $manager->setSerializer(new JsonApiSerializer($baseUrl));
$objects = $paginator->getCollection(); $objects = $paginator->getCollection();
// the transformer, at this point, needs to collect information that ALL items in the collection
// require, like meta data and stuff like that, and save it for later.
$transformer->collectMetaData($objects);
$resource = new FractalCollection($objects, $transformer, $key); $resource = new FractalCollection($objects, $transformer, $key);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
class AccountController extends Controller class AccountController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
class AccountController extends Controller class AccountController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
class AccountController extends Controller class AccountController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* ShowController.php * ShowController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* SumController.php * SumController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* SumController.php * SumController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* NetWorthController.php * NetWorthController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
class AccountController extends Controller class AccountController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* ConfigurationController.php * ConfigurationController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -24,4 +25,4 @@ namespace FireflyIII\Api\V2\Controllers\System;
class ConfigurationController class ConfigurationController
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* DebugController.php * DebugController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -26,4 +27,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
class DebugController extends Controller class DebugController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* PreferencesController.php * PreferencesController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountController.php * AccountController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* BillController.php * BillController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* VersionUpdateController.php * VersionUpdateController.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -27,4 +28,4 @@ namespace FireflyIII\Api\V2\Controllers;
class VersionUpdateController extends Controller class VersionUpdateController extends Controller
{ {
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* ListRequest.php * ListRequest.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AutoSum.php * AutoSum.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -142,10 +142,10 @@ class Cron extends Command
$this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message)); $this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
} }
if ($recurring->jobFired) { if ($recurring->jobFired) {
$this->error(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message)); $this->line(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message));
} }
if ($recurring->jobSucceeded) { if ($recurring->jobSucceeded) {
$this->error(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message)); $this->info(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message));
} }
} }
@@ -169,10 +169,10 @@ class Cron extends Command
$this->error(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message)); $this->error(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message));
} }
if ($autoBudget->jobFired) { if ($autoBudget->jobFired) {
$this->error(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message)); $this->line(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message));
} }
if ($autoBudget->jobSucceeded) { if ($autoBudget->jobSucceeded) {
$this->error(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message)); $this->info(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message));
} }
} }
@@ -197,10 +197,10 @@ class Cron extends Command
$this->error(sprintf('Error in "bill warnings" cron: %s', $autoBudget->message)); $this->error(sprintf('Error in "bill warnings" cron: %s', $autoBudget->message));
} }
if ($autoBudget->jobFired) { if ($autoBudget->jobFired) {
$this->error(sprintf('"Send bill warnings" cron fired: %s', $autoBudget->message)); $this->line(sprintf('"Send bill warnings" cron fired: %s', $autoBudget->message));
} }
if ($autoBudget->jobSucceeded) { if ($autoBudget->jobSucceeded) {
$this->error(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message)); $this->info(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message));
} }
} }
@@ -225,10 +225,10 @@ class Cron extends Command
$this->error(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message)); $this->error(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message));
} }
if ($exchangeRates->jobFired) { if ($exchangeRates->jobFired) {
$this->error(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message)); $this->line(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message));
} }
if ($exchangeRates->jobSucceeded) { if ($exchangeRates->jobSucceeded) {
$this->error(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); $this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
} }
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountTypeEnum.php * AccountTypeEnum.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -41,4 +42,4 @@ enum AccountTypeEnum: string
case RECONCILIATION = 'Reconciliation account'; case RECONCILIATION = 'Reconciliation account';
case REVENUE = 'Revenue account'; case REVENUE = 'Revenue account';
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AutoBudgetType.php * AutoBudgetType.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -28,4 +29,4 @@ enum AutoBudgetType: int
{ {
case AUTO_BUDGET_RESET = 1; case AUTO_BUDGET_RESET = 1;
case AUTO_BUDGET_ROLLOVER = 2; case AUTO_BUDGET_ROLLOVER = 2;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* RecurrenceRepetitionWeekend.php * RecurrenceRepetitionWeekend.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -27,4 +28,4 @@ enum RecurrenceRepetitionWeekend: int
case WEEKEND_SKIP_CREATION = 2; case WEEKEND_SKIP_CREATION = 2;
case WEEKEND_TO_FRIDAY = 3; case WEEKEND_TO_FRIDAY = 3;
case WEEKEND_TO_MONDAY = 4; case WEEKEND_TO_MONDAY = 4;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* TransactionTypeEnum.php * TransactionTypeEnum.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -33,4 +34,4 @@ enum TransactionTypeEnum: string
case RECONCILIATION = 'Reconciliation'; case RECONCILIATION = 'Reconciliation';
case TRANSFER = 'Transfer'; case TRANSFER = 'Transfer';
case WITHDRAWAL = 'Withdrawal'; case WITHDRAWAL = 'Withdrawal';
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* UserRoleEnum.php * UserRoleEnum.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -31,4 +32,4 @@ enum UserRoleEnum: string
case OWNER = 'owner'; case OWNER = 'owner';
case READ_ONLY = 'ro'; case READ_ONLY = 'ro';
case VIEW_REPORTS = 'view_reports'; case VIEW_REPORTS = 'view_reports';
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* WebhookDelivery.php * WebhookDelivery.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -24,4 +25,4 @@ namespace FireflyIII\Enums;
enum WebhookDelivery: int enum WebhookDelivery: int
{ {
case JSON = 300; case JSON = 300;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* WebhookResponse.php * WebhookResponse.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -26,4 +27,4 @@ enum WebhookResponse: int
case TRANSACTIONS = 200; case TRANSACTIONS = 200;
case ACCOUNTS = 210; case ACCOUNTS = 210;
case NONE = 220; case NONE = 220;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* WebhookTrigger.php * WebhookTrigger.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -26,4 +27,4 @@ enum WebhookTrigger: int
case STORE_TRANSACTION = 100; case STORE_TRANSACTION = 100;
case UPDATE_TRANSACTION = 110; case UPDATE_TRANSACTION = 110;
case DESTROY_TRANSACTION = 120; case DESTROY_TRANSACTION = 120;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace FireflyIII\Exceptions; namespace FireflyIII\Exceptions;
@@ -10,4 +11,4 @@ use Exception;
class BadHttpHeaderException extends Exception class BadHttpHeaderException extends Exception
{ {
public int $statusCode = 406; public int $statusCode = 406;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace FireflyIII\Http\Middleware; namespace FireflyIII\Http\Middleware;
@@ -42,4 +43,4 @@ class AcceptHeaders
return $next($request); return $next($request);
} }
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* DownloadExchangeRates.php * DownloadExchangeRates.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -77,6 +78,7 @@ class DownloadExchangeRates implements ShouldQueue
*/ */
public function handle(): void public function handle(): void
{ {
Log::debug('Now in handle()');
$currencies = $this->repository->get(); $currencies = $this->repository->get();
/** @var TransactionCurrency $currency */ /** @var TransactionCurrency $currency */
@@ -108,7 +110,7 @@ class DownloadExchangeRates implements ShouldQueue
$res = $client->get($url); $res = $client->get($url);
$statusCode = $res->getStatusCode(); $statusCode = $res->getStatusCode();
if (200 !== $statusCode) { if (200 !== $statusCode) {
Log::warning(sprintf('Trying to grab "%s" resulted in %d.', $url, $statusCode)); Log::warning(sprintf('Trying to grab "%s" resulted in status code %d.', $url, $statusCode));
return; return;
} }
$body = (string) $res->getBody(); $body = (string) $res->getBody();

View File

@@ -68,14 +68,14 @@ class ExchangeRatesCronjob extends AbstractCronjob
Log::info(sprintf('It has been %s since the exchange rates cron-job has fired. It will fire now!', $diffForHumans)); Log::info(sprintf('It has been %s since the exchange rates cron-job has fired. It will fire now!', $diffForHumans));
} }
$this->fireAutoBudget(); $this->fireExchangeRateJob();
app('preferences')->mark(); app('preferences')->mark();
} }
/** /**
* *
*/ */
private function fireAutoBudget(): void private function fireExchangeRateJob(): void
{ {
Log::info(sprintf('Will now fire exchange rates cron job task for date "%s".', $this->date->format('Y-m-d'))); Log::info(sprintf('Will now fire exchange rates cron job task for date "%s".', $this->date->format('Y-m-d')));
/** @var DownloadExchangeRates $job */ /** @var DownloadExchangeRates $job */

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* ConvertsExchangeRates.php * ConvertsExchangeRates.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AbstractTransformer.php * AbstractTransformer.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -21,6 +22,7 @@
namespace FireflyIII\Transformers\V2; namespace FireflyIII\Transformers\V2;
use Illuminate\Support\Collection;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
/** /**
@@ -29,4 +31,9 @@ use League\Fractal\TransformerAbstract;
abstract class AbstractTransformer extends TransformerAbstract abstract class AbstractTransformer extends TransformerAbstract
{ {
/**
* @param Collection $objects
* @return void
*/
abstract public function collectMetaData(Collection $objects): void;
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* AccountTransformer.php * AccountTransformer.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* TransactionGroupTransformer.php * TransactionGroupTransformer.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org
@@ -21,14 +22,27 @@
namespace FireflyIII\Transformers\V2; namespace FireflyIII\Transformers\V2;
use Carbon\Carbon;
use FireflyIII\Factory\TransactionFactory;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Support\Http\Api\ConvertsExchangeRates;
use FireflyIII\Support\NullArrayObject; use FireflyIII\Support\NullArrayObject;
use Illuminate\Support\Collection;
/** /**
* Class TransactionGroupTransformer * Class TransactionGroupTransformer
*/ */
class TransactionGroupTransformer extends AbstractTransformer class TransactionGroupTransformer extends AbstractTransformer
{ {
use ConvertsExchangeRates;
private array $currencies = [];
private TransactionCurrency $default;
private array $meta;
/** /**
* @param array $group * @param array $group
* *
@@ -69,76 +83,105 @@ class TransactionGroupTransformer extends AbstractTransformer
private function transformTransaction(array $transaction): array private function transformTransaction(array $transaction): array
{ {
$transaction = new NullArrayObject($transaction); $transaction = new NullArrayObject($transaction);
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL); $journalId = (int) $transaction['transaction_journal_id'];
$amount = app('steam')->positive((string) ($row['amount'] ?? '0')); $meta = new NullArrayObject($this->meta[$journalId] ?? []);
$foreignAmount = null; $type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
$amount = app('steam')->positive((string) ($transaction['amount'] ?? '0'));
$foreignAmount = null;
$foreignNativeAmount = null;
if (null !== $transaction['foreign_amount']) { if (null !== $transaction['foreign_amount']) {
$foreignAmount = app('steam')->positive($transaction['foreign_amount']); $foreignAmount = app('steam')->positive($transaction['foreign_amount']);
$foreignNativeAmount = $foreignAmount;
if ($transaction['foreign_currency_id'] !== $this->default->id) {
$rate = $this->getRate($this->currencies[$transaction['foreign_currency_id']], $this->default, $transaction['date']);
$foreignNativeAmount = bcmul($foreignAmount, $rate);
}
}
$nativeAmount = $amount;
if ($transaction['currency_id'] !== $this->default->id) {
$rate = $this->getRate($this->currencies[$transaction['currency_id']], $this->default, $transaction['date']);
$nativeAmount = bcmul($amount, $rate);
} }
return [ return [
'user' => (string) $transaction['user_id'], 'user' => (string) $transaction['user_id'],
'transaction_journal_id' => (string) $transaction['transaction_journal_id'], 'transaction_journal_id' => (string) $transaction['transaction_journal_id'],
'type' => strtolower($type), 'type' => strtolower($type),
'date' => $transaction['date']->toAtomString(), 'date' => $transaction['date']->toAtomString(),
'order' => $transaction['order'], 'order' => $transaction['order'],
'currency_id' => (string) $transaction['currency_id'], 'currency_id' => (string) $transaction['currency_id'],
'currency_code' => $transaction['currency_code'], 'currency_code' => $transaction['currency_code'],
'currency_name' => $transaction['currency_name'], 'currency_name' => $transaction['currency_name'],
'currency_symbol' => $transaction['currency_symbol'], 'currency_symbol' => $transaction['currency_symbol'],
'currency_decimal_places' => (int) $transaction['currency_decimal_places'], 'currency_decimal_places' => (int) $transaction['currency_decimal_places'],
// converted to native currency
'native_currency_converted' => $transaction['currency_id'] !== $this->default->id,
'native_currency_id' => (string) $this->default->id,
'native_currency_code' => $this->default->code,
'native_currency_name' => $this->default->name,
'native_currency_symbol' => $this->default->symbol,
'native_currency_decimal_places' => (int) $this->default->decimal_places,
'foreign_currency_id' => $this->stringFromArray($transaction, 'foreign_currency_id', null), 'foreign_currency_id' => $this->stringFromArray($transaction, 'foreign_currency_id', null),
'foreign_currency_code' => $transaction['foreign_currency_code'], 'foreign_currency_code' => $transaction['foreign_currency_code'],
'foreign_currency_name' => $transaction['foreign_currency_name'],
'foreign_currency_symbol' => $transaction['foreign_currency_symbol'], 'foreign_currency_symbol' => $transaction['foreign_currency_symbol'],
'foreign_currency_decimal_places' => $transaction['foreign_currency_decimal_places'], 'foreign_currency_decimal_places' => $transaction['foreign_currency_decimal_places'],
'amount' => $amount,
'foreign_amount' => $foreignAmount, // foreign converted to native currency:
'description' => $transaction['description'], 'foreign_currency_converted' => null !== $transaction['foreign_currency_id'] && $transaction['foreign_currency_id'] !== $this->default->id,
'source_id' => (string) $transaction['source_account_id'],
'source_name' => $transaction['source_account_name'], 'amount' => $amount,
'source_iban' => $transaction['source_account_iban'], 'native_amount' => $nativeAmount,
'source_type' => $transaction['source_account_type'], 'foreign_amount' => $foreignAmount,
'destination_id' => (string) $transaction['destination_account_id'], 'foreign_native_amount' => $foreignNativeAmount,
'destination_name' => $transaction['destination_account_name'], 'description' => $transaction['description'],
'destination_iban' => $transaction['destination_account_iban'], 'source_id' => (string) $transaction['source_account_id'],
'destination_type' => $transaction['destination_account_type'], 'source_name' => $transaction['source_account_name'],
'budget_id' => $this->stringFromArray($transaction, 'budget_id', null), 'source_iban' => $transaction['source_account_iban'],
'budget_name' => $transaction['budget_name'], 'source_type' => $transaction['source_account_type'],
'category_id' => $this->stringFromArray($transaction, 'category_id', null), 'destination_id' => (string) $transaction['destination_account_id'],
'category_name' => $transaction['category_name'], 'destination_name' => $transaction['destination_account_name'],
'bill_id' => $this->stringFromArray($transaction, 'bill_id', null), 'destination_iban' => $transaction['destination_account_iban'],
'bill_name' => $transaction['bill_name'], 'destination_type' => $transaction['destination_account_type'],
'reconciled' => $transaction['reconciled'], 'budget_id' => $this->stringFromArray($transaction, 'budget_id', null),
'budget_name' => $transaction['budget_name'],
'category_id' => $this->stringFromArray($transaction, 'category_id', null),
'category_name' => $transaction['category_name'],
'bill_id' => $this->stringFromArray($transaction, 'bill_id', null),
'bill_name' => $transaction['bill_name'],
'reconciled' => $transaction['reconciled'],
//'notes' => $this->groupRepos->getNoteText((int) $row['transaction_journal_id']), //'notes' => $this->groupRepos->getNoteText((int) $row['transaction_journal_id']),
//'tags' => $this->groupRepos->getTags((int) $row['transaction_journal_id']), //'tags' => $this->groupRepos->getTags((int) $row['transaction_journal_id']),
// 'internal_reference' => $metaFieldData['internal_reference'], 'internal_reference' => $meta['internal_reference'],
// 'external_id' => $metaFieldData['external_id'], 'external_id' => $meta['external_id'],
// 'original_source' => $metaFieldData['original_source'], 'original_source' => $meta['original_source'],
// 'recurrence_id' => $this->stringFromArray($metaFieldData->getArrayCopy(), 'recurrence_id', null), 'recurrence_id' => $meta['recurrence_id'],
// 'recurrence_total' => $this->integerFromArray($metaFieldData->getArrayCopy(), 'recurrence_total'), 'recurrence_total' => $meta['recurrence_total'],
// 'recurrence_count' => $this->integerFromArray($metaFieldData->getArrayCopy(), 'recurrence_count'), 'recurrence_count' => $meta['recurrence_count'],
// 'bunq_payment_id' => $metaFieldData['bunq_payment_id'], 'bunq_payment_id' => $meta['bunq_payment_id'],
// 'external_url' => $metaFieldData['external_url'], 'external_url' => $meta['external_url'],
// 'import_hash_v2' => $metaFieldData['import_hash_v2'], 'import_hash_v2' => $meta['import_hash_v2'],
'sepa_cc' => $meta['sepa_cc'],
'sepa_ct_op' => $meta['sepa_ct_op'],
'sepa_ct_id' => $meta['sepa_ct_id'],
'sepa_db' => $meta['sepa_db'],
'sepa_country' => $meta['sepa_country'],
'sepa_ep' => $meta['sepa_ep'],
'sepa_ci' => $meta['sepa_ci'],
'sepa_batch_id' => $meta['sepa_batch_id'],
// 'sepa_cc' => $metaFieldData['sepa_cc'], 'interest_date' => $this->date($meta['interest_date']),
// 'sepa_ct_op' => $metaFieldData['sepa_ct_op'], 'book_date' => $this->date($meta['book_date']),
// 'sepa_ct_id' => $metaFieldData['sepa_ct_id'], 'process_date' => $this->date($meta['process_date']),
// 'sepa_db' => $metaFieldData['sepa_db'], 'due_date' => $this->date($meta['due_date']),
// 'sepa_country' => $metaFieldData['sepa_country'], 'payment_date' => $this->date($meta['payment_date']),
// 'sepa_ep' => $metaFieldData['sepa_ep'], 'invoice_date' => $this->date($meta['invoice_date']),
// 'sepa_ci' => $metaFieldData['sepa_ci'],
// 'sepa_batch_id' => $metaFieldData['sepa_batch_id'],
// 'interest_date' => $this->dateFromArray($metaDateData, 'interest_date'),
// 'book_date' => $this->dateFromArray($metaDateData, 'book_date'),
// 'process_date' => $this->dateFromArray($metaDateData, 'process_date'),
// 'due_date' => $this->dateFromArray($metaDateData, 'due_date'),
// 'payment_date' => $this->dateFromArray($metaDateData, 'payment_date'),
// 'invoice_date' => $this->dateFromArray($metaDateData, 'invoice_date'),
// location data // location data
// 'longitude' => $longitude, // 'longitude' => $longitude,
@@ -174,4 +217,50 @@ class TransactionGroupTransformer extends AbstractTransformer
return null; return null;
} }
/**
* @inheritDoc
*/
public function collectMetaData(Collection $objects): void
{
// start with currencies:
$currencies = [];
$journals = [];
/** @var array $object */
foreach ($objects as $object) {
foreach ($object['sums'] as $sum) {
$id = $sum['currency_id'];
if (!array_key_exists($id, $currencies)) {
$currencyObject = TransactionCurrency::find($sum['currency_id']);
$currencies[$id] = $currencyObject;
}
}
/** @var array $transaction */
foreach ($object['transactions'] as $transaction) {
$id = $transaction['transaction_journal_id'];
$journals[$id] = [];
}
}
$this->currencies = $currencies;
$this->default = app('amount')->getDefaultCurrency();
// grab meta for all journals:
$meta = TransactionJournalMeta::whereIn('transaction_journal_id', array_keys($journals))->get();
/** @var TransactionJournalMeta $entry */
foreach ($meta as $entry) {
$id = (int) $entry->transaction_journal_id;
$this->meta[$id][$entry->name] = $entry->data;
}
}
/**
* @param string|null $string
* @return Carbon|null
*/
private function date(?string $string): ?Carbon
{
if(null === $string) {
return null;
}
return Carbon::createFromFormat('Y-m-d', $string);
}
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* default_cer.php * default_cer.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/* /*
* ExchangeRateSeeder.php * ExchangeRateSeeder.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2022 james@firefly-iii.org