4 require 'prawn/measurement_extensions'
8 attr_reader :member, :amount
10 def initialize(member, amount)
12 unless member.up_to_date?
13 raise ArgumentError.new("membership fee has not been paid for this year")
20 dir = ENV['NOS_OIGNONS_RECEIPTS_DIR'] || 'receipts'
21 "#{dir}/receipt-#{@member.member_id}-#{@member.membership_fee_paid_on.strftime("%Y-%m-%d")}.pdf"
30 BODY_WIDTH = 210.mm - (BODY_LEFT * 2)
32 DARK_LOGO_COLOR = '57075f'
33 FONT_PATH = File.expand_path("../../../share/fonts/OpenSans/OpenSans.ttf", __FILE__)
34 LOGO_PATH = File.expand_path("../../../share/images/nos-oignons.jpg", __FILE__)
36 def generate_header(pdf)
37 header_height = pdf.bounds.height / 6
38 pdf.bounding_box([0, pdf.cursor], :width => pdf.bounds.width, :height => header_height) do
39 logo_width = 2 * pdf.bounds.width / 3
40 pdf.bounding_box([0, pdf.bounds.top], :width => logo_width, :height => pdf.bounds.height) do
41 pdf.image LOGO_PATH, :width => pdf.bounds.width, :align => :center, :vposition => :center
43 pdf.bounding_box([logo_width, pdf.bounds.top], :width => pdf.bounds.width / 3, :height => pdf.bounds.height) do
44 pdf.text 'Nœuds de sortie Tor financés par la communauté', :align => :center, :valign => :center
47 pdf.bounding_box([WINDOW_LEFT - pdf.bounds.absolute_left, pdf.bounds.absolute_top - WINDOW_TOP], :width => WINDOW_WIDTH, :height => WINDOW_BOTTOM - WINDOW_TOP) do
48 pdf.text member.name + "\n" + member.address, :valign => :bottom
52 def generate_body(pdf)
53 body_height = pdf.cursor - (pdf.bounds.height / 6)
55 pdf.bounding_box([BODY_LEFT, pdf.cursor], :width => BODY_WIDTH, :height => body_height) do
58 pdf.text "Objet : reçu de cotisation"
60 margin = pdf.bounds.width / 6
62 pdf.bounding_box([WINDOW_LEFT - pdf.bounds.absolute_left, pdf.cursor], :width => WINDOW_WIDTH) do
63 pdf.text "Le #{@now.strftime("%d/%m/%Y")}"
66 pdf.text <<-EOT.gsub(/^ /, '').gsub(/\n/, ' ')
67 Nous avons bien enregistré la cotisation annuelle de #{member.name}
68 à l'association Nos oignons reçue à la date du
69 #{member.membership_fee_paid_on.strftime("%d/%m/%Y")} pour un montant
73 pdf.bounding_box([margin, pdf.cursor], :width => 5 * margin) do
74 pdf.text "Le Conseil d'Administration"
81 def generate_footer(pdf)
82 pdf.bounding_box([0, FOOTER_HEIGHT + pdf.bounds.bottom], :width => pdf.bounds.width, :height => FOOTER_HEIGHT) do
84 pdf.stroke_color DARK_LOGO_COLOR
86 pdf.stroke_horizontal_rule
89 pdf.column_box([0, pdf.cursor], :width => pdf.bounds.width, :columns => 2) do
90 pdf.text NosOignons::CONTACT_INFO, :align => :center, :valign => :center
91 pdf.bounds.move_past_bottom
92 pdf.text NosOignons::POSTAL_ADDRESS, :align => :center, :valign => :center
99 raise "File exists!" if File.exists?(filename)
100 Prawn::Document.generate(filename) do |pdf|
101 pdf.font(FONT_PATH) do