receipts 0.2.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ffe69c912de6f283a23d70695c3c83c3e3fdcb9e
4
- data.tar.gz: d02dcdf880e8d20a212fb2dad00a30908169ed4f
2
+ SHA256:
3
+ metadata.gz: '065796e25d569a927cf67ebaa208b8d33c189a4ce3786196dc236c563191bb89'
4
+ data.tar.gz: 4f59197b6b35a5cbd71f23586b69a3808655b79127c2c520dd13ee9d6c7efc3d
5
5
  SHA512:
6
- metadata.gz: 17f10bce71d24b7b7a1c7f578786610fc10b0cea401457e3990d7ab9de49426ddfaeaa68a8d086475511a0b16089d5bf0bb5991d83186ca974174e99c09552c9
7
- data.tar.gz: 1f0142ca8dfd892f54b8050db23da2b7e51a2e69ad64b7cb34f6aa44b72eaf13f499a58083a7d6ed405b0406a3e0bf7d529a26385446b3bb51aa94214fa79fd0
6
+ metadata.gz: d44d166eef2ea75f01ffe9c990b42e6a59ab932bc4e9a773ba00b7f11944448e1e4a16b426c6fc0649b472839825244f84e9825860bae0efb7d1d8c34209541b
7
+ data.tar.gz: 6c2a3f9378751854d21daf34de2940a8a09f112a629fbaccbfb90f35c7e8bef56179cbae596d319749f165dd77e5413f712a8bdbb3d7b7e23f85cea9ecd6d321
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [excid3] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .DS_Store
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.2.2
3
+ - 2.3.3
4
+ - 2.4.0
@@ -0,0 +1,7 @@
1
+ ### 1.0.1
2
+
3
+ * [FIX] Make tables full width
4
+
5
+ ### 1.0.0
6
+
7
+ * [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
 
@@ -60,11 +60,12 @@ class Charge < ActiveRecord::Base
60
60
  def receipt
61
61
  Receipts::Receipt.new(
62
62
  id: id,
63
+ subheading: "RECEIPT FOR CHARGE #%{id}",
63
64
  product: "GoRails",
64
65
  company: {
65
- name: "One Month, Inc.",
66
- address: "37 Great Jones\nFloor 2\nNew York City, NY 10012",
67
- email: "teachers@onemonth.com",
66
+ name: "GoRails, LLC.",
67
+ address: "123 Fake Street\nNew York City, NY 10012",
68
+ email: "support@example.com",
68
69
  logo: Rails.root.join("app/assets/images/one-month-dark.png")
69
70
  },
70
71
  line_items: [
@@ -169,9 +170,52 @@ resources :charges
169
170
  <%= link_to "Download Receipt", charge_path(@charge, format: :pdf) %>
170
171
  ```
171
172
 
173
+ ## Invoices
174
+
175
+ Invoices follow the exact same set of steps as above, with a few minor changes and have a few extra arguments you can use:
176
+
177
+ * `issue_date` - Date the invoice was issued
178
+
179
+ * `due_date` - Date the invoice payment is due
180
+
181
+ * `status` - A status for the invoice (Pending, Paid, etc)
182
+
183
+ * `bill_to` - A string or Array of lines with billing details
184
+
185
+ You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
186
+
187
+ ```ruby
188
+ Receipts::Invoice.new(
189
+ id: "123",
190
+ issue_date: Date.today,
191
+ due_date: Date.today + 30,
192
+ status: "<b><color rgb='#5eba7d'>PAID</color></b>",
193
+ bill_to: [
194
+ "GoRails, LLC",
195
+ "123 Fake Street",
196
+ "New York City, NY 10012",
197
+ nil,
198
+ "mail@example.com",
199
+ ],
200
+ company: {
201
+ name: "GoRails, LLC",
202
+ address: "123 Fake Street\nNew York City, NY 10012",
203
+ email: "support@example.com",
204
+ logo: File.expand_path("./examples/gorails.png")
205
+ },
206
+ line_items: [
207
+ ["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
208
+ ["GoRails Subscription", "$19.00", "1", "$19.00"],
209
+ [nil, nil, "Subtotal", "$19.00"],
210
+ [nil, nil, "Tax Rate", "0%"],
211
+ [nil, nil, "Total", "$19.00"],
212
+ ],
213
+ )
214
+ ```
215
+
172
216
  ## Contributing
173
217
 
174
- 1. Fork it ( https://github.com/[my-github-username]/receipts/fork )
218
+ 1. Fork it ( https://github.com/excid3/receipts/fork )
175
219
  2. Create your feature branch (`git checkout -b my-new-feature`)
176
220
  3. Commit your changes (`git commit -am 'Add some feature'`)
177
221
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -10,3 +10,58 @@ task :test => :spec
10
10
  task :console do
11
11
  exec "irb -r receipts -I ./lib"
12
12
  end
13
+
14
+ task :receipt do
15
+ require "./lib/receipts"
16
+
17
+ Receipts::Receipt.new(
18
+ id: "123",
19
+ subheading: "RECEIPT FOR CHARGE #1",
20
+ product: "GoRails",
21
+ company: {
22
+ name: "GoRails, LLC",
23
+ address: "123 Fake Street\nNew York City, NY 10012",
24
+ email: "support@example.com",
25
+ logo: File.expand_path("./examples/gorails.png")
26
+ },
27
+ line_items: [
28
+ ["Date", Time.now.to_s],
29
+ ["Account Billed", "Example User (user@example.com)"],
30
+ ["Product", "GoRails"],
31
+ ["Amount", "$19.00"],
32
+ ["Charged to", "Visa (**** **** **** 1234)"],
33
+ ["Transaction ID", "123456"]
34
+ ],
35
+ ).render_file "examples/receipt.pdf"
36
+ end
37
+
38
+ task :invoice do
39
+ require "./lib/receipts"
40
+
41
+ Receipts::Invoice.new(
42
+ id: "123",
43
+ issue_date: Date.today,
44
+ due_date: Date.today + 30,
45
+ status: "<b><color rgb='#5eba7d'>PAID</color></b>",
46
+ bill_to: [
47
+ "GoRails, LLC",
48
+ "Address",
49
+ "City, State Zipcode",
50
+ nil,
51
+ "mail@example.com",
52
+ ],
53
+ company: {
54
+ name: "GoRails, LLC",
55
+ address: "123 Fake Street\nNew York City, NY 10012",
56
+ email: "support@example.com",
57
+ logo: File.expand_path("./examples/gorails.png")
58
+ },
59
+ line_items: [
60
+ ["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
61
+ ["GoRails Subscription", "$19.00", "1", "$19.00"],
62
+ [nil, nil, "Subtotal", "$19.00"],
63
+ [nil, nil, "Tax Rate", "0%"],
64
+ [nil, nil, "Amount Due", "$19.00"],
65
+ ],
66
+ ).render_file "examples/invoice.pdf"
67
+ 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,123 @@
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_path = company.fetch(:logo, '')
56
+
57
+ if logo_path.empty?
58
+ move_down 32
59
+ else
60
+ image open(logo_path), height: 32
61
+ end
62
+
63
+ move_down 8
64
+ label (subheading % {id: id})
65
+
66
+ move_down 10
67
+
68
+ # Cache the Y value so we can have both boxes at the same height
69
+ top = y
70
+ bounding_box([0, y], width: 200) do
71
+ label "BILL TO"
72
+
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 "INVOICE 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 "DUE DATE"
86
+
87
+ move_down 5
88
+ text due_date.to_s, inline_format: true, size: 12, leading: 4
89
+
90
+ move_down 10
91
+ label "STATUS"
92
+
93
+ move_down 5
94
+ text status, inline_format: true, size: 12, leading: 4
95
+ end
96
+ end
97
+
98
+ def charge_details
99
+ move_down 30
100
+
101
+ borders = line_items.length - 2
102
+
103
+ table(line_items, width: bounds.width, cell_style: { border_color: 'cccccc', inline_format: true }) do
104
+ cells.padding = 12
105
+ cells.borders = []
106
+ row(0..borders).borders = [:bottom]
107
+ end
108
+ end
109
+
110
+ def footer
111
+ move_down 30
112
+ text message, inline_format: true, size: 12, leading: 4
113
+
114
+ move_down 30
115
+ text company.fetch(:name), inline_format: true
116
+ text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
117
+ end
118
+
119
+ def label(text)
120
+ text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
121
+ end
122
+ end
123
+ end
@@ -3,7 +3,7 @@ require 'prawn/table'
3
3
 
4
4
  module Receipts
5
5
  class Receipt < Prawn::Document
6
- attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product
6
+ attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading
7
7
 
8
8
  def initialize(attributes)
9
9
  @attributes = attributes
@@ -12,6 +12,7 @@ module Receipts
12
12
  @line_items = attributes.fetch(:line_items)
13
13
  @custom_font = attributes.fetch(:font, {})
14
14
  @message = attributes.fetch(:message) { default_message }
15
+ @subheading = attributes.fetch(:subheading) { default_subheading }
15
16
 
16
17
  super(margin: 0)
17
18
 
@@ -22,7 +23,11 @@ module Receipts
22
23
  private
23
24
 
24
25
  def default_message
25
- "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)}.com?subject=\"Charge ##{id}\"'><b>#{company.fetch(:email)}</b></link></color>."
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
+
29
+ def default_subheading
30
+ "RECEIPT FOR CHARGE #%{id}"
26
31
  end
27
32
 
28
33
  def setup_fonts
@@ -43,14 +48,16 @@ module Receipts
43
48
  def header
44
49
  move_down 60
45
50
 
46
- if company.has_key? :logo
47
- image open(company.fetch(:logo)), height: 32
48
- else
51
+ logo_path = company.fetch(:logo, '')
52
+
53
+ if logo_path.empty?
49
54
  move_down 32
55
+ else
56
+ image open(logo_path), height: 32
50
57
  end
51
58
 
52
59
  move_down 8
53
- text "<color rgb='a6a6a6'>RECEIPT FOR CHARGE ##{id}</color>", inline_format: true
60
+ text "<color rgb='a6a6a6'>#{subheading % { id: id }}</color>", inline_format: true
54
61
 
55
62
  move_down 30
56
63
  text message, inline_format: true, size: 12.5, leading: 4
@@ -61,7 +68,7 @@ module Receipts
61
68
 
62
69
  borders = line_items.length - 2
63
70
 
64
- table(line_items, cell_style: { border_color: 'cccccc' }) do
71
+ table(line_items, width: bounds.width, cell_style: { border_color: 'cccccc', inline_format: true }) do
65
72
  cells.padding = 12
66
73
  cells.borders = []
67
74
  row(0..borders).borders = [:bottom]
@@ -1,3 +1,3 @@
1
1
  module Receipts
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "pry"
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'
28
29
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: receipts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
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: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2020-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,20 @@ 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
103
117
  description: Receipts for your Rails application that works with any payment provider.
104
118
  email:
105
119
  - excid3@gmail.com
@@ -107,14 +121,19 @@ executables: []
107
121
  extensions: []
108
122
  extra_rdoc_files: []
109
123
  files:
124
+ - ".github/FUNDING.yml"
110
125
  - ".gitignore"
111
126
  - ".travis.yml"
127
+ - CHANGELOG.md
112
128
  - Gemfile
113
129
  - LICENSE.txt
114
130
  - README.md
115
131
  - Rakefile
132
+ - examples/gorails.png
133
+ - examples/invoice.pdf
116
134
  - examples/receipt.pdf
117
135
  - lib/receipts.rb
136
+ - lib/receipts/invoice.rb
118
137
  - lib/receipts/receipt.rb
119
138
  - lib/receipts/version.rb
120
139
  - receipts.gemspec
@@ -124,7 +143,7 @@ homepage: ''
124
143
  licenses:
125
144
  - MIT
126
145
  metadata: {}
127
- post_install_message:
146
+ post_install_message:
128
147
  rdoc_options: []
129
148
  require_paths:
130
149
  - lib
@@ -139,9 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
158
  - !ruby/object:Gem::Version
140
159
  version: '0'
141
160
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.6.8
144
- signing_key:
161
+ rubygems_version: 3.1.4
162
+ signing_key:
145
163
  specification_version: 4
146
164
  summary: Receipts for your Rails application that works with any payment provider.
147
165
  test_files: