mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add strict types, add debug info
This commit is contained in:
parent
5c3b4d1663
commit
9493046212
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* Controller.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -82,6 +83,11 @@ class Controller extends BaseController
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$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->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* ShowController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* SumController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* SumController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* NetWorthController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -29,4 +30,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* ConfigurationController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -24,4 +25,4 @@ namespace FireflyIII\Api\V2\Controllers\System;
|
||||
class ConfigurationController
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* DebugController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -26,4 +27,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
|
||||
class DebugController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* PreferencesController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* BillController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* VersionUpdateController.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -27,4 +28,4 @@ namespace FireflyIII\Api\V2\Controllers;
|
||||
class VersionUpdateController extends Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* ListRequest.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AutoSum.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -142,10 +142,10 @@ class Cron extends Command
|
||||
$this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
|
||||
}
|
||||
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) {
|
||||
$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));
|
||||
}
|
||||
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) {
|
||||
$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));
|
||||
}
|
||||
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) {
|
||||
$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));
|
||||
}
|
||||
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) {
|
||||
$this->error(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
|
||||
$this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountTypeEnum.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -41,4 +42,4 @@ enum AccountTypeEnum: string
|
||||
case RECONCILIATION = 'Reconciliation account';
|
||||
case REVENUE = 'Revenue account';
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AutoBudgetType.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -28,4 +29,4 @@ enum AutoBudgetType: int
|
||||
{
|
||||
case AUTO_BUDGET_RESET = 1;
|
||||
case AUTO_BUDGET_ROLLOVER = 2;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* RecurrenceRepetitionWeekend.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -27,4 +28,4 @@ enum RecurrenceRepetitionWeekend: int
|
||||
case WEEKEND_SKIP_CREATION = 2;
|
||||
case WEEKEND_TO_FRIDAY = 3;
|
||||
case WEEKEND_TO_MONDAY = 4;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* TransactionTypeEnum.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -33,4 +34,4 @@ enum TransactionTypeEnum: string
|
||||
case RECONCILIATION = 'Reconciliation';
|
||||
case TRANSFER = 'Transfer';
|
||||
case WITHDRAWAL = 'Withdrawal';
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* UserRoleEnum.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -31,4 +32,4 @@ enum UserRoleEnum: string
|
||||
case OWNER = 'owner';
|
||||
case READ_ONLY = 'ro';
|
||||
case VIEW_REPORTS = 'view_reports';
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* WebhookDelivery.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -24,4 +25,4 @@ namespace FireflyIII\Enums;
|
||||
enum WebhookDelivery: int
|
||||
{
|
||||
case JSON = 300;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* WebhookResponse.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -26,4 +27,4 @@ enum WebhookResponse: int
|
||||
case TRANSACTIONS = 200;
|
||||
case ACCOUNTS = 210;
|
||||
case NONE = 220;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* WebhookTrigger.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -26,4 +27,4 @@ enum WebhookTrigger: int
|
||||
case STORE_TRANSACTION = 100;
|
||||
case UPDATE_TRANSACTION = 110;
|
||||
case DESTROY_TRANSACTION = 120;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Exceptions;
|
||||
|
||||
@ -10,4 +11,4 @@ use Exception;
|
||||
class BadHttpHeaderException extends Exception
|
||||
{
|
||||
public int $statusCode = 406;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
@ -42,4 +43,4 @@ class AcceptHeaders
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* DownloadExchangeRates.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -77,6 +78,7 @@ class DownloadExchangeRates implements ShouldQueue
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Log::debug('Now in handle()');
|
||||
$currencies = $this->repository->get();
|
||||
|
||||
/** @var TransactionCurrency $currency */
|
||||
@ -108,7 +110,7 @@ class DownloadExchangeRates implements ShouldQueue
|
||||
$res = $client->get($url);
|
||||
$statusCode = $res->getStatusCode();
|
||||
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;
|
||||
}
|
||||
$body = (string) $res->getBody();
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
$this->fireAutoBudget();
|
||||
$this->fireExchangeRateJob();
|
||||
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')));
|
||||
/** @var DownloadExchangeRates $job */
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* ConvertsExchangeRates.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AbstractTransformer.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -21,6 +22,7 @@
|
||||
|
||||
namespace FireflyIII\Transformers\V2;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
/**
|
||||
@ -29,4 +31,9 @@ use League\Fractal\TransformerAbstract;
|
||||
abstract class AbstractTransformer extends TransformerAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $objects
|
||||
* @return void
|
||||
*/
|
||||
abstract public function collectMetaData(Collection $objects): void;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* AccountTransformer.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* TransactionGroupTransformer.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
@ -21,14 +22,27 @@
|
||||
|
||||
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\Support\Http\Api\ConvertsExchangeRates;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class TransactionGroupTransformer
|
||||
*/
|
||||
class TransactionGroupTransformer extends AbstractTransformer
|
||||
{
|
||||
use ConvertsExchangeRates;
|
||||
|
||||
private array $currencies = [];
|
||||
private TransactionCurrency $default;
|
||||
private array $meta;
|
||||
|
||||
/**
|
||||
* @param array $group
|
||||
*
|
||||
@ -69,76 +83,105 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
|
||||
private function transformTransaction(array $transaction): array
|
||||
{
|
||||
$transaction = new NullArrayObject($transaction);
|
||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
|
||||
$amount = app('steam')->positive((string) ($row['amount'] ?? '0'));
|
||||
$foreignAmount = null;
|
||||
$transaction = new NullArrayObject($transaction);
|
||||
$journalId = (int) $transaction['transaction_journal_id'];
|
||||
$meta = new NullArrayObject($this->meta[$journalId] ?? []);
|
||||
$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']) {
|
||||
$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 [
|
||||
'user' => (string) $transaction['user_id'],
|
||||
'transaction_journal_id' => (string) $transaction['transaction_journal_id'],
|
||||
'type' => strtolower($type),
|
||||
'date' => $transaction['date']->toAtomString(),
|
||||
'order' => $transaction['order'],
|
||||
'currency_id' => (string) $transaction['currency_id'],
|
||||
'currency_code' => $transaction['currency_code'],
|
||||
'currency_name' => $transaction['currency_name'],
|
||||
'currency_symbol' => $transaction['currency_symbol'],
|
||||
'currency_decimal_places' => (int) $transaction['currency_decimal_places'],
|
||||
'user' => (string) $transaction['user_id'],
|
||||
'transaction_journal_id' => (string) $transaction['transaction_journal_id'],
|
||||
'type' => strtolower($type),
|
||||
'date' => $transaction['date']->toAtomString(),
|
||||
'order' => $transaction['order'],
|
||||
'currency_id' => (string) $transaction['currency_id'],
|
||||
'currency_code' => $transaction['currency_code'],
|
||||
'currency_name' => $transaction['currency_name'],
|
||||
'currency_symbol' => $transaction['currency_symbol'],
|
||||
'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_code' => $transaction['foreign_currency_code'],
|
||||
'foreign_currency_name' => $transaction['foreign_currency_name'],
|
||||
'foreign_currency_symbol' => $transaction['foreign_currency_symbol'],
|
||||
'foreign_currency_decimal_places' => $transaction['foreign_currency_decimal_places'],
|
||||
'amount' => $amount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'description' => $transaction['description'],
|
||||
'source_id' => (string) $transaction['source_account_id'],
|
||||
'source_name' => $transaction['source_account_name'],
|
||||
'source_iban' => $transaction['source_account_iban'],
|
||||
'source_type' => $transaction['source_account_type'],
|
||||
'destination_id' => (string) $transaction['destination_account_id'],
|
||||
'destination_name' => $transaction['destination_account_name'],
|
||||
'destination_iban' => $transaction['destination_account_iban'],
|
||||
'destination_type' => $transaction['destination_account_type'],
|
||||
'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'],
|
||||
|
||||
// foreign converted to native currency:
|
||||
'foreign_currency_converted' => null !== $transaction['foreign_currency_id'] && $transaction['foreign_currency_id'] !== $this->default->id,
|
||||
|
||||
'amount' => $amount,
|
||||
'native_amount' => $nativeAmount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'foreign_native_amount' => $foreignNativeAmount,
|
||||
'description' => $transaction['description'],
|
||||
'source_id' => (string) $transaction['source_account_id'],
|
||||
'source_name' => $transaction['source_account_name'],
|
||||
'source_iban' => $transaction['source_account_iban'],
|
||||
'source_type' => $transaction['source_account_type'],
|
||||
'destination_id' => (string) $transaction['destination_account_id'],
|
||||
'destination_name' => $transaction['destination_account_name'],
|
||||
'destination_iban' => $transaction['destination_account_iban'],
|
||||
'destination_type' => $transaction['destination_account_type'],
|
||||
'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']),
|
||||
//'tags' => $this->groupRepos->getTags((int) $row['transaction_journal_id']),
|
||||
|
||||
// 'internal_reference' => $metaFieldData['internal_reference'],
|
||||
// 'external_id' => $metaFieldData['external_id'],
|
||||
// 'original_source' => $metaFieldData['original_source'],
|
||||
// 'recurrence_id' => $this->stringFromArray($metaFieldData->getArrayCopy(), 'recurrence_id', null),
|
||||
// 'recurrence_total' => $this->integerFromArray($metaFieldData->getArrayCopy(), 'recurrence_total'),
|
||||
// 'recurrence_count' => $this->integerFromArray($metaFieldData->getArrayCopy(), 'recurrence_count'),
|
||||
// 'bunq_payment_id' => $metaFieldData['bunq_payment_id'],
|
||||
// 'external_url' => $metaFieldData['external_url'],
|
||||
// 'import_hash_v2' => $metaFieldData['import_hash_v2'],
|
||||
'internal_reference' => $meta['internal_reference'],
|
||||
'external_id' => $meta['external_id'],
|
||||
'original_source' => $meta['original_source'],
|
||||
'recurrence_id' => $meta['recurrence_id'],
|
||||
'recurrence_total' => $meta['recurrence_total'],
|
||||
'recurrence_count' => $meta['recurrence_count'],
|
||||
'bunq_payment_id' => $meta['bunq_payment_id'],
|
||||
'external_url' => $meta['external_url'],
|
||||
'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'],
|
||||
// 'sepa_ct_op' => $metaFieldData['sepa_ct_op'],
|
||||
// 'sepa_ct_id' => $metaFieldData['sepa_ct_id'],
|
||||
// 'sepa_db' => $metaFieldData['sepa_db'],
|
||||
// 'sepa_country' => $metaFieldData['sepa_country'],
|
||||
// 'sepa_ep' => $metaFieldData['sepa_ep'],
|
||||
// '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'),
|
||||
'interest_date' => $this->date($meta['interest_date']),
|
||||
'book_date' => $this->date($meta['book_date']),
|
||||
'process_date' => $this->date($meta['process_date']),
|
||||
'due_date' => $this->date($meta['due_date']),
|
||||
'payment_date' => $this->date($meta['payment_date']),
|
||||
'invoice_date' => $this->date($meta['invoice_date']),
|
||||
|
||||
// location data
|
||||
// 'longitude' => $longitude,
|
||||
@ -174,4 +217,50 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* default_cer.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* ExchangeRateSeeder.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
|
Loading…
Reference in New Issue
Block a user