Various fixes.

This commit is contained in:
James Cole
2018-06-20 16:27:57 +02:00
parent 138f67581c
commit 18f779c6de
8 changed files with 50 additions and 14 deletions

View File

@@ -107,7 +107,7 @@ class TransactionFactory
Log::debug(sprintf('Expect source destination to be of type %s', $destinationType)); 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']);
Log::debug(sprintf('Source type is "%s", destination type is "%s"', $sourceType, $destinationType)); Log::debug(sprintf('Source type is "%s", destination type is "%s"', $sourceAccount->accountType->type, $destinationAccount->accountType->type));
// throw big fat error when source type === dest type // throw big fat error when source type === dest type
if ($sourceAccount->accountType->type === $destinationAccount->accountType->type && $journal->transactionType->type !== TransactionType::TRANSFER) { if ($sourceAccount->accountType->type === $destinationAccount->accountType->type && $journal->transactionType->type !== TransactionType::TRANSFER) {
throw new FireflyException(sprintf('Source and destination account cannot be both of the type "%s"', $destinationAccount->accountType->type)); throw new FireflyException(sprintf('Source and destination account cannot be both of the type "%s"', $destinationAccount->accountType->type));

View File

@@ -158,9 +158,11 @@ trait FindAccountsTrait
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id)); Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
return $account; return $account;
} else{
Log::debug(sprintf('"%s" does not equal "%s"', $account->name, $name));
} }
} }
Log::debug(sprintf('There is no account with name "%s" or types', $name), $types); Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
return null; return null;
} }

View File

@@ -23,7 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Spectre\Request; namespace FireflyIII\Services\Spectre\Request;
use FireflyIII\Services\Spectre\Object\Customer; use FireflyIII\Services\Spectre\Object\Customer;
use Log;
/** /**
* Class NewCustomerRequest * Class NewCustomerRequest
*/ */
@@ -43,6 +43,7 @@ class NewCustomerRequest extends SpectreRequest
], ],
]; ];
$uri = '/api/v4/customers/'; $uri = '/api/v4/customers/';
Log::debug(sprintf('Going to call %s with info:', $uri), $data);
$response = $this->sendSignedSpectrePost($uri, $data); $response = $this->sendSignedSpectrePost($uri, $data);
// create customer: // create customer:
$this->customer = new Customer($response['data']); $this->customer = new Customer($response['data']);

View File

