Lots of new code for the Spectre routine.

This commit is contained in:
James Cole
2018-05-19 10:44:33 +02:00
parent 1732ce63f3
commit 04953b5645
26 changed files with 1729 additions and 242 deletions

View File

@@ -78,7 +78,6 @@ class JobConfigurationController extends Controller
return redirect(route('import.index'));
}
Log::debug(sprintf('Now in JobConfigurationController::index() with job "%s" and status "%s"', $importJob->key, $importJob->status));
// if provider has no config, just push it through:

View File

@@ -0,0 +1,153 @@
<?php
/**
* SpectreJobConfiguration.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticateConfig;
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedConfigHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccount;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewConfig;
use FireflyIII\Support\Import\JobConfiguration\Spectre\SpectreJobConfig;
use Illuminate\Support\MessageBag;
/**
* Class SpectreJobConfiguration
*
* @package FireflyIII\Import\JobConfiguration
*/
class SpectreJobConfiguration implements JobConfigurationInterface
{
/** @var SpectreJobConfig */
private $handler;
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* ConfiguratorInterface constructor.
*/
public function __construct()
{
}
/**
* Returns true when the initial configuration for this job is complete.
*
* @return bool
*/
public function configurationComplete(): bool
{
return $this->handler->configurationComplete();
}
/**
* Store any data from the $data array into the job. Anything in the message bag will be flashed
* as an error to the user, regardless of its content.
*
* @param array $data
*
* @return MessageBag
*/
public function configureJob(array $data): MessageBag
{
return $this->handler->configureJob($data);
}
/**
* Return the data required for the next step in the job configuration.
*
* @return array
*/
public function getNextData(): array
{
return $this->handler->getNextData();
}
/**
* Returns the view of the next step in the job configuration.
*
* @return string
*/
public function getNextView(): string
{
return $this->handler->getNextView();
}
/**
* @param ImportJob $importJob
*
* @throws FireflyException
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
$this->handler = $this->getHandler();
}
/**
* @return SpectreJobConfig
* @throws FireflyException
*/
private function getHandler(): SpectreJobConfig
{
$handler = null;
switch ($this->importJob->stage) {
case 'new':
$handler = app(NewConfig::class);
$handler->setImportJob($this->importJob);
break;
case 'authenticate':
/** @var SpectreJobConfig $handler */
$handler = app(AuthenticateConfig::class);
$handler->setImportJob($this->importJob);
break;
case 'choose-login':
/** @var SpectreJobConfig $handler */
$handler = app(ChooseLoginHandler::class);
$handler->setImportJob($this->importJob);
break;
case 'authenticated':
/** @var AuthenticatedConfigHandler $handler */
$handler = app(AuthenticatedConfigHandler::class);
$handler->setImportJob($this->importJob);
break;
case 'choose-account':
/** @var ChooseAccount $handler */
$handler = app(ChooseAccount::class);
$handler->setImportJob($this->importJob);
break;
default:
throw new FireflyException(sprintf('Firefly III cannot create a configuration handler for stage "%s"', $this->importJob->stage));
}
return $handler;
}
}

View File

