This commit is contained in:
James Cole
2020-01-08 05:48:45 +01:00
parent 6019638388
commit 2485f74302
3 changed files with 24 additions and 23 deletions

View File

@@ -76,7 +76,7 @@ class PiggyBankFormRequest extends Request
$rules = [ $rules = [
'name' => $nameRule, 'name' => $nameRule,
'account_id' => 'required|belongsToUser:accounts', 'account_id' => 'required|belongsToUser:accounts',
'targetamount' => 'required|numeric|more:0|max:1000000000', 'targetamount' => 'required|numeric|gte:0.01|max:1000000000',
'startdate' => 'date', 'startdate' => 'date',
'targetdate' => 'date|nullable', 'targetdate' => 'date|nullable',
'order' => 'integer|min:1', 'order' => 'integer|min:1',

View File

@@ -77,12 +77,7 @@ class PiggyBankTransformer extends AbstractTransformer
$this->piggyRepos->setUser($account->user); $this->piggyRepos->setUser($account->user);
// get currency from account, or use default. // get currency from account, or use default.
// TODO we can use getAccountCurrency() instead $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
$currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id');
$currency = $this->currencyRepos->findNull($currencyId);
if (null === $currency) {
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
}
// note // note
$notes = $this->piggyRepos->getNoteText($piggyBank); $notes = $this->piggyRepos->getNoteText($piggyBank);
@@ -99,6 +94,7 @@ class PiggyBankTransformer extends AbstractTransformer
// target and percentage: // target and percentage:
$targetAmount = round($piggyBank->targetamount, $currency->decimal_places); $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); $percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmount / $targetAmount * 100 : 0);
$data = [ $data = [
'id' => (int)$piggyBank->id, 'id' => (int)$piggyBank->id,

View File

@@ -57,7 +57,7 @@ return [
'at_least_one_action' => 'Rule must have at least one action.', 'at_least_one_action' => 'Rule must have at least one action.',
'base64' => 'This is not valid base64 encoded data.', 'base64' => 'This is not valid base64 encoded data.',
'model_id_invalid' => 'The given ID seems invalid for this model.', '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', 'less' => ':attribute must be less than 10,000,000',
'active_url' => 'The :attribute is not a valid URL.', 'active_url' => 'The :attribute is not a valid URL.',
'after' => 'The :attribute must be a date after :date.', 'after' => 'The :attribute must be a date after :date.',
@@ -121,19 +121,19 @@ return [
'string' => 'The :attribute must be a string.', 'string' => 'The :attribute must be a string.',
'url' => 'The :attribute format is invalid.', 'url' => 'The :attribute format is invalid.',
'timezone' => 'The :attribute must be a valid zone.', 'timezone' => 'The :attribute must be a valid zone.',
'2fa_code' => 'The :attribute field is invalid.', '2fa_code' => 'The :attribute field is invalid.',
'dimensions' => 'The :attribute has invalid image dimensions.', 'dimensions' => 'The :attribute has invalid image dimensions.',
'distinct' => 'The :attribute field has a duplicate value.', 'distinct' => 'The :attribute field has a duplicate value.',
'file' => 'The :attribute must be a file.', 'file' => 'The :attribute must be a file.',
'in_array' => 'The :attribute field does not exist in :other.', 'in_array' => 'The :attribute field does not exist in :other.',
'present' => 'The :attribute field must be present.', 'present' => 'The :attribute field must be present.',
'amount_zero' => 'The total amount cannot be zero.', 'amount_zero' => 'The total amount cannot be zero.',
'current_target_amount' => 'The current amount must be less than the target amount.', '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.', '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', '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_type' => 'Invalid repetition type for recurring transactions.',
'valid_recurrence_rep_moment' => 'Invalid repetition moment for this type of repetition.', 'valid_recurrence_rep_moment' => 'Invalid repetition moment for this type of repetition.',
'invalid_account_info' => 'Invalid account information.', 'invalid_account_info' => 'Invalid account information.',
'attributes' => [ 'attributes' => [
'email' => 'email address', 'email' => 'email address',
'description' => 'description', '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_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_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_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_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".', '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_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".', '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.', '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.',
]; ];