stripe_invoice 0.4.1 → 0.4.2

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
  SHA1:
3
- metadata.gz: 5847b25cb39ed67a3982233423427cc9255176f0
4
- data.tar.gz: 195a936e7bbcd0cb063fa680db16d0015a99409a
3
+ metadata.gz: 4242a3c58f8c9de6a698c8bad07af86ba3e9a2cd
4
+ data.tar.gz: 027b5f465b65caafeac60a58a6ebff931c27ef26
5
5
  SHA512:
6
- metadata.gz: 8874ad8fa24ea69f7168f4a5c8f52a49ef1ff2ea0d66047095450118830a474d4438703420ea6819e16a6d68cc8918f48120584a71cec338f2f7adb2b9e4b10c
7
- data.tar.gz: 22b608ca46be7c0c08c007895de5851bf8235feaad501c65f6f2262d731cdaa727b36fa51ad1f8244f9a29142b19ada3d646f7e0916b7d5f6801420418a90136
6
+ metadata.gz: 776db1e5aa2d16e979474cf242b942eed67b6eb471ac32e95a404dd471e7c96fcd79ead6f48a9ff10cdcdd6eaddc6025fbb82569abea3d383b64fd8102ac0589
7
+ data.tar.gz: bcdede71a52a9cafea9487a18411c4280b475c001a0a1113fe320dcb258d9f9d6b686ba53dbb255cb548cb7e3611a7ff2a716c08f2c987de44fcebf6ef2fd40a
@@ -49,7 +49,7 @@ module StripeInvoice
49
49
  locals: {sicharges: arr_data, year: @year, totals: totals(arr_data)},
50
50
  formats: [:pdf]
51
51
 
52
- #InvoiceMailer.tax_report.deliver!
52
+ InvoiceMailer.tax_report(res).deliver! #unless ::Rails.env.development?
53
53
  end
54
54
 
55
55
 
@@ -61,6 +61,7 @@ module StripeInvoice
61
61
  def totals(sicharges)
62
62
  result = {
63
63
  transaction_volume: total_transaction_volume(sicharges),
64
+ transaction_volume_by_country: transaction_volume_by_country(sicharges),
64
65
  }
65
66
  end
66
67
 
@@ -69,5 +70,27 @@ module StripeInvoice
69
70
  number_to_currency(sicharges.inject(0) {|sum, hash_ch| sum + hash_ch[:bt][:amount]} / 100.0,
70
71
  unit: "#{sicharges.first[:bt][:currency].upcase} ")
71
72
  end
73
+
74
+ def transaction_volume_by_country(sicharges)
75
+ result = {}
76
+
77
+ sicharges.each do |hash_ch|
78
+ # get value or 0 if not present
79
+ value = result.fetch(hash_ch[:owner].country) { 0 }
80
+
81
+ if hash_ch[:refunds]
82
+ hash_ch[:refunds].each do |refund|
83
+ value -= refund[:bt][:amount]
84
+ end
85
+ end # deduct refunds
86
+ result[hash_ch[:owner].country] = value + hash_ch[:bt][:amount]
87
+ end
88
+
89
+ result.each do |key, value|
90
+ result[key] = value / 100.0
91
+ end
92
+
93
+ result.with_indifferent_access
94
+ end
72
95
  end
73
96
  end
@@ -20,16 +20,17 @@ module StripeInvoice
20
20
  end
21
21
 
22
22
 
23
- def tax_report
24
- attachments['tax-report.pdf'] = {
25
- content: File.read(::Rails.root.join('tmp', 'tax_report.pdf')),
26
- mime_type: "application/pdf"
27
- }
23
+ def tax_report(rendered_pdf)
24
+ attachments['income-report.pdf'] = rendered_pdf # File.read(::Rails.root.join('tmp', 'tax_report.pdf'))
25
+ # {
26
+ # content: File.read(::Rails.root.join('tmp', 'tax_report.pdf')),
27
+ # mime_type: "application/pdf"
28
+ # }
28
29
 
29
30
  # sends the email to the default from address
30
31
  addr_to = ActionMailer::Base.default[:from]
31
- mail subject: "Tax report", to: addr_to
32
- puts "[InvoiceMailer] tax report sent to #{addr_to}"
32
+ mail subject: "Income report", to: addr_to
33
+ puts "[InvoiceMailer] income report sent to #{addr_to}"
33
34
  end
34
35
  end
35
36
  end
@@ -0,0 +1,4 @@
1
+ Hi there,
2
+
3
+ Here's your income report for last year.
4
+ Note: I can not be held accountable for the data presented here. Use at your own risk.
@@ -4,12 +4,28 @@ prawn_document(:page_layout => :portrait) do |pdf|
4
4
  pdf.fill_color "333333"
5
5
  pdf.font_size = 14
6
6
 
7
- pdf.font_size(17.5) { pdf.text "Tax Report", :style => :bold }
8
-
7
+ pdf.font_size(17.5) { pdf.text "Income Report", :style => :bold }
8
+ pdf.text "DO NOT USE THIS DATA FOR REPORTING TO YOUR TAX AUTHORITY OR ANYTHING WHERE THAT DATA NEEDS TO BE ACCURATE." +
9
+ "I CAN NOT BE HELD ACCOUNTABLE FOR ANY DAMAGE DONE FROM USING THIS DATA"
9
10
 
10
11
  pdf.move_down 10
11
12
  pdf.text "Total charges in #{year}: #{sicharges.size}"
12
13
  pdf.text "Total transactions: #{totals[:transaction_volume]}"
14
+
15
+ rows = [["Country", "Transaction volume"]]
16
+ bt_unit = sicharges.first[:bt][:currency].upcase
17
+ totals[:transaction_volume_by_country].each do |country, volume|
18
+ rows << [country, number_to_currency(volume, unit: "#{bt_unit} ")]
19
+ end
20
+
21
+ pdf.table(rows,:cell_style => { :border_width => 1,:border_color=> 'C1C1C1', :width=>'100%' }) do |table|
22
+ table.column(0).style(:align => :left)
23
+ table.column(1).style(:align => :right)
24
+ table.column(0).width = 320
25
+ table.column(1).width = 140
26
+ table.row(0).style(:border_width => 1, :borders => [:top], :color => 'dddddd')
27
+ end
28
+
13
29
  pdf.start_new_page
14
30
  sicharges.each do |hash_ch|
15
31
  pdf.text "Invoice: #{hash_ch[:charge].invoice_number}" +
@@ -1,3 +1,3 @@
1
1
  module StripeInvoice
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -19,6 +19,6 @@ namespace :stripe_invoice do
19
19
 
20
20
  task(:tax_report => :environment) do
21
21
  #Delayed::Job.enqueue StripeInvoice::DJTaxReport.new
22
- StripeInvoice::DJTaxReport.new(2015).perform
22
+ StripeInvoice::DJTaxReport.new.perform
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe_invoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Engelhardt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-22 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -223,6 +223,7 @@ files:
223
223
  - app/views/layouts/stripe_invoice/application.html.erb
224
224
  - app/views/stripe_invoice/invoice_mailer/new_invoice.text.erb
225
225
  - app/views/stripe_invoice/invoice_mailer/refund_invoice.text.erb
226
+ - app/views/stripe_invoice/invoice_mailer/tax_report.text.erb
226
227
  - app/views/stripe_invoice/invoices/index.html.haml
227
228
  - app/views/stripe_invoice/invoices/show.html.haml
228
229
  - app/views/stripe_invoice/invoices/show.pdf.prawn