@@ -25,6 +25,9 @@ namespace FireflyIII\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Spectre\ImportDataHandler;
use FireflyIII\Support\Import\Routine\Spectre\ManageLoginsHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
/**
@@ -54,21 +57,59 @@ class SpectreRoutine implements RoutineInterface
*/
public function run(): void
{
$valid = ['ready_to_run','error']; // should be only ready_to_run
if(in_array($this->importJob->status, $valid)) {
$valid = ['ready_to_run']; // should be only ready_to_run
if (in_array($this->importJob->status, $valid)) {
switch ($this->importJob->stage) {
default:
throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage));
case 'new':
case 'authenticate':
/** @var StageNewHandler $handler */
$handler = app(StageNewHandler::class);
$handler->setImportJob($this->importJob);
$handler->run();
$this->repository->setStage($this->importJob, 'authenticate');
var_dump($this->repository->getConfiguration($this->importJob));
exit;
$this->repository->setStage($this->importJob, 'manage-logins');
break;
case 'authenticate':
// set job to require config.
$this->repository->setStatus($this->importJob, 'need_job_config');
return;
case 'manage-logins':
// list all of the users logins.
$handler = new ManageLoginsHandler;
$handler->setImportJob($this->importJob);
$handler->run();
// if count logins is zero, go to authenticate stage
if ($handler->countLogins === 0) {
$this->repository->setStage($this->importJob, 'authenticate');
$this->repository->setStatus($this->importJob, 'ready_to_run');
return;
}
// or return to config to select login.
$this->repository->setStage($this->importJob, 'choose-login');
$this->repository->setStatus($this->importJob, 'need_job_config');
break;
case 'authenticated':
// get accounts from login, store in job.
$handler = new StageAuthenticatedHandler;
$handler->setImportJob($this->importJob);
$handler->run();
// return to config to select account(s).
$this->repository->setStage($this->importJob, 'choose-account');
$this->repository->setStatus($this->importJob, 'need_job_config');
break;
case 'go-for-import':
// user has chosen account mapping. Should now be ready to import data.
//$this->repository->setStatus($this->importJob, 'running');
//$this->repository->setStage($this->importJob, 'do_import');
$handler = new ImportDataHandler;
$handler->setImportJob($this->importJob);
$handler->run();
$this->repository->setStatus($this->importJob, 'provider_finished');
$this->repository->setStage($this->importJob, 'final');
}
}

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Models;
use Crypt;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\User;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
@@ -31,16 +32,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\JoinClause;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Log;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\AccountMeta;
use FireflyIII\User;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\PiggyBank;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Account.
*
* @property string $name
* @property string $iban
*/
class Account extends Model
{

View File

@@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class ImportJob.
*
* @property array $configuration
* @property User $user
*/
class ImportJob extends Model

View File

@@ -354,12 +354,13 @@ class ImportJobRepository implements ImportJobRepositoryInterface
*/
public function setConfiguration(ImportJob $job, array $configuration): ImportJob
{
Log::debug(sprintf('Incoming config for job "%s" is: ', $job->key), $configuration);
Log::debug('Updating configuration...');
//Log::debug(sprintf('Incoming config for job "%s" is: ', $job->key), $configuration);
$currentConfig = $job->configuration;
$newConfig = array_merge($currentConfig, $configuration);
$job->configuration = $newConfig;
$job->save();
Log::debug(sprintf('Set config of job "%s" to: ', $job->key), $newConfig);
//Log::debug(sprintf('Set config of job "%s" to: ', $job->key), $newConfig);
return $job;
}

View File

@@ -49,6 +49,40 @@ class Account extends SpectreObject
/** @var Carbon */
private $updatedAt;
/**
* @return string
*/
public function getNature(): string
{
return $this->nature;
}
/**
* @return float
*/
public function getBalance(): float
{
return $this->balance;
}
/**
* @return string
*/
public function getCurrencyCode(): string
{
return $this->currencyCode;
}
/**
* @return array
*/
public function getExtra(): array
{
return $this->extra;
}
/**
* Account constructor.
*

View File

@@ -68,6 +68,49 @@ class Login extends SpectreObject
/** @var Carbon */
private $updatedAt;
/**
* @return string
*/
public function getCountryCode(): string
{
return $this->countryCode;
}
/**
* @return Carbon
*/
public function getLastSuccessAt(): Carbon
{
return $this->lastSuccessAt;
}
/**
* @return string
*/
public function getProviderName(): string
{
return $this->providerName;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @return Carbon
*/
public function getUpdatedAt(): Carbon
{
return $this->updatedAt;
}
/**
* Login constructor.
*
@@ -129,7 +172,7 @@ class Login extends SpectreObject
'id' => $this->id,
'last_attempt' => $this->lastAttempt->toArray(),
'last_success_at' => $this->lastSuccessAt->toIso8601String(),
'next_refresh_possible_at' => $this->nextRefreshPossibleAt,
'next_refresh_possible_at' => $this->nextRefreshPossibleAt->toIso8601String(),
'provider_code' => $this->providerCode,
'provider_id' => $this->providerId,
'provider_name' => $this->providerName,

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Services\Spectre\Request;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Spectre\Object\Customer;
use FireflyIII\Services\Spectre\Object\Login;
use Illuminate\Support\Collection;
use Log;
/**
@@ -64,12 +65,19 @@ class ListLoginsRequest extends SpectreRequest
} else {
Log::debug('No next page.');
}
$collection = new Collection;
// store logins:
/** @var array $loginArray */
foreach ($response['data'] as $loginArray) {
$this->logins[] = new Login($loginArray);
$collection->push(new Login($loginArray));
}
// sort logins by date created:
$sorted = $collection->sortByDesc(
function (Login $login) {
return $login->getUpdatedAt()->timestamp;
}
);
$this->logins = $sorted->toArray();
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* AuthenticateConfig.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\JobConfiguration\Spectre;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Services\Spectre\Object\Token;
use Illuminate\Support\MessageBag;
/**
* Class AuthenticateConfig
*
* @package FireflyIII\Support\Import\JobConfiguration\Spectre
*/
class AuthenticateConfig implements SpectreJobConfig
{
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* Return true when this stage is complete.
*
* always returns false.
*
* @return bool
*/
public function configurationComplete(): bool
{
return false;
}
/**
* Store the job configuration.
*
* @param array $data
*
* @return MessageBag
*/
public function configureJob(array $data): MessageBag
{
// does nothing
return new MessageBag;
}
/**
* Get data for config view.
*
* @return array
* @throws FireflyException
*/
public function getNextData(): array
{
// next data only makes sure the job is ready for the next stage.
$this->repository->setStatus($this->importJob, 'ready_to_run');
$this->repository->setStage($this->importJob, 'authenticated');
$config = $this->importJob->configuration;
$token = isset($config['token']) ? new Token($config['token']) : null;
if (null !== $token) {
return ['token-url' => $token->getConnectUrl()];
}
throw new FireflyException('The import routine cannot continue without a Spectre token. Apologies.');
}
/**
* Get the view for this stage.
*
* @return string
*/
public function getNextView(): string
{
return 'import.spectre.redirect';
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* AuthenticatedConfigHandler.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\JobConfiguration\Spectre;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Illuminate\Support\MessageBag;
class AuthenticatedConfigHandler implements SpectreJobConfig
{
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* Return true when this stage is complete.
*
* @return bool
*/
public function configurationComplete(): bool
{
return true;
}
/**
* Store the job configuration.
*
* @param array $data
*
* @return MessageBag
*/
public function configureJob(array $data): MessageBag
{
return new MessageBag();
}
/**
* Get data for config view.
*
* @return array
*/
public function getNextData(): array
{
return [];
}
/**
* Get the view for this stage.
*
* @return string
*/
public function getNextView(): string
{
return '';
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
}
}

View File

@@ -0,0 +1,241 @@
<?php
/**
* ChooseAccount.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\JobConfiguration\Spectre;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account as AccountModel;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Services\Spectre\Object\Account as SpectreAccount;
use FireflyIII\Services\Spectre\Object\Login;
use Illuminate\Support\MessageBag;
/**
* Class ChooseAccount
*
* @package FireflyIII\Support\Import\JobConfiguration\Spectre
*/
class ChooseAccount implements SpectreJobConfig
{
/** @var AccountRepositoryInterface */
private $accountRepository;
/** @var CurrencyRepositoryInterface */
private $currencyRepository;
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* Return true when this stage is complete.
*
* @return bool
*/
public function configurationComplete(): bool
{
$config = $this->importJob->configuration;
$importAccounts = $config['account_mapping'] ?? [];
$complete = \count($importAccounts) > 0 && $importAccounts !== [0 => 0];
if ($complete) {
$this->repository->setStage($this->importJob, 'go-for-import');
}
return $complete;
}
/**
* Store the job configuration.
*
* @param array $data
*
* @return MessageBag
*/
public function configureJob(array $data): MessageBag
{
$config = $this->importJob->configuration;
$mapping = $data['account_mapping'] ?? [];
$final = [];
foreach ($mapping as $spectreId => $fireflyIIIId) {
// validate each
$spectreId = $this->validSpectreAccount((int)$spectreId);
$accountId = $this->validFireflyIIIAccount((int)$fireflyIIIId);
$final[$spectreId] = $accountId;
}
$messages = new MessageBag;
$config['account_mapping'] = $final;
$this->repository->setConfiguration($this->importJob, $config);
if (\count($final) === 0 || $final === [0 => 0]) {
$messages->add('count', trans('import.spectre_no_mapping'));
}
return $messages;
}
/**
* Get data for config view.
*
* @return array
* @throws FireflyException
*/
public function getNextData(): array
{
$config = $this->importJob->configuration;
$accounts = $config['accounts'] ?? [];
if (\count($accounts) === 0) {
throw new FireflyException('It seems you have no accounts with this bank. The import cannot continue.');
}
$converted = [];
foreach ($accounts as $accountArray) {
$converted[] = new SpectreAccount($accountArray);
}
// get the provider that was used.
$login = null;
$logins = $config['all-logins'] ?? [];
$selected = $config['selected-login'] ?? 0;
if (\count($logins) === 0) {
throw new FireflyException('It seems you have no configured logins in this import job. The import cannot continue.');
}
if ($selected === 0) {
$login = new Login($logins[0]);
}
if ($selected !== 0) {
foreach ($logins as $loginArray) {
$loginId = $loginArray['id'] ?? -1;
if ($loginId === $selected) {
$login = new Login($loginArray);
}
}
}
if (null === $login) {
throw new FireflyException('Was not able to determine which login to use. The import cannot continue.');
}
// list the users accounts:
$accounts = $this->accountRepository->getAccountsByType([AccountType::ASSET]);
$array = [];
/** @var AccountModel $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id');
$currency = $this->getCurrency($currencyId);
$array[$accountId] = [
'name' => $account->name,
'iban' => $account->iban,
'code' => $currency->code,
];
}
return [
'accounts' => $converted,
'ff_accounts' => $array,
'login' => $login,
];
}
/**
* Get the view for this stage.
*
* @return string
*/
public function getNextView(): string
{
return 'import.spectre.accounts';
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->repository->setUser($importJob->user);
$this->currencyRepository->setUser($importJob->user);
$this->accountRepository->setUser($importJob->user);
}
/**
* @param int $currencyId
*
* @return TransactionCurrency
*/
private function getCurrency(int $currencyId): TransactionCurrency
{
$currency = $this->currencyRepository->findNull($currencyId);
if (null === $currency) {
return app('amount')->getDefaultCurrencyByUser($this->importJob->user);
}
return $currency;
}
/**
* @param int $accountId
*
* @return int
*/
private function validFireflyIIIAccount(int $accountId): int
{
$account = $this->accountRepository->findNull($accountId);
if (null === $account) {
return 0;
}
return $accountId;
}
/**
* @param int $accountId
*
* @return int
*/
private function validSpectreAccount(int $accountId): int
{
$config = $this->importJob->configuration;
$accounts = $config['accounts'] ?? [];
foreach ($accounts as $account) {
if ((int)$account['id'] === $accountId) {
return $accountId;
}
}
return 0;
}
}

View File

@@ -0,0 +1,205 @@
<?php
/**
* ChooseLoginHandler.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\JobConfiguration\Spectre;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Services\Spectre\Object\Customer;
use FireflyIII\Services\Spectre\Object\Login;
use FireflyIII\Services\Spectre\Object\Token;
use FireflyIII\Services\Spectre\Request\CreateTokenRequest;
use FireflyIII\Services\Spectre\Request\ListCustomersRequest;
use FireflyIII\Services\Spectre\Request\NewCustomerRequest;
use Illuminate\Support\MessageBag;
use Log;
/**
* Class ChooseLoginHandler
*
* @package FireflyIII\Support\Import\JobConfiguration\Spectre
*/
class ChooseLoginHandler implements SpectreJobConfig
{
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* Return true when this stage is complete.
*
* @return bool
*/
public function configurationComplete(): bool
{
$config = $this->importJob->configuration;
if(isset($config['selected-login'])) {
return true;
}
return false;
}
/**
* Store the job configuration.
*
* @param array $data
*
* @return MessageBag
* @throws FireflyException
*/
public function configureJob(array $data): MessageBag
{
$selectedLogin = (int)$data['spectre_login_id'];
$config = $this->importJob->configuration;
$config['selected-login'] = $selectedLogin;
$this->repository->setConfiguration($this->importJob, $config);
// if selected login is zero, create a new one.
if ($selectedLogin === 0) {
$customer = $this->getCustomer();
// get a token for the user and redirect to next stage
$token = $this->getToken($customer);
$config['token'] = $token->toArray();
$this->repository->setConfiguration($this->importJob, $config);
// move job to correct stage to redirect to Spectre:
$this->repository->setStage($this->importJob, 'authenticate');
return new MessageBag;
}
$this->repository->setStage($this->importJob, 'authenticated');
return new MessageBag;
}
/**
* Get data for config view.
*
* @return array
*/
public function getNextData(): array
{
$config = $this->importJob->configuration;
$data = ['logins' => []];
$logins = $config['all-logins'] ?? [];
foreach ($logins as $login) {
$data['logins'][] = new Login($login);
}
return $data;
}
/**
* Get the view for this stage.
*
* @return string
*/
public function getNextView(): string
{
return 'import.spectre.choose-login';
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
}
/**
* @return Customer
* @throws FireflyException
*/
private function getCustomer(): Customer
{
Log::debug('Now in stageNewHandler::getCustomer()');
$customer = $this->getExistingCustomer();
if (null === $customer) {
Log::debug('The customer is NULL, will fire a newCustomerRequest.');
$newCustomerRequest = new NewCustomerRequest($this->importJob->user);
$customer = $newCustomerRequest->getCustomer();
}
Log::debug('The customer is not null.');
return $customer;
}
/**
* @return Customer|null
* @throws FireflyException
*/
private function getExistingCustomer(): ?Customer
{
Log::debug('Now in getExistingCustomer()');
$preference = app('preferences')->getForUser($this->importJob->user, 'spectre_customer');
if (null !== $preference) {
Log::debug('Customer is in user configuration');
$customer = new Customer($preference->data);
return $customer;
}
Log::debug('Customer is not in user config');
$customer = null;
$getCustomerRequest = new ListCustomersRequest($this->importJob->user);
$getCustomerRequest->call();
$customers = $getCustomerRequest->getCustomers();
Log::debug(sprintf('Found %d customer(s)', \count($customers)));
/** @var Customer $current */
foreach ($customers as $current) {
if ('default_ff3_customer' === $current->getIdentifier()) {
$customer = $current;
Log::debug('Found the correct customer.');
break;
}
}
return $customer;
}
/**
* @param Customer $customer
*
* @throws FireflyException
* @return Token
*/
private function getToken(Customer $customer): Token
{
Log::debug('Now in ChooseLoginsHandler::getToken()');
$request = new CreateTokenRequest($this->importJob->user);
$request->setUri(route('import.job.status.index', [$this->importJob->key]));
$request->setCustomer($customer);
$request->call();
Log::debug('Call to get token is finished');
return $request->getToken();
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* NewConfig.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\JobConfiguration\Spectre;
use FireflyIII\Models\ImportJob;
use Illuminate\Support\MessageBag;
/**
* Class NewConfig
*
* @package FireflyIII\Support\Import\JobConfiguration\Spectre
*/
class NewConfig implements SpectreJobConfig
{
/**
* Return true when this stage is complete.
*
* @return bool
*/
public function configurationComplete(): bool
{
return true;
}
/**
* Store the job configuration.
*
* @param array $data
*
* @return MessageBag
*/
public function configureJob(array $data): MessageBag
{
return new MessageBag;
}
/**
* Get data for config view.
*
* @return array
*/
public function getNextData(): array
{
return [];
}
/**
* Get the view for this stage.
*
* @return string
*/
public function getNextView(): string
{
return '';
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
return;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* SpectreJobConfig.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\JobConfiguration\Spectre;
use FireflyIII\Models\ImportJob;
use Illuminate\Support\MessageBag;
interface SpectreJobConfig
{
/**
* Return true when this stage is complete.
*
* @return bool
*/
public function configurationComplete(): bool;
/**
* Store the job configuration.
*
* @param array $data
*
* @return MessageBag
*/
public function configureJob(array $data): MessageBag;
/**
* Get data for config view.
*
* @return array
*/
public function getNextData(): array;
/**
* Get the view for this stage.
*
* @return string
*/
public function getNextView(): string;
/**
* Set the import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void;
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* ImportDataHandler.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Spectre;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
/**
* Class ImportDataHandler
*
* @package FireflyIII\Support\Import\Routine\Spectre
*/
class ImportDataHandler
{
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
*
*/
public function run()
{
die('here we are');
}
/**
* @param ImportJob $importJob
*
* @return void
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* ManageLoginsHandler.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Spectre;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Services\Spectre\Object\Customer;
use FireflyIII\Services\Spectre\Object\Login;
use FireflyIII\Services\Spectre\Request\ListCustomersRequest;
use FireflyIII\Services\Spectre\Request\ListLoginsRequest;
use FireflyIII\Services\Spectre\Request\NewCustomerRequest;
use Log;
class ManageLoginsHandler
{
public $countLogins = 0;
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* Tasks for this stage:
*
* - List all of the users logins.
* - If zero, return to "get-token" stage and make user make a login. That stage redirects here.
* - If one or more, list and let user select.
*
* @throws FireflyException
*/
public function run(): void
{
$customer = $this->getCustomer();
$request = new ListLoginsRequest($this->importJob->user);
$request->setCustomer($customer);
$request->call();
$list = $request->getLogins();
// count is zero?
$this->countLogins = \count($list);
if ($this->countLogins > 0) {
$store = [];
/** @var Login $login */
foreach ($list as $login) {
$store[] = $login->toArray();
}
$config = $this->repository->getConfiguration($this->importJob);
$config['all-logins'] = $store;
$this->repository->setConfiguration($this->importJob, $config);
}
}
/**
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
}
/**
* @return Customer
* @throws FireflyException
*/
private function getCustomer(): Customer
{
Log::debug('Now in manageLoginsHandler::getCustomer()');
$customer = $this->getExistingCustomer();
if (null === $customer) {
Log::debug('The customer is NULL, will fire a newCustomerRequest.');
$newCustomerRequest = new NewCustomerRequest($this->importJob->user);
$customer = $newCustomerRequest->getCustomer();
}
Log::debug('The customer is not null.');
return $customer;
}
/**
* @return Customer|null
* @throws FireflyException
*/
private function getExistingCustomer(): ?Customer
{
Log::debug('Now in getExistingCustomer()');
$customer = null;
$getCustomerRequest = new ListCustomersRequest($this->importJob->user);
$getCustomerRequest->call();
$customers = $getCustomerRequest->getCustomers();
Log::debug(sprintf('Found %d customer(s)', \count($customers)));
/** @var Customer $current */
foreach ($customers as $current) {
if ('default_ff3_customer' === $current->getIdentifier()) {
$customer = $current;
Log::debug('Found the correct customer.');
break;
}
}
return $customer;
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* StageAuthenticatedHandler.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Spectre;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Services\Spectre\Object\Account;
use FireflyIII\Services\Spectre\Object\Login;
use FireflyIII\Services\Spectre\Request\ListAccountsRequest;
class StageAuthenticatedHandler
{
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* User has selected a login (a bank). Will grab all accounts from this bank.
* Then make user pick some to import from.
*
* @throws FireflyException
*/
public function run()
{
// grab a list of logins.
$config = $this->importJob->configuration;
$logins = $config['all-logins'] ?? [];
if (\count($logins) === 0) {
throw new FireflyException('StageAuthenticatedHandler expects more than 0 logins. Apologies, the import has stopped.');
}
$selectedLogin = $config['selected-login'];
$login = null;
foreach ($logins as $loginArray) {
$loginId = $loginArray['id'] ?? -1;
if ($loginId === $selectedLogin) {
$login = new Login($loginArray);
}
}
if (null === $login) {
$login = new Login($logins[0]);
}
// with existing login we can grab accounts from this login.
$accounts = $this->getAccounts($login);
$config['accounts'] = [];
/** @var Account $account */
foreach ($accounts as $account) {
$config['accounts'][] = $account->toArray();
}
$this->repository->setConfiguration($this->importJob, $config);
}
/**
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
{
$this->importJob = $importJob;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($importJob->user);
}
/**
* @param Login $login
*
* @return array
* @throws FireflyException
*/
private function getAccounts(Login $login): array
{
$request = new ListAccountsRequest($this->importJob->user);
$request->setLogin($login);
$request->call();
$accounts = $request->getAccounts();
return $accounts;
}
}

View File

@@ -61,11 +61,14 @@ class StageNewHandler
{
Log::debug('Now in stageNewHandler::run()');
$customer = $this->getCustomer();
// get token using customer.
$token = $this->getToken($customer);
// get token using customer.
app('preferences')->setForUser($this->importJob->user, 'spectre_customer', $customer->toArray());
app('preferences')->setForUser($this->importJob->user, 'spectre_token', $token->toArray());
// store token in the job.
$config = $this->repository->getConfiguration($this->importJob);
$this->repository->setConfiguration($this->importJob, $config);
}
/**
@@ -122,23 +125,6 @@ class StageNewHandler
return $customer;
}
/**
* @param Customer $customer
*
* @throws FireflyException
* @return Token
*/
private function getToken(Customer $customer): Token
{
Log::debug('Now in getToken()');
$request = new CreateTokenRequest($this->importJob->user);
$request->setUri(route('import.job.status.index', [$this->importJob->key]));
$request->setCustomer($customer);
$request->call();
Log::debug('Call to get token is finished');
return $request->getToken();
}
}

View File

@@ -88,9 +88,9 @@ return [
'is_demo_site' => false,
],
'encryption' => null === env('USE_ENCRYPTION') || env('USE_ENCRYPTION') === true,
'version' => '4.7.3.2',
'version' => '4.7.4',
'api_version' => '0.3',
'db_version' => 3,
'db_version' => 4,
'maxUploadSize' => 15242880,
'allowedMimes' => [
/* plain files */

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
use FireflyIII\Import\JobConfiguration\FakeJobConfiguration;
use FireflyIII\Import\JobConfiguration\FileJobConfiguration;
use FireflyIII\Import\JobConfiguration\SpectreJobConfiguration;
use FireflyIII\Import\Prerequisites\FakePrerequisites;
use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
use FireflyIII\Import\Routine\FakeRoutine;
@@ -87,7 +88,7 @@ return [
'fake' => true,
'file' => true,
'bunq' => false,
'spectre' => false,
'spectre' => true,
'plaid' => false,
'quovo' => false,
'yodlee' => false,
@@ -97,7 +98,7 @@ return [
'fake' => FakeJobConfiguration::class,
'file' => FileJobConfiguration::class,
'bunq' => false,
'spectre' => false,
'spectre' => SpectreJobConfiguration::class,
'plaid' => false,
'quovo' => false,
'yodlee' => false,

View File

@@ -66,11 +66,12 @@ function reportJobJSONDone(data) {
recheckJobJSONStatus();
break;
case "need_job_config":
console.log("Will redirect user to " + jobConfigurationUri);
// redirect user to configuration for this job.
window.location.replace(jobConfigurationUri);
break;
case 'error':
reportJobError();
reportJobError(data);
break;
case 'provider_finished':
// call routine to store stuff:
@@ -251,7 +252,7 @@ function reportJobPOSTFailure(xhr, status, error) {
/**
* Show error to user.
*/
function reportJobError() {
function reportJobError(data) {
console.log('In reportJobError()');
// cancel checking again for job status:
clearTimeout(timeOutId);
@@ -262,7 +263,7 @@ function reportJobError() {
// show fatal error box:
$('.fatal_error').show();
$('.fatal_error_txt').text('Job reports error. Please start again. Apologies.');
$('.fatal_error_txt').text('Job reports error. Please start again. Apologies. Error message is: ' + data.report_txt);
// show error box.
}

View File

@@ -108,6 +108,40 @@ return [
'job_config_uc_specifics_txt' => 'Some banks deliver badly formatted files. Firefly III can fix those automatically. If your bank delivers such files but it\'s not listed here, please open an issue on GitHub.',
'job_config_uc_submit' => 'Continue',
'invalid_import_account' => 'You have selected an invalid account to import into.',
// job configuration for Spectre:
'job_config_spectre_login_title' => 'Choose your login',
'job_config_spectre_login_text' => 'Firefly III has found :count existing login(s) in your Spectre account. Which one would you like to use to import from?',
'spectre_login_status_active' => 'Active',
'spectre_login_status_inactive' => 'Inactive',
'spectre_login_status_disabled' => 'Disabled',
'spectre_login_new_login' => 'Login with another bank, or one of these banks with different credentials.',
'job_config_spectre_accounts_title' => 'Select accounts to import from',
'job_config_spectre_accounts_text' => 'You have selected ":name" (:country). You have :count account(s) available from this provider. Please select the Firefly III asset account(s) where the transactions from these accounts should be stored. Remember, in order to import data both the Firefly III account and the ":name"-account must have the same currency.',
'spectre_no_supported_accounts' => 'You cannot import from this account due to a currency mismatch.',
'spectre_do_not_import' => '(do not import)',
'spectre_no_mapping' => 'It seems you have not selected any accounts to import from.',
// keys from "extra" array:
'spectre_extra_key_iban' => 'IBAN',
'spectre_extra_key_swift' => 'SWIFT',
'spectre_extra_key_status' => 'Status',
'spectre_extra_key_card_type' => 'Card type',
'spectre_extra_key_account_name' => 'Account name',
'spectre_extra_key_client_name' => 'Client name',
'spectre_extra_key_account_number' => 'Account number',
'spectre_extra_key_blocked_amount' => 'Blocked amount',
'spectre_extra_key_available_amount' => 'Available amount',
'spectre_extra_key_credit_limit' => 'Credit limit',
'spectre_extra_key_interest_rate' => 'Interest rate',
'spectre_extra_key_expiry_date' => 'Expiry date',
'spectre_extra_key_open_date' => 'Open date',
'spectre_extra_key_current_time' => 'Current time',
'spectre_extra_key_current_date' => 'Current date',
'spectre_extra_key_cards' => 'Cards',
'spectre_extra_key_units' => 'Units',
'spectre_extra_key_unit_price' => 'Unit price',
'spectre_extra_key_transactions_count' => 'Transaction count',
// specifics:
'specific_ing_name' => 'ING NL',
'specific_ing_descr' => 'Create better descriptions in ING exports',
@@ -156,7 +190,7 @@ return [
'status_finished_text' => 'The import has finished.',
'finished_with_errors' => 'There were some errors during the import. Please review them carefully.',
'unknown_import_result' => 'Unknown import result',
'result_no_transactions' => 'No transactions have been imported. Perhaps they were all duplicates is simply no transactions where present to be imported. Perhaps the error message below can tell you what happened.',
'result_no_transactions' => 'No transactions have been imported. Perhaps they were all duplicates is simply no transactions where present to be imported. Perhaps the log files can tell you what happened. If you import data regularly, this is normal.',
'result_one_transaction' => 'Exactly one transaction has been imported. It is stored under tag <a href=":route" class="label label-success" style="font-size:100%;font-weight:normal;">:tag</a> where you can inspect it further.',
'result_many_transactions' => 'Firefly III has imported :count transactions. They are stored under tag <a href=":route" class="label label-success" style="font-size:100%;font-weight:normal;">:tag</a> where you can inspect them further.',
@@ -403,7 +437,6 @@ return [
// 'spectre_accounts_title' => 'Select accounts to import from',
// 'spectre_accounts_text' => 'Each account on the left below has been found by Spectre and can be imported into Firefly III. Please select the asset account that should hold any given transactions. If you do not wish to import from any particular account, remove the check from the checkbox.',
// 'spectre_do_import' => 'Yes, import from this account',
// 'spectre_no_supported_accounts' => 'You cannot import from this account due to a currency mismatch.',
//
// // keys from "extra" array:
// 'spectre_extra_key_iban' => 'IBAN',

View File

@@ -119,4 +119,7 @@ return [
'file_type' => 'File type',
'attached_to' => 'Attached to',
'file_exists' => 'File exists',
'spectre_bank' => 'Bank',
'spectre_last_use' => 'Last login',
'spectre_status' => 'Status',
];

View File

@@ -5,22 +5,21 @@
{% endblock %}
{% block content %}
<div class="row">
<form class="form-horizontal" action="{{ route('import.configure.post',[job.key]) }}" method="post">
<form class="form-horizontal" action="{{ route('import.job.configuration.post',[importJob.key]) }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">{{ trans('import.spectre_accounts_title') }}</h3>
<h3 class="box-title">{{ trans('import.job_config_spectre_accounts_title') }}</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-8">
<p>
{{ trans('import.spectre_accounts_text')|raw }}
{{ trans('import.job_config_spectre_accounts_text', {count: data.accounts|length,country: data.login.getCountryCode(),name: data.login.getProviderName()}) }}
</p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered table-striped">
@@ -28,46 +27,40 @@
<tr>
<th>{{ trans('list.account_on_spectre') }}</th>
<th>{{ trans('list.account') }}</th>
<th>{{ trans('list.do_import') }}</th>
</tr>
</thead>
<tbody>
{% for account in data.config.accounts %}
{% for account in data.accounts %}
<tr>
<td>
<input type="hidden" name="spectre_account_id[]" value="{{ account.id }}" />
{{ account.nature|capitalize }} "<strong>{{ account.name }}</strong>" ({{ formatAmountBySymbol(account.balance, account.currency_code~' ') }})<br />
{% for name, value in account.extra %}
{{ account.getNature()|capitalize }} "<strong>{{ account.getName() }}</strong>"
({{ formatAmountBySymbol(account.getBalance(), account.getCurrencyCode()~' ') }})<br/>
{% set currentIban = '' %}
{% for name, value in account.getExtra() %}
{% if not value is iterable and name != 'sort_code' and name !='current_date' and name != 'available_amount' and name !='current_time' and name != 'last_posted_transaction_id' %}
{{ trans('import.spectre_extra_key_'~name) }}: {{ value }}<br />
{{ trans('import.spectre_extra_key_'~name) }}: {{ value }}<br/>
{% endif %}
{% if name == 'available_amount' %}
{{ trans('import.spectre_extra_key_'~name) }}: {{ formatAmountBySymbol(value, account.currency_code~' ') }}
{{ trans('import.spectre_extra_key_'~name) }}: {{ formatAmountBySymbol(value, account.getCurrencyCode()~' ') }}
{% endif %}
{% if name == 'iban' %}
{% set currentIban = value %}
{% endif %}
{% endfor %}
</td>
<td>
{% if account.options|length > 0 %}
<select class="form-control" name="import[{{ account.id }}]">
{% for id,name in account.options %}
<option value="{{ id }}" label="{{ name }}">{{ name }}</option>
<select class="form-control" name="account_mapping[{{ account.getId() }}]">
<option value="0" label="{{ trans('import.spectre_do_not_import') }}">
{{ trans('import.spectre_do_not_import') }}
</option>
{% for ffId, ffAccount in data.ff_accounts %}
{% if ffAccount.code == account.getCurrencyCode() %}
<option value="{{ ffId }}"{% if currentIban != '' and currentIban == ffAccount.iban %} selected{% endif %}>
{{ ffAccount.name }}{% if ffAccount.iban !='' %} ({{ ffAccount.iban }}){% endif %}
</option>
{% endif %}
{% endfor %}
</select>
{% else %}
<em>
{{ trans('import.spectre_no_supported_accounts') }}
</em>
{% endif %}
</td>
<td>
{% if account.options|length > 0 %}
<div class="checkbox">
<label>
<input type="checkbox" value="1" name="do_import[{{ account.id }}]" checked>
{{ trans('import.spectre_do_import') }}
</label>
</div>
{% endif %}
</td>
</tr>
@@ -76,7 +69,6 @@
</table>
</div>
</div>
<div class="box-footer">

View File

@@ -0,0 +1,87 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
{{ Breadcrumbs.render }}
{% endblock %}
{% block content %}
<div class="row">
<form class="form-horizontal" action="{{ route('import.job.configuration.post',[importJob.key]) }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">{{ trans('import.job_config_spectre_login_title') }}</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-8">
<p>
{{ trans('import.job_config_spectre_login_text', {count: data.logins|length}) }}
</p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>&nbsp;</th>
<th>{{ trans('list.spectre_bank') }}</th>
<th>{{ trans('list.spectre_last_use') }}</th>
<th>{{ trans('list.spectre_status') }}</th>
</tr>
</thead>
<tbody>
{% for login in data.logins %}
<tr>
<td>
<input
{% if login.getStatus() == 'disabled' %}disabled{% endif %}
id="{{ login.getId() }}" type="radio" name="spectre_login_id" value="{{ login.getId() }}">
</td>
<td>
<label for="{{ login.getId() }}">
{{ login.getProviderName() }} ({{ login.getCountryCode() }})
</label>
</td>
<td>
{{ login.getLastSuccessAt().formatLocalized(monthAndDayFormat) }}<br>
{{ login.getUpdatedAt().format("Y-m-d H:i:s") }}<br>
</td>
<td>
{{ trans('import.spectre_login_status_'~login.getStatus()) }}
</td>
</tr>
{% endfor %}
<tr>
<td>
<input id="new_login" type="radio" name="spectre_login_id" value="00">
</td>
<td colspan="3">
<label for="new_login"><em>
{{ trans('import.spectre_login_new_login') }}
</em>
</label>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn pull-right btn-success">
{{ ('submit')|_ }}
</button>
</div>
</div>
</div>
</form>
</div>
{% endblock %}
{% block scripts %}
{% endblock %}
{% block styles %}
{% endblock %}