receipts 1.0.2 → 1.1.1

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: 3d6ebae8a7ca039194ecf740410f4bf187553f02a31fc78e93b7a34b3b086afb
4
- data.tar.gz: 6617c60cf1d35cf645dc174243f3e4af6aae57d921896bb8fbb772409de54e48
3
+ metadata.gz: dfed87396d5ed2beb0064ead6f0ac9ca457e06a7b67427ec8963b9f6404db0ce
4
+ data.tar.gz: a8a4cbff0f9eadf7552ad5a533522dd6e6746cefa548f3d146a7a3e6bb0f07d3
5
5
  SHA512:
6
- metadata.gz: 7e4793df5b3719104cc32c0fffb24abf28d5346ffbcc69ce91e8c8a7c91ea67be774801112002dd922b6f1647cd37389bc0901ab6f3d6cfc7a5c41102a33805a
7
- data.tar.gz: 9ad1a70dcd8751166d6f125d477e874ec48355f40550b15d2ecde71f42383ace50680174a756a11f75609ea5394066c37e09bd652def125fafeb4a644db17687
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,3 +1,20 @@
1
+ ### Unreleased
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
+
10
+ ### 1.1.0
11
+
12
+ * [NEW] Add Statements - @anquinn
13
+
14
+ ### 1.0.3
15
+
16
+ * [FIX] Fixes typo introduced in 1.0.2
17
+
1
18
  ### 1.0.2
2
19
 
3
20
  * [NEW] Add ability to specify file-like objects for logo
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in receipts.gemspec
4
4
  gemspec
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
 
@@ -227,6 +238,49 @@ You can also use line_items to flexibly generate and display the table with item
227
238
  )
