Class: Kaui::CreditsController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/credits_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_ability, #current_user, #options_for_klient

Instance Method Details

#createObject



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

#newObject



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]
   = 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)
       = @invoice.
      amount     ||= @invoice.balance
      currency   = @invoice.currency
    rescue => e
      flash.now[:error] = "Unable to retrieve invoice: #{as_string(e)}"
    end
  end

  # TODO Specifying a custom currency is not supported yet
  @credit = Kaui::Credit.new(:invoice_id    => invoice_id,
                             :account_id    => ,
                             :credit_amount => amount)
end