Class: Kaui::PaymentsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::PaymentsController
- Defined in:
- app/controllers/kaui/payments_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #pagination ⇒ Object
- #restful_show ⇒ Object
- #show ⇒ Object
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
#create ⇒ Object
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], ) redirect_to kaui_engine.account_invoice_path(payment.account_id, payment.target_invoice_id), :notice => 'Payment created' end |
#index ⇒ Object
3 4 5 |
# File 'app/controllers/kaui/payments_controller.rb', line 3 def index @search_query = params[:account_id] end |
#new ⇒ Object
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', ) } fetch_account = lambda { @account = Kaui::Account.find_by_id(params.require(:account_id), false, false, ) } fetch_payment_methods = lambda { @payment_methods = Kaui::PaymentMethod.find_all_by_account_id(params.require(:account_id), false, ) } run_in_parallel fetch_invoice, fetch_account, fetch_payment_methods @payment = Kaui::InvoicePayment.new('accountId' => @account.account_id, 'targetInvoiceId' => @invoice.invoice_id, 'purchasedAmount' => @invoice.balance) end |
#pagination ⇒ Object
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| account = Kaui::Account::find_by_id_or_key(search_key, false, false, ) rescue nil if account.nil? payments = Kaui::Payment.list_or_search(search_key, offset, limit, ) else payments = account.payments().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.account_id, :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_show ⇒ Object
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, ) redirect_to account_payment_path(payment.account_id, payment.payment_id) end |
#show ⇒ Object
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, ) fetch_account = lambda { @account = Kaui::Account.find_by_id(@payment.account_id, false, false, ) } # The payment method may have been deleted fetch_payment_method = lambda { @payment_method = Kaui::PaymentMethod.find_by_id(@payment.payment_method_id, true, ) rescue nil } run_in_parallel fetch_account, fetch_payment_method end |