mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Extra code for #1668
This commit is contained in:
parent
d2c1e30979
commit
c7043dffc2
@ -50,17 +50,19 @@ class GetBudgetsRequest extends YnabRequest
|
|||||||
Log::debug(sprintf('URI is %s', $uri));
|
Log::debug(sprintf('URI is %s', $uri));
|
||||||
|
|
||||||
$result = $this->authenticatedGetRequest($uri, []);
|
$result = $this->authenticatedGetRequest($uri, []);
|
||||||
//Log::debug('Raw GetBudgetsRequest result', $result);
|
Log::debug('Raw GetBudgetsRequest result', $result);
|
||||||
|
|
||||||
// expect data in [data][budgets]
|
// expect data in [data][budgets]
|
||||||
$rawBudgets = $result['data']['budgets'] ?? [];
|
$rawBudgets = $result['data']['budgets'] ?? [];
|
||||||
$freshBudgets = [];
|
$freshBudgets = [];
|
||||||
foreach ($rawBudgets as $rawBudget) {
|
foreach ($rawBudgets as $rawBudget) {
|
||||||
Log::debug('Raw content of budget is:', $rawBudget);
|
Log::debug(sprintf('Raw content of budget is: %s', json_encode($rawBudget, true)));
|
||||||
|
Log::debug(sprintf('Content of currency format is: %s', json_encode($rawBudget['currency_format'] ?? [], true)));
|
||||||
|
Log::debug(sprintf('ISO code is: %s', $rawBudget['currency_format']['iso_code'] ?? '(none)'));
|
||||||
$freshBudgets[] = [
|
$freshBudgets[] = [
|
||||||
'id' => $rawBudget['id'],
|
'id' => $rawBudget['id'],
|
||||||
'name' => $rawBudget['name'],
|
'name' => $rawBudget['name'],
|
||||||
'currency_code' => $rawBudget['currency_format']['iso_code'] ?? 'EUR',
|
'currency_code' => $rawBudget['currency_format']['iso_code'] ?? null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$this->budgets = $freshBudgets;
|
$this->budgets = $freshBudgets;
|
||||||
|
@ -74,6 +74,7 @@ abstract class YnabRequest
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$content = trim($res->getBody()->getContents());
|
$content = trim($res->getBody()->getContents());
|
||||||
|
Log::debug(sprintf('Raw body is: %s', $content));
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
|
@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
use FireflyIII\Services\Ynab\Request\GetTransactionsRequest;
|
use FireflyIII\Services\Ynab\Request\GetTransactionsRequest;
|
||||||
@ -42,6 +43,8 @@ class ImportDataHandler
|
|||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface */
|
/** @var AccountRepositoryInterface */
|
||||||
private $accountRepository;
|
private $accountRepository;
|
||||||
|
/** @var TransactionCurrency */
|
||||||
|
private $defaultCurrency;
|
||||||
/** @var ImportJob */
|
/** @var ImportJob */
|
||||||
private $importJob;
|
private $importJob;
|
||||||
/** @var OpposingAccountMapper */
|
/** @var OpposingAccountMapper */
|
||||||
@ -56,8 +59,9 @@ class ImportDataHandler
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$config = $this->repository->getConfiguration($this->importJob);
|
$config = $this->repository->getConfiguration($this->importJob);
|
||||||
$token = $config['access_token'];
|
$this->defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->importJob->user);
|
||||||
|
$token = $config['access_token'];
|
||||||
// make request for each mapping:
|
// make request for each mapping:
|
||||||
$mapping = $config['mapping'] ?? [];
|
$mapping = $config['mapping'] ?? [];
|
||||||
$total = [[]];
|
$total = [[]];
|
||||||
@ -179,7 +183,7 @@ class ImportDataHandler
|
|||||||
'transactions' => [
|
'transactions' => [
|
||||||
[
|
[
|
||||||
'currency_id' => null,
|
'currency_id' => null,
|
||||||
'currency_code' => $budget['currency_code'],
|
'currency_code' => $budget['currency_code'] ?? $this->defaultCurrency->code,
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'amount' => bcdiv((string)$transaction['amount'], '1000'),
|
'amount' => bcdiv((string)$transaction['amount'], '1000'),
|
||||||
'budget_id' => null,
|
'budget_id' => null,
|
||||||
|
Loading…
Reference in New Issue
Block a user