Class: Admin::InvoicesController

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExtensibleObjectHelper

append_features

Methods included from AdminLayoutHelper

append_features, #controller_url, #define_layout_variables, #index_with_admin_helper

Methods included from ApplicationHelper

#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



68
69
70
71
72
73
74
75
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 68

def after_update_save(invoice)
  super
  
  if successful? and invoice.is_published # TODO: And only if is_published has changed?...
    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

#downloadObject



97
98
99
100
101
102
# File 'app/controllers/admin/invoices_controller.rb', line 97

def download
  define_invoice Invoice.find(params[:id].to_i, :include => [:client])
  
  rescue 
    render :file => RAILS_ROOT+'/public/500.html', :status => 500
end