mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
added action
This commit is contained in:
parent
d25847571f
commit
43518b5832
3 changed files with 26 additions and 6 deletions
|
@ -16,12 +16,12 @@ module Admin
|
|||
|
||||
def update
|
||||
if @account.valid?
|
||||
@sum = params[:account][:balance].to_f - @account.balance
|
||||
action = Actions::AccountActivityCreate.new(@account, @sum, params[:description],
|
||||
AccountActivity::UPDATE_CREDIT)
|
||||
redirect_to admin_accounts_path, notice: t('.updated') if action.call
|
||||
action = Actions::AccountActivityCreate.new(@account, params[:account][:balance],
|
||||
params[:description], AccountActivity::UPDATE_CREDIT)
|
||||
redirect_to admin_accounts_path, notice: t('.updated') and return if action.call
|
||||
end
|
||||
|
||||
flash[:alert] = t('invalid_balance')
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
|
|
|
@ -1,17 +1,35 @@
|
|||
module Actions
|
||||
class AccountActivityCreate
|
||||
def initialize(account, sum, description, type)
|
||||
def initialize(account, new_balance, description, type)
|
||||
@account = account
|
||||
@sum = sum
|
||||
@new_balance = new_balance
|
||||
@description = description
|
||||
@type = type
|
||||
end
|
||||
|
||||
def call
|
||||
validate_new_balance
|
||||
return false if @error
|
||||
|
||||
calc_sum
|
||||
create_activity
|
||||
commit
|
||||
end
|
||||
|
||||
def calc_sum
|
||||
@sum = @new_balance.to_f - @account.balance
|
||||
end
|
||||
|
||||
def validate_new_balance
|
||||
return if @new_balance.blank?
|
||||
|
||||
begin
|
||||
!Float(@new_balance).nil?
|
||||
rescue StandardError
|
||||
@error = true
|
||||
end
|
||||
end
|
||||
|
||||
def create_activity
|
||||
@activity = AccountActivity.new(account: @account,
|
||||
sum: @sum,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
en:
|
||||
edit_balance: Edit balance
|
||||
invalid_balance: The balance must be a number
|
||||
|
||||
admin:
|
||||
accounts:
|
||||
index:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue