Prev | Current Page 220 | Next

David Berube

"Practical Reporting with Ruby and Rails"

close_write
pdf_source = process_handle.read
end
File.open('report.pdf','wb+') do |pdf_file_handle|
pdf_file_handle.puts pdf_source
end
Save this file as calculate_rewards.rb. Next, create the HTML template, as shown in
Listing 8-3.
Listing 8-3. HTML Template for the Salesperson Reward Report (rewards_report_
template.rhtml)


Salesperson Reward Report








<%@users.each do |user|%>
<% meeting_count = user.meetings.count
CHAPTER 8 n CREATING SALES PERFORMANCE REPORTS WITH SUGARCRM 160
next if meeting_count==0 or !user.reward%>



<%end%>
NameMeetingsReward
<%=user.last_name%>, <%=user.first_name%><%=meeting_count%><%=user.reward.description%>



Save this file as rewards_report_template.rhtml.
You can run this script using the following command:
ruby calculate_rewards.rb
Now open the file report.pdf (you??™ll need a PDF viewer, such as Adobe Acrobat or
GSview). You should see a screen similar to Figure 8-1.


Pages:
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232