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

@@ -62,6 +62,7 @@ class TransactionFactory
throw new FireflyException('Cannot store transaction without currency information.'); throw new FireflyException('Cannot store transaction without currency information.');
} }
$data['foreign_amount'] = '' === (string)$data['foreign_amount'] ? null : $data['foreign_amount']; $data['foreign_amount'] = '' === (string)$data['foreign_amount'] ? null : $data['foreign_amount'];
Log::debug(sprintf('Create transaction for account #%d ("%s") with amount %s', $data['account']->id, $data['account']->name, $data['amount']));
return Transaction::create( return Transaction::create(
[ [
@@ -96,10 +97,12 @@ class TransactionFactory
// type of source account depends on journal type: // type of source account depends on journal type:
$sourceType = $this->accountType($journal, 'source'); $sourceType = $this->accountType($journal, 'source');
Log::debug(sprintf('Expect source account to be of type %s', $sourceType));
$sourceAccount = $this->findAccount($sourceType, $data['source_id'], $data['source_name']); $sourceAccount = $this->findAccount($sourceType, $data['source_id'], $data['source_name']);
// same for destination account: // same for destination account:
$destinationType = $this->accountType($journal, 'destination'); $destinationType = $this->accountType($journal, 'destination');
Log::debug(sprintf('Expect source destination to be of type %s', $destinationType));
$destinationAccount = $this->findAccount($destinationType, $data['destination_id'], $data['destination_name']); $destinationAccount = $this->findAccount($destinationType, $data['destination_id'], $data['destination_name']);
// first make a "negative" (source) transaction based on the data in the array. // first make a "negative" (source) transaction based on the data in the array.
$source = $this->create( $source = $this->create(

View File

@@ -52,6 +52,7 @@ class TransactionJournalFactory
// store basic journal first. // store basic journal first.
$type = $this->findTransactionType($data['type']); $type = $this->findTransactionType($data['type']);
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user); $defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
Log::debug(sprintf('Going to store a %s', $type->type));
$journal = TransactionJournal::create( $journal = TransactionJournal::create(
[ [
'user_id' => $data['user'], 'user_id' => $data['user'],

View File

@@ -29,6 +29,7 @@ use FireflyIII\Models\TransactionJournal;
/** /**
* Class TransactionType. * Class TransactionType.
* @property string $type
*/ */
class TransactionType extends Model class TransactionType extends Model
{ {

View File

@@ -108,6 +108,8 @@ trait TransactionServiceTrait
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user); $repository->setUser($this->user);
Log::debug(sprintf('Going to find account #%d ("%s")', $accountId, $accountName));
if (null === $expectedType) { if (null === $expectedType) {
return $repository->findNull($accountId); return $repository->findNull($accountId);
} }

View File

@@ -69,13 +69,13 @@ class StageAuthenticatedHandler
foreach ($logins as $loginArray) { foreach ($logins as $loginArray) {
$loginId = $loginArray['id'] ?? -1; $loginId = $loginArray['id'] ?? -1;
if ($loginId === $selectedLogin) { if ($loginId === $selectedLogin) {
Log::debug('Selected login is in the array with logins.');
$login = new Login($loginArray); $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) { if (null === $login) {
Log::debug('Login is null, simply use the first one from the array.');
$login = new Login($logins[0]); $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. // with existing login we can grab accounts from this login.
@@ -83,6 +83,7 @@ class StageAuthenticatedHandler
$config['accounts'] = []; $config['accounts'] = [];
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
Log::debug(sprintf('Found account #%d ("%s") within Login.', $account->getId(), $account->getName()));
$config['accounts'][] = $account->toArray(); $config['accounts'][] = $account->toArray();
} }
$this->repository->setConfiguration($this->importJob, $config); $this->repository->setConfiguration($this->importJob, $config);
@@ -125,6 +126,7 @@ class StageAuthenticatedHandler
*/ */
private function getLogins(): array private function getLogins(): array
{ {
Log::debug('Now in StageAuthenticatedHandler::getLogins().');
$customer = $this->getCustomer($this->importJob); $customer = $this->getCustomer($this->importJob);
/** @var ListLoginsRequest $request */ /** @var ListLoginsRequest $request */
@@ -134,6 +136,9 @@ class StageAuthenticatedHandler
$request->call(); $request->call();
$logins = $request->getLogins(); $logins = $request->getLogins();
$return = []; $return = [];
Log::debug(sprintf('Found %d logins in users Spectre account.', \count($logins)));
/** @var Login $login */ /** @var Login $login */
foreach ($logins as $login) { foreach ($logins as $login) {
$return[] = $login->toArray(); $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 throw new FireflyException('There are no accounts in this import job. Cannot continue.'); // @codeCoverageIgnore
} }
$toImport = $config['account_mapping'] ?? []; $toImport = $config['account_mapping'] ?? [];
$totalSet = [[]];
foreach ($toImport as $spectreId => $localId) { foreach ($toImport as $spectreId => $localId) {
if ((int)$localId > 0) { if ((int)$localId > 0) {
Log::debug(sprintf('Will get transactions from Spectre account #%d and save them in Firefly III account #%d', $spectreId, $localId)); 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); $spectreAccount = $this->getSpectreAccount((int)$spectreId);
$localAccount = $this->getLocalAccount((int)$localId); $localAccount = $this->getLocalAccount((int)$localId);
$set = $this->getTransactions($spectreAccount, $localAccount); $merge = $this->getTransactions($spectreAccount, $localAccount);
$this->repository->setTransactions($this->importJob, $set); $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 * @param ImportJob $importJob
* *
@@ -151,9 +161,11 @@ class StageImportDataHandler
break; break;
case 'original_amount': case 'original_amount':
$foreignAmount = $value; $foreignAmount = $value;
Log::debug(sprintf('Foreign amount is now %s', $value));
break; break;
case 'original_currency_code': case 'original_currency_code':
$foreignCurrencyCode = $value; $foreignCurrencyCode = $value;
Log::debug(sprintf('Foreign currency code is now %s', $value));
break; break;
default: default:
$notes .= $key . ': ' . $value . ' ' . "\n"; // for newline in Markdown. $notes .= $key . ': ' . $value . ' ' . "\n"; // for newline in Markdown.