receipts 0.2.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0466ac55f2ba9f07b0caac72cc9785a78ef44a0ce8ba507d9c8bb1ed81675a6
4
- data.tar.gz: d8daa107a52b0cfe63af6c8f1b927e0e590dd80a316893ce984a0a14f7d98829
3
+ metadata.gz: aa3e56021ccff37e48f340cea424f548b1f52c6782203cde1002049a1f470571
4
+ data.tar.gz: db562a59a36abcc235718f59420bc730ddcb70a3b057536df824692cfbfd4909
5
5
  SHA512:
6
- metadata.gz: 560016286cb1ea373742c3f855b8cb8677f0fb74ac4cfc90808f54efbca8955902f4775012697d2a0b85b8637bb3158d2250893745eaf6eb4b87fb011a7484ef
7
- data.tar.gz: f07a19f5860698341e9edddf96872297016c63fbc2a31c1d2c9cb2980ca69ebb98603aae6b020e0cb77e5bb18f2aa198a03859796221cf64fc66747c8276a2a0
6
+ metadata.gz: a2ed85aa3947b15ca345d01b88e9f267335e181ef4a8950b496cd99c4d9c9187844d92f993b82dfc3018ece6dcee9765777842135d330dbe61e08599676b43d8
7
+ data.tar.gz: 9d2c8edb71e5d0204431f2053bb1a8518a8e766201950327c0581c8c4914d7edee96ea1f435ee9dd4c800d687886f79dcc6e97596a0cd689fadf6b827d30dcd9
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .DS_Store
@@ -0,0 +1,15 @@
1
+ ### 1.0.3
2
+
3
+ * [FIX] Fixes typo introduced in 1.0.2
4
+
5
+ ### 1.0.2
6
+
7
+ * [NEW] Add ability to specify file-like objects for logo
8
+
9
+ ### 1.0.1
10
+
11
+ * [FIX] Make tables full width
12
+
13
+ ### 1.0.0
14
+
15
+ * [NEW] Invoices!
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Receipts for your Rails application that works with any payment provider.
6
6
 
