mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #2501
This commit is contained in:
parent
7720519076
commit
33d0b8ca22
@ -135,7 +135,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
@ -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:
|
||||
@ -206,8 +206,8 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int|null $accountId
|
||||
* @param array $validTypes
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
@ -276,6 +276,52 @@ class AccountValidator
|
||||
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 $accountName
|
||||
@ -322,56 +368,11 @@ class AccountValidator
|
||||
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
|
||||
* or an "initial balance account". The latter can be created.
|
||||
* @param int|null $accountId
|
||||
*
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
@ -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,12 +506,13 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
@ -493,7 +543,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
@ -537,7 +587,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
@ -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
2
public/v1/js/app.js
vendored
File diff suppressed because one or more lines are too long
@ -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));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -605,73 +610,73 @@
|
||||
},
|
||||
addTransactionToArray: function (e) {
|
||||
this.transactions.push({
|
||||
description: "",
|
||||
date: "",
|
||||
amount: "",
|
||||
category: "",
|
||||
piggy_bank: 0,
|
||||
errors: {
|
||||
source_account: [],
|
||||
destination_account: [],
|
||||
description: [],
|
||||
amount: [],
|
||||
date: [],
|
||||
budget_id: [],
|
||||
foreign_amount: [],
|
||||
category: [],
|
||||
piggy_bank: [],
|
||||
tags: [],
|
||||
// custom fields:
|
||||
custom_errors: {
|
||||
interest_date: [],
|
||||
book_date: [],
|
||||
process_date: [],
|
||||
due_date: [],
|
||||
payment_date: [],
|
||||
invoice_date: [],
|
||||
internal_reference: [],
|
||||
notes: [],
|
||||
attachments: [],
|
||||
},
|
||||
},
|
||||
budget: 0,
|
||||
tags: [],
|
||||
custom_fields: {
|
||||
"interest_date": "",
|
||||
"book_date": "",
|
||||
"process_date": "",
|
||||
"due_date": "",
|
||||
"payment_date": "",
|
||||
"invoice_date": "",
|
||||
"internal_reference": "",
|
||||
"notes": "",
|
||||
"attachments": []
|
||||
},
|
||||
foreign_amount: {
|
||||
amount: "",
|
||||
currency_id: 0
|
||||
},
|
||||
source_account: {
|
||||
id: 0,
|
||||
name: "",
|
||||
type: "",
|
||||
currency_id: 0,
|
||||
currency_name: '',
|
||||
currency_code: '',
|
||||
currency_decimal_places: 2,
|
||||
allowed_types: []
|
||||
},
|
||||
destination_account: {
|
||||
id: 0,
|
||||
name: "",
|
||||
type: "",
|
||||
currency_id: 0,
|
||||
currency_name: '',
|
||||
currency_code: '',
|
||||
currency_decimal_places: 2,
|
||||
allowed_types: []
|
||||
}
|
||||
});
|
||||
description: "",
|
||||
date: "",
|
||||
amount: "",
|
||||
category: "",
|
||||
piggy_bank: 0,
|
||||
errors: {
|
||||
source_account: [],
|
||||
destination_account: [],
|
||||
description: [],
|
||||
amount: [],
|
||||
date: [],
|
||||
budget_id: [],
|
||||
foreign_amount: [],
|
||||
category: [],
|
||||
piggy_bank: [],
|
||||
tags: [],
|
||||
// custom fields:
|
||||
custom_errors: {
|
||||
interest_date: [],
|
||||
book_date: [],
|
||||
process_date: [],
|
||||
due_date: [],
|
||||
payment_date: [],
|
||||
invoice_date: [],
|
||||
internal_reference: [],
|
||||
notes: [],
|
||||
attachments: [],
|
||||
},
|
||||
},
|
||||
budget: 0,
|
||||
tags: [],
|
||||
custom_fields: {
|
||||
"interest_date": "",
|
||||
"book_date": "",
|
||||
"process_date": "",
|
||||
"due_date": "",
|
||||
"payment_date": "",
|
||||
"invoice_date": "",
|
||||
"internal_reference": "",
|
||||
"notes": "",
|
||||
"attachments": []
|
||||
},
|
||||
foreign_amount: {
|
||||
amount: "",
|
||||
currency_id: 0
|
||||
},
|
||||
source_account: {
|
||||
id: 0,
|
||||
name: "",
|
||||
type: "",
|
||||
currency_id: 0,
|
||||
currency_name: '',
|
||||
currency_code: '',
|
||||
currency_decimal_places: 2,
|
||||
allowed_types: []
|
||||
},
|
||||
destination_account: {
|
||||
id: 0,
|
||||
name: "",
|
||||
type: "",
|
||||
currency_id: 0,
|
||||
currency_name: '',
|
||||
currency_code: '',
|
||||
currency_decimal_places: 2,
|
||||
allowed_types: []
|
||||
}
|
||||
});
|
||||
if (this.transactions.length === 1) {
|
||||
// set first date.
|
||||
let today = new Date();
|
||||
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user