Class: Kaui::InvoicesController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::InvoicesController
- Defined in:
- app/controllers/kaui/invoices_controller.rb
Constant Summary
Constants included from EngineControllerUtil
EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD
Instance Method Summary collapse
- #commit_invoice ⇒ Object
- #index ⇒ Object
- #pagination ⇒ Object
- #restful_show ⇒ Object
- #show ⇒ Object
- #show_html ⇒ Object
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
#commit_invoice ⇒ Object
87 88 89 90 91 |
# File 'app/controllers/kaui/invoices_controller.rb', line 87 def commit_invoice invoice = KillBillClient::Model::Invoice.find_by_id(params.require(:id), false, 'NONE', ) invoice.commit(current_user.kb_username, params[:reason], params[:comment], ) redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id), :notice => 'Invoice successfully committed' end |
#index ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/controllers/kaui/invoices_controller.rb', line 3 def index @search_query = params[:account_id] @ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc') @offset = params[:offset] || 0 @limit = params[:limit] || 50 @max_nb_records = @search_query.blank? ? Kaui::Invoice.list_or_search(nil, 0, 0, ).pagination_max_nb_records : 0 end |
#pagination ⇒ Object
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 |
# File 'app/controllers/kaui/invoices_controller.rb', line 13 def pagination searcher = lambda do |search_key, offset, limit| account = Kaui::Account::find_by_id_or_key(search_key, false, false, ) rescue nil if account.nil? Kaui::Invoice.list_or_search(search_key, offset, limit, ) else account.invoices(true, ).map! { |invoice| Kaui::Invoice.build_from_raw_invoice(invoice) } end end data_extractor = lambda do |invoice, column| [ invoice.invoice_number.to_i, invoice.invoice_date, invoice.amount, invoice.balance ][column] end formatter = lambda do |invoice| [ view_context.link_to(invoice.invoice_number, view_context.url_for(:controller => :invoices, :action => :show, :account_id => invoice.account_id, :id => invoice.invoice_id)), invoice.invoice_date, view_context.humanized_money_with_symbol(invoice.amount_to_money), view_context.humanized_money_with_symbol(invoice.balance_to_money) ] end paginate searcher, data_extractor, formatter end |
#restful_show ⇒ Object
78 79 80 81 |
# File 'app/controllers/kaui/invoices_controller.rb', line 78 def restful_show invoice = Kaui::Invoice.find_by_id(params.require(:id), false, 'NONE', ) redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) end |
#show ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/kaui/invoices_controller.rb', line 44 def show # Go to the database once = @invoice = Kaui::Invoice.find_by_id(params.require(:id), true, 'FULL', ) fetch_payments = promise { @invoice.payments(true, true, 'FULL', ).map { |payment| Kaui::InvoicePayment.build_from_raw_payment(payment) } } fetch_pms = fetch_payments.then { |payments| Kaui::PaymentMethod.payment_methods_for_payments(payments, ) } fetch_invoice_fields = promise { @invoice.custom_fields('NONE', ).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } } fetch_payment_fields = promise { all_payment_fields = @account.all_custom_fields(:PAYMENT, 'NONE', ) all_payment_fields.inject({}) { |hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh } } = promise { Kaui::TagDefinition.all_for_invoice_item() } = promise { = @account.(:INVOICE_ITEM, false, 'NONE', ) .inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh} } fetch_custom_fields_per_invoice_item = promise { custom_fields_per_invoice_item = @account.all_custom_fields(:INVOICE_ITEM, 'NONE', ) custom_fields_per_invoice_item.inject({}) { |hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh } } @payments = wait(fetch_payments) @payment_methods = wait(fetch_pms) @custom_fields = wait(fetch_invoice_fields) @payment_custom_fields = wait(fetch_payment_fields) @custom_fields_per_invoice_item = wait(fetch_custom_fields_per_invoice_item) @tags_per_invoice_item = wait() @available_invoice_item_tags = wait() end |