228
239
  ```
229
240
 
241
+ ## Statements
242
+
243
+ Statements follow the exact same set of steps as receipts, with a few minor changes and have a few extra arguments you can use:
244
+
245
+ * `issue_date` - Date the invoice was issued
246
+
247
+ * `start_date` - The start date of the statement period
248
+
249
+ * `start_date` - The end date of the statement period
250
+
251
+ * `bill_to` - A string or Array of lines with account details
252
+
253
+ You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
254
+
255
+ ```ruby
256
+ Receipts::Statement.new(
257
+ id: "123",
258
+ issue_date: Date.today,
259
+ start_date: Date.today - 30,
260
+ end_date: Date.today,
261
+ bill_to: [
262
+ "GoRails, LLC",
263
+ "123 Fake Street",
264
+ "New York City, NY 10012",
265
+ nil,
266
+ "mail@example.com",
267
+ ],
268
+ company: {
269
+ name: "GoRails, LLC",
270
+ address: "123 Fake Street\nNew York City, NY 10012",
271
+ email: "support@example.com",
272
+ logo: File.expand_path("./examples/gorails.png")
273
+ },
274
+ line_items: [
275
+ ["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
276
+ ["GoRails Subscription", "$19.00", "1", "$19.00"],
277
+ [nil, nil, "Subtotal", "$19.00"],
278
+ [nil, nil, "Tax Rate", "0%"],
279
+ [nil, nil, "Total", "$19.00"],
280
+ ],
281
+ )
282
+ ```
283
+
230
284
  ## Contributing
231
285
 
232
286
  1. Fork it ( https://github.com/excid3/receipts/fork )
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('spec')
5
+ RSpec::Core::RakeTask.new("spec")
6
6
 
7
7
  # If you want to make this the default task
8
- task :default => :spec
9
- task :test => :spec
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", Time.now.to_s],
29
+ ["Date", Time.now.to_s],
30
30
  ["Account Billed", "Example User (user@example.com)"],
31
- ["Product", "GoRails"],
32
- ["Amount", "$19.00"],
33
- ["Charged to", "Visa (**** **** **** 1234)"],
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,7 +64,38 @@ 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
+
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/receipt.pdf CHANGED
Binary file
Binary file
data/lib/receipts.rb CHANGED
@@ -1,3 +1,8 @@
1
+ require "open-uri"
1
2
  require "receipts/version"
2
- require "receipts/receipt"
3
- require "receipts/invoice"
3
+
4
+ module Receipts
5
+ autoload :Invoice, "receipts/invoice"
6
+ autoload :Receipt, "receipts/receipt"
7
+ autoload :Statement, "receipts/statement"
8
+ end
@@ -1,22 +1,22 @@
1
- require 'prawn'
2
- require 'prawn/table'
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 = attributes
10
- @id = attributes.fetch(:id)
11
- @company = attributes.fetch(:company)
12
- @line_items = attributes.fetch(: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 = 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)
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
- 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
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
- def default_subheading
34
- "INVOICE #%{id}"
35
- end
33
+ def default_subheading
34
+ "INVOICE #%{id}"
35
+ end
36
36
 
37
- def setup_fonts
38
- font_families.update "Primary" => custom_font
39
- font "Primary"
40
- end
37
+ def setup_fonts
38
+ font_families.update "Primary" => custom_font
39
+ font "Primary"
40
+ end
41
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
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
- def header
53
- move_down 60
54
-
55
- logo = company[:logo]
52
+ def header
53
+ move_down 60
56
54
 
57
- if logo.nil?
58
- move_down 32
59
- elsif logo.is_a?(String)
60
- image open(logo_path), height: 32
61
- else
62
- image logo, height: 32
63
- end
55
+ logo = company[:logo]
64
56
 
65
- move_down 8
66
- label (subheading % {id: id})
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
- move_down 10
65
+ move_down 8
66
+ label(subheading % {id: id})
69
67
 
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"
68
+ move_down 10
74
69
 
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
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
- end
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
- bounding_box([250, top], width: 200) do
81
- label "INVOICE DATE"
79
+ bounding_box([250, top], width: 200) do
80
+ label "INVOICE DATE"
82
81
 
83
- move_down 5
84
- text issue_date.to_s, inline_format: true, size: 12, leading: 4
82
+ move_down 5
83
+ text issue_date.to_s, inline_format: true, size: 12, leading: 4
85
84
 
86
- move_down 10
87
- label "DUE DATE"
85
+ move_down 10
86
+ label "DUE DATE"
88
87
 
89
- move_down 5
90
- text due_date.to_s, inline_format: true, size: 12, leading: 4
88
+ move_down 5
89
+ text due_date.to_s, inline_format: true, size: 12, leading: 4
91
90
 
92
- move_down 10
93
- label "STATUS"
91
+ move_down 10
92
+ label "STATUS"
94
93
 
95
- move_down 5
96
- text status, inline_format: true, size: 12, leading: 4
97
- end
94
+ move_down 5
95
+ text status, inline_format: true, size: 12, leading: 4
98
96
  end
97
+ end
99
98
 
100
- def charge_details
101
- move_down 30
99
+ def charge_details
100
+ move_down 30
102
101
 
103
- borders = line_items.length - 2
102
+ borders = line_items.length - 2
104
103
 
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
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
- def footer
113
- move_down 30
114
- text message, inline_format: true, size: 12, leading: 4
111
+ def footer
112
+ move_down 30
113
+ text message, inline_format: true, size: 12, leading: 4
115
114
 
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
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
- def label(text)
122
- text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
123
- end
120
+ def label(text)
121
+ text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
122
+ end
124
123
  end
125
124
  end
@@ -1,18 +1,18 @@
1
- require 'prawn'
2
- require 'prawn/table'
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 = attributes
10
- @id = attributes.fetch(:id)
11
- @company = attributes.fetch(:company)
12
- @line_items = attributes.fetch(: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 = attributes.fetch(:message) { default_message }
15
- @subheading = attributes.fetch(:subheading) { default_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
- 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
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
- def default_subheading
30
- "RECEIPT FOR CHARGE #%{id}"
31
- end
29
+ def default_subheading
30
+ "RECEIPT FOR CHARGE #%{id}"
31
+ end
32
32
 
33
- def setup_fonts
34
- font_families.update "Primary" => custom_font
35
- font "Primary"
36
- end
33
+ def setup_fonts
34
+ font_families.update "Primary" => custom_font
35
+ font "Primary"
36
+ end
37
37
 
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
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
- def header
49
- move_down 60
48
+ def header
49
+ move_down 60
50
50
 
51
- logo = company[:logo]
51
+ logo = company[:logo]
52
52
 
53
- if logo.nil?
54
- move_down 32
55
- elsif logo.is_a?(String)
56
- image open(logo_path), height: 32
57
- else
58
- image logo, height: 32
59
- end
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
- move_down 8
62
- text "<color rgb='a6a6a6'>#{subheading % { id: id }}</color>", inline_format: true
61
+ move_down 8
62
+ text "<color rgb='a6a6a6'>#{subheading % {id: id}}</color>", inline_format: true
63
63
 
64
- move_down 30
65
- text message, inline_format: true, size: 12.5, leading: 4
66
- end
64
+ move_down 30
65
+ text message, inline_format: true, size: 12.5, leading: 4
66
+ end
67
67
 
68
- def charge_details
69
- move_down 30
68
+ def charge_details
69
+ move_down 30
70
70
 
71
- borders = line_items.length - 2
71
+ borders = line_items.length - 2
72
72
 
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]
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
- 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
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
@@ -0,0 +1,116 @@
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 URI.parse(logo).open, 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
+ end
76
+
77
+ bounding_box([250, top], width: 200) do
78
+ label "STATEMENT DATE"
79
+
80
+ move_down 5
81
+ text issue_date.to_s, inline_format: true, size: 12, leading: 4
82
+
83
+ move_down 10
84
+ label "STATEMENT PERIOD"
85
+
86
+ move_down 5
87
+ text "#{start_date} - #{end_date}", inline_format: true, size: 12, leading: 4
88
+ end
89
+ end
90
+
91
+ def charge_details
92
+ move_down 30
93
+
94
+ borders = line_items.length - 2
95
+
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]
100
+ end
101
+ end
102
+
103
+ def footer
104
+ move_down 30
105
+ text message, inline_format: true, size: 12, leading: 4
106
+
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
111
+
112
+ def label(text)
113
+ text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
114
+ end
115
+ end
116
+ end
@@ -1,3 +1,3 @@
1
1
  module Receipts
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.1"
3
3
  end
data/receipts.gemspec CHANGED
@@ -1,29 +1,28 @@
1
- # coding: utf-8
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 'receipts/version'
3
+ require "receipts/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "receipts"
8
- spec.version = Receipts::VERSION
9
- spec.authors = ["Chris Oliver"]
10
- spec.email = ["excid3@gmail.com"]
11
- spec.summary = %q{Receipts for your Rails application that works with any payment provider.}
12
- spec.description = %q{Receipts for your Rails application that works with any payment provider.}
13
- spec.homepage = ""
14
- spec.license = "MIT"
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 = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
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 'prawn', '>= 1.3.0', '< 3.0.0'
27
- spec.add_dependency 'prawn-table', '~> 0.2.1'
28
- spec.add_dependency 'ttfunk', '~> 1.5.1'
26
+ spec.add_dependency "prawn", ">= 1.3.0", "< 3.0.0"
27
+ spec.add_dependency "prawn-table", "~> 0.2.1"
29
28
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
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", "GoRails"],
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
@@ -1,9 +1,9 @@
1
1
  begin
2
- require 'pry'
2
+ require "pry"
3
3
  rescue LoadError
4
4
  end
5
5
 
6
- require 'receipts'
6
+ require "receipts"
7
7
 
8
8
  RSpec.configure do |config|
9
9
  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: 1.0.2
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: 2020-07-05 00:00:00.000000000 Z
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
@@ -100,20 +114,6 @@ dependencies:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
116
  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
117
  description: Receipts for your Rails application that works with any payment provider.
118
118
  email:
119
119
  - excid3@gmail.com
@@ -122,6 +122,7 @@ extensions: []
122
122
  extra_rdoc_files: []
123
123
  files:
124
124
  - ".github/FUNDING.yml"
125
+ - ".github/workflows/ci.yml"
125
126
  - ".gitignore"
126
127
  - ".travis.yml"
127
128
  - CHANGELOG.md
@@ -132,9 +133,11 @@ files:
132
133
  - examples/gorails.png
133
134
  - examples/invoice.pdf
134
135
  - examples/receipt.pdf
136
+ - examples/statement.pdf
135
137
  - lib/receipts.rb
136
138
  - lib/receipts/invoice.rb
137
139
  - lib/receipts/receipt.rb
140
+ - lib/receipts/statement.rb
138
141
  - lib/receipts/version.rb
139
142
  - receipts.gemspec
140
143
  - spec/receipts_spec.rb
@@ -158,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
161
  - !ruby/object:Gem::Version
159
162
  version: '0'
160
163
  requirements: []
161
- rubygems_version: 3.1.4
164
+ rubygems_version: 3.2.15
162
165
  signing_key:
163
166
  specification_version: 4
164
167
  summary: Receipts for your Rails application that works with any payment provider.