Class: Admin::PaymentsController

Inherits:
ApplicationController
  • Object
show all
Includes:
AdminLayoutHelper, ApplicationHelper, ExtensibleObjectHelper
Defined in:
app/controllers/admin/payments_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#controller_id, #define_application_layout_variables, #h_money, #money_for_input

Methods included from ExtensibleObjectHelper

append_features

Methods included from AdminLayoutHelper

append_features, #controller_url, #define_layout_variables, #index_with_admin_helper

Instance Method Details

#before_update_save(payment) ⇒ Object Also known as: before_create_save



43
44
45
# File 'app/controllers/admin/payments_controller.rb', line 43

def before_update_save(payment)      
  payment.invoice_assignments = payment.client.recommend_invoice_assignments_for payment.amount
end

#on_invoice_assignment_observationObject



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
77
78
79
# File 'app/controllers/admin/payments_controller.rb', line 50

def on_invoice_assignment_observation
  record_id = (/^[\d]+$/.match(params[:record_id])) ? params[:record_id].to_i : nil
  
  # TODO: if amount is no integer - highlight...
  
  render(:update) do |page|
    
    #TODO: We need to load the pre-existing payment here...
    
    # Let's do some (minimal) Amount input handling
    unless params[:amount].empty?
      begin
        record_amount_js_id = "record_amount_#{record_id}"
        
        new_amount = Money.new($1.to_f*100) if /^[ ]*([\d]+\.[\d]{0,2}|[\d]+)[ ]*$/.match params[:amount]
        
        raise StandardError unless new_amount
        
        page[record_amount_js_id].value = new_amount.to_s
        page.replace_html "record_unallocated_amount_#{record_id}", :text => h_money(new_amount)
      rescue
        page[record_amount_js_id].value = ''
        page[record_amount_js_id].focus
        page.visual_effect :highlight, record_amount_js_id, :duration => 3, :startcolor => "#FF0000"
      end
    end
    
    # TODO: Generate the invoices div...
  end
end