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
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
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.');
}
$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(
[
@ -96,10 +97,12 @@ class TransactionFactory
// type of source account depends on journal type:
$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']);
// same for destination account:
$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']);
// first make a "negative" (source) transaction based on the data in the array.
$source = $this->create(

View File

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

View File

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

View File

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

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.