Class: Kaui::CreditsController
Instance Method Summary
collapse
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient
Instance Method Details
#create ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/kaui/credits_controller.rb', line 26
def create
@credit = Kaui::Credit.new(params[:credit].delete_if { |key, value| value.blank? })
begin
@credit = @credit.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
redirect_to kaui_engine.invoice_path(:id => @credit.invoice_id), :notice => 'Credit was successfully created'
rescue => e
flash.now[:error] = "Error while creating a credit: #{as_string(e)}"
render :action => :new
end
end
|
#new ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/kaui/credits_controller.rb', line 3
def new
invoice_id = params[:invoice_id]
account_id = params[:account_id]
amount = params[:amount]
currency = params[:currency] || 'USD'
if invoice_id.present?
begin
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
account_id = @invoice.account_id
amount ||= @invoice.balance
currency = @invoice.currency
rescue => e
flash.now[:error] = "Unable to retrieve invoice: #{as_string(e)}"
end
end
@credit = Kaui::Credit.new(:invoice_id => invoice_id,
:account_id => account_id,
:credit_amount => amount)
end
|