Created
May 24, 2009 15:27
-
-
Save wesbillman/117146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hazards = Hazard.find :all | |
states = State.find :all | |
for hazard in hazards | |
for state in states | |
sorted_mats = Array.new | |
total_storage = 0.0000 | |
total_closed = 0.0000 | |
total_open = 0.0000 | |
for proj_mat in @project.project_materials | |
if proj_mat.material.state == state.symbol and | |
proj_mat.material.hazards.gsub(' ', '').split(',').include?(hazard.name) | |
sorted_mats << proj_mat | |
total_storage += proj_mat.storage | |
total_closed += proj_mat.uc_amount | |
total_open += proj_mat.uo_amount | |
end | |
end | |
if not sorted_mats.empty? | |
puts "#{state.name} #{hazard.name} Items #{sorted_mats.size}" | |
parent_pdf.start_new_page(:layout => :landscape) | |
parent_pdf.header [parent_pdf.margin_box.left,parent_pdf.margin_box.top+40], :width => | |
parent_pdf.margin_box.width, :height => 40 do | |
parent_pdf.move_down 15 | |
parent_pdf.text "#{project.name.upcase}: #{hazard.description}/#{state.name.upcase}", :size => 10, :style => :bold | |
parent_pdf.move_down 5 | |
parent_pdf.stroke_horizontal_rule | |
end | |
parent_pdf.footer parent_pdf.margin_box.bottom_left do | |
parent_pdf.stroke_horizontal_rule | |
parent_pdf.move_down(5) | |
parent_pdf.text Date.today, :size => 10, :style => :bold, :align => :left | |
parent_pdf.text parent_pdf.page_count, :size => 10, :align => :right | |
end | |
row_num = 0 | |
proj_mats = sorted_mats.map do |proj_mat| | |
[ | |
row_num = row_num +1, | |
proj_mat.material.cas_number, | |
proj_mat.material.state, | |
proj_mat.material.concentration, | |
proj_mat.material.name, | |
proj_mat.material.hazards, | |
"#{proj_mat.storage} #{states.to_ary.find{|state| state.symbol == proj_mat.material.state}.unit.capitalize}",#"#{State.find_by_symbol(proj_mat.material.state).unit.capitalize}", | |
"#{proj_mat.uc_amount} #{states.to_ary.find{|state| state.symbol == proj_mat.material.state}.unit.capitalize}",#{State.find_by_symbol(proj_mat.material.state).unit.capitalize}", | |
"#{proj_mat.uo_amount} #{states.to_ary.find{|state| state.symbol == proj_mat.material.state}.unit.capitalize}",#{State.find_by_symbol(proj_mat.material.state).unit.capitalize}", | |
proj_mat.cabinets? ? "Y":"N", | |
proj_mat.above_15psi? ? "Y":"N", | |
proj_mat.location | |
] | |
end | |
parent_pdf.table proj_mats, :border_style => :no_top, | |
:font_size => 8, | |
:position => :center, | |
:header_color => 'FFCC00', | |
:align_headers => {0 => :left, 1 => :center, 2 => :center, 3 => :center, 4 => :center, | |
5 => :center, 6 => :center, 7 => :center, 7 => :center, 8 => :center}, | |
:border_width => 1, | |
:row_colors => :pdf_writer, | |
:headers => ["Item", "CAS#", "State", "Conc%", "Material", | |
"Hazard Class", "Storage", "Use-Closed", "Use-Open", "Cabs", | |
">15psi", "Location"], | |
:align => {0 => :right, 1 => :center, 2 => :center, 3 => :center, 4 => :left, | |
5 => :center, 6 => :center, 7 => :center, 7 => :center, 8 => :center, | |
9 => :center, 10 => :center, 11 => :left}, | |
:column_widths => {0 => 30, 1 => 60, 2 => 30, 3 => 40, 5 => 60, 6 => 55, 7 => 55, | |
8 => 50, 9 => 30, 10 => 35, 11 => 100}, | |
:width => parent_pdf.margin_box.width | |
totals = [] | |
totals << ["TOTAL - #{hazard.description}/#{state.name}", | |
sprintf("%5.4f", "#{total_storage}"), | |
sprintf("%5.4f", "#{total_open}"), | |
sprintf("%5.4f", "#{total_closed}"), | |
""] | |
totals << ["AGGREGATE TOTAL - #{hazard.description}/#{state.name}", | |
sprintf("%5.4f", "#{total_storage + total_open + total_closed}"), | |
"","",""] | |
parent_pdf.table totals, :border_style => :sides, | |
:font_size => 8, | |
:border_width => 1, | |
:row_colors => ['FFCC00'], | |
:align => {0 => :left, 1 => :center, 2 => :center, 3 => :center}, | |
:column_widths => {0 => 395, 1 => 55, 2 => 55, 3 => 50}, | |
:width => parent_pdf.margin_box.width | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment