Class: Kaui::PaymentsController

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

Instance Method Summary collapse

Methods inherited from EngineController

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

Instance Method Details

#createObject



61
62
63
64
65
# File 'app/controllers/kaui/payments_controller.rb', line 61

def create
  payment = Kaui::InvoicePayment.new(invoice_payment_params)
  payment = payment.create(params[:external] == '1', current_user.kb_username, params[:reason], params[:comment], options_for_klient)
  redirect_to kaui_engine.(payment., payment.target_invoice_id), :notice => 'Payment created'
end

#indexObject



3
4
5
# File 'app/controllers/kaui/payments_controller.rb', line 3

def index
  @search_query = params[:account_id]
end

#newObject



51
52
53
54
55
56
57
58
59
# File 'app/controllers/kaui/payments_controller.rb', line 51

def new
  fetch_invoice = lambda { @invoice = Kaui::Invoice.find_by_id_or_number(params.require(:invoice_id), true, 'NONE', options_for_klient) }
   = lambda { @account = Kaui::Account.find_by_id(params.require(:account_id), false, false, options_for_klient) }
  fetch_payment_methods = lambda { @payment_methods = Kaui::PaymentMethod.(params.require(:account_id), false, options_for_klient) }

  run_in_parallel fetch_invoice, , fetch_payment_methods

  @payment = Kaui::InvoicePayment.new('accountId' => @account., 'targetInvoiceId' => @invoice.invoice_id, 'purchasedAmount' => @invoice.balance)
end

#paginationObject



7
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
45
46
47
48
49
# File 'app/controllers/kaui/payments_controller.rb', line 7

def pagination
  searcher = lambda do |search_key, offset, limit|
     = Kaui::Account::find_by_id_or_key(search_key, false, false, options_for_klient) rescue nil
    if .nil?
      payments = Kaui::Payment.list_or_search(search_key, offset, limit, options_for_klient)
    else
      payments = .payments(options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) }
    end

    payments.each do |payment|
      created_date = nil
      payment.transactions.each do |transaction|
        transaction_date = Date.parse(transaction.effective_date)
        if created_date.nil? or transaction_date < created_date
          created_date = transaction_date
        end
      end
      payment.payment_date = created_date
    end

    payments
  end

  data_extractor = lambda do |payment, column|
    [
        payment.payment_number.to_i,
        payment.payment_date,
        payment.paid_amount_to_money,
        payment.returned_amount_to_money
    ][column]
  end

  formatter = lambda do |payment|
    [
        view_context.link_to(payment.payment_number, view_context.url_for(:controller => :payments, :action => :show, :account_id => payment., :id => payment.payment_id)),
        view_context.format_date(payment.payment_date),
        view_context.humanized_money_with_symbol(payment.paid_amount_to_money),
        view_context.humanized_money_with_symbol(payment.returned_amount_to_money)
    ]
  end

  paginate searcher, data_extractor, formatter
end

#restful_showObject



77
78
79
80
# File 'app/controllers/kaui/payments_controller.rb', line 77

def restful_show
  payment = Kaui::InvoicePayment.find_by_id(params.require(:id), false, options_for_klient)
  redirect_to (payment., payment.payment_id)
end

#showObject



67
68
69
70
71
72
73
74
75
# File 'app/controllers/kaui/payments_controller.rb', line 67

def show
  @payment = Kaui::InvoicePayment.find_by_id(params.require(:id), true, options_for_klient)

   = lambda { @account = Kaui::Account.find_by_id(@payment., false, false, options_for_klient) }
  # The payment method may have been deleted
  fetch_payment_method = lambda { @payment_method = Kaui::PaymentMethod.find_by_id(@payment.payment_method_id, true, options_for_klient) rescue nil }

  run_in_parallel , fetch_payment_method
end