Class: Admin::InvoicesController
Class Method Summary
collapse
Instance Method Summary
collapse
append_features
append_features, #controller_url, #define_layout_variables, #index_with_admin_helper
#controller_id, #define_application_layout_variables, #h_money, #money_for_input
Class Method Details
.active_scaffold_controller_for(klass) ⇒ Object
64
65
66
|
# File 'app/controllers/admin/invoices_controller.rb', line 64
def self.active_scaffold_controller_for(klass)
(klass == Activity) ? Admin::ActivitiesWithPricesController : super
end
|
Instance Method Details
#after_update_save(invoice) ⇒ Object
Also known as:
after_create_save
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
|
# File 'app/controllers/admin/invoices_controller.rb', line 97
def after_update_save(invoice)
super
if successful? and invoice.is_published and (@invoice_new_record || @invoice_changes.include?(:is_published))
invoice.client.recommend_payment_assignments_for(invoice.amount).each do |ip|
InvoicePayment.quick_create! invoice.id, ip.payment_id, ip.amount
end
define_invoice invoice
attachments = [
{
:content_type => "application/pdf",
:body => render_to_string(:action => 'download', :layout => false),
:disposition => "attachment",
:filename => @rails_pdf_name
}
]
mail = Notifier.deliver_invoice_available @invoice, @client, @footer_text, attachments
dest_addresses = []
dest_addresses += mail.to_addrs if mail.to_addrs
dest_addresses += mail.cc_addrs if mail.cc_addrs
dest_addresses.collect!{|t_a| '%s <%s>' % [t_a.name, t_a.address] }
flash[:warning] = "Invoice e-mailed to : %s" % dest_addresses.join(',')
end
end
|
#before_update_save(invoice) ⇒ Object
Also known as:
before_create_save
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/admin/invoices_controller.rb', line 76
def before_update_save(invoice)
super
invoice.activities = invoice.recommended_activities if (
invoice.new_record? or (
!invoice.is_published and
(invoice.issued_on_changed? || (@activity_type_ids_before != invoice.activity_type_ids))
)
)
invoice.payment_assignments.clear if !invoice.is_published and invoice.is_published_changed?
@invoice_changes = invoice.changes.keys.collect(&:to_sym)
@invoice_new_record = invoice.new_record?
end
|
#download ⇒ Object
133
134
135
136
137
138
|
# File 'app/controllers/admin/invoices_controller.rb', line 133
def download
define_invoice Invoice.find(params[:id].to_i, :include => [:client])
rescue
render :file => RAILS_ROOT+'/public/500.html', :status => 500
end
|
#update_record_from_params(*args) ⇒ Object
We ovverride the defaut behavior here only so that we can use this method as a hook to detyermine the invoice.activity_type_ids Before they’ve been updated by the form. We reference @activity_type_ids_before in before_update_save to determine whether we need to update the activity associations for this invoice.
71
72
73
74
|
# File 'app/controllers/admin/invoices_controller.rb', line 71
def update_record_from_params(*args)
@activity_type_ids_before = @record.activity_type_ids.dup if @record
super
end
|