class User < ActiveRecord::Base
has_many :meetings, :foreign_key=>:assigned_user_id
def reward
Reward.find(:first,
:conditions=>['meeting_count < ? ',
self.meetings.count],
:order=>'meeting_count DESC',
:limit=>1)
end
end
class Meeting < ActiveRecord::Base
belongs_to :users, :foreign_key=>:assigned_user_id
end
class Reward < ActiveRecord::Base
end
html = '
Salesperson Reward Report
Name |
Meetings |
Reward |
|---|
'
users = User.find(:all,
:conditions=>['not is_admin'],
CHAPTER 8 n CREATING SALES PERFORMANCE REPORTS WITH SUGARCRM 159
:order=>'last_name ASC, first_name ASC'
)
html = Erubis::Eruby.new(File.read('rewards_report_template.rhtml')
).evaluate({ :users=>users })
open('|"'+path_to_html2ps+'"', 'wb+') do |process_handle|
process_handle.puts html
process_handle.close_write
ps_source = process_handle.read
end
pdf_source = ''
open('|"' + path_to_ps2pdf +'" - -', 'wb+') do |process_handle|
process_handle.puts ps_source
process_handle.
Pages:
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
Kąty Rybackie noclegi trener nlp ceny żywca leczenie alkoholizmu Kołobrzeg