This commit is contained in:
James Cole
2019-08-27 07:51:34 +02:00
parent 7720519076
commit 33d0b8ca22
4 changed files with 184 additions and 169 deletions

View File

@@ -146,7 +146,7 @@ class AccountValidator
switch ($this->transactionType) {
default:
$result = false;
$this->sourceError = sprintf('Cannot handle type "%s" :(', $this->transactionType);
$this->sourceError = 'Firefly III cannot validate the account information you submitted.';
Log::error(sprintf('AccountValidator::validateSource cannot handle "%s", so it will always return false.', $this->transactionType));
break;
case TransactionType::WITHDRAWAL:
@@ -276,52 +276,6 @@ class AccountValidator
return $result;
}
/**
* @param int|null $accountId
* @param $accountName
*
* @return bool
*/
private function validateOBDestination(?int $accountId, $accountName): bool
{
$result = null;
Log::debug(sprintf('Now in validateOBDestination(%d, "%s")', $accountId, $accountName));
// source can be any of the following types.
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
// if both values are NULL we return false,
// because the destination of a deposit can't be created.
$this->destError = (string)trans('validation.ob_dest_need_data');
Log::error('Both values are NULL, cant create OB destination.');
$result = false;
}
// if the account can be created anyway we don't need to search.
if (null === $result && true === $this->canCreateTypes($validTypes)) {
Log::debug('Can create some of these types, so return true.');
$result = true;
}
if (null === $result) {
// otherwise try to find the account:
$search = $this->findExistingAccount($validTypes, (int)$accountId, (string)$accountName);
if (null === $search) {
Log::debug('findExistingAccount() returned NULL, so the result is false.', $validTypes);
$this->destError = (string)trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
$result = false;
}
if (null !== $search) {
Log::debug(sprintf('findExistingAccount() returned #%d ("%s"), so the result is true.', $search->id, $search->name));
$this->destination = $search;
$result = true;
}
}
$result = $result ?? false;
Log::debug(sprintf('validateOBDestination(%d, "%s") will return %s', $accountId, $accountName, var_export($result, true)));
return $result;
}
/**
* @param int|null $accountId
* @param string|null $accountName
@@ -368,9 +322,56 @@ class AccountValidator
return $result;
}
/**
* @param int|null $accountId
* @param $accountName
*
* @return bool
*/
private function validateOBDestination(?int $accountId, $accountName): bool
{
$result = null;
Log::debug(sprintf('Now in validateOBDestination(%d, "%s")', $accountId, $accountName));
// source can be any of the following types.
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
// if both values are NULL we return false,
// because the destination of a deposit can't be created.
$this->destError = (string)trans('validation.ob_dest_need_data');
Log::error('Both values are NULL, cant create OB destination.');
$result = false;
}
// if the account can be created anyway we don't need to search.
if (null === $result && true === $this->canCreateTypes($validTypes)) {
Log::debug('Can create some of these types, so return true.');
$result = true;
}
if (null === $result) {
// otherwise try to find the account:
$search = $this->findExistingAccount($validTypes, (int)$accountId, (string)$accountName);
if (null === $search) {
Log::debug('findExistingAccount() returned NULL, so the result is false.', $validTypes);
$this->destError = (string)trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
$result = false;
}
if (null !== $search) {
Log::debug(sprintf('findExistingAccount() returned #%d ("%s"), so the result is true.', $search->id, $search->name));
$this->destination = $search;
$result = true;
}
}
$result = $result ?? false;
Log::debug(sprintf('validateOBDestination(%d, "%s") will return %s', $accountId, $accountName, var_export($result, true)));
return $result;
}
/**
* Source of an opening balance can either be an asset account
* or an "initial balance account". The latter can be created.
*
* @param int|null $accountId
* @param string|null $accountName
*
@@ -429,6 +430,54 @@ class AccountValidator
return $result;
}
/**
* @param int|null $accountId
*
* @return bool
*/
private function validateReconciliationDestination(?int $accountId): bool
{
if (null === $accountId) {
return false;
}
$result = $this->accountRepository->findNull($accountId);
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::RECONCILIATION];
if (null === $result) {
return false;
}
if (in_array($result->accountType->type, $types, true)) {
$this->destination = $result;
return true;
}
return false;
}
/**
* @param int|null $accountId
*
* @return bool
*/
private function validateReconciliationSource(?int $accountId): bool
{
if (null === $accountId) {
return false;
}
$result = $this->accountRepository->findNull($accountId);
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::RECONCILIATION];
if (null === $result) {
return false;
}
if (in_array($result->accountType->type, $types, true)) {
$this->source = $result;
return true;
}
return false;
}
/**
* @param int|null $accountId
* @param $accountName
@@ -457,6 +506,7 @@ class AccountValidator
return false;
}
$this->destination = $search;
// must not be the same as the source account
return !(null !== $this->source && $this->source->id === $this->destination->id);
}
@@ -567,51 +617,5 @@ class AccountValidator
return true;
}
/**
* @param int|null $accountId
* @return bool
*/
private function validateReconciliationSource(?int $accountId): bool
{
if (null === $accountId) {
return false;
}
$result = $this->accountRepository->findNull($accountId);
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::RECONCILIATION];
if (null === $result) {
return false;
}
if (in_array($result->accountType->type, $types, true)) {
$this->source = $result;
return true;
}
return false;
}
/**
* @param int|null $accountId
* @return bool
*/
private function validateReconciliationDestination(?int $accountId): bool
{
if (null === $accountId) {
return false;
}
$result = $this->accountRepository->findNull($accountId);
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::RECONCILIATION];
if (null === $result) {
return false;
}
if (in_array($result->accountType->type, $types, true)) {
$this->destination = $result;
return true;
}
return false;
}
}

2
public/v1/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -415,7 +415,7 @@
}
} else {
console.log('Will redirect to previous URL. (' + previousUri + ')');
window.location.href = window.previousUri + '?transaction_group_id=' + groupId+ '&message=created';
window.location.href = window.previousUri + '?transaction_group_id=' + groupId + '&message=created';
}
},
@@ -597,6 +597,11 @@
break;
}
}
// unique some things
this.transactions[transactionIndex].errors.source_account =
Array.from(new Set(this.transactions[transactionIndex].errors.source_account));
this.transactions[transactionIndex].errors.destination_account =
Array.from(new Set(this.transactions[transactionIndex].errors.destination_account));
}
}
},

View File

@@ -852,6 +852,12 @@
break;
}
}
// unique some things
this.transactions[transactionIndex].errors.source_account =
Array.from(new Set(this.transactions[transactionIndex].errors.source_account));
this.transactions[transactionIndex].errors.destination_account =
Array.from(new Set(this.transactions[transactionIndex].errors.destination_account));
}
}
},