3 # Système de gestion des adhésions de Nos oignons
4 # Copyright © 2013-2014 Nos oignons <contact@nos-oignons.net>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 require 'prawn/measurement_extensions'
24 attr_reader :member, :amount
26 def initialize(member, amount)
28 unless member.up_to_date?
29 raise ArgumentError.new("membership fee has not been paid for this year")
36 dir = ENV['NOS_OIGNONS_RECEIPTS_DIR'] || 'receipts'
37 "#{dir}/receipt-#{@member.member_id}-#{@member.membership_fee_paid_on.strftime("%Y-%m-%d")}.pdf"
46 BODY_WIDTH = 210.mm - (BODY_LEFT * 2)
48 DARK_LOGO_COLOR = '57075f'
49 FONT_PATH = File.expand_path("../../../share/fonts/OpenSans/OpenSans.ttf", __FILE__)
50 LOGO_PATH = File.expand_path("../../../share/images/nos-oignons.jpg", __FILE__)
52 def generate_header(pdf)
53 header_height = pdf.bounds.height / 6
54 pdf.bounding_box([0, pdf.cursor], :width => pdf.bounds.width, :height => header_height) do
55 logo_width = 2 * pdf.bounds.width / 3
56 pdf.bounding_box([0, pdf.bounds.top], :width => logo_width, :height => pdf.bounds.height) do
57 pdf.image LOGO_PATH, :width => pdf.bounds.width, :align => :center, :vposition => :center
59 pdf.bounding_box([logo_width, pdf.bounds.top], :width => pdf.bounds.width / 3, :height => pdf.bounds.height) do
60 pdf.text 'Nœuds de sortie Tor financés par la communauté', :align => :center, :valign => :center
63 pdf.bounding_box([WINDOW_LEFT - pdf.bounds.absolute_left, pdf.bounds.absolute_top - WINDOW_TOP], :width => WINDOW_WIDTH, :height => WINDOW_BOTTOM - WINDOW_TOP) do
64 pdf.text member.name + "\n" + member.address, :valign => :bottom
68 def generate_body(pdf)
69 body_height = pdf.cursor - (pdf.bounds.height / 6)
71 pdf.bounding_box([BODY_LEFT, pdf.cursor], :width => BODY_WIDTH, :height => body_height) do
74 pdf.text "Objet : reçu de cotisation"
76 margin = pdf.bounds.width / 6
78 pdf.bounding_box([WINDOW_LEFT - pdf.bounds.absolute_left, pdf.cursor], :width => WINDOW_WIDTH) do
79 pdf.text "Le #{@now.strftime("%d/%m/%Y")}"
82 pdf.text <<-EOT.gsub(/^ /, '').gsub(/\n/, ' ')
83 Nous avons bien enregistré la cotisation annuelle de #{member.name}
84 à l'association Nos oignons reçue à la date du
85 #{member.membership_fee_paid_on.strftime("%d/%m/%Y")} pour un montant
89 pdf.bounding_box([margin, pdf.cursor], :width => 5 * margin) do
90 pdf.text "Le Conseil d'Administration"
97 def generate_footer(pdf)
98 pdf.bounding_box([0, FOOTER_HEIGHT + pdf.bounds.bottom], :width => pdf.bounds.width, :height => FOOTER_HEIGHT) do
100 pdf.stroke_color DARK_LOGO_COLOR
102 pdf.stroke_horizontal_rule
105 pdf.column_box([0, pdf.cursor], :width => pdf.bounds.width, :columns => 2) do
106 pdf.text NosOignons::CONTACT_INFO, :align => :center, :valign => :center
107 pdf.bounds.move_past_bottom
108 pdf.text NosOignons::POSTAL_ADDRESS, :align => :center, :valign => :center
115 raise "File exists!" if File.exists?(filename)
116 Prawn::Document.generate(filename) do |pdf|
117 pdf.font(FONT_PATH) do