From 60196383885a311a62409b6a7ac9e664f3e5d696 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 7 Jan 2020 17:18:56 +0100 Subject: [PATCH 1/5] Fix old todo item --- .../Commands/Upgrade/OtherCurrenciesCorrections.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php index c16c3e85d0..8c4fa54d40 100644 --- a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php +++ b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php @@ -125,19 +125,17 @@ class OtherCurrenciesCorrections extends Command if (isset($this->accountCurrencies[$accountId]) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) { return $this->accountCurrencies[$accountId]; // @codeCoverageIgnore } - // TODO we can use getAccountCurrency() instead - $currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id'); - $result = $this->currencyRepos->findNull($currencyId); - if (null === $result) { + $currency = $this->accountRepos->getAccountCurrency($account); + if (null === $currency) { // @codeCoverageIgnoreStart $this->accountCurrencies[$accountId] = 0; return null; // @codeCoverageIgnoreEnd } - $this->accountCurrencies[$accountId] = $result; + $this->accountCurrencies[$accountId] = $currency; - return $result; + return $currency; } From 2485f743026563f3cf6872ffc92ab83580f30229 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 8 Jan 2020 05:48:45 +0100 Subject: [PATCH 2/5] Fix #2975 --- app/Http/Requests/PiggyBankFormRequest.php | 2 +- app/Transformers/PiggyBankTransformer.php | 8 ++--- resources/lang/en_US/validation.php | 37 ++++++++++++---------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/Http/Requests/PiggyBankFormRequest.php b/app/Http/Requests/PiggyBankFormRequest.php index 1fdc6f0ca0..a927beb79b 100644 --- a/app/Http/Requests/PiggyBankFormRequest.php +++ b/app/Http/Requests/PiggyBankFormRequest.php @@ -76,7 +76,7 @@ class PiggyBankFormRequest extends Request $rules = [ 'name' => $nameRule, 'account_id' => 'required|belongsToUser:accounts', - 'targetamount' => 'required|numeric|more:0|max:1000000000', + 'targetamount' => 'required|numeric|gte:0.01|max:1000000000', 'startdate' => 'date', 'targetdate' => 'date|nullable', 'order' => 'integer|min:1', diff --git a/app/Transformers/PiggyBankTransformer.php b/app/Transformers/PiggyBankTransformer.php index cedbd94ffb..a08fba07a4 100644 --- a/app/Transformers/PiggyBankTransformer.php +++ b/app/Transformers/PiggyBankTransformer.php @@ -77,12 +77,7 @@ class PiggyBankTransformer extends AbstractTransformer $this->piggyRepos->setUser($account->user); // get currency from account, or use default. - // TODO we can use getAccountCurrency() instead - $currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id'); - $currency = $this->currencyRepos->findNull($currencyId); - if (null === $currency) { - $currency = app('amount')->getDefaultCurrencyByUser($account->user); - } + $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user); // note $notes = $this->piggyRepos->getNoteText($piggyBank); @@ -99,6 +94,7 @@ class PiggyBankTransformer extends AbstractTransformer // target and percentage: $targetAmount = round($piggyBank->targetamount, $currency->decimal_places); + $targetAmount = 1 === bccomp('0.01', (string)$targetAmount) ? '0.01' : $targetAmount; $percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmount / $targetAmount * 100 : 0); $data = [ 'id' => (int)$piggyBank->id, diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php index 38188ec846..e8c654c283 100644 --- a/resources/lang/en_US/validation.php +++ b/resources/lang/en_US/validation.php @@ -57,7 +57,7 @@ return [ 'at_least_one_action' => 'Rule must have at least one action.', 'base64' => 'This is not valid base64 encoded data.', 'model_id_invalid' => 'The given ID seems invalid for this model.', - 'more' => ':attribute must be larger than zero.', + 'more' => ':attribute must be larger than ":more".', 'less' => ':attribute must be less than 10,000,000', 'active_url' => 'The :attribute is not a valid URL.', 'after' => 'The :attribute must be a date after :date.', @@ -121,19 +121,19 @@ return [ 'string' => 'The :attribute must be a string.', 'url' => 'The :attribute format is invalid.', 'timezone' => 'The :attribute must be a valid zone.', - '2fa_code' => 'The :attribute field is invalid.', - 'dimensions' => 'The :attribute has invalid image dimensions.', - 'distinct' => 'The :attribute field has a duplicate value.', - 'file' => 'The :attribute must be a file.', - 'in_array' => 'The :attribute field does not exist in :other.', - 'present' => 'The :attribute field must be present.', - 'amount_zero' => 'The total amount cannot be zero.', - 'current_target_amount' => 'The current amount must be less than the target amount.', - 'unique_piggy_bank_for_user' => 'The name of the piggy bank must be unique.', - 'secure_password' => 'This is not a secure password. Please try again. For more information, visit https://bit.ly/FF3-password-security', - 'valid_recurrence_rep_type' => 'Invalid repetition type for recurring transactions.', - 'valid_recurrence_rep_moment' => 'Invalid repetition moment for this type of repetition.', - 'invalid_account_info' => 'Invalid account information.', + '2fa_code' => 'The :attribute field is invalid.', + 'dimensions' => 'The :attribute has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'file' => 'The :attribute must be a file.', + 'in_array' => 'The :attribute field does not exist in :other.', + 'present' => 'The :attribute field must be present.', + 'amount_zero' => 'The total amount cannot be zero.', + 'current_target_amount' => 'The current amount must be less than the target amount.', + 'unique_piggy_bank_for_user' => 'The name of the piggy bank must be unique.', + 'secure_password' => 'This is not a secure password. Please try again. For more information, visit https://bit.ly/FF3-password-security', + 'valid_recurrence_rep_type' => 'Invalid repetition type for recurring transactions.', + 'valid_recurrence_rep_moment' => 'Invalid repetition moment for this type of repetition.', + 'invalid_account_info' => 'Invalid account information.', 'attributes' => [ 'email' => 'email address', 'description' => 'description', @@ -181,7 +181,7 @@ return [ 'deposit_source_bad_data' => 'Could not find a valid source account when searching for ID ":id" or name ":name".', 'deposit_dest_need_data' => 'Need to get a valid destination account ID and/or valid destination account name to continue.', 'deposit_dest_bad_data' => 'Could not find a valid destination account when searching for ID ":id" or name ":name".', - 'deposit_dest_wrong_type' => 'The submitted destination account is not of the right type.', + 'deposit_dest_wrong_type' => 'The submitted destination account is not of the right type.', 'transfer_source_need_data' => 'Need to get a valid source account ID and/or valid source account name to continue.', 'transfer_source_bad_data' => 'Could not find a valid source account when searching for ID ":id" or name ":name".', @@ -193,6 +193,11 @@ return [ 'ob_dest_need_data' => 'Need to get a valid destination account ID and/or valid destination account name to continue.', 'ob_dest_bad_data' => 'Could not find a valid destination account when searching for ID ":id" or name ":name".', - 'generic_invalid_source' => 'You can\'t use this account as the source account.', + 'generic_invalid_source' => 'You can\'t use this account as the source account.', 'generic_invalid_destination' => 'You can\'t use this account as the destination account.', + + 'gte.numeric' => 'The :attribute must be greater than or equal to :value.', + 'gte.file' => 'The :attribute must be greater than or equal to :value kilobytes.', + 'gte.string' => 'The :attribute must be greater than or equal to :value characters.', + 'gte.array' => 'The :attribute must have :value items or more.', ]; From a2a980e3de76959f7aa576377ea43aafa586d7e1 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 8 Jan 2020 06:05:00 +0100 Subject: [PATCH 3/5] Fix #2966 --- .../Json/AutoCompleteController.php | 81 ++++++++++--------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/Json/AutoCompleteController.php b/app/Http/Controllers/Json/AutoCompleteController.php index d57aa9ea24..9fe3cacfe3 100644 --- a/app/Http/Controllers/Json/AutoCompleteController.php +++ b/app/Http/Controllers/Json/AutoCompleteController.php @@ -125,6 +125,14 @@ class AutoCompleteController extends Controller $filtered = $result->unique('description'); $limited = $filtered->slice(0, 15); $array = $limited->toArray(); + // duplicate 'description' value into 'name': + $array = array_map( + static function (array $journal) { + $journal['name'] = $journal['description']; + + return $journal; + }, $array + ); return response()->json(array_values($array)); } @@ -174,6 +182,38 @@ class AutoCompleteController extends Controller return response()->json($array); } + /** + * An auto-complete specifically for asset accounts and liabilities, used when mass updating and for rules mostly. + * + * @param Request $request + * + * @return JsonResponse + */ + public function assetAccounts(Request $request): JsonResponse + { + $search = $request->get('search'); + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + + // filter the account types: + $allowedAccountTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; + Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes); + + $return = []; + $result = $repository->searchAccount((string)$search, $allowedAccountTypes); + + /** @var Account $account */ + foreach ($result as $account) { + $return[] = [ + 'id' => $account->id, + 'name' => $account->name, + 'type' => $account->accountType->type, + ]; + } + + return response()->json($return); + } + /** * @param Request $request * @@ -283,39 +323,6 @@ class AutoCompleteController extends Controller return response()->json($return); } - - /** - * An auto-complete specifically for asset accounts and liabilities, used when mass updating and for rules mostly. - * - * @param Request $request - * - * @return JsonResponse - */ - public function assetAccounts(Request $request): JsonResponse - { - $search = $request->get('search'); - /** @var AccountRepositoryInterface $repository */ - $repository = app(AccountRepositoryInterface::class); - - // filter the account types: - $allowedAccountTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; - Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes); - - $return = []; - $result = $repository->searchAccount((string)$search, $allowedAccountTypes); - - /** @var Account $account */ - foreach ($result as $account) { - $return[] = [ - 'id' => $account->id, - 'name' => $account->name, - 'type' => $account->accountType->type, - ]; - } - - return response()->json($return); - } - /** * @return JsonResponse * @codeCoverageIgnore @@ -328,12 +335,12 @@ class AutoCompleteController extends Controller /** @var AccountRepositoryInterface $accountRepos */ $accountRepos = app(AccountRepositoryInterface::class); - $piggies = $repository->getPiggyBanks(); + $piggies = $repository->getPiggyBanks(); $defaultCurrency = \Amount::getDefaultCurrency(); - $response = []; + $response = []; /** @var PiggyBank $piggy */ foreach ($piggies as $piggy) { - $currency = $accountRepos->getAccountCurrency($piggy->account) ?? $defaultCurrency; + $currency = $accountRepos->getAccountCurrency($piggy->account) ?? $defaultCurrency; $currentAmount = $repository->getRepetition($piggy)->currentamount ?? '0'; $piggy->name_with_amount = sprintf( '%s (%s / %s)', @@ -341,7 +348,7 @@ class AutoCompleteController extends Controller app('amount')->formatAnything($currency, $currentAmount, false), app('amount')->formatAnything($currency, $piggy->targetamount, false), ); - $response[] = $piggy->toArray(); + $response[] = $piggy->toArray(); } return response()->json($response); From bb1483f196be749a5fbfd45554db1bfe7e2d28f8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 8 Jan 2020 08:06:42 +0100 Subject: [PATCH 4/5] Update custom template. --- .github/ISSUE_TEMPLATE/Custom.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Custom.md b/.github/ISSUE_TEMPLATE/Custom.md index bb31ec7299..90cbcaf332 100644 --- a/.github/ISSUE_TEMPLATE/Custom.md +++ b/.github/ISSUE_TEMPLATE/Custom.md @@ -4,7 +4,7 @@ about: Ask away! --- -I am running Firefly III version x.x.x +I am running Firefly III version x.x.x. **Description** @@ -13,10 +13,11 @@ I am running Firefly III version x.x.x **Bonus points** - \ No newline at end of file + + +- [ ] I have read the FAQ at https://bit.ly/FF3-FAQ +- [ ] I added a screenshot +- [ ] I added log files (see https://bit.ly/FF3-get-logs) +- [ ] I was able to replicate the issue on the demo site. + From 8c611901b86016e989a81c4054ca111ffc2ef192 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 8 Jan 2020 18:13:42 +0100 Subject: [PATCH 5/5] Fix #2976 --- app/Repositories/Budget/BudgetRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index b89c8b28f2..40c6d4e35e 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -243,7 +243,7 @@ class BudgetRepository implements BudgetRepositoryInterface if ('' !== $query) { $search->where('name', 'LIKE', sprintf('%%%s%%', $query)); } - $search->orderBy('order', 'DESC') + $search->orderBy('order', 'ASC') ->orderBy('name', 'ASC')->where('active', 1); return $search->get();