receipts 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +67 -10
- data/Rakefile +37 -3
- data/examples/invoice.pdf +0 -0
- data/examples/receipt.pdf +0 -0
- data/examples/statement.pdf +0 -0
- data/lib/receipts.rb +1 -0
- data/lib/receipts/invoice.rb +6 -4
- data/lib/receipts/receipt.rb +6 -4
- data/lib/receipts/statement.rb +117 -0
- data/lib/receipts/version.rb +1 -1
- data/receipts.gemspec +0 -1
- metadata +8 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7437916678e9856f57b022945c52fb49c3004bc929e77ec2c2d96b049b9231bc
|
4
|
+
data.tar.gz: 6a5b02fcf9aba5fc5e1e0060acc1403bfe47674f68e9453b3162064181eeb888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1685c620c7b21433644ffc6bd153ad0e3f008751f02fe8b888acbec7da03ebba1f0088804742f2b5d71aa46c713fd523655c15eda7a726ff0fe92111ab4f623
|
7
|
+
data.tar.gz: efd79f9bd4fb9a8e188dff1b149dc1d267d7eb5ca0c38124c976d9b142428c9998927948b6ed57825b8b1ec2f8f8cd8aa54237f6a226f6d0094f4464bfd566df
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
### Unreleased
|
2
|
+
|
3
|
+
### 1.1.0
|
4
|
+
|
5
|
+
* [NEW] Add Statements - @anquinn
|
6
|
+
|
7
|
+
### 1.0.3
|
8
|
+
|
9
|
+
* [FIX] Fixes typo introduced in 1.0.2
|
10
|
+
|
11
|
+
### 1.0.2
|
12
|
+
|
13
|
+
* [NEW] Add ability to specify file-like objects for logo
|
14
|
+
|
15
|
+
### 1.0.1
|
16
|
+
|
17
|
+
* [FIX] Make tables full width
|
18
|
+
|
1
19
|
### 1.0.0
|
2
20
|
|
3
21
|
* [NEW] Invoices!
|
data/README.md
CHANGED
@@ -63,10 +63,10 @@ class Charge < ActiveRecord::Base
|
|
63
63
|
subheading: "RECEIPT FOR CHARGE #%{id}",
|
64
64
|
product: "GoRails",
|
65
65
|
company: {
|
66
|
-
name: "
|
67
|
-
address: "
|
68
|
-
email: "
|
69
|
-
logo: Rails.root.join("app/assets/images/
|
66
|
+
name: "GoRails, LLC.",
|
67
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
68
|
+
email: "support@example.com",
|
69
|
+
logo: Rails.root.join("app/assets/images/logo.png")
|
70
70
|
},
|
71
71
|
line_items: [
|
72
72
|
["Date", created_at.to_s],
|
@@ -105,11 +105,25 @@ Company consists of several required nested attributes.
|
|
105
105
|
* `name` - **Required**
|
106
106
|
* `address` - **Required**
|
107
107
|
* `email` - **Required**
|
108
|
+
* `line_items` - **Required**
|
109
|
+
|
110
|
+
You can set as many line items on the receipts as you want. Just pass in an array with each item containing a name and a value to display on the receipt.
|
111
|
+
|
108
112
|
* `logo` - *Optional*
|
109
113
|
|
110
|
-
|
114
|
+
The logo must be either a string path to a file or a file-like object.
|
111
115
|
|
112
|
-
|
116
|
+
```ruby
|
117
|
+
logo: Rails.root.join("app/assets/images/logo.png")
|
118
|
+
# or
|
119
|
+
logo: File.open("app/assets/images/logo.png", "rb")
|
120
|
+
```
|
121
|
+
|
122
|
+
To use an image from a URL, we recommend using `open-uri` to open the remote file as a StringIO object.
|
123
|
+
|
124
|
+
`require 'open-uri'`
|
125
|
+
|
126
|
+
`logo: URI.open("https://www.ruby-lang.org/images/header-ruby-logo@2x.png")`
|
113
127
|
|
114
128
|
* `font` - *Optional*
|
115
129
|
|
@@ -182,7 +196,7 @@ Invoices follow the exact same set of steps as above, with a few minor changes a
|
|
182
196
|
|
183
197
|
* `bill_to` - A string or Array of lines with billing details
|
184
198
|
|
185
|
-
You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
|
199
|
+
You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
|
186
200
|
|
187
201
|
```ruby
|
188
202
|
Receipts::Invoice.new(
|
@@ -192,8 +206,51 @@ You can also use line_items to flexibly generate and display the table with item
|
|
192
206
|
status: "<b><color rgb='#5eba7d'>PAID</color></b>",
|
193
207
|
bill_to: [
|
194
208
|
"GoRails, LLC",
|
195
|
-
"
|
196
|
-
"City,
|
209
|
+
"123 Fake Street",
|
210
|
+
"New York City, NY 10012",
|
211
|
+
nil,
|
212
|
+
"mail@example.com",
|
213
|
+
],
|
214
|
+
company: {
|
215
|
+
name: "GoRails, LLC",
|
216
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
217
|
+
email: "support@example.com",
|
218
|
+
logo: File.expand_path("./examples/gorails.png")
|
219
|
+
},
|
220
|
+
line_items: [
|
221
|
+
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
222
|
+
["GoRails Subscription", "$19.00", "1", "$19.00"],
|
223
|
+
[nil, nil, "Subtotal", "$19.00"],
|
224
|
+
[nil, nil, "Tax Rate", "0%"],
|
225
|
+
[nil, nil, "Total", "$19.00"],
|
226
|
+
],
|
227
|
+
)
|
228
|
+
```
|
229
|
+
|
230
|
+
## Statements
|
231
|
+
|
232
|
+
Statements follow the exact same set of steps as receipts, with a few minor changes and have a few extra arguments you can use:
|
233
|
+
|
234
|
+
* `issue_date` - Date the invoice was issued
|
235
|
+
|
236
|
+
* `start_date` - The start date of the statement period
|
237
|
+
|
238
|
+
* `start_date` - The end date of the statement period
|
239
|
+
|
240
|
+
* `bill_to` - A string or Array of lines with account details
|
241
|
+
|
242
|
+
You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
Receipts::Statement.new(
|
246
|
+
id: "123",
|
247
|
+
issue_date: Date.today,
|
248
|
+
start_date: Date.today - 30,
|
249
|
+
end_date: Date.today,
|
250
|
+
bill_to: [
|
251
|
+
"GoRails, LLC",
|
252
|
+
"123 Fake Street",
|
253
|
+
"New York City, NY 10012",
|
197
254
|
nil,
|
198
255
|
"mail@example.com",
|
199
256
|
],
|
@@ -215,7 +272,7 @@ You can also use line_items to flexibly generate and display the table with item
|
|
215
272
|
|
216
273
|
## Contributing
|
217
274
|
|
218
|
-
1. Fork it ( https://github.com/
|
275
|
+
1. Fork it ( https://github.com/excid3/receipts/fork )
|
219
276
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
220
277
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
221
278
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "open-uri"
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new('spec')
|
5
6
|
|
@@ -22,7 +23,7 @@ task :receipt do
|
|
22
23
|
name: "GoRails, LLC",
|
23
24
|
address: "123 Fake Street\nNew York City, NY 10012",
|
24
25
|
email: "support@example.com",
|
25
|
-
logo:
|
26
|
+
logo: URI.open("https://www.ruby-lang.org/images/header-ruby-logo@2x.png")
|
26
27
|
},
|
27
28
|
line_items: [
|
28
29
|
["Date", Time.now.to_s],
|
@@ -54,7 +55,9 @@ task :invoice do
|
|
54
55
|
name: "GoRails, LLC",
|
55
56
|
address: "123 Fake Street\nNew York City, NY 10012",
|
56
57
|
email: "support@example.com",
|
57
|
-
logo:
|
58
|
+
#logo: Rails.root.join("app/assets/images/gorails.png")
|
59
|
+
#logo: File.expand_path("./examples/gorails.png")
|
60
|
+
logo: File.open("./examples/gorails.png")
|
58
61
|
},
|
59
62
|
line_items: [
|
60
63
|
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
@@ -65,3 +68,34 @@ task :invoice do
|
|
65
68
|
],
|
66
69
|
).render_file "examples/invoice.pdf"
|
67
70
|
end
|
71
|
+
|
72
|
+
task :statement do
|
73
|
+
require "./lib/receipts"
|
74
|
+
|
75
|
+
Receipts::Statement.new(
|
76
|
+
id: "123",
|
77
|
+
issue_date: Date.today,
|
78
|
+
start_date: Date.today - 30,
|
79
|
+
end_date: Date.today,
|
80
|
+
bill_to: [
|
81
|
+
"GoRails, LLC",
|
82
|
+
"123 Fake Street",
|
83
|
+
"New York City, NY 10012",
|
84
|
+
nil,
|
85
|
+
"mail@example.com",
|
86
|
+
],
|
87
|
+
company: {
|
88
|
+
name: "GoRails, LLC",
|
89
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
90
|
+
email: "support@example.com",
|
91
|
+
logo: File.expand_path("./examples/gorails.png")
|
92
|
+
},
|
93
|
+
line_items: [
|
94
|
+
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
95
|
+
["GoRails Subscription", "$19.00", "1", "$19.00"],
|
96
|
+
[nil, nil, "Subtotal", "$19.00"],
|
97
|
+
[nil, nil, "Tax Rate", "0%"],
|
98
|
+
[nil, nil, "Total", "$19.00"],
|
99
|
+
],
|
100
|
+
).render_file "examples/statement.pdf"
|
101
|
+
end
|
data/examples/invoice.pdf
CHANGED
Binary file
|
data/examples/receipt.pdf
CHANGED
Binary file
|
Binary file
|
data/lib/receipts.rb
CHANGED
data/lib/receipts/invoice.rb
CHANGED
@@ -52,12 +52,14 @@ module Receipts
|
|
52
52
|
def header
|
53
53
|
move_down 60
|
54
54
|
|
55
|
-
|
55
|
+
logo = company[:logo]
|
56
56
|
|
57
|
-
if
|
57
|
+
if logo.nil?
|
58
58
|
move_down 32
|
59
|
+
elsif logo.is_a?(String)
|
60
|
+
image open(logo), height: 32
|
59
61
|
else
|
60
|
-
image
|
62
|
+
image logo, height: 32
|
61
63
|
end
|
62
64
|
|
63
65
|
move_down 8
|
@@ -100,7 +102,7 @@ module Receipts
|
|
100
102
|
|
101
103
|
borders = line_items.length - 2
|
102
104
|
|
103
|
-
table(line_items, cell_style: { border_color: 'cccccc', inline_format: true }) do
|
105
|
+
table(line_items, width: bounds.width, cell_style: { border_color: 'cccccc', inline_format: true }) do
|
104
106
|
cells.padding = 12
|
105
107
|
cells.borders = []
|
106
108
|
row(0..borders).borders = [:bottom]
|
data/lib/receipts/receipt.rb
CHANGED
@@ -48,12 +48,14 @@ module Receipts
|
|
48
48
|
def header
|
49
49
|
move_down 60
|
50
50
|
|
51
|
-
|
51
|
+
logo = company[:logo]
|
52
52
|
|
53
|
-
if
|
53
|
+
if logo.nil?
|
54
54
|
move_down 32
|
55
|
+
elsif logo.is_a?(String)
|
56
|
+
image open(logo), height: 32
|
55
57
|
else
|
56
|
-
image
|
58
|
+
image logo, height: 32
|
57
59
|
end
|
58
60
|
|
59
61
|
move_down 8
|
@@ -68,7 +70,7 @@ module Receipts
|
|
68
70
|
|
69
71
|
borders = line_items.length - 2
|
70
72
|
|
71
|
-
table(line_items, cell_style: { border_color: 'cccccc', inline_format: true }) do
|
73
|
+
table(line_items, width: bounds.width, cell_style: { border_color: 'cccccc', inline_format: true }) do
|
72
74
|
cells.padding = 12
|
73
75
|
cells.borders = []
|
74
76
|
row(0..borders).borders = [:bottom]
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
require 'prawn/table'
|
3
|
+
|
4
|
+
module Receipts
|
5
|
+
class Statement < Prawn::Document
|
6
|
+
attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading, :bill_to, :issue_date, :start_date, :end_date
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
@attributes = attributes
|
10
|
+
@id = attributes.fetch(:id)
|
11
|
+
@company = attributes.fetch(:company)
|
12
|
+
@line_items = attributes.fetch(:line_items)
|
13
|
+
@custom_font = attributes.fetch(:font, {})
|
14
|
+
@message = attributes.fetch(:message) { default_message }
|
15
|
+
@subheading = attributes.fetch(:subheading) { default_subheading }
|
16
|
+
@bill_to = Array(attributes.fetch(:bill_to)).join("\n")
|
17
|
+
@issue_date = attributes.fetch(:issue_date)
|
18
|
+
@start_date = attributes.fetch(:start_date)
|
19
|
+
@end_date = attributes.fetch(:end_date)
|
20
|
+
|
21
|
+
super(margin: 0)
|
22
|
+
|
23
|
+
setup_fonts if custom_font.any?
|
24
|
+
generate
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_message
|
30
|
+
"For questions, contact us anytime at <color rgb='326d92'><link href='mailto:#{company.fetch(:email)}?subject=Charge ##{id}'><b>#{company.fetch(:email)}</b></link></color>."
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_subheading
|
34
|
+
"STATEMENT #%{id}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_fonts
|
38
|
+
font_families.update "Primary" => custom_font
|
39
|
+
font "Primary"
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate
|
43
|
+
bounding_box [0, 792], width: 612, height: 792 do
|
44
|
+
bounding_box [85, 792], width: 442, height: 792 do
|
45
|
+
header
|
46
|
+
charge_details
|
47
|
+
footer
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def header
|
53
|
+
move_down 60
|
54
|
+
|
55
|
+
logo = company[:logo]
|
56
|
+
|
57
|
+
if logo.nil?
|
58
|
+
move_down 32
|
59
|
+
elsif logo.is_a?(String)
|
60
|
+
image open(logo), height: 32
|
61
|
+
else
|
62
|
+
image logo, height: 32
|
63
|
+
end
|
64
|
+
|
65
|
+
move_down 8
|
66
|
+
label (subheading % {id: id})
|
67
|
+
|
68
|
+
move_down 10
|
69
|
+
|
70
|
+
# Cache the Y value so we can have both boxes at the same height
|
71
|
+
top = y
|
72
|
+
bounding_box([0, y], width: 200) do
|
73
|
+
move_down 5
|
74
|
+
text_box bill_to, at: [0, cursor], width: 200, height: 75, inline_format: true, size: 10, leading: 4, overflow: :shrink_to_fit
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
bounding_box([250, top], width: 200) do
|
79
|
+
label "STATEMENT DATE"
|
80
|
+
|
81
|
+
move_down 5
|
82
|
+
text issue_date.to_s, inline_format: true, size: 12, leading: 4
|
83
|
+
|
84
|
+
move_down 10
|
85
|
+
label "STATEMENT PERIOD"
|
86
|
+
|
87
|
+
move_down 5
|
88
|
+
text "#{start_date.to_s} - #{end_date.to_s}", inline_format: true, size: 12, leading: 4
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def charge_details
|
93
|
+
move_down 30
|
94
|
+
|
95
|
+
borders = line_items.length - 2
|
96
|
+
|
97
|
+
table(line_items, width: bounds.width, cell_style: { border_color: 'cccccc', inline_format: true }) do
|
98
|
+
cells.padding = 12
|
99
|
+
cells.borders = []
|
100
|
+
row(0..borders).borders = [:bottom]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def footer
|
105
|
+
move_down 30
|
106
|
+
text message, inline_format: true, size: 12, leading: 4
|
107
|
+
|
108
|
+
move_down 30
|
109
|
+
text company.fetch(:name), inline_format: true
|
110
|
+
text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
|
111
|
+
end
|
112
|
+
|
113
|
+
def label(text)
|
114
|
+
text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/receipts/version.rb
CHANGED
data/receipts.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: receipts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,20 +100,6 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 0.2.1
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: ttfunk
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 1.5.1
|
110
|
-
type: :runtime
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: 1.5.1
|
117
103
|
description: Receipts for your Rails application that works with any payment provider.
|
118
104
|
email:
|
119
105
|
- excid3@gmail.com
|
@@ -132,9 +118,11 @@ files:
|
|
132
118
|
- examples/gorails.png
|
133
119
|
- examples/invoice.pdf
|
134
120
|
- examples/receipt.pdf
|
121
|
+
- examples/statement.pdf
|
135
122
|
- lib/receipts.rb
|
136
123
|
- lib/receipts/invoice.rb
|
137
124
|
- lib/receipts/receipt.rb
|
125
|
+
- lib/receipts/statement.rb
|
138
126
|
- lib/receipts/version.rb
|
139
127
|
- receipts.gemspec
|
140
128
|
- spec/receipts_spec.rb
|
@@ -143,7 +131,7 @@ homepage: ''
|
|
143
131
|
licenses:
|
144
132
|
- MIT
|
145
133
|
metadata: {}
|
146
|
-
post_install_message:
|
134
|
+
post_install_message:
|
147
135
|
rdoc_options: []
|
148
136
|
require_paths:
|
149
137
|
- lib
|
@@ -158,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
146
|
- !ruby/object:Gem::Version
|
159
147
|
version: '0'
|
160
148
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
162
|
-
signing_key:
|
149
|
+
rubygems_version: 3.2.3
|
150
|
+
signing_key:
|
163
151
|
specification_version: 4
|
164
152
|
summary: Receipts for your Rails application that works with any payment provider.
|
165
153
|
test_files:
|