receipts 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +36 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +11 -0
- data/Rakefile +16 -16
- data/lib/receipts.rb +7 -3
- data/lib/receipts/invoice.rb +80 -81
- data/lib/receipts/receipt.rb +53 -53
- data/lib/receipts/statement.rb +75 -76
- data/lib/receipts/version.rb +1 -1
- data/receipts.gemspec +16 -16
- data/spec/receipts_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -2
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfed87396d5ed2beb0064ead6f0ac9ca457e06a7b67427ec8963b9f6404db0ce
|
4
|
+
data.tar.gz: a8a4cbff0f9eadf7552ad5a533522dd6e6746cefa548f3d146a7a3e6bb0f07d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6f01ec38f45f6d6e2ed3642ef004185e1b52f7d53a23802014e338d52965099865d5e6c0269ee5528c45c959bec4d4a3fcecf1cbc6774190efa424f01f73c51
|
7
|
+
data.tar.gz: 338d4628dd34e5af7d4e7de7a00d3c1758b19a26b7fb5c5f1ea561c0f4ce71150841a5c915b20e2270b16e3f63c25ea6d789fe6641a8818b605935fc3b814d63
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- '*'
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
jobs:
|
11
|
+
tests:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby: ['2.7', '3.0']
|
16
|
+
env:
|
17
|
+
BUNDLE_PATH_RELATIVE_TO_CWD: true
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@master
|
21
|
+
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
bundler: default
|
27
|
+
bundler-cache: true
|
28
|
+
|
29
|
+
- name: StandardRb check
|
30
|
+
run: bundle exec standardrb
|
31
|
+
|
32
|
+
- name: Run tests
|
33
|
+
env:
|
34
|
+
RAILS_ENV: test
|
35
|
+
run: |
|
36
|
+
bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### 1.1.1
|
4
|
+
|
5
|
+
* [FIX] Use `URI.parse().open` instead - @excid3 @reckerswartz
|
6
|
+
* Add I18n notes to the readme - @excid3 @reckerswartz
|
7
|
+
* Add standardrb formatting - @excid3
|
8
|
+
* Add GitHub Actions for standardrb and tests - @excid3
|
9
|
+
|
3
10
|
### 1.1.0
|
4
11
|
|
5
12
|
* [NEW] Add Statements - @anquinn
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -129,6 +129,17 @@ To use an image from a URL, we recommend using `open-uri` to open the remote fil
|
|
129
129
|
|
130
130
|
If you'd like to use your own custom font, you can pass in the file paths to the `normal` and `bold` variations of your font. The bold font variation is required because it is used in the default message. If you wish to override that, you can pass in your own custom message instead.
|
131
131
|
|
132
|
+
#### Internationalization (I18n)
|
133
|
+
|
134
|
+
You can use `I18n.t` when rendering your receipts to internationalize them.
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
line_items: [
|
138
|
+
[I18n.t("receipts.date"), created_at.to_s],
|
139
|
+
[I18n.t("receipts.product"), "GoRails"],
|
140
|
+
[I18n.t("receipts.transaction"), uuid]
|
141
|
+
]
|
142
|
+
```
|
132
143
|
|
133
144
|
## Rendering the Receipt PDF in your Controller
|
134
145
|
|
data/Rakefile
CHANGED
@@ -2,11 +2,11 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
require "open-uri"
|
4
4
|
|
5
|
-
RSpec::Core::RakeTask.new(
|
5
|
+
RSpec::Core::RakeTask.new("spec")
|
6
6
|
|
7
7
|
# If you want to make this the default task
|
8
|
-
task :
|
9
|
-
task :
|
8
|
+
task default: :spec
|
9
|
+
task test: :spec
|
10
10
|
|
11
11
|
task :console do
|
12
12
|
exec "irb -r receipts -I ./lib"
|
@@ -26,13 +26,13 @@ task :receipt do
|
|
26
26
|
logo: URI.open("https://www.ruby-lang.org/images/header-ruby-logo@2x.png")
|
27
27
|
},
|
28
28
|
line_items: [
|
29
|
-
["Date",
|
29
|
+
["Date", Time.now.to_s],
|
30
30
|
["Account Billed", "Example User (user@example.com)"],
|
31
|
-
["Product",
|
32
|
-
["Amount",
|
33
|
-
["Charged to",
|
31
|
+
["Product", "GoRails"],
|
32
|
+
["Amount", "$19.00"],
|
33
|
+
["Charged to", "Visa (**** **** **** 1234)"],
|
34
34
|
["Transaction ID", "123456"]
|
35
|
-
]
|
35
|
+
]
|
36
36
|
).render_file "examples/receipt.pdf"
|
37
37
|
end
|
38
38
|
|
@@ -49,14 +49,14 @@ task :invoice do
|
|
49
49
|
"Address",
|
50
50
|
"City, State Zipcode",
|
51
51
|
nil,
|
52
|
-
"mail@example.com"
|
52
|
+
"mail@example.com"
|
53
53
|
],
|
54
54
|
company: {
|
55
55
|
name: "GoRails, LLC",
|
56
56
|
address: "123 Fake Street\nNew York City, NY 10012",
|
57
57
|
email: "support@example.com",
|
58
|
-
#logo: Rails.root.join("app/assets/images/gorails.png")
|
59
|
-
#logo: File.expand_path("./examples/gorails.png")
|
58
|
+
# logo: Rails.root.join("app/assets/images/gorails.png")
|
59
|
+
# logo: File.expand_path("./examples/gorails.png")
|
60
60
|
logo: File.open("./examples/gorails.png")
|
61
61
|
},
|
62
62
|
line_items: [
|
@@ -64,8 +64,8 @@ task :invoice do
|
|
64
64
|
["GoRails Subscription", "$19.00", "1", "$19.00"],
|
65
65
|
[nil, nil, "Subtotal", "$19.00"],
|
66
66
|
[nil, nil, "Tax Rate", "0%"],
|
67
|
-
[nil, nil, "Amount Due", "$19.00"]
|
68
|
-
]
|
67
|
+
[nil, nil, "Amount Due", "$19.00"]
|
68
|
+
]
|
69
69
|
).render_file "examples/invoice.pdf"
|
70
70
|
end
|
71
71
|
|
@@ -82,7 +82,7 @@ task :statement do
|
|
82
82
|
"123 Fake Street",
|
83
83
|
"New York City, NY 10012",
|
84
84
|
nil,
|
85
|
-
"mail@example.com"
|
85
|
+
"mail@example.com"
|
86
86
|
],
|
87
87
|
company: {
|
88
88
|
name: "GoRails, LLC",
|
@@ -95,7 +95,7 @@ task :statement do
|
|
95
95
|
["GoRails Subscription", "$19.00", "1", "$19.00"],
|
96
96
|
[nil, nil, "Subtotal", "$19.00"],
|
97
97
|
[nil, nil, "Tax Rate", "0%"],
|
98
|
-
[nil, nil, "Total", "$19.00"]
|
99
|
-
]
|
98
|
+
[nil, nil, "Total", "$19.00"]
|
99
|
+
]
|
100
100
|
).render_file "examples/statement.pdf"
|
101
101
|
end
|
data/lib/receipts.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require "open-uri"
|
1
2
|
require "receipts/version"
|
2
|
-
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
module Receipts
|
5
|
+
autoload :Invoice, "receipts/invoice"
|
6
|
+
autoload :Receipt, "receipts/receipt"
|
7
|
+
autoload :Statement, "receipts/statement"
|
8
|
+
end
|
data/lib/receipts/invoice.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "prawn"
|
2
|
+
require "prawn/table"
|
3
3
|
|
4
4
|
module Receipts
|
5
5
|
class Invoice < Prawn::Document
|
6
6
|
attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading, :bill_to, :issue_date, :due_date, :status
|
7
7
|
|
8
8
|
def initialize(attributes)
|
9
|
-
@attributes
|
10
|
-
@id
|
11
|
-
@company
|
12
|
-
@line_items
|
9
|
+
@attributes = attributes
|
10
|
+
@id = attributes.fetch(:id)
|
11
|
+
@company = attributes.fetch(:company)
|
12
|
+
@line_items = attributes.fetch(:line_items)
|
13
13
|
@custom_font = attributes.fetch(:font, {})
|
14
|
-
@message
|
15
|
-
@subheading
|
16
|
-
@bill_to
|
17
|
-
@issue_date
|
18
|
-
@due_date
|
19
|
-
@status
|
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
|
+
@due_date = attributes.fetch(:due_date)
|
19
|
+
@status = attributes.fetch(:status)
|
20
20
|
|
21
21
|
super(margin: 0)
|
22
22
|
|
@@ -26,100 +26,99 @@ module Receipts
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
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
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def default_subheading
|
34
|
+
"INVOICE #%{id}"
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def setup_fonts
|
38
|
+
font_families.update "Primary" => custom_font
|
39
|
+
font "Primary"
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
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
|
49
48
|
end
|
50
49
|
end
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
logo = company[:logo]
|
52
|
+
def header
|
53
|
+
move_down 60
|
56
54
|
|
57
|
-
|
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
|
55
|
+
logo = company[:logo]
|
64
56
|
|
65
|
-
|
66
|
-
|
57
|
+
if logo.nil?
|
58
|
+
move_down 32
|
59
|
+
elsif logo.is_a?(String)
|
60
|
+
image URI.parse(logo).open, height: 32
|
61
|
+
else
|
62
|
+
image logo, height: 32
|
63
|
+
end
|
67
64
|
|
68
|
-
|
65
|
+
move_down 8
|
66
|
+
label(subheading % {id: id})
|
69
67
|
|
70
|
-
|
71
|
-
top = y
|
72
|
-
bounding_box([0, y], width: 200) do
|
73
|
-
label "BILL TO"
|
68
|
+
move_down 10
|
74
69
|
|
75
|
-
|
76
|
-
|
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
|
+
label "BILL TO"
|
77
74
|
|
78
|
-
|
75
|
+
move_down 5
|
76
|
+
text_box bill_to, at: [0, cursor], width: 200, height: 75, inline_format: true, size: 10, leading: 4, overflow: :shrink_to_fit
|
77
|
+
end
|
79
78
|
|
80
|
-
|
81
|
-
|
79
|
+
bounding_box([250, top], width: 200) do
|
80
|
+
label "INVOICE DATE"
|
82
81
|
|
83
|
-
|
84
|
-
|
82
|
+
move_down 5
|
83
|
+
text issue_date.to_s, inline_format: true, size: 12, leading: 4
|
85
84
|
|
86
|
-
|
87
|
-
|
85
|
+
move_down 10
|
86
|
+
label "DUE DATE"
|
88
87
|
|
89
|
-
|
90
|
-
|
88
|
+
move_down 5
|
89
|
+
text due_date.to_s, inline_format: true, size: 12, leading: 4
|
91
90
|
|
92
|
-
|
93
|
-
|
91
|
+
move_down 10
|
92
|
+
label "STATUS"
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
end
|
94
|
+
move_down 5
|
95
|
+
text status, inline_format: true, size: 12, leading: 4
|
98
96
|
end
|
97
|
+
end
|
99
98
|
|
100
|
-
|
101
|
-
|
99
|
+
def charge_details
|
100
|
+
move_down 30
|
102
101
|
|
103
|
-
|
102
|
+
borders = line_items.length - 2
|
104
103
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
104
|
+
table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
|
105
|
+
cells.padding = 12
|
106
|
+
cells.borders = []
|
107
|
+
row(0..borders).borders = [:bottom]
|
110
108
|
end
|
109
|
+
end
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
def footer
|
112
|
+
move_down 30
|
113
|
+
text message, inline_format: true, size: 12, leading: 4
|
115
114
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
115
|
+
move_down 30
|
116
|
+
text company.fetch(:name), inline_format: true
|
117
|
+
text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
|
118
|
+
end
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
def label(text)
|
121
|
+
text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
|
122
|
+
end
|
124
123
|
end
|
125
124
|
end
|
data/lib/receipts/receipt.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "prawn"
|
2
|
+
require "prawn/table"
|
3
3
|
|
4
4
|
module Receipts
|
5
5
|
class Receipt < Prawn::Document
|
6
6
|
attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading
|
7
7
|
|
8
8
|
def initialize(attributes)
|
9
|
-
@attributes
|
10
|
-
@id
|
11
|
-
@company
|
12
|
-
@line_items
|
9
|
+
@attributes = attributes
|
10
|
+
@id = attributes.fetch(:id)
|
11
|
+
@company = attributes.fetch(:company)
|
12
|
+
@line_items = attributes.fetch(:line_items)
|
13
13
|
@custom_font = attributes.fetch(:font, {})
|
14
|
-
@message
|
15
|
-
@subheading
|
14
|
+
@message = attributes.fetch(:message) { default_message }
|
15
|
+
@subheading = attributes.fetch(:subheading) { default_subheading }
|
16
16
|
|
17
17
|
super(margin: 0)
|
18
18
|
|
@@ -22,65 +22,65 @@ module Receipts
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def default_message
|
26
|
+
"We've received your payment for #{attributes.fetch(:product)}. You can keep this receipt for your records. 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>."
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def default_subheading
|
30
|
+
"RECEIPT FOR CHARGE #%{id}"
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def setup_fonts
|
34
|
+
font_families.update "Primary" => custom_font
|
35
|
+
font "Primary"
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
38
|
+
def generate
|
39
|
+
bounding_box [0, 792], width: 612, height: 792 do
|
40
|
+
bounding_box [85, 792], width: 442, height: 792 do
|
41
|
+
header
|
42
|
+
charge_details
|
43
|
+
footer
|
45
44
|
end
|
46
45
|
end
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
def header
|
49
|
+
move_down 60
|
50
50
|
|
51
|
-
|
51
|
+
logo = company[:logo]
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
if logo.nil?
|
54
|
+
move_down 32
|
55
|
+
elsif logo.is_a?(String)
|
56
|
+
image URI.parse(logo).open, height: 32
|
57
|
+
else
|
58
|
+
image logo, height: 32
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
move_down 8
|
62
|
+
text "<color rgb='a6a6a6'>#{subheading % {id: id}}</color>", inline_format: true
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
move_down 30
|
65
|
+
text message, inline_format: true, size: 12.5, leading: 4
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
def charge_details
|
69
|
+
move_down 30
|
70
70
|
|
71
|
-
|
71
|
+
borders = line_items.length - 2
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
73
|
+
table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
|
74
|
+
cells.padding = 12
|
75
|
+
cells.borders = []
|
76
|
+
row(0..borders).borders = [:bottom]
|
78
77
|
end
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
def footer
|
81
|
+
move_down 45
|
82
|
+
text company.fetch(:name), inline_format: true
|
83
|
+
text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
|
84
|
+
end
|
85
85
|
end
|
86
86
|
end
|
data/lib/receipts/statement.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "prawn"
|
2
|
+
require "prawn/table"
|
3
3
|
|
4
4
|
module Receipts
|
5
5
|
class Statement < Prawn::Document
|
6
6
|
attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading, :bill_to, :issue_date, :start_date, :end_date
|
7
7
|
|
8
8
|
def initialize(attributes)
|
9
|
-
@attributes
|
10
|
-
@id
|
11
|
-
@company
|
12
|
-
@line_items
|
9
|
+
@attributes = attributes
|
10
|
+
@id = attributes.fetch(:id)
|
11
|
+
@company = attributes.fetch(:company)
|
12
|
+
@line_items = attributes.fetch(:line_items)
|
13
13
|
@custom_font = attributes.fetch(:font, {})
|
14
|
-
@message
|
15
|
-
@subheading
|
16
|
-
@bill_to
|
17
|
-
@issue_date
|
18
|
-
@start_date
|
19
|
-
@end_date
|
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
20
|
|
21
21
|
super(margin: 0)
|
22
22
|
|
@@ -26,92 +26,91 @@ module Receipts
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
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
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def default_subheading
|
34
|
+
"STATEMENT #%{id}"
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def setup_fonts
|
38
|
+
font_families.update "Primary" => custom_font
|
39
|
+
font "Primary"
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
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
|
49
48
|
end
|
50
49
|
end
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
logo = company[:logo]
|
52
|
+
def header
|
53
|
+
move_down 60
|
56
54
|
|
57
|
-
|
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
|
55
|
+
logo = company[:logo]
|
64
56
|
|
65
|
-
|
66
|
-
|
57
|
+
if logo.nil?
|
58
|
+
move_down 32
|
59
|
+
elsif logo.is_a?(String)
|
60
|
+
image URI.parse(logo).open, height: 32
|
61
|
+
else
|
62
|
+
image logo, height: 32
|
63
|
+
end
|
67
64
|
|
68
|
-
|
65
|
+
move_down 8
|
66
|
+
label(subheading % {id: id})
|
69
67
|
|
70
|
-
|
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
|
68
|
+
move_down 10
|
75
69
|
|
76
|
-
|
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
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
bounding_box([250, top], width: 200) do
|
78
|
+
label "STATEMENT DATE"
|
80
79
|
|
81
|
-
|
82
|
-
|
80
|
+
move_down 5
|
81
|
+
text issue_date.to_s, inline_format: true, size: 12, leading: 4
|
83
82
|
|
84
|
-
|
85
|
-
|
83
|
+
move_down 10
|
84
|
+
label "STATEMENT PERIOD"
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
end
|
86
|
+
move_down 5
|
87
|
+
text "#{start_date} - #{end_date}", inline_format: true, size: 12, leading: 4
|
90
88
|
end
|
89
|
+
end
|
91
90
|
|
92
|
-
|
93
|
-
|
91
|
+
def charge_details
|
92
|
+
move_down 30
|
94
93
|
|
95
|
-
|
94
|
+
borders = line_items.length - 2
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
96
|
+
table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
|
97
|
+
cells.padding = 12
|
98
|
+
cells.borders = []
|
99
|
+
row(0..borders).borders = [:bottom]
|
102
100
|
end
|
101
|
+
end
|
103
102
|
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
def footer
|
104
|
+
move_down 30
|
105
|
+
text message, inline_format: true, size: 12, leading: 4
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
move_down 30
|
108
|
+
text company.fetch(:name), inline_format: true
|
109
|
+
text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
|
110
|
+
end
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
def label(text)
|
113
|
+
text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
|
114
|
+
end
|
116
115
|
end
|
117
116
|
end
|
data/lib/receipts/version.rb
CHANGED
data/receipts.gemspec
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "receipts/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
6
|
+
spec.name = "receipts"
|
7
|
+
spec.version = Receipts::VERSION
|
8
|
+
spec.authors = ["Chris Oliver"]
|
9
|
+
spec.email = ["excid3@gmail.com"]
|
10
|
+
spec.summary = "Receipts for your Rails application that works with any payment provider."
|
11
|
+
spec.description = "Receipts for your Rails application that works with any payment provider."
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
15
14
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
20
|
spec.add_development_dependency "bundler"
|
22
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
22
|
spec.add_development_dependency "rspec"
|
24
23
|
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "standard"
|
25
25
|
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
26
|
+
spec.add_dependency "prawn", ">= 1.3.0", "< 3.0.0"
|
27
|
+
spec.add_dependency "prawn-table", "~> 0.2.1"
|
28
28
|
end
|
data/spec/receipts_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Receipts do
|
4
4
|
it "lets you create a new receipt" do
|
@@ -11,8 +11,8 @@ describe Receipts do
|
|
11
11
|
email: "teachers@onemonth.com"
|
12
12
|
},
|
13
13
|
line_items: [
|
14
|
-
["Product",
|
15
|
-
]
|
14
|
+
["Product", "GoRails"]
|
15
|
+
]
|
16
16
|
).class.name).to eq("Receipts::Receipt")
|
17
17
|
end
|
18
18
|
end
|
data/spec/spec_helper.rb
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: standard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: prawn
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,7 @@ extensions: []
|
|
108
122
|
extra_rdoc_files: []
|
109
123
|
files:
|
110
124
|
- ".github/FUNDING.yml"
|
125
|
+
- ".github/workflows/ci.yml"
|
111
126
|
- ".gitignore"
|
112
127
|
- ".travis.yml"
|
113
128
|
- CHANGELOG.md
|
@@ -146,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
161
|
- !ruby/object:Gem::Version
|
147
162
|
version: '0'
|
148
163
|
requirements: []
|
149
|
-
rubygems_version: 3.2.
|
164
|
+
rubygems_version: 3.2.15
|
150
165
|
signing_key:
|
151
166
|
specification_version: 4
|
152
167
|
summary: Receipts for your Rails application that works with any payment provider.
|