mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This commit is contained in:
parent
8ee358551c
commit
b942fa4b09
@ -108,6 +108,7 @@ trait WithdrawalValidation
|
|||||||
if (null !== $found) {
|
if (null !== $found) {
|
||||||
$type = $found->accountType->type;
|
$type = $found->accountType->type;
|
||||||
if (in_array($type, $validTypes, true)) {
|
if (in_array($type, $validTypes, true)) {
|
||||||
|
$this->destination = $found;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
$this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||||
|
@ -43,6 +43,9 @@ trait CurrencyValidation
|
|||||||
*/
|
*/
|
||||||
protected function validateForeignCurrencyInformation(Validator $validator): void
|
protected function validateForeignCurrencyInformation(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in validateForeignCurrencyInformation()');
|
Log::debug('Now in validateForeignCurrencyInformation()');
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
|
|
||||||
|
@ -90,6 +90,9 @@ trait GroupValidation
|
|||||||
*/
|
*/
|
||||||
protected function validateDescriptions(Validator $validator): void
|
protected function validateDescriptions(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in GroupValidation::validateDescriptions()');
|
Log::debug('Now in GroupValidation::validateDescriptions()');
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
$validDescriptions = 0;
|
$validDescriptions = 0;
|
||||||
@ -113,6 +116,9 @@ trait GroupValidation
|
|||||||
*/
|
*/
|
||||||
protected function validateGroupDescription(Validator $validator): void
|
protected function validateGroupDescription(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in validateGroupDescription()');
|
Log::debug('Now in validateGroupDescription()');
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
|
@ -43,6 +43,9 @@ trait TransactionValidation
|
|||||||
*/
|
*/
|
||||||
public function validateAccountInformation(Validator $validator): void
|
public function validateAccountInformation(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if ($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in validateAccountInformation (TransactionValidation) ()');
|
Log::debug('Now in validateAccountInformation (TransactionValidation) ()');
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
@ -137,9 +140,49 @@ trait TransactionValidation
|
|||||||
$validator->errors()->add(sprintf('transactions.%d.destination_id', $index), $accountValidator->destError);
|
$validator->errors()->add(sprintf('transactions.%d.destination_id', $index), $accountValidator->destError);
|
||||||
$validator->errors()->add(sprintf('transactions.%d.destination_name', $index), $accountValidator->destError);
|
$validator->errors()->add(sprintf('transactions.%d.destination_name', $index), $accountValidator->destError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanity check for reconciliation accounts. They can't both be null.
|
// sanity check for reconciliation accounts. They can't both be null.
|
||||||
$this->sanityCheckReconciliation($validator, $transactionType, $index, $source, $destination);
|
$this->sanityCheckReconciliation($validator, $transactionType, $index, $source, $destination);
|
||||||
|
|
||||||
|
// deposit and the source is a liability or an asset account with a different
|
||||||
|
// currency than submitted? then the foreign currency info must be present as well (and filled in).
|
||||||
|
if (0 === $validator->errors()->count() && null !== $accountValidator->source && TransactionType::DEPOSIT === ucfirst($transactionType)) {
|
||||||
|
$accountType = $accountValidator?->source?->accountType?->type;
|
||||||
|
if (in_array($accountType, config('firefly.valid_currency_account_types'), true) && !$this->hasForeignCurrencyInfo($transaction)) {
|
||||||
|
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_currency'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// withdrawal or transfer and the destination is a liability or an asset account with a different
|
||||||
|
// currency than submitted? then the foreign currency info must be present as well (and filled in).
|
||||||
|
if (0 === $validator->errors()->count() && null !== $accountValidator->destination &&
|
||||||
|
(TransactionType::WITHDRAWAL === ucfirst($transactionType) || (TransactionType::TRANSFER === ucfirst($transactionType)))) {
|
||||||
|
$accountType = $accountValidator?->destination?->accountType?->type;
|
||||||
|
if (in_array($accountType, config('firefly.valid_currency_account_types'), true) && !$this->hasForeignCurrencyInfo($transaction)) {
|
||||||
|
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_currency'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// account validator has a valid source and a valid destination
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $transaction
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasForeignCurrencyInfo(array $transaction): bool
|
||||||
|
{
|
||||||
|
if (!array_key_exists('foreign_currency_code', $transaction) && !array_key_exists('foreign_currency_id', $transaction)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('foreign_amount', $transaction)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ('' === $transaction['foreign_amount']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (bccomp('0', $transaction['foreign_amount']) === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,6 +367,9 @@ trait TransactionValidation
|
|||||||
*/
|
*/
|
||||||
public function validateOneTransaction(Validator $validator): void
|
public function validateOneTransaction(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if ($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in validateOneTransaction()');
|
Log::debug('Now in validateOneTransaction()');
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
// need at least one transaction
|
// need at least one transaction
|
||||||
@ -341,6 +387,9 @@ trait TransactionValidation
|
|||||||
*/
|
*/
|
||||||
public function validateTransactionArray(Validator $validator): void
|
public function validateTransactionArray(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if ($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
foreach ($transactions as $key => $value) {
|
foreach ($transactions as $key => $value) {
|
||||||
if (!is_int($key)) {
|
if (!is_int($key)) {
|
||||||
@ -359,6 +408,9 @@ trait TransactionValidation
|
|||||||
*/
|
*/
|
||||||
public function validateTransactionTypes(Validator $validator): void
|
public function validateTransactionTypes(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if ($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in validateTransactionTypes()');
|
Log::debug('Now in validateTransactionTypes()');
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
|
|
||||||
@ -427,6 +479,9 @@ trait TransactionValidation
|
|||||||
*/
|
*/
|
||||||
private function validateEqualAccounts(Validator $validator): void
|
private function validateEqualAccounts(Validator $validator): void
|
||||||
{
|
{
|
||||||
|
if ($validator->errors()->count() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log::debug('Now in validateEqualAccounts()');
|
Log::debug('Now in validateEqualAccounts()');
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ return [
|
|||||||
'require_currency_info' => 'The content of this field is invalid without currency information.',
|
'require_currency_info' => 'The content of this field is invalid without currency information.',
|
||||||
'not_transfer_account' => 'This account is not an account that can be used for transfers.',
|
'not_transfer_account' => 'This account is not an account that can be used for transfers.',
|
||||||
'require_currency_amount' => 'The content of this field is invalid without foreign amount information.',
|
'require_currency_amount' => 'The content of this field is invalid without foreign amount information.',
|
||||||
|
'require_foreign_currency' => 'This field requires a number',
|
||||||
'equal_description' => 'Transaction description should not equal global description.',
|
'equal_description' => 'Transaction description should not equal global description.',
|
||||||
'file_invalid_mime' => 'File ":name" is of type ":mime" which is not accepted as a new upload.',
|
'file_invalid_mime' => 'File ":name" is of type ":mime" which is not accepted as a new upload.',
|
||||||
'file_too_large' => 'File ":name" is too large.',
|
'file_too_large' => 'File ":name" is too large.',
|
||||||
|
Loading…
Reference in New Issue
Block a user