Class: Kaui::PaymentsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::PaymentsController
- 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
Instance Method Details
#create ⇒ Object
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], ) 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.account_timeline_path(:id => payment.account_id) end |
#index ⇒ Object
3 4 |
# File 'app/controllers/kaui/payments_controller.rb', line 3 def index end |
#new ⇒ Object
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 account_id = 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 account_id.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', ) 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(account_id, false, false, ) rescue => e flash[:error] = "Unable to retrieve account: #{as_string(e)}" render :action => :index and return end @payment = Kaui::InvoicePayment.new('accountId' => account_id, 'targetInvoiceId' => invoice_id, 'purchasedAmount' => amount) end |
#pagination ⇒ Object
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, ) else payments = Kaui::Payment::find_in_batches(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, ) 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.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => payment.account_id)), 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 |
#show ⇒ Object
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, )] @account = Kaui::Account.find_by_id(@payments.first.account_id, false, false, ) @payment_methods = Kaui::PaymentMethod.payment_methods_for_payments(@payments, ) rescue => e flash.now[:error] = "Error while looking up payment: #{as_string(e)}" render :action => :index end end |