Class: Kaui::InvoiceItemsController

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

Constant Summary

Constants included from EngineControllerUtil

EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD

Instance Method Summary collapse

Methods inherited from EngineController

#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user

Instance Method Details

#destroyObject


29
30
31
32
33
34
35
36
# File 'app/controllers/kaui/invoice_items_controller.rb', line 29

def destroy
  invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params.require(:id),
                                       :invoice_id => params.require(:invoice_id),
                                       :account_id => params.require(:account_id))

  invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
  redirect_to kaui_engine.(invoice_item., invoice_item.invoice_id), :notice => 'CBA item was successfully deleted'
end

#editObject


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/kaui/invoice_items_controller.rb', line 3

def edit
  invoice_item_id = params.require(:id)
  invoice_id = params.require(:invoice_id)

  # See https://github.com/killbill/killbill/issues/7
  invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
  @invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }

  if @invoice_item.nil?
    flash[:error] = "Unable to find invoice item #{invoice_item_id}"
    redirect_to (params.require(:account_id), invoice_id)
  end
end

#updateObject


17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/kaui/invoice_items_controller.rb', line 17

def update
  @invoice_item = Kaui::InvoiceItem.new(params.require(:invoice_item))

  begin
    invoice = @invoice_item.update(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
    redirect_to kaui_engine.(invoice., invoice.invoice_id), :notice => 'Adjustment item was successfully created'
  rescue => e
    flash.now[:error] = "Error while adjusting invoice item: #{as_string(e)}"
    render :action => :edit
  end
end

#update_tagsObject


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/kaui/invoice_items_controller.rb', line 38

def update_tags
  @invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params.require(:id))
  invoice_id = params.require(:invoice_id)
   = params.require(:account_id)
  @invoice_item. = 

  tags = []
  params.each do |tag|
    tag_info = tag.split('_')
    next if tag_info.size != 2 or tag_info[0] != 'tag'
    tags << tag_info[1]
  end

  @invoice_item.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
  redirect_to (, invoice_id), :notice => 'Invoice Item tags successfully set'
end