Class: Kaui::PaymentsController

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

Instance Method Summary collapse

Methods inherited from EngineController

#current_ability, #current_user, #options_for_klient

Instance Method Details

#createObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/kaui/payments_controller.rb', line 74

def create
  payment = Kaui::InvoicePayment.new(params[:invoice_payment])

  begin
    payment        = payment.create(params[:external] == '1', current_user.kb_username, params[:reason], params[:comment], options_for_klient)
    flash[:notice] = 'Payment created'
  rescue => e
    flash[:error] = "Error while creating a new payment: #{as_string(e)}"
    render :action => :index and return
  end

  redirect_to kaui_engine.(:id => payment.)
end

#indexObject



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

def index
end

#newObject



41
42
43
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
# File 'app/controllers/kaui/payments_controller.rb', line 41

def new
   = params[:account_id]
  invoice_id = params[:invoice_id]
  amount     = 0

  if invoice_id.nil?
    flash[:error] = 'No invoice id specified'
    render :action => :index and return
  end

  if .nil?
    flash[:error] = 'No account id specified'
    render :action => :index and return
  end

  begin
    @invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
    amount   = @invoice.balance
  rescue => e
    flash[:error] = "Unable to retrieve invoice: #{as_string(e)}"
    render :action => :index and return
  end

  begin
    @account = Kaui::Account.find_by_id(, false, false, options_for_klient)
  rescue => e
    flash[:error] = "Unable to retrieve account: #{as_string(e)}"
    render :action => :index and return
  end

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

#paginationObject



6
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
# File 'app/controllers/kaui/payments_controller.rb', line 6

def pagination
  json = {:sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => []}

  search_key = params[:sSearch]
  if search_key.present?
    payments = Kaui::Payment::find_in_batches_by_search_key(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
  else
    payments = Kaui::Payment::find_in_batches(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
  end
  json[:iTotalDisplayRecords] = payments.pagination_total_nb_records
  json[:iTotalRecords]        = payments.pagination_max_nb_records

  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

    json[:aaData] << [
        view_context.link_to(view_context.truncate_uuid(payment.), view_context.url_for(:controller => :accounts, :action => :show, :id => payment.)),
        payment.payment_number,
        view_context.format_date(created_date),
        view_context.humanized_money_with_symbol(payment.paid_amount_to_money),
        view_context.humanized_money_with_symbol(payment.returned_amount_to_money)
    ]
  end

  respond_to do |format|
    format.json { render :json => json }
  end
end

#showObject



88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/kaui/payments_controller.rb', line 88

def show
  begin
    @payments        = [Kaui::InvoicePayment.find_by_id(params[:id], true, options_for_klient)]
    @account         = Kaui::Account.find_by_id(@payments.first., false, false, options_for_klient)
    @payment_methods = Kaui::PaymentMethod.payment_methods_for_payments(@payments, options_for_klient)
  rescue => e
    flash.now[:error] = "Error while looking up payment: #{as_string(e)}"
    render :action => :index
  end
end