@@ -562,7 +562,9 @@ class ExpandedForm
/** @var PiggyBankRepositoryInterface $repository */ /** @var PiggyBankRepositoryInterface $repository */
$repository = app(PiggyBankRepositoryInterface::class); $repository = app(PiggyBankRepositoryInterface::class);
$piggyBanks = $repository->getPiggyBanksWithAmount(); $piggyBanks = $repository->getPiggyBanksWithAmount();
$array = []; $array = [
0 => trans('firefly.none_in_select_list'),
];
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($piggyBanks as $piggy) { foreach ($piggyBanks as $piggy) {
$array[$piggy->id] = $piggy->name; $array[$piggy->id] = $piggy->name;

View File

@@ -71,10 +71,13 @@ class CurrencyMapper
return $result; return $result;
} }
} }
if (null === $data['code']) {
return null;
}
// if still nothing, and fields not null, try to create it // if still nothing, and fields not null, try to create it
$code = $data['code'] ?? null;
$creation = [ $creation = [
'code' => $code, 'code' => $data['code'],
'name' => $data['name'] ?? $code, 'name' => $data['name'] ?? $code,
'symbol' => $data['symbol'] ?? $code, 'symbol' => $data['symbol'] ?? $code,
'decimal_places' => 2, 'decimal_places' => 2,

View File

@@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Placeholder\ImportTransaction; use FireflyIII\Support\Import\Placeholder\ImportTransaction;
use InvalidArgumentException; use InvalidArgumentException;
@@ -39,6 +40,8 @@ use Log;
*/ */
class ImportableConverter class ImportableConverter
{ {
/** @var AccountRepositoryInterface */
private $accountRepository;
/** @var AssetAccountMapper */ /** @var AssetAccountMapper */
private $assetMapper; private $assetMapper;
/** @var array */ /** @var array */
@@ -102,6 +105,10 @@ class ImportableConverter
$this->assetMapper->setUser($importJob->user); $this->assetMapper->setUser($importJob->user);
$this->assetMapper->setDefaultAccount($this->config['import-account'] ?? 0); $this->assetMapper->setDefaultAccount($this->config['import-account'] ?? 0);
// asset account repository is used for currency information
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUser($importJob->user);
// opposing account mapper: // opposing account mapper:
$this->opposingMapper = app(OpposingAccountMapper::class); $this->opposingMapper = app(OpposingAccountMapper::class);
$this->opposingMapper->setUser($importJob->user); $this->opposingMapper->setUser($importJob->user);
@@ -154,10 +161,6 @@ class ImportableConverter
$currency = $this->currencyMapper->map($currencyId, $importable->getCurrencyData()); $currency = $this->currencyMapper->map($currencyId, $importable->getCurrencyData());
$foreignCurrency = $this->currencyMapper->map($foreignCurrencyId, $importable->getForeignCurrencyData()); $foreignCurrency = $this->currencyMapper->map($foreignCurrencyId, $importable->getForeignCurrencyData());
if (null === $currency) {
Log::debug(sprintf('Could not map currency, use default (%s)', $this->defaultCurrency->code));
$currency = $this->defaultCurrency;
}
Log::debug(sprintf('"%s" (#%d) is source and "%s" (#%d) is destination.', $source->name, $source->id, $destination->name, $destination->id)); Log::debug(sprintf('"%s" (#%d) is source and "%s" (#%d) is destination.', $source->name, $source->id, $destination->name, $destination->id));
if (bccomp($amount, '0') === 1) { if (bccomp($amount, '0') === 1) {
@@ -171,6 +174,28 @@ class ImportableConverter
); );
} }
// get currency preference from source asset account (preferred)
// or destination asset account
if (null === $currency) {
if ($destination->accountType->type === AccountType::ASSET) {
// destination is asset, might have currency preference:
$destinationCurrencyId = (int)$this->accountRepository->getMetaValue($destination, 'currency_id');
$currency = $destinationCurrencyId === 0 ? $this->defaultCurrency : $this->currencyMapper->map($destinationCurrencyId, []);
Log::debug(sprintf('Destination is an asset account, and has currency preference %s', $currency->code));
}
if ($source->accountType->type === AccountType::ASSET) {
// source is asset, might have currency preference:
$sourceCurrencyId = (int)$this->accountRepository->getMetaValue($source, 'currency_id');
$currency = $sourceCurrencyId === 0 ? $this->defaultCurrency : $this->currencyMapper->map($sourceCurrencyId, []);
Log::debug(sprintf('Source is an asset account, and has currency preference %s', $currency->code));
}
}
if (null === $currency) {
Log::debug(sprintf('Could not map currency, use default (%s)', $this->defaultCurrency->code));
$currency = $this->defaultCurrency;
}
if ($source->accountType->type === AccountType::ASSET && $destination->accountType->type === AccountType::ASSET) { if ($source->accountType->type === AccountType::ASSET && $destination->accountType->type === AccountType::ASSET) {
Log::debug('Source and destination are asset accounts. This is a transfer.'); Log::debug('Source and destination are asset accounts. This is a transfer.');
$transactionType = 'transfer'; $transactionType = 'transfer';
@@ -281,11 +306,13 @@ class ImportableConverter
{ {
if (isset($this->mappedValues[$key]) && \in_array($objectId, $this->mappedValues[$key], true)) { if (isset($this->mappedValues[$key]) && \in_array($objectId, $this->mappedValues[$key], true)) {
Log::debug(sprintf('verifyObjectId(%s, %d) is valid!',$key, $objectId)); Log::debug(sprintf('verifyObjectId(%s, %d) is valid!', $key, $objectId));
return $objectId; return $objectId;
} }
Log::debug(sprintf('verifyObjectId(%s, %d) is NOT in the list, but it could still be valid.',$key, $objectId)); Log::debug(sprintf('verifyObjectId(%s, %d) is NOT in the list, but it could still be valid.', $key, $objectId));
return $objectId; return $objectId;
} }

View File

@@ -1155,8 +1155,9 @@ return [
'cannot_convert_split_journal' => 'Cannot convert a split transaction', 'cannot_convert_split_journal' => 'Cannot convert a split transaction',
// Import page (general strings only) // Import page (general strings only)
'import_index_title' => 'Import data into Firefly III', 'import_index_title' => 'Import transactions into Firefly III',
'import_data' => 'Import data', 'import_data' => 'Import data',
'import_transactions' => 'Import transactions',
// sandstorm.io errors and messages: // sandstorm.io errors and messages:
'sandstorm_not_available' => 'This function is not available when you are using Firefly III within a Sandstorm.io environment.', 'sandstorm_not_available' => 'This function is not available when you are using Firefly III within a Sandstorm.io environment.',

View File

@@ -117,7 +117,7 @@
</a> </a>
<ul class="treeview-menu"> <ul class="treeview-menu">
<li class="{{ activeRoutePartial('import') }}"> <li class="{{ activeRoutePartial('import') }}">
<a href="{{ route('import.index') }}"><i class="fa fa-archive fa-fw"></i> {{ 'import_data'|_ }}</a> <a href="{{ route('import.index') }}"><i class="fa fa-archive fa-fw"></i> {{ 'import_transactions'|_ }}</a>
</li> </li>
<li class="{{ activeRoutePartial('export') }}"> <li class="{{ activeRoutePartial('export') }}">
<a href="{{ route('export.index') }}"><i class="fa fa-file-archive-o fa-fw"></i> {{ 'export_and_backup_data'|_ }}</a> <a href="{{ route('export.index') }}"><i class="fa fa-file-archive-o fa-fw"></i> {{ 'export_and_backup_data'|_ }}</a>