Add debug info and update routine for multiple accounts.

This commit is contained in:
James Cole
2018-05-23 07:38:03 +02:00
parent 50bf79ab18
commit 039e8d6e17
6 changed files with 28 additions and 4 deletions

View File

@@ -69,13 +69,13 @@ class StageAuthenticatedHandler
foreach ($logins as $loginArray) {
$loginId = $loginArray['id'] ?? -1;
if ($loginId === $selectedLogin) {
Log::debug('Selected login is in the array with logins.');
$login = new Login($loginArray);
Log::debug(sprintf('Selected login "%s" ("%s") which is in the array with logins.', $login->getProviderName(), $login->getCountryCode()));
}
}
if (null === $login) {
Log::debug('Login is null, simply use the first one from the array.');
$login = new Login($logins[0]);
Log::debug(sprintf('Login is null, simply use the first one "%s" ("%s") from the array.', $login->getProviderName(), $login->getCountryCode()));
}
// with existing login we can grab accounts from this login.
@@ -83,6 +83,7 @@ class StageAuthenticatedHandler
$config['accounts'] = [];
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Found account #%d ("%s") within Login.', $account->getId(), $account->getName()));
$config['accounts'][] = $account->toArray();
}
$this->repository->setConfiguration($this->importJob, $config);
@@ -125,6 +126,7 @@ class StageAuthenticatedHandler
*/
private function getLogins(): array
{
Log::debug('Now in StageAuthenticatedHandler::getLogins().');
$customer = $this->getCustomer($this->importJob);
/** @var ListLoginsRequest $request */
@@ -134,6 +136,9 @@ class StageAuthenticatedHandler
$request->call();
$logins = $request->getLogins();
$return = [];
Log::debug(sprintf('Found %d logins in users Spectre account.', \count($logins)));
/** @var Login $login */
foreach ($logins as $login) {
$return[] = $login->toArray();

View File

@@ -64,17 +64,27 @@ class StageImportDataHandler
throw new FireflyException('There are no accounts in this import job. Cannot continue.'); // @codeCoverageIgnore
}
$toImport = $config['account_mapping'] ?? [];
$totalSet = [[]];
foreach ($toImport as $spectreId => $localId) {
if ((int)$localId > 0) {
Log::debug(sprintf('Will get transactions from Spectre account #%d and save them in Firefly III account #%d', $spectreId, $localId));
$spectreAccount = $this->getSpectreAccount((int)$spectreId);
$localAccount = $this->getLocalAccount((int)$localId);
$set = $this->getTransactions($spectreAccount, $localAccount);
$this->repository->setTransactions($this->importJob, $set);
$merge = $this->getTransactions($spectreAccount, $localAccount);
$totalSet[] = $merge;
Log::debug(
sprintf('Found %d transactions in account "%s" (%s)', \count($merge), $spectreAccount->getName(), $spectreAccount->getCurrencyCode())
);
continue;
}
Log::debug(sprintf('Local account is = zero, will not import from Spectr account with ID #%d', $spectreId));
}
$totalSet = array_merge(...$totalSet);
Log::debug(sprintf('Found %d transactions in total.', \count($totalSet)));
$this->repository->setTransactions($this->importJob, $totalSet);
}
/**
* @param ImportJob $importJob
*
@@ -151,9 +161,11 @@ class StageImportDataHandler
break;
case 'original_amount':
$foreignAmount = $value;
Log::debug(sprintf('Foreign amount is now %s', $value));
break;
case 'original_currency_code':
$foreignCurrencyCode = $value;
Log::debug(sprintf('Foreign currency code is now %s', $value));
break;
default:
$notes .= $key . ': ' . $value . ' ' . "\n"; // for newline in Markdown.