7
- Check out an [example PDF receipt](https://github.com/excid3/receipts/blob/master/examples/receipt.pdf?raw=true)
7
+ Check out the [example receipt](https://github.com/excid3/receipts/blob/master/examples/receipt.pdf?raw=true) and [example invoice](https://github.com/excid3/receipts/blob/master/examples/invoice.pdf?raw=true) PDFs.
8
8
 
9
9
  ## Installation
10
10
 
@@ -63,10 +63,10 @@ class Charge < ActiveRecord::Base
63
63
  subheading: "RECEIPT FOR CHARGE #%{id}",
64
64
  product: "GoRails",
65
65
  company: {
66
- name: "One Month, Inc.",
67
- address: "37 Great Jones\nFloor 2\nNew York City, NY 10012",
68
- email: "teachers@onemonth.com",
69
- logo: Rails.root.join("app/assets/images/one-month-dark.png")
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
- * `line_items` - **Required**
114
+ The logo must be either a string path to a file or a file-like object.
111
115
 
112
- 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.
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
 
@@ -170,9 +184,52 @@ resources :charges
170
184
  <%= link_to "Download Receipt", charge_path(@charge, format: :pdf) %>
171
185
  ```
172
186
 
187
+ ## Invoices
188
+
189
+ Invoices follow the exact same set of steps as above, with a few minor changes and have a few extra arguments you can use:
190
+
191
+ * `issue_date` - Date the invoice was issued
192
+
193
+ * `due_date` - Date the invoice payment is due
194
+
195
+ * `status` - A status for the invoice (Pending, Paid, etc)
196
+
197
+ * `bill_to` - A string or Array of lines with billing details
198
+
199
+ You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
200
+
201
+ ```ruby
202
+ Receipts::Invoice.new(
203
+ id: "123",
204
+ issue_date: Date.today,
205
+ due_date: Date.today + 30,
206
+ status: "<b><color rgb='#5eba7d'>PAID</color></b>",
207
+ bill_to: [
208
+ "GoRails, LLC",
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
+
173
230
  ## Contributing
174
231
 
175
- 1. Fork it ( https://github.com/[my-github-username]/receipts/fork )
232
+ 1. Fork it ( https://github.com/excid3/receipts/fork )
176
233
  2. Create your feature branch (`git checkout -b my-new-feature`)
177
234
  3. Commit your changes (`git commit -am 'Add some feature'`)
178
235
  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 'rspec/core/rake_task'
2
+ require "rspec/core/rake_task"
3
+ require "open-uri"
3
4
 
4
5
  RSpec::Core::RakeTask.new('spec')
5
6
 
@@ -10,3 +11,60 @@ task :test => :spec
10
11
  task :console do
11
12
  exec "irb -r receipts -I ./lib"
12
13
  end
14
+
15
+ task :receipt do
16
+ require "./lib/receipts"
17
+
18
+ Receipts::Receipt.new(
19
+ id: "123",
20
+ subheading: "RECEIPT FOR CHARGE #1",
21
+ product: "GoRails",
22
+ company: {
23
+ name: "GoRails, LLC",
24
+ address: "123 Fake Street\nNew York City, NY 10012",
25
+ email: "support@example.com",
26
+ logo: URI.open("https://www.ruby-lang.org/images/header-ruby-logo@2x.png")
27
+ },
28
+ line_items: [
29
+ ["Date", Time.now.to_s],
30
+ ["Account Billed", "Example User (user@example.com)"],
31
+ ["Product", "GoRails"],
32
+ ["Amount", "$19.00"],
33
+ ["Charged to", "Visa (**** **** **** 1234)"],
34
+ ["Transaction ID", "123456"]
35
+ ],
36
+ ).render_file "examples/receipt.pdf"
37
+ end
38
+
39
+ task :invoice do
40
+ require "./lib/receipts"
41
+
42
+ Receipts::Invoice.new(
43
+ id: "123",
44
+ issue_date: Date.today,
45
+ due_date: Date.today + 30,
46
+ status: "<b><color rgb='#5eba7d'>PAID</color></b>",
47
+ bill_to: [
48
+ "GoRails, LLC",
49
+ "Address",
50
+ "City, State Zipcode",
51
+ nil,
52
+ "mail@example.com",
53
+ ],
54
+ company: {
55
+ name: "GoRails, LLC",
56
+ address: "123 Fake Street\nNew York City, NY 10012",
57
+ email: "support@example.com",
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")
61
+ },
62
+ line_items: [
63
+ ["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
64
+ ["GoRails Subscription", "$19.00", "1", "$19.00"],
65
+ [nil, nil, "Subtotal", "$19.00"],
66
+ [nil, nil, "Tax Rate", "0%"],
67
+ [nil, nil, "Amount Due", "$19.00"],
68
+ ],
69
+ ).render_file "examples/invoice.pdf"
70
+ end
Binary file
Binary file
Binary file
@@ -1,2 +1,3 @@
1
1
  require "receipts/version"
2
2
  require "receipts/receipt"
3
+ require "receipts/invoice"
@@ -0,0 +1,125 @@
1
+ require 'prawn'
2
+ require 'prawn/table'
3
+
4
+ module Receipts
5
+ class Invoice < Prawn::Document
6
+ attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading, :bill_to, :issue_date, :due_date, :status
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
+ @due_date = attributes.fetch(:due_date)
19
+ @status = attributes.fetch(:status)
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
+ "INVOICE #%{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
+ label "BILL TO"
74
+
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
+
78
+ end
79
+
80
+ bounding_box([250, top], width: 200) do
81
+ label "INVOICE DATE"
82
+
83
+ move_down 5
84
+ text issue_date.to_s, inline_format: true, size: 12, leading: 4
85
+
86
+ move_down 10
87
+ label "DUE DATE"
88
+
89
+ move_down 5
90
+ text due_date.to_s, inline_format: true, size: 12, leading: 4
91
+
92
+ move_down 10
93
+ label "STATUS"
94
+
95
+ move_down 5
96
+ text status, inline_format: true, size: 12, leading: 4
97
+ end
98
+ end
99
+
100
+ def charge_details
101
+ move_down 30
102
+
103
+ borders = line_items.length - 2
104
+
105
+ table(line_items, width: bounds.width, cell_style: { border_color: 'cccccc', inline_format: true }) do
106
+ cells.padding = 12
107
+ cells.borders = []
108
+ row(0..borders).borders = [:bottom]
109
+ end
110
+ end
111
+
112
+ def footer
113
+ move_down 30
114
+ text message, inline_format: true, size: 12, leading: 4
115
+
116
+ move_down 30
117
+ text company.fetch(:name), inline_format: true
118
+ text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
119
+ end
120
+
121
+ def label(text)
122
+ text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
123
+ end
124
+ end
125
+ end
@@ -48,12 +48,14 @@ module Receipts
48
48
  def header
49
49
  move_down 60
50
50
 
51
- logo_path = company.fetch(:logo, '')
51
+ logo = company[:logo]
52
52
 
53
- if logo_path.empty?
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 open(logo_path), height: 32
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' }) 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]
@@ -1,3 +1,3 @@
1
1
  module Receipts
2
- VERSION = "0.2.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -25,5 +25,4 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency 'prawn', '>= 1.3.0', '< 3.0.0'
27
27
  spec.add_dependency 'prawn-table', '~> 0.2.1'
28
- spec.add_dependency 'ttfunk', '~> 1.5.1'
29
28
  end
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: 0.2.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-29 00:00:00.000000000 Z
11
+ date: 2020-08-02 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
@@ -124,12 +110,16 @@ files:
124
110
  - ".github/FUNDING.yml"
125
111
  - ".gitignore"
126
112
  - ".travis.yml"
113
+ - CHANGELOG.md
127
114
  - Gemfile
128
115
  - LICENSE.txt
129
116
  - README.md
130
117
  - Rakefile
118
+ - examples/gorails.png
119
+ - examples/invoice.pdf
131
120
  - examples/receipt.pdf
132
121
  - lib/receipts.rb
122
+ - lib/receipts/invoice.rb
133
123
  - lib/receipts/receipt.rb
134
124
  - lib/receipts/version.rb
135
125
  - receipts.gemspec
@@ -154,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
144
  - !ruby/object:Gem::Version
155
145
  version: '0'
156
146
  requirements: []
157
- rubygems_version: 3.0.3
147
+ rubygems_version: 3.1.2
158
148
  signing_key:
159
149
  specification_version: 4
160
150
  summary: Receipts for your Rails application that works with any payment provider.