mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
Fix #8425
This commit is contained in:
@@ -99,27 +99,28 @@ class Transaction extends Model
|
|||||||
|
|
||||||
protected $casts
|
protected $casts
|
||||||
= [
|
= [
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
'updated_at' => 'datetime',
|
'updated_at' => 'datetime',
|
||||||
'deleted_at' => 'datetime',
|
'deleted_at' => 'datetime',
|
||||||
'identifier' => 'int',
|
'identifier' => 'int',
|
||||||
'encrypted' => 'boolean', // model does not have these fields though
|
'encrypted' => 'boolean', // model does not have these fields though
|
||||||
'bill_name_encrypted' => 'boolean',
|
'bill_name_encrypted' => 'boolean',
|
||||||
'reconciled' => 'boolean',
|
'reconciled' => 'boolean',
|
||||||
];
|
'date' => 'datetime',
|
||||||
|
];
|
||||||
|
|
||||||
protected $fillable
|
protected $fillable
|
||||||
= [
|
= [
|
||||||
'account_id',
|
'account_id',
|
||||||
'transaction_journal_id',
|
'transaction_journal_id',
|
||||||
'description',
|
'description',
|
||||||
'amount',
|
'amount',
|
||||||
'identifier',
|
'identifier',
|
||||||
'transaction_currency_id',
|
'transaction_currency_id',
|
||||||
'foreign_currency_id',
|
'foreign_currency_id',
|
||||||
'foreign_amount',
|
'foreign_amount',
|
||||||
'reconciled',
|
'reconciled',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $hidden = ['encrypted'];
|
protected $hidden = ['encrypted'];
|
||||||
|
|
||||||
|
@@ -456,7 +456,7 @@ class RuleRepository implements RuleRepositoryInterface
|
|||||||
|
|
||||||
// empty the value in case the rule needs no context
|
// empty the value in case the rule needs no context
|
||||||
// TODO create a helper to automatically return these.
|
// TODO create a helper to automatically return these.
|
||||||
$needTrue = [
|
$needTrue = [
|
||||||
'reconciled',
|
'reconciled',
|
||||||
'has_attachments',
|
'has_attachments',
|
||||||
'has_any_category',
|
'has_any_category',
|
||||||
|
@@ -232,7 +232,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
$this->collector->setUser($user);
|
$this->collector->setUser($user);
|
||||||
$this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation();
|
$this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation();
|
||||||
|
|
||||||
$this->setLimit((int) app('preferences')->getForUser($user, 'listPageSize', 50)->data);
|
$this->setLimit((int)app('preferences')->getForUser($user, 'listPageSize', 50)->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLimit(int $limit): void
|
public function setLimit(int $limit): void
|
||||||
@@ -274,7 +274,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
case Emoticon::class:
|
case Emoticon::class:
|
||||||
case Emoji::class:
|
case Emoji::class:
|
||||||
case Mention::class:
|
case Mention::class:
|
||||||
$allWords = (string) $searchNode->getValue();
|
$allWords = (string)$searchNode->getValue();
|
||||||
app('log')->debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class));
|
app('log')->debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class));
|
||||||
$this->words[] = $allWords;
|
$this->words[] = $allWords;
|
||||||
|
|
||||||
@@ -304,11 +304,11 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
// must be valid operator:
|
// must be valid operator:
|
||||||
if (
|
if (
|
||||||
in_array($operator, $this->validOperators, true)
|
in_array($operator, $this->validOperators, true)
|
||||||
&& $this->updateCollector($operator, (string) $value, $prohibited)) {
|
&& $this->updateCollector($operator, (string)$value, $prohibited)) {
|
||||||
$this->operators->push(
|
$this->operators->push(
|
||||||
[
|
[
|
||||||
'type' => self::getRootOperator($operator),
|
'type' => self::getRootOperator($operator),
|
||||||
'value' => (string) $value,
|
'value' => (string)$value,
|
||||||
'prohibited' => $prohibited,
|
'prohibited' => $prohibited,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -318,7 +318,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator));
|
app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator));
|
||||||
$this->invalidOperators[] = [
|
$this->invalidOperators[] = [
|
||||||
'type' => $operator,
|
'type' => $operator,
|
||||||
'value' => (string) $value,
|
'value' => (string)$value,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +518,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'source_account_id':
|
case 'source_account_id':
|
||||||
$account = $this->accountRepository->find((int) $value);
|
$account = $this->accountRepository->find((int)$value);
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
$this->collector->setSourceAccounts(new Collection([$account]));
|
$this->collector->setSourceAccounts(new Collection([$account]));
|
||||||
}
|
}
|
||||||
@@ -530,7 +530,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '-source_account_id':
|
case '-source_account_id':
|
||||||
$account = $this->accountRepository->find((int) $value);
|
$account = $this->accountRepository->find((int)$value);
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
$this->collector->excludeSourceAccounts(new Collection([$account]));
|
$this->collector->excludeSourceAccounts(new Collection([$account]));
|
||||||
}
|
}
|
||||||
@@ -646,7 +646,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'destination_account_id':
|
case 'destination_account_id':
|
||||||
$account = $this->accountRepository->find((int) $value);
|
$account = $this->accountRepository->find((int)$value);
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
$this->collector->setDestinationAccounts(new Collection([$account]));
|
$this->collector->setDestinationAccounts(new Collection([$account]));
|
||||||
}
|
}
|
||||||
@@ -657,7 +657,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '-destination_account_id':
|
case '-destination_account_id':
|
||||||
$account = $this->accountRepository->find((int) $value);
|
$account = $this->accountRepository->find((int)$value);
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
$this->collector->excludeDestinationAccounts(new Collection([$account]));
|
$this->collector->excludeDestinationAccounts(new Collection([$account]));
|
||||||
}
|
}
|
||||||
@@ -671,7 +671,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
$parts = explode(',', $value);
|
$parts = explode(',', $value);
|
||||||
$collection = new Collection();
|
$collection = new Collection();
|
||||||
foreach ($parts as $accountId) {
|
foreach ($parts as $accountId) {
|
||||||
$account = $this->accountRepository->find((int) $accountId);
|
$account = $this->accountRepository->find((int)$accountId);
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
$collection->push($account);
|
$collection->push($account);
|
||||||
}
|
}
|
||||||
@@ -689,7 +689,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
$parts = explode(',', $value);
|
$parts = explode(',', $value);
|
||||||
$collection = new Collection();
|
$collection = new Collection();
|
||||||
foreach ($parts as $accountId) {
|
foreach ($parts as $accountId) {
|
||||||
$account = $this->accountRepository->find((int) $accountId);
|
$account = $this->accountRepository->find((int)$accountId);
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
$collection->push($account);
|
$collection->push($account);
|
||||||
}
|
}
|
||||||
@@ -1904,6 +1904,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
|
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||||
*/
|
*/
|
||||||
private function searchAccount(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
|
private function searchAccount(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
|
||||||
{
|
{
|
||||||
@@ -2043,7 +2044,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
$filtered = $accounts->filter(
|
$filtered = $accounts->filter(
|
||||||
static function (Account $account) use ($value, $stringMethod) {
|
static function (Account $account) use ($value, $stringMethod) {
|
||||||
// either IBAN or account number
|
// either IBAN or account number
|
||||||
$ibanMatch = $stringMethod(strtolower((string) $account->iban), strtolower($value));
|
$ibanMatch = $stringMethod(strtolower((string)$account->iban), strtolower($value));
|
||||||
$accountNrMatch = false;
|
$accountNrMatch = false;
|
||||||
|
|
||||||
/** @var AccountMeta $meta */
|
/** @var AccountMeta $meta */
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Carbon\Exceptions\InvalidFormatException;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
@@ -44,7 +45,7 @@ class Steam
|
|||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$repository->setUser($account->user);
|
$repository->setUser($account->user);
|
||||||
|
|
||||||
$currencyId = (int) $repository->getMetaValue($account, 'currency_id');
|
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
|
||||||
$transactions = $account->transactions()
|
$transactions = $account->transactions()
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||||
@@ -73,7 +74,7 @@ class Steam
|
|||||||
|
|
||||||
/** @var array $transaction */
|
/** @var array $transaction */
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$value = (string) ($transaction[$key] ?? '0');
|
$value = (string)($transaction[$key] ?? '0');
|
||||||
$value = '' === $value ? '0' : $value;
|
$value = '' === $value ? '0' : $value;
|
||||||
$sum = bcadd($sum, $value);
|
$sum = bcadd($sum, $value);
|
||||||
}
|
}
|
||||||
@@ -142,14 +143,14 @@ class Steam
|
|||||||
/** @var Transaction $entry */
|
/** @var Transaction $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
// normal amount and foreign amount
|
// normal amount and foreign amount
|
||||||
$modified = (string) (null === $entry->modified ? '0' : $entry->modified);
|
$modified = (string)(null === $entry->modified ? '0' : $entry->modified);
|
||||||
$foreignModified = (string) (null === $entry->modified_foreign ? '0' : $entry->modified_foreign);
|
$foreignModified = (string)(null === $entry->modified_foreign ? '0' : $entry->modified_foreign);
|
||||||
$amount = '0';
|
$amount = '0';
|
||||||
if ($currencyId === (int) $entry->transaction_currency_id || 0 === $currencyId) {
|
if ($currencyId === (int)$entry->transaction_currency_id || 0 === $currencyId) {
|
||||||
// use normal amount:
|
// use normal amount:
|
||||||
$amount = $modified;
|
$amount = $modified;
|
||||||
}
|
}
|
||||||
if ($currencyId === (int) $entry->foreign_currency_id) {
|
if ($currencyId === (int)$entry->foreign_currency_id) {
|
||||||
// use foreign amount:
|
// use foreign amount:
|
||||||
$amount = $foreignModified;
|
$amount = $foreignModified;
|
||||||
}
|
}
|
||||||
@@ -274,7 +275,7 @@ class Steam
|
|||||||
}
|
}
|
||||||
$format = $day->format('Y-m-d');
|
$format = $day->format('Y-m-d');
|
||||||
// if the transaction is in the expected currency, change nothing.
|
// if the transaction is in the expected currency, change nothing.
|
||||||
if ((int) $transaction['transaction_currency_id'] === $native->id) {
|
if ((int)$transaction['transaction_currency_id'] === $native->id) {
|
||||||
// change the current balance, set it to today, continue the loop.
|
// change the current balance, set it to today, continue the loop.
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['amount']);
|
$currentBalance = bcadd($currentBalance, $transaction['amount']);
|
||||||
$balances[$format] = $currentBalance;
|
$balances[$format] = $currentBalance;
|
||||||
@@ -283,7 +284,7 @@ class Steam
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// if foreign currency is in the expected currency, do nothing:
|
// if foreign currency is in the expected currency, do nothing:
|
||||||
if ((int) $transaction['foreign_currency_id'] === $native->id) {
|
if ((int)$transaction['foreign_currency_id'] === $native->id) {
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['foreign_amount']);
|
$currentBalance = bcadd($currentBalance, $transaction['foreign_amount']);
|
||||||
$balances[$format] = $currentBalance;
|
$balances[$format] = $currentBalance;
|
||||||
Log::debug(sprintf('%s: transaction in %s (foreign), new balance is %s.', $format, $native->code, $currentBalance));
|
Log::debug(sprintf('%s: transaction in %s (foreign), new balance is %s.', $format, $native->code, $currentBalance));
|
||||||
@@ -291,7 +292,7 @@ class Steam
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// otherwise, convert 'amount' to the necessary currency:
|
// otherwise, convert 'amount' to the necessary currency:
|
||||||
$currencyId = (int) $transaction['transaction_currency_id'];
|
$currencyId = (int)$transaction['transaction_currency_id'];
|
||||||
$currency = $currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
$currency = $currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
||||||
$currencies[$currencyId] = $currency;
|
$currencies[$currencyId] = $currency;
|
||||||
|
|
||||||
@@ -429,7 +430,13 @@ class Steam
|
|||||||
$converter = new ExchangeRateConverter();
|
$converter = new ExchangeRateConverter();
|
||||||
foreach ($new as $set) {
|
foreach ($new as $set) {
|
||||||
foreach ($set as $transaction) {
|
foreach ($set as $transaction) {
|
||||||
$currentDate = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);
|
$currentDate = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$currentDate = Carbon::parse($transaction['date'], config('app.timezone'));
|
||||||
|
} catch(InvalidFormatException $e) {
|
||||||
|
Log::error(sprintf('Could not parse date "%s" in %s', $transaction['date'], __METHOD__));
|
||||||
|
}
|
||||||
if (false === $currentDate) {
|
if (false === $currentDate) {
|
||||||
$currentDate = today(config('app.timezone'));
|
$currentDate = today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
@@ -443,7 +450,13 @@ class Steam
|
|||||||
|
|
||||||
foreach ($new as $set) {
|
foreach ($new as $set) {
|
||||||
foreach ($set as $transaction) {
|
foreach ($set as $transaction) {
|
||||||
$currentDate = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);
|
$currentDate = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$currentDate = Carbon::parse($transaction['date'], config('app.timezone'));
|
||||||
|
} catch(InvalidFormatException $e) {
|
||||||
|
Log::error(sprintf('Could not parse date "%s" in %s', $transaction['date'], __METHOD__));
|
||||||
|
}
|
||||||
if (false === $currentDate) {
|
if (false === $currentDate) {
|
||||||
$currentDate = today(config('app.timezone'));
|
$currentDate = today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
@@ -578,7 +591,7 @@ class Steam
|
|||||||
|
|
||||||
/** @var \stdClass $entry */
|
/** @var \stdClass $entry */
|
||||||
foreach ($balances as $entry) {
|
foreach ($balances as $entry) {
|
||||||
$return[(int) $entry->transaction_currency_id] = (string) $entry->sum_for_currency;
|
$return[(int)$entry->transaction_currency_id] = (string)$entry->sum_for_currency;
|
||||||
}
|
}
|
||||||
$cache->store($return);
|
$cache->store($return);
|
||||||
|
|
||||||
@@ -681,7 +694,7 @@ class Steam
|
|||||||
throw new FireflyException($e->getMessage(), 0, $e);
|
throw new FireflyException($e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $hostName;
|
return (string)$hostName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLastActivities(array $accounts): array
|
public function getLastActivities(array $accounts): array
|
||||||
@@ -716,7 +729,7 @@ class Steam
|
|||||||
if ('equal' === $locale) {
|
if ('equal' === $locale) {
|
||||||
$locale = $this->getLanguage();
|
$locale = $this->getLanguage();
|
||||||
}
|
}
|
||||||
$locale = (string) $locale;
|
$locale = (string)$locale;
|
||||||
|
|
||||||
// Check for Windows to replace the locale correctly.
|
// Check for Windows to replace the locale correctly.
|
||||||
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
|
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
|
||||||
@@ -815,20 +828,20 @@ class Steam
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$number = substr($value, 0, (int) strpos($value, 'E'));
|
$number = substr($value, 0, (int)strpos($value, 'E'));
|
||||||
if (str_contains($number, '.')) {
|
if (str_contains($number, '.')) {
|
||||||
$post = strlen(substr($number, (int) strpos($number, '.') + 1));
|
$post = strlen(substr($number, (int)strpos($number, '.') + 1));
|
||||||
$mantis = substr($value, (int) strpos($value, 'E') + 1);
|
$mantis = substr($value, (int)strpos($value, 'E') + 1);
|
||||||
if ($mantis < 0) {
|
if ($mantis < 0) {
|
||||||
$post += abs((int) $mantis);
|
$post += abs((int)$mantis);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO careless float could break financial math.
|
// TODO careless float could break financial math.
|
||||||
return number_format((float) $value, $post, '.', '');
|
return number_format((float)$value, $post, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO careless float could break financial math.
|
// TODO careless float could break financial math.
|
||||||
return number_format((float) $value, 0, '.', '');
|
return number_format((float)$value, 0, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function opposite(string $amount = null): ?string
|
public function opposite(string $amount = null): ?string
|
||||||
@@ -848,24 +861,24 @@ class Steam
|
|||||||
// has a K in it, remove the K and multiply by 1024.
|
// has a K in it, remove the K and multiply by 1024.
|
||||||
$bytes = bcmul(rtrim($string, 'k'), '1024');
|
$bytes = bcmul(rtrim($string, 'k'), '1024');
|
||||||
|
|
||||||
return (int) $bytes;
|
return (int)$bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== stripos($string, 'm')) {
|
if (false !== stripos($string, 'm')) {
|
||||||
// has a M in it, remove the M and multiply by 1048576.
|
// has a M in it, remove the M and multiply by 1048576.
|
||||||
$bytes = bcmul(rtrim($string, 'm'), '1048576');
|
$bytes = bcmul(rtrim($string, 'm'), '1048576');
|
||||||
|
|
||||||
return (int) $bytes;
|
return (int)$bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== stripos($string, 'g')) {
|
if (false !== stripos($string, 'g')) {
|
||||||
// has a G in it, remove the G and multiply by (1024)^3.
|
// has a G in it, remove the G and multiply by (1024)^3.
|
||||||
$bytes = bcmul(rtrim($string, 'g'), '1073741824');
|
$bytes = bcmul(rtrim($string, 'g'), '1073741824');
|
||||||
|
|
||||||
return (int) $bytes;
|
return (int)$bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $string;
|
return (int)$string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function positive(string $amount): string
|
public function positive(string $amount): string
|
||||||
|
@@ -72,7 +72,7 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
'uri' => '/rules/' . $rule->id,
|
'uri' => '/rules/'.$rule->id,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -115,7 +115,7 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
$triggerValue = 'true';
|
$triggerValue = 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'id' => (string)$ruleTrigger->id,
|
'id' => (string)$ruleTrigger->id,
|
||||||
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
||||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
||||||
|
@@ -62,7 +62,7 @@ class FireflyValidator extends Validator
|
|||||||
if (!is_string($value) || 6 !== strlen($value)) {
|
if (!is_string($value) || 6 !== strlen($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
if (null === $user) {
|
if (null === $user) {
|
||||||
app('log')->error('No user during validate2faCode');
|
app('log')->error('No user during validate2faCode');
|
||||||
|
|
||||||
@@ -183,10 +183,10 @@ class FireflyValidator extends Validator
|
|||||||
$replace = ['', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35'];
|
$replace = ['', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35'];
|
||||||
|
|
||||||
// take
|
// take
|
||||||
$first = substr($value, 0, 4);
|
$first = substr($value, 0, 4);
|
||||||
$last = substr($value, 4);
|
$last = substr($value, 4);
|
||||||
$iban = $last . $first;
|
$iban = $last.$first;
|
||||||
$iban = trim(str_replace($search, $replace, $iban));
|
$iban = trim(str_replace($search, $replace, $iban));
|
||||||
if ('' === $iban) {
|
if ('' === $iban) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -257,8 +257,8 @@ class FireflyValidator extends Validator
|
|||||||
{
|
{
|
||||||
// first, get the index from this string:
|
// first, get the index from this string:
|
||||||
$value ??= '';
|
$value ??= '';
|
||||||
$parts = explode('.', $attribute);
|
$parts = explode('.', $attribute);
|
||||||
$index = (int)($parts[1] ?? '0');
|
$index = (int)($parts[1] ?? '0');
|
||||||
|
|
||||||
// get the name of the trigger from the data array:
|
// get the name of the trigger from the data array:
|
||||||
$actionType = $this->data['actions'][$index]['type'] ?? 'invalid';
|
$actionType = $this->data['actions'][$index]['type'] ?? 'invalid';
|
||||||
@@ -322,8 +322,8 @@ class FireflyValidator extends Validator
|
|||||||
public function validateRuleTriggerValue(string $attribute, string $value = null): bool
|
public function validateRuleTriggerValue(string $attribute, string $value = null): bool
|
||||||
{
|
{
|
||||||
// first, get the index from this string:
|
// first, get the index from this string:
|
||||||
$parts = explode('.', $attribute);
|
$parts = explode('.', $attribute);
|
||||||
$index = (int)($parts[1] ?? '0');
|
$index = (int)($parts[1] ?? '0');
|
||||||
|
|
||||||
// get the name of the trigger from the data array:
|
// get the name of the trigger from the data array:
|
||||||
$triggerType = $this->data['triggers'][$index]['type'] ?? 'invalid';
|
$triggerType = $this->data['triggers'][$index]['type'] ?? 'invalid';
|
||||||
@@ -334,14 +334,14 @@ class FireflyValidator extends Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// these trigger types need a numerical check:
|
// these trigger types need a numerical check:
|
||||||
$numerical = ['amount_less', 'amount_more', 'amount_exactly'];
|
$numerical = ['amount_less', 'amount_more', 'amount_exactly'];
|
||||||
if (in_array($triggerType, $numerical, true)) {
|
if (in_array($triggerType, $numerical, true)) {
|
||||||
return is_numeric($value);
|
return is_numeric($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// these triggers need just the word "true":
|
// these triggers need just the word "true":
|
||||||
// TODO create a helper to automatically return these.
|
// TODO create a helper to automatically return these.
|
||||||
$needTrue = [
|
$needTrue = [
|
||||||
'reconciled',
|
'reconciled',
|
||||||
'has_attachments',
|
'has_attachments',
|
||||||
'has_any_category',
|
'has_any_category',
|
||||||
@@ -370,7 +370,7 @@ class FireflyValidator extends Validator
|
|||||||
|
|
||||||
// these trigger types need a simple strlen check:
|
// these trigger types need a simple strlen check:
|
||||||
// TODO create a helper to automatically return these.
|
// TODO create a helper to automatically return these.
|
||||||
$length = [
|
$length = [
|
||||||
'source_account_starts',
|
'source_account_starts',
|
||||||
'source_account_ends',
|
'source_account_ends',
|
||||||
'source_account_is',
|
'source_account_is',
|
||||||
@@ -512,18 +512,19 @@ class FireflyValidator extends Validator
|
|||||||
$accountId = (int)($parameters[0] ?? 0.0);
|
$accountId = (int)($parameters[0] ?? 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||||
->whereNull('accounts.deleted_at')
|
->whereNull('accounts.deleted_at')
|
||||||
->where('accounts.user_id', auth()->user()->id)
|
->where('accounts.user_id', auth()->user()->id)
|
||||||
->where('account_meta.name', 'account_number')
|
->where('account_meta.name', 'account_number')
|
||||||
->where('account_meta.data', json_encode($value));
|
->where('account_meta.data', json_encode($value))
|
||||||
|
;
|
||||||
|
|
||||||
if ($accountId > 0) {
|
if ($accountId > 0) {
|
||||||
// exclude current account from check.
|
// exclude current account from check.
|
||||||
$query->where('account_meta.account_id', '!=', $accountId);
|
$query->where('account_meta.account_id', '!=', $accountId);
|
||||||
}
|
}
|
||||||
$set = $query->get(['account_meta.*']);
|
$set = $query->get(['account_meta.*']);
|
||||||
$count = $set->count();
|
$count = $set->count();
|
||||||
if (0 === $count) {
|
if (0 === $count) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -531,7 +532,7 @@ class FireflyValidator extends Validator
|
|||||||
// pretty much impossible but still.
|
// pretty much impossible but still.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$type = $this->data['objectType'] ?? 'unknown';
|
$type = $this->data['objectType'] ?? 'unknown';
|
||||||
if ('expense' !== $type && 'revenue' !== $type) {
|
if ('expense' !== $type && 'revenue' !== $type) {
|
||||||
app('log')->warning(sprintf('Account number "%s" is not unique and account type "%s" cannot share its account number.', $value, $type));
|
app('log')->warning(sprintf('Account number "%s" is not unique and account type "%s" cannot share its account number.', $value, $type));
|
||||||
|
|
||||||
@@ -558,7 +559,7 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*/
|
*/
|
||||||
public function validateUniqueCurrencyCode(null | string $attribute, null | string $value): bool
|
public function validateUniqueCurrencyCode(null|string $attribute, null|string $value): bool
|
||||||
{
|
{
|
||||||
return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
|
return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
|
||||||
}
|
}
|
||||||
@@ -571,12 +572,12 @@ class FireflyValidator extends Validator
|
|||||||
return 0 === \DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
return 0 === \DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateUniqueCurrencyName(null | string $attribute, null | string $value): bool
|
public function validateUniqueCurrencyName(null|string $attribute, null|string $value): bool
|
||||||
{
|
{
|
||||||
return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
|
return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateUniqueCurrencySymbol(null | string $attribute, null | string $value): bool
|
public function validateUniqueCurrencySymbol(null|string $attribute, null|string $value): bool
|
||||||
{
|
{
|
||||||
return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
|
return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
|
||||||
}
|
}
|
||||||
@@ -601,7 +602,7 @@ class FireflyValidator extends Validator
|
|||||||
// get existing webhook value:
|
// get existing webhook value:
|
||||||
if (0 !== $existingId) {
|
if (0 !== $existingId) {
|
||||||
/** @var null|Webhook $webhook */
|
/** @var null|Webhook $webhook */
|
||||||
$webhook = auth()->user()->webhooks()->find($existingId);
|
$webhook = auth()->user()->webhooks()->find($existingId);
|
||||||
if (null === $webhook) {
|
if (null === $webhook) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -619,11 +620,12 @@ class FireflyValidator extends Validator
|
|||||||
$userId = auth()->user()->id;
|
$userId = auth()->user()->id;
|
||||||
|
|
||||||
return 0 === Webhook::whereUserId($userId)
|
return 0 === Webhook::whereUserId($userId)
|
||||||
->where('trigger', $trigger)
|
->where('trigger', $trigger)
|
||||||
->where('response', $response)
|
->where('response', $response)
|
||||||
->where('delivery', $delivery)
|
->where('delivery', $delivery)
|
||||||
->where('id', '!=', $existingId)
|
->where('id', '!=', $existingId)
|
||||||
->where('url', $url)->count();
|
->where('url', $url)->count()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -645,21 +647,22 @@ class FireflyValidator extends Validator
|
|||||||
public function validateUniqueObjectForUser($attribute, $value, $parameters): bool
|
public function validateUniqueObjectForUser($attribute, $value, $parameters): bool
|
||||||
{
|
{
|
||||||
[$table, $field] = $parameters;
|
[$table, $field] = $parameters;
|
||||||
$exclude = (int)($parameters[2] ?? 0.0);
|
$exclude = (int)($parameters[2] ?? 0.0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If other data (in $this->getData()) contains
|
* If other data (in $this->getData()) contains
|
||||||
* ID field, set that field to be the $exclude.
|
* ID field, set that field to be the $exclude.
|
||||||
*/
|
*/
|
||||||
$data = $this->getData();
|
$data = $this->getData();
|
||||||
if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) {
|
if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) {
|
||||||
$exclude = (int)$data['id'];
|
$exclude = (int)$data['id'];
|
||||||
}
|
}
|
||||||
// get entries from table
|
// get entries from table
|
||||||
$result = \DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
$result = \DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||||
->where('id', '!=', $exclude)
|
->where('id', '!=', $exclude)
|
||||||
->where($field, $value)
|
->where($field, $value)
|
||||||
->first([$field]);
|
->first([$field])
|
||||||
|
;
|
||||||
if (null === $result) {
|
if (null === $result) {
|
||||||
return true; // not found, so true.
|
return true; // not found, so true.
|
||||||
}
|
}
|
||||||
@@ -679,9 +682,10 @@ class FireflyValidator extends Validator
|
|||||||
{
|
{
|
||||||
$exclude = $parameters[0] ?? null;
|
$exclude = $parameters[0] ?? null;
|
||||||
$query = \DB::table('object_groups')
|
$query = \DB::table('object_groups')
|
||||||
->whereNull('object_groups.deleted_at')
|
->whereNull('object_groups.deleted_at')
|
||||||
->where('object_groups.user_id', auth()->user()->id)
|
->where('object_groups.user_id', auth()->user()->id)
|
||||||
->where('object_groups.title', $value);
|
->where('object_groups.title', $value)
|
||||||
|
;
|
||||||
if (null !== $exclude) {
|
if (null !== $exclude) {
|
||||||
$query->where('object_groups.id', '!=', (int)$exclude);
|
$query->where('object_groups.id', '!=', (int)$exclude);
|
||||||
}
|
}
|
||||||
@@ -700,7 +704,8 @@ class FireflyValidator extends Validator
|
|||||||
{
|
{
|
||||||
$exclude = $parameters[0] ?? null;
|
$exclude = $parameters[0] ?? null;
|
||||||
$query = \DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
|
$query = \DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id);
|
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id)
|
||||||
|
;
|
||||||
if (null !== $exclude) {
|
if (null !== $exclude) {
|
||||||
$query->where('piggy_banks.id', '!=', (int)$exclude);
|
$query->where('piggy_banks.id', '!=', (int)$exclude);
|
||||||
}
|
}
|
||||||
@@ -723,17 +728,18 @@ class FireflyValidator extends Validator
|
|||||||
$deliveries = Webhook::getDeliveriesForValidation();
|
$deliveries = Webhook::getDeliveriesForValidation();
|
||||||
|
|
||||||
// integers
|
// integers
|
||||||
$trigger = $triggers[$this->data['trigger']] ?? 0;
|
$trigger = $triggers[$this->data['trigger']] ?? 0;
|
||||||
$response = $responses[$this->data['response']] ?? 0;
|
$response = $responses[$this->data['response']] ?? 0;
|
||||||
$delivery = $deliveries[$this->data['delivery']] ?? 0;
|
$delivery = $deliveries[$this->data['delivery']] ?? 0;
|
||||||
$url = $this->data['url'];
|
$url = $this->data['url'];
|
||||||
$userId = auth()->user()->id;
|
$userId = auth()->user()->id;
|
||||||
|
|
||||||
return 0 === Webhook::whereUserId($userId)
|
return 0 === Webhook::whereUserId($userId)
|
||||||
->where('trigger', $trigger)
|
->where('trigger', $trigger)
|
||||||
->where('response', $response)
|
->where('response', $response)
|
||||||
->where('delivery', $delivery)
|
->where('delivery', $delivery)
|
||||||
->where('url', $url)->count();
|
->where('url', $url)->count()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -746,9 +752,9 @@ class FireflyValidator extends Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = User::find($this->data['user_id']);
|
$user = User::find($this->data['user_id']);
|
||||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||||
$value = $this->data['name'];
|
$value = $this->data['name'];
|
||||||
|
|
||||||
/** @var null|Account $result */
|
/** @var null|Account $result */
|
||||||
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
|
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
|
||||||
@@ -759,7 +765,7 @@ class FireflyValidator extends Validator
|
|||||||
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
|
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
|
||||||
{
|
{
|
||||||
/** @var null|array $search */
|
/** @var null|array $search */
|
||||||
$search = \Config::get('firefly.accountTypeByIdentifier.' . $type);
|
$search = \Config::get('firefly.accountTypeByIdentifier.'.$type);
|
||||||
|
|
||||||
if (null === $search) {
|
if (null === $search) {
|
||||||
return false;
|
return false;
|
||||||
@@ -770,9 +776,10 @@ class FireflyValidator extends Validator
|
|||||||
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
||||||
|
|
||||||
/** @var null|Account $result */
|
/** @var null|Account $result */
|
||||||
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
|
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
|
||||||
->where('name', $value)
|
->where('name', $value)
|
||||||
->first();
|
->first()
|
||||||
|
;
|
||||||
|
|
||||||
return null === $result;
|
return null === $result;
|
||||||
}
|
}
|
||||||
@@ -788,8 +795,9 @@ class FireflyValidator extends Validator
|
|||||||
|
|
||||||
/** @var null|Account $result */
|
/** @var null|Account $result */
|
||||||
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||||
->where('name', $value)
|
->where('name', $value)
|
||||||
->first();
|
->first()
|
||||||
|
;
|
||||||
|
|
||||||
return null === $result;
|
return null === $result;
|
||||||
}
|
}
|
||||||
@@ -802,12 +810,13 @@ class FireflyValidator extends Validator
|
|||||||
/** @var Account $existingAccount */
|
/** @var Account $existingAccount */
|
||||||
$existingAccount = Account::find($accountId);
|
$existingAccount = Account::find($accountId);
|
||||||
|
|
||||||
$type = $existingAccount->accountType;
|
$type = $existingAccount->accountType;
|
||||||
$ignore = $existingAccount->id;
|
$ignore = $existingAccount->id;
|
||||||
|
|
||||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||||
->where('name', $value)
|
->where('name', $value)
|
||||||
->first();
|
->first()
|
||||||
|
;
|
||||||
|
|
||||||
return null === $entry;
|
return null === $entry;
|
||||||
}
|
}
|
||||||
@@ -820,12 +829,13 @@ class FireflyValidator extends Validator
|
|||||||
/** @var Account $existingAccount */
|
/** @var Account $existingAccount */
|
||||||
$existingAccount = Account::find($this->data['id']);
|
$existingAccount = Account::find($this->data['id']);
|
||||||
|
|
||||||
$type = $existingAccount->accountType;
|
$type = $existingAccount->accountType;
|
||||||
$ignore = $existingAccount->id;
|
$ignore = $existingAccount->id;
|
||||||
|
|
||||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||||
->where('name', $value)
|
->where('name', $value)
|
||||||
->first();
|
->first()
|
||||||
|
;
|
||||||
|
|
||||||
return null === $entry;
|
return null === $entry;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user