Class: Kaui::InvoicesController

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

Instance Method Summary collapse

Methods inherited from EngineController

#current_user

Methods included from ErrorHelper

#as_string

Instance Method Details

#indexObject



2
3
4
5
6
# File 'app/controllers/kaui/invoices_controller.rb', line 2

def index
  if params[:invoice_id].present?
    redirect_to kaui_engine.invoice_path(params[:invoice_id])
  end
end

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/kaui/invoices_controller.rb', line 8

def show
  @invoice_id = params[:id]
  if @invoice_id.present?
    begin
      @invoice = Kaui::KillbillHelper.get_invoice(@invoice_id)
      if @invoice.present?
        @account = Kaui::KillbillHelper.(@invoice.)
        @payments = Kaui::KillbillHelper.get_payments(@invoice_id)

        @subscriptions = {}
        @bundles = {}
        @cba_items_not_deleteable = []
        if @invoice.items.present?
          @invoice.items.each do |item|
            @cba_items_not_deleteable << item.linked_invoice_item_id if item.description =~ /account credit/ and item.amount < 0

            unless item.subscription_id.nil? || @subscriptions.has_key?(item.subscription_id)
              @subscriptions[item.subscription_id] = Kaui::KillbillHelper.get_subscription(item.subscription_id)
            end
            unless item.bundle_id.nil? || @bundles.has_key?(item.bundle_id)
              @bundles[item.bundle_id] = Kaui::KillbillHelper.get_bundle(item.bundle_id)
            end
        end
        else
          flash[:error] = "Invoice items for #{@invoice_id} not found"
        end
      else
        flash[:error] = "Invoice #{@invoice_id} not found"
        render :action => :index
      end
    rescue => e
      flash[:error] = "Error while getting information for invoice #{@invoice_id}: #{as_string(e)}"
    end
  else
    flash[:error] = "No id given"
  end
end

#show_htmlObject



46
47
48
49
50
51
52
# File 'app/controllers/kaui/invoices_controller.rb', line 46

def show_html
  begin
    render :text => Kaui::KillbillHelper.get_invoice_html(params[:id])
  rescue => e
    flash[:error] = "Error rendering invoice html #{invoice_id}: #{as_string(e)}"
  end
end