mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-21 02:31:19 +00:00
Fix #2501
This commit is contained in:
@@ -135,7 +135,7 @@ class AccountValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|null $accountId
|
* @param int|null $accountId
|
||||||
* @param string|null $accountName
|
* @param string|null $accountName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -146,7 +146,7 @@ class AccountValidator
|
|||||||
switch ($this->transactionType) {
|
switch ($this->transactionType) {
|
||||||
default:
|
default:
|
||||||
$result = false;
|
$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));
|
Log::error(sprintf('AccountValidator::validateSource cannot handle "%s", so it will always return false.', $this->transactionType));
|
||||||
break;
|
break;
|
||||||
case TransactionType::WITHDRAWAL:
|
case TransactionType::WITHDRAWAL:
|
||||||
@@ -206,8 +206,8 @@ class AccountValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $validTypes
|
* @param array $validTypes
|
||||||
* @param int|null $accountId
|
* @param int|null $accountId
|
||||||
* @param string|null $accountName
|
* @param string|null $accountName
|
||||||
*
|
*
|
||||||
* @return Account|null
|
* @return Account|null
|
||||||
@@ -276,6 +276,52 @@ class AccountValidator
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|null $accountId
|
||||||
|
* @param string|null $accountName
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function validateDepositSource(?int $accountId, ?string $accountName): bool
|
||||||
|
{
|
||||||
|
Log::debug(sprintf('Now in validateDepositSource(%d, "%s")', $accountId, $accountName));
|
||||||
|
$result = null;
|
||||||
|
// source can be any of the following types.
|
||||||
|
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||||
|
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||||
|
// if both values are NULL return false,
|
||||||
|
// because the source of a deposit can't be created.
|
||||||
|
// (this never happens).
|
||||||
|
$this->sourceError = (string)trans('validation.deposit_source_need_data');
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the user submits an ID only but that ID is not of the correct type,
|
||||||
|
// return false.
|
||||||
|
if (null !== $accountId && null === $accountName) {
|
||||||
|
$search = $this->accountRepository->findNull($accountId);
|
||||||
|
if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) {
|
||||||
|
Log::debug(sprintf('User submitted only an ID (#%d), which is a "%s", so this is not a valid source.', $accountId, $search->accountType->type));
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the account can be created anyway we don't need to search.
|
||||||
|
if (null === $result && true === $this->canCreateTypes($validTypes)) {
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
// set the source to be a (dummy) revenue account.
|
||||||
|
$account = new Account;
|
||||||
|
$accountType = AccountType::whereType(AccountType::REVENUE)->first();
|
||||||
|
$account->accountType = $accountType;
|
||||||
|
$this->source = $account;
|
||||||
|
}
|
||||||
|
$result = $result ?? false;
|
||||||
|
|
||||||
|
// don't expect to end up here:
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|null $accountId
|
* @param int|null $accountId
|
||||||
* @param $accountName
|
* @param $accountName
|
||||||
@@ -322,56 +368,11 @@ class AccountValidator
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int|null $accountId
|
|
||||||
* @param string|null $accountName
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function validateDepositSource(?int $accountId, ?string $accountName): bool
|
|
||||||
{
|
|
||||||
Log::debug(sprintf('Now in validateDepositSource(%d, "%s")', $accountId, $accountName));
|
|
||||||
$result = null;
|
|
||||||
// source can be any of the following types.
|
|
||||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
|
||||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
|
||||||
// if both values are NULL return false,
|
|
||||||
// because the source of a deposit can't be created.
|
|
||||||
// (this never happens).
|
|
||||||
$this->sourceError = (string)trans('validation.deposit_source_need_data');
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the user submits an ID only but that ID is not of the correct type,
|
|
||||||
// return false.
|
|
||||||
if (null !== $accountId && null === $accountName) {
|
|
||||||
$search = $this->accountRepository->findNull($accountId);
|
|
||||||
if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) {
|
|
||||||
Log::debug(sprintf('User submitted only an ID (#%d), which is a "%s", so this is not a valid source.', $accountId, $search->accountType->type));
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the account can be created anyway we don't need to search.
|
|
||||||
if (null === $result && true === $this->canCreateTypes($validTypes)) {
|
|
||||||
$result = true;
|
|
||||||
|
|
||||||
// set the source to be a (dummy) revenue account.
|
|
||||||
$account = new Account;
|
|
||||||
$accountType = AccountType::whereType(AccountType::REVENUE)->first();
|
|
||||||
$account->accountType = $accountType;
|
|
||||||
$this->source = $account;
|
|
||||||
}
|
|
||||||
$result = $result ?? false;
|
|
||||||
|
|
||||||
// don't expect to end up here:
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source of an opening balance can either be an asset account
|
* Source of an opening balance can either be an asset account
|
||||||
* or an "initial balance account". The latter can be created.
|
* or an "initial balance account". The latter can be created.
|
||||||
* @param int|null $accountId
|
*
|
||||||
|
* @param int|null $accountId
|
||||||
* @param string|null $accountName
|
* @param string|null $accountName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -429,6 +430,54 @@ class AccountValidator
|
|||||||
return $result;
|
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 int|null $accountId
|
||||||
* @param $accountName
|
* @param $accountName
|
||||||
@@ -457,12 +506,13 @@ class AccountValidator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->destination = $search;
|
$this->destination = $search;
|
||||||
|
|
||||||
// must not be the same as the source account
|
// must not be the same as the source account
|
||||||
return !(null !== $this->source && $this->source->id === $this->destination->id);
|
return !(null !== $this->source && $this->source->id === $this->destination->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|null $accountId
|
* @param int|null $accountId
|
||||||
* @param string|null $accountName
|
* @param string|null $accountName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -493,7 +543,7 @@ class AccountValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|null $accountId
|
* @param int|null $accountId
|
||||||
* @param string|null $accountName
|
* @param string|null $accountName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -537,7 +587,7 @@ class AccountValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|null $accountId
|
* @param int|null $accountId
|
||||||
* @param string|null $accountName
|
* @param string|null $accountName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -567,51 +617,5 @@ class AccountValidator
|
|||||||
return true;
|
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
2
public/v1/js/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -415,7 +415,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('Will redirect to previous URL. (' + previousUri + ')');
|
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;
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -605,73 +610,73 @@
|
|||||||
},
|
},
|
||||||
addTransactionToArray: function (e) {
|
addTransactionToArray: function (e) {
|
||||||
this.transactions.push({
|
this.transactions.push({
|
||||||
description: "",
|
description: "",
|
||||||
date: "",
|
date: "",
|
||||||
amount: "",
|
amount: "",
|
||||||
category: "",
|
category: "",
|
||||||
piggy_bank: 0,
|
piggy_bank: 0,
|
||||||
errors: {
|
errors: {
|
||||||
source_account: [],
|
source_account: [],
|
||||||
destination_account: [],
|
destination_account: [],
|
||||||
description: [],
|
description: [],
|
||||||
amount: [],
|
amount: [],
|
||||||
date: [],
|
date: [],
|
||||||
budget_id: [],
|
budget_id: [],
|
||||||
foreign_amount: [],
|
foreign_amount: [],
|
||||||
category: [],
|
category: [],
|
||||||
piggy_bank: [],
|
piggy_bank: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
// custom fields:
|
// custom fields:
|
||||||
custom_errors: {
|
custom_errors: {
|
||||||
interest_date: [],
|
interest_date: [],
|
||||||
book_date: [],
|
book_date: [],
|
||||||
process_date: [],
|
process_date: [],
|
||||||
due_date: [],
|
due_date: [],
|
||||||
payment_date: [],
|
payment_date: [],
|
||||||
invoice_date: [],
|
invoice_date: [],
|
||||||
internal_reference: [],
|
internal_reference: [],
|
||||||
notes: [],
|
notes: [],
|
||||||
attachments: [],
|
attachments: [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
budget: 0,
|
budget: 0,
|
||||||
tags: [],
|
tags: [],
|
||||||
custom_fields: {
|
custom_fields: {
|
||||||
"interest_date": "",
|
"interest_date": "",
|
||||||
"book_date": "",
|
"book_date": "",
|
||||||
"process_date": "",
|
"process_date": "",
|
||||||
"due_date": "",
|
"due_date": "",
|
||||||
"payment_date": "",
|
"payment_date": "",
|
||||||
"invoice_date": "",
|
"invoice_date": "",
|
||||||
"internal_reference": "",
|
"internal_reference": "",
|
||||||
"notes": "",
|
"notes": "",
|
||||||
"attachments": []
|
"attachments": []
|
||||||
},
|
},
|
||||||
foreign_amount: {
|
foreign_amount: {
|
||||||
amount: "",
|
amount: "",
|
||||||
currency_id: 0
|
currency_id: 0
|
||||||
},
|
},
|
||||||
source_account: {
|
source_account: {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "",
|
name: "",
|
||||||
type: "",
|
type: "",
|
||||||
currency_id: 0,
|
currency_id: 0,
|
||||||
currency_name: '',
|
currency_name: '',
|
||||||
currency_code: '',
|
currency_code: '',
|
||||||
currency_decimal_places: 2,
|
currency_decimal_places: 2,
|
||||||
allowed_types: []
|
allowed_types: []
|
||||||
},
|
},
|
||||||
destination_account: {
|
destination_account: {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "",
|
name: "",
|
||||||
type: "",
|
type: "",
|
||||||
currency_id: 0,
|
currency_id: 0,
|
||||||
currency_name: '',
|
currency_name: '',
|
||||||
currency_code: '',
|
currency_code: '',
|
||||||
currency_decimal_places: 2,
|
currency_decimal_places: 2,
|
||||||
allowed_types: []
|
allowed_types: []
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this.transactions.length === 1) {
|
if (this.transactions.length === 1) {
|
||||||
// set first date.
|
// set first date.
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
|
|||||||
@@ -852,6 +852,12 @@
|
|||||||
break;
|
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));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user