payday 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +0 -1
- data/lib/payday/pdf_renderer.rb +41 -41
- data/lib/payday/version.rb +1 -1
- data/payday.gemspec +1 -1
- metadata +53 -60
data/Gemfile
CHANGED
data/lib/payday/pdf_renderer.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
module Payday
|
2
|
-
|
2
|
+
|
3
3
|
# The PDF renderer. We use this internally in Payday to render pdfs, but really you should just need to call
|
4
4
|
# {{Payday::Invoiceable#render_pdf}} to render pdfs yourself.
|
5
5
|
class PdfRenderer
|
6
|
-
|
6
|
+
|
7
7
|
# Renders the given invoice as a pdf on disk
|
8
|
-
def self.render_to_file(invoice, path)
|
8
|
+
def self.render_to_file(invoice, path)
|
9
9
|
pdf(invoice).render_file(path)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
# Renders the given invoice as a pdf, returning a string
|
13
13
|
def self.render(invoice)
|
14
14
|
pdf(invoice).render
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
private
|
18
18
|
def self.pdf(invoice)
|
19
19
|
pdf = Prawn::Document.new(:page_size => invoice_or_default(invoice, :page_size))
|
20
20
|
|
21
21
|
# set up some default styling
|
22
22
|
pdf.font_size(8)
|
23
|
-
|
23
|
+
|
24
24
|
stamp(invoice, pdf)
|
25
25
|
company_banner(invoice, pdf)
|
26
26
|
bill_to_ship_to(invoice, pdf)
|
@@ -28,12 +28,12 @@ module Payday
|
|
28
28
|
line_items_table(invoice, pdf)
|
29
29
|
totals_lines(invoice, pdf)
|
30
30
|
notes(invoice, pdf)
|
31
|
-
|
31
|
+
|
32
32
|
page_numbers(pdf)
|
33
33
|
|
34
34
|
pdf
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def self.stamp(invoice, pdf)
|
38
38
|
stamp = nil
|
39
39
|
if invoice.paid?
|
@@ -53,41 +53,41 @@ module Payday
|
|
53
53
|
|
54
54
|
pdf.fill_color "000000"
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def self.company_banner(invoice, pdf)
|
58
58
|
# render the logo
|
59
59
|
logo_info = pdf.image(invoice_or_default(invoice, :invoice_logo), :at => pdf.bounds.top_left)
|
60
|
-
|
60
|
+
|
61
61
|
# render the company details
|
62
62
|
table_data = []
|
63
63
|
table_data << [bold_cell(pdf, invoice_or_default(invoice, :company_name).strip, :size => 12)]
|
64
|
-
|
64
|
+
|
65
65
|
invoice_or_default(invoice, :company_details).lines.each { |line| table_data << [line] }
|
66
|
-
|
66
|
+
|
67
67
|
table = pdf.make_table(table_data, :cell_style => { :borders => [], :padding => 0 })
|
68
68
|
pdf.bounding_box([pdf.bounds.width - table.width, pdf.bounds.top], :width => table.width, :height => table.height + 5) do
|
69
69
|
table.draw
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
pdf.move_cursor_to(pdf.bounds.top - logo_info.scaled_height - 20)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def self.bill_to_ship_to(invoice, pdf)
|
76
76
|
bill_to_cell_style = { :borders => [], :padding => [2, 0]}
|
77
77
|
bill_to_ship_to_bottom = 0
|
78
|
-
|
78
|
+
|
79
79
|
# render bill to
|
80
80
|
pdf.float do
|
81
|
-
table = pdf.table([[bold_cell(pdf, I18n.t('payday.invoice.bill_to', :default => "Bill To"))],
|
81
|
+
table = pdf.table([[bold_cell(pdf, I18n.t('payday.invoice.bill_to', :default => "Bill To"))],
|
82
82
|
[invoice.bill_to]], :column_widths => [200], :cell_style => bill_to_cell_style)
|
83
83
|
bill_to_ship_to_bottom = pdf.cursor
|
84
84
|
end
|
85
85
|
|
86
86
|
# render ship to
|
87
87
|
if defined?(invoice.ship_to) && !invoice.ship_to.nil?
|
88
|
-
table = pdf.make_table([[bold_cell(pdf, I18n.t('payday.invoice.ship_to', :default => "Ship To"))],
|
88
|
+
table = pdf.make_table([[bold_cell(pdf, I18n.t('payday.invoice.ship_to', :default => "Ship To"))],
|
89
89
|
[invoice.ship_to]], :column_widths => [200], :cell_style => bill_to_cell_style)
|
90
|
-
|
90
|
+
|
91
91
|
pdf.bounding_box([pdf.bounds.width - table.width, pdf.cursor], :width => table.width, :height => table.height + 2) do
|
92
92
|
table.draw
|
93
93
|
end
|
@@ -97,14 +97,14 @@ module Payday
|
|
97
97
|
bill_to_ship_to_bottom = pdf.cursor if pdf.cursor < bill_to_ship_to_bottom
|
98
98
|
pdf.move_cursor_to(bill_to_ship_to_bottom - 20)
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def self.invoice_details(invoice, pdf)
|
102
102
|
# invoice details
|
103
103
|
table_data = []
|
104
104
|
|
105
105
|
# invoice number
|
106
106
|
if defined?(invoice.invoice_number) && invoice.invoice_number
|
107
|
-
table_data << [bold_cell(pdf, I18n.t('payday.invoice.invoice_no', :default => "Invoice #:")),
|
107
|
+
table_data << [bold_cell(pdf, I18n.t('payday.invoice.invoice_no', :default => "Invoice #:")),
|
108
108
|
bold_cell(pdf, invoice.invoice_number.to_s, :align => :right)]
|
109
109
|
end
|
110
110
|
|
@@ -116,7 +116,7 @@ module Payday
|
|
116
116
|
due_date = invoice.due_at.to_s
|
117
117
|
end
|
118
118
|
|
119
|
-
table_data << [bold_cell(pdf, I18n.t('payday.invoice.due_date', :default => "Due Date:")),
|
119
|
+
table_data << [bold_cell(pdf, I18n.t('payday.invoice.due_date', :default => "Due Date:")),
|
120
120
|
bold_cell(pdf, due_date, :align => :right)]
|
121
121
|
end
|
122
122
|
|
@@ -128,13 +128,13 @@ module Payday
|
|
128
128
|
paid_date = invoice.paid_at.to_s
|
129
129
|
end
|
130
130
|
|
131
|
-
table_data << [bold_cell(pdf, I18n.t('payday.invoice.paid_date', :default => "Paid Date:")),
|
131
|
+
table_data << [bold_cell(pdf, I18n.t('payday.invoice.paid_date', :default => "Paid Date:")),
|
132
132
|
bold_cell(pdf, paid_date, :align => :right)]
|
133
133
|
end
|
134
134
|
|
135
135
|
# loop through invoice_details and include them
|
136
136
|
invoice.each_detail do |key, value|
|
137
|
-
table_data << [bold_cell(pdf, key),
|
137
|
+
table_data << [bold_cell(pdf, key),
|
138
138
|
bold_cell(pdf, value, :align => :right)]
|
139
139
|
end
|
140
140
|
|
@@ -142,12 +142,12 @@ module Payday
|
|
142
142
|
pdf.table(table_data, :cell_style => { :borders => [], :padding => [1, 10, 1, 1] })
|
143
143
|
end
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
def self.line_items_table(invoice, pdf)
|
147
147
|
table_data = []
|
148
|
-
table_data << [bold_cell(pdf, I18n.t('payday.line_item.description', :default => "Description"), :borders => []),
|
149
|
-
bold_cell(pdf, I18n.t('payday.line_item.unit_price', :default => "Unit Price"), :align => :center, :borders => []),
|
150
|
-
bold_cell(pdf, I18n.t('payday.line_item.quantity', :default => "Quantity"), :align => :center, :borders => []),
|
148
|
+
table_data << [bold_cell(pdf, I18n.t('payday.line_item.description', :default => "Description"), :borders => []),
|
149
|
+
bold_cell(pdf, I18n.t('payday.line_item.unit_price', :default => "Unit Price"), :align => :center, :borders => []),
|
150
|
+
bold_cell(pdf, I18n.t('payday.line_item.quantity', :default => "Quantity"), :align => :center, :borders => []),
|
151
151
|
bold_cell(pdf, I18n.t('payday.line_item.amount', :default => "Amount"), :align => :center, :borders => [])]
|
152
152
|
invoice.line_items.each do |line|
|
153
153
|
table_data << [line.description,
|
@@ -157,7 +157,7 @@ module Payday
|
|
157
157
|
end
|
158
158
|
|
159
159
|
pdf.move_cursor_to(pdf.cursor - 20)
|
160
|
-
pdf.table(table_data, :width => pdf.bounds.width, :header => true,
|
160
|
+
pdf.table(table_data, :width => pdf.bounds.width, :header => true,
|
161
161
|
:cell_style => {:border_width => 0.5, :border_color => "cccccc", :padding => [5, 10]},
|
162
162
|
:row_colors => ["dfdfdf", "ffffff"]) do
|
163
163
|
# left align the number columns
|
@@ -170,29 +170,29 @@ module Payday
|
|
170
170
|
column_widths = natural
|
171
171
|
end
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
def self.totals_lines(invoice, pdf)
|
175
175
|
table_data = []
|
176
|
-
table_data << [bold_cell(pdf, I18n.t('payday.invoice.subtotal', :default => "Subtotal:")),
|
176
|
+
table_data << [bold_cell(pdf, I18n.t('payday.invoice.subtotal', :default => "Subtotal:")),
|
177
177
|
cell(pdf, number_to_currency(invoice.subtotal, invoice), :align => :right)]
|
178
178
|
if invoice.tax_rate > 0
|
179
179
|
table_data << [bold_cell(pdf,
|
180
|
-
invoice.tax_description.nil? ? I18n.t('payday.invoice.tax', :default => "Tax:") : invoice.tax_description),
|
180
|
+
invoice.tax_description.nil? ? I18n.t('payday.invoice.tax', :default => "Tax:") : invoice.tax_description),
|
181
181
|
cell(pdf, number_to_currency(invoice.tax, invoice), :align => :right)]
|
182
182
|
end
|
183
183
|
if invoice.shipping_rate > 0
|
184
184
|
table_data << [bold_cell(pdf,
|
185
|
-
invoice.shipping_description.nil? ? I18n.t('payday.invoice.shipping', :default => "Shipping:") : invoice.shipping_description),
|
185
|
+
invoice.shipping_description.nil? ? I18n.t('payday.invoice.shipping', :default => "Shipping:") : invoice.shipping_description),
|
186
186
|
cell(pdf, number_to_currency(invoice.shipping, invoice), :align => :right)]
|
187
187
|
end
|
188
|
-
table_data << [bold_cell(pdf, I18n.t('payday.invoice.total', :default => "Total:"), :size => 12),
|
188
|
+
table_data << [bold_cell(pdf, I18n.t('payday.invoice.total', :default => "Total:"), :size => 12),
|
189
189
|
cell(pdf, number_to_currency(invoice.total, invoice), :size => 12, :align => :right)]
|
190
190
|
table = pdf.make_table(table_data, :cell_style => { :borders => [] })
|
191
191
|
pdf.bounding_box([pdf.bounds.width - table.width, pdf.cursor], :width => table.width, :height => table.height + 2) do
|
192
192
|
table.draw
|
193
193
|
end
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
def self.notes(invoice, pdf)
|
197
197
|
if defined?(invoice.notes) && invoice.notes
|
198
198
|
pdf.move_cursor_to(pdf.cursor - 30)
|
@@ -206,13 +206,13 @@ module Payday
|
|
206
206
|
pdf.text(invoice.notes.to_s)
|
207
207
|
end
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
def self.page_numbers(pdf)
|
211
211
|
if pdf.page_count > 1
|
212
212
|
pdf.number_pages("<page> / <total>", [pdf.bounds.right - 18, -15])
|
213
213
|
end
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
def self.invoice_or_default(invoice, property)
|
217
217
|
if invoice.respond_to?(property) && invoice.send(property)
|
218
218
|
invoice.send(property)
|
@@ -220,21 +220,21 @@ module Payday
|
|
220
220
|
Payday::Config.default.send(property)
|
221
221
|
end
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
def self.cell(pdf, text, options = {})
|
225
225
|
Prawn::Table::Cell::Text.make(pdf, text, options)
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
def self.bold_cell(pdf, text, options = {})
|
229
229
|
options[:font] = "Helvetica-Bold"
|
230
230
|
cell(pdf, text, options)
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
# Converts this number to a formatted currency string
|
234
234
|
def self.number_to_currency(number, invoice)
|
235
235
|
number.to_money(invoice_or_default(invoice, :currency)).format
|
236
236
|
end
|
237
|
-
|
237
|
+
|
238
238
|
def self.max_cell_width(cell_proxy)
|
239
239
|
max = 0
|
240
240
|
cell_proxy.each do |cell|
|
@@ -242,7 +242,7 @@ module Payday
|
|
242
242
|
max = cell.natural_content_width
|
243
243
|
end
|
244
244
|
end
|
245
|
-
|
245
|
+
|
246
246
|
max
|
247
247
|
end
|
248
248
|
end
|
data/lib/payday/version.rb
CHANGED
data/payday.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{git remote add origin git@github.com:commondream/payday.git}
|
13
13
|
s.description = %q{Payday is a library for rendering invoices. At present it supports rendering invoices to pdfs, but we're planning on adding support for other formats in the near future.}
|
14
14
|
|
15
|
-
s.add_dependency("prawn", "~> 0.
|
15
|
+
s.add_dependency("prawn", "~> 0.12.0")
|
16
16
|
s.add_dependency("money", "~> 3.6.1")
|
17
17
|
s.add_dependency("i18n", ">= 0.5.0")
|
18
18
|
|
metadata
CHANGED
@@ -1,72 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: payday
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Alan Johnson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-17 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: prawn
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70204475070780 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
18
|
+
requirements:
|
22
19
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.12.0
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: money
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *70204475070780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: money
|
27
|
+
requirement: &70204475070280 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
29
|
+
requirements:
|
33
30
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
31
|
+
- !ruby/object:Gem::Version
|
35
32
|
version: 3.6.1
|
36
33
|
type: :runtime
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: i18n
|
40
34
|
prerelease: false
|
41
|
-
|
35
|
+
version_requirements: *70204475070280
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: i18n
|
38
|
+
requirement: &70204475069820 !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
46
43
|
version: 0.5.0
|
47
44
|
type: :runtime
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: minitest
|
51
45
|
prerelease: false
|
52
|
-
|
46
|
+
version_requirements: *70204475069820
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: minitest
|
49
|
+
requirement: &70204475069380 !ruby/object:Gem::Requirement
|
53
50
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
58
55
|
type: :development
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70204475069380
|
58
|
+
description: Payday is a library for rendering invoices. At present it supports rendering
|
59
|
+
invoices to pdfs, but we're planning on adding support for other formats in the
|
60
|
+
near future.
|
61
|
+
email:
|
62
62
|
- alan@commondream.net
|
63
63
|
executables: []
|
64
|
-
|
65
64
|
extensions: []
|
66
|
-
|
67
65
|
extra_rdoc_files: []
|
68
|
-
|
69
|
-
files:
|
66
|
+
files:
|
70
67
|
- .gitignore
|
71
68
|
- Gemfile
|
72
69
|
- README.md
|
@@ -94,35 +91,31 @@ files:
|
|
94
91
|
- test/invoice_test.rb
|
95
92
|
- test/line_item_test.rb
|
96
93
|
- test/test_helper.rb
|
97
|
-
|
98
|
-
homepage: ""
|
94
|
+
homepage: ''
|
99
95
|
licenses: []
|
100
|
-
|
101
96
|
post_install_message:
|
102
97
|
rdoc_options: []
|
103
|
-
|
104
|
-
require_paths:
|
98
|
+
require_paths:
|
105
99
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
101
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version:
|
112
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
107
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version:
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
118
112
|
requirements: []
|
119
|
-
|
120
113
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.
|
114
|
+
rubygems_version: 1.8.10
|
122
115
|
signing_key:
|
123
116
|
specification_version: 3
|
124
117
|
summary: git remote add origin git@github.com:commondream/payday.git
|
125
|
-
test_files:
|
118
|
+
test_files:
|
126
119
|
- test/invoice_test.rb
|
127
120
|
- test/line_item_test.rb
|
128
121
|
- test/test_helper.rb
|