Module: Admin::PaymentsHelper
- Includes:
- IsActiveColumnHelper
- Defined in:
- app/helpers/admin/payments_helper.rb
Instance Method Summary collapse
-
#amount_field_id ⇒ Object
This keeps our rjs files a little DRY-er.
-
#amount_unallocated_field_id ⇒ Object
This keeps our rjs files a little DRY-er.
- #payment_amount_column(record) ⇒ Object
- #payment_amount_form_column(record, options) ⇒ Object
- #payment_amount_unallocated_form_column(record, options) ⇒ Object
- #payment_assignments_column(record) ⇒ Object
- #payment_assignments_form_column(record, options = nil) ⇒ Object
- #payment_client_form_column(record, options) ⇒ Object
- #payment_invoice_assignments_column(record) ⇒ Object
- #payment_is_allocated_column(record) ⇒ Object
- #payment_paid_on_form_column(record, options) ⇒ Object
- #payment_payment_method_form_column(record, options) ⇒ Object
- #payment_payment_method_identifier_form_column(record, options) ⇒ Object
-
#submit_tag(*args) ⇒ Object
All this craziness exists to show a modal dialog asking the user to confirm any payment that isn’t fully allocated.
Instance Method Details
#amount_field_id ⇒ Object
This keeps our rjs files a little DRY-er
148 149 150 |
# File 'app/helpers/admin/payments_helper.rb', line 148 def amount_field_id "record_amount_%s" % @record.id end |
#amount_unallocated_field_id ⇒ Object
This keeps our rjs files a little DRY-er
153 154 155 |
# File 'app/helpers/admin/payments_helper.rb', line 153 def amount_unallocated_field_id "record_amount_unallocated_%s" % @record.id end |
#payment_amount_column(record) ⇒ Object
8 9 10 |
# File 'app/helpers/admin/payments_helper.rb', line 8 def payment_amount_column(record) h_money record.amount end |
#payment_amount_form_column(record, options) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/admin/payments_helper.rb', line 31 def payment_amount_form_column(record, ) (record.new_record?) ? text_field_tag( [:name], record.amount, ('amount').merge( {:size => 8, :class=>'text-input' } ) ) : span_field(h_money(record.amount)) end |
#payment_amount_unallocated_form_column(record, options) ⇒ Object
64 65 66 67 68 69 |
# File 'app/helpers/admin/payments_helper.rb', line 64 def payment_amount_unallocated_form_column(record, ) span_field( (record.amount) ? h_money(record.amount_unallocated) : t(:enter_a_payment_amount), :id => ('record_amount_unallocated_%s' % record.id) ) end |
#payment_assignments_column(record) ⇒ Object
71 72 73 74 75 |
# File 'app/helpers/admin/payments_helper.rb', line 71 def payment_assignments_column(record) record.invoice_assignments.collect{|ia| '%s to Invoice %d' % [ia.amount.format, ia.invoice.id ] }.join ', ' end |
#payment_assignments_form_column(record, options = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/helpers/admin/payments_helper.rb', line 83 def payment_assignments_form_column(record, = nil) content_tag(:div, :id => 'record_invoice_assignment_%s' % record.id ) do if record.client # First, we show the easy, upaid invoices. These should always be visible: show_invoices = record.client.unpaid_invoices.to_a # Now - we add any additional invoices that might be around from existing assignments (the case for an edit...) record.invoice_assignments.each do |inv_asgn| show_invoices << inv_asgn.invoice unless show_invoices.find{|show_inv| show_inv.id == inv_asgn.invoice_id} end # And now let's sort everything by the id show_invoices = show_invoices.sort!{|a,b| a.id <=> b.id } if show_invoices.length > 0 assignment_observation = @active_scaffold_observations.find{|o| o[:action] == :on_assignment_observation}.dup assignment_observation[:fields] += show_invoices.collect{ |inv| 'invoice_assignments_%d_amount' % inv.id } # This is a look-up map that will tell us the field values to use below: inv_assignments = record.invoice_assignments.inject({}){|ret,ia| ret.merge({ia.invoice_id => ia.amount}) } content_tag(:ul, :class => 'invoice_assignment_inputs') do show_invoices.collect{|inv| col_name = 'invoice_assignments_%d_amount' % inv.id assignment_amount = nil assignment_amount = (inv_assignments.has_key? inv.id) ? inv_assignments[inv.id] : '0.00' if record.amount '<li>%s%s %s</li>' % [ text_field_tag( 'record[invoice_assignments][%d][amount]' % inv.id, assignment_amount, :size => 8, :class => 'text-input', :id => (col_name)[:id] ), active_scaffold_observe_field(col_name,assignment_observation), t( :invoice_outstanding_details, :inv_id => inv.id, :issued_on => h(inv.issued_on.strftime('%m/%d/%y')), :amount_outstanding => span_field( h_money(invoice_amount_outstanding_for(inv, record.id,inv_assignments[inv.id])), :id => ('%s_outstanding' % (col_name)[:id]) ) ) ] }.join end else span_field t(:no_outstanding_invoices_for_account) end else span_field t(:choose_a_client) end end end |
#payment_client_form_column(record, options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/admin/payments_helper.rb', line 12 def payment_client_form_column(record, ) (record.new_record?) ? select_tag( "record[client][id]", ( [["- select -", nil]]+Client.find(:all, :order => 'company_name ASC').collect{|c| [c.company_name, c.id] }, record.client_id ), ('client') ) : span_field(h(record.client.company_name)) end |
#payment_invoice_assignments_column(record) ⇒ Object
77 78 79 80 81 |
# File 'app/helpers/admin/payments_helper.rb', line 77 def payment_invoice_assignments_column(record) record.invoice_assignments.collect{ |asgn| '%s to (Invoice %d)' % [asgn.amount.format, asgn.invoice_id ] }.join ', ' end |
#payment_is_allocated_column(record) ⇒ Object
4 5 6 |
# File 'app/helpers/admin/payments_helper.rb', line 4 def payment_is_allocated_column(record) record.is_allocated? ? 'Yes' : 'No' end |
#payment_paid_on_form_column(record, options) ⇒ Object
25 26 27 28 29 |
# File 'app/helpers/admin/payments_helper.rb', line 25 def payment_paid_on_form_column(record, ) (record.new_record?) ? input(:record, :paid_on, ('paid_on')) : span_field(h(record.paid_on.strftime('%m/%d/%y %I:%M %p'))) end |
#payment_payment_method_form_column(record, options) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/admin/payments_helper.rb', line 41 def payment_payment_method_form_column(record, ) (record.new_record?) ? select_tag( "record[payment_method][id]", ( [["- select -", nil]]+PaymentMethod.find(:all, :order => 'name ASC').collect{|pm| [pm.name, pm.id] }, record.payment_method_id ), ('payment_method') ) : span_field(h(record.payment_method.name)) end |
#payment_payment_method_identifier_form_column(record, options) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/admin/payments_helper.rb', line 54 def payment_payment_method_identifier_form_column(record, ) (record.new_record?) ? text_field_tag( [:name], record.payment_method_identifier, ('payment_method_identifier').merge( {:size => 30, :class=>'text-input' } ) )+span_field(t(:payment_method_identifier_description), :class => "description") : span_field(h(record.payment_method_identifier)) end |
#submit_tag(*args) ⇒ Object
All this craziness exists to show a modal dialog asking the user to confirm any payment that isn’t fully allocated.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/helpers/admin/payments_helper.rb', line 158 def submit_tag(*args) if (/\A(?:#{as_(:update)}|#{as_(:create)})\Z/.match args[0]) action = args[0] == as_(:update) ? :update : :create ( args[0], "amt_unalloc = $$('#record_amount_unallocated_%s span'); if (amt_unalloc.length > 0 && amt_unalloc.first().innerHTML != '%s') { show_modal_after_close(%s,%s); } else { $('%s').onsubmit(); }" % [ @record.id, Money.new(0).format, render(:file => 'admin/payments/commit_payment_warning.html.erb', :layout => false, :locals => {:action => action}).to_json, {:title => 'Are you sure you wish to save?', :width => 600}.to_json, element_form_id(:action => action) ], args[1] ) else super(*args) end end |