skv_report 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gempush.yml +41 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +115 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/skv_report.rb +11 -0
- data/lib/skv_report/exchange_rates.rb +49 -0
- data/lib/skv_report/stripe.rb +126 -0
- data/lib/skv_report/stripe_charge_row.rb +64 -0
- data/lib/skv_report/version.rb +5 -0
- data/skv_report.gemspec +40 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fd4ecad8c4ea82f45641e416b37f9046fe39048b7bde532e2998f3ede8d934b
|
4
|
+
data.tar.gz: e359d4e13c9ca9a311c06bb3450cb7d0f008f80b9d5ada0dbdfded8b3aef50ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5bcf4cafe1ba9310c2f17c356414346608ec9fd3c17bf65b2e53ddc3d300f8c4156ad3fdb4fbdb1a8b26d4dd3246cc114841d77235e21fcb4be051c6403ba33
|
7
|
+
data.tar.gz: 14ea05feda440ea52e57a38e2c6ff670cb15321e577461534fc19ee1c95f8c74ae17b1a62eb2a726d446cb7d9150994e256ffc102936259eaae3ef11c29fd406
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Gem push
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types: [published]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
github:
|
9
|
+
name: Build + Publish to GitHub
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- name: Set up Ruby 2.6
|
14
|
+
uses: actions/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
version: 2.6.5
|
17
|
+
- name: Publish to GitHub
|
18
|
+
uses: jstastny/publish-gem-to-github@master
|
19
|
+
with:
|
20
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
21
|
+
owner: standout
|
22
|
+
|
23
|
+
rubygems:
|
24
|
+
name: Build + Publish to Rubygems
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby 2.6
|
29
|
+
uses: actions/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
version: 2.6.x
|
32
|
+
- name: Publish to RubyGems
|
33
|
+
run: |
|
34
|
+
mkdir -p $HOME/.gem
|
35
|
+
touch $HOME/.gem/credentials
|
36
|
+
chmod 0600 $HOME/.gem/credentials
|
37
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
38
|
+
gem build *.gemspec
|
39
|
+
gem push *.gem
|
40
|
+
env:
|
41
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.5
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.3
|
17
|
+
bundle install
|
18
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
- rubocop-rake
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
NewCops: enable
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 80
|
12
|
+
|
13
|
+
Metrics/BlockLength:
|
14
|
+
Exclude:
|
15
|
+
- 'spec/**/*'
|
16
|
+
|
17
|
+
RSpec/NestedGroups:
|
18
|
+
Max: 4
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in moss_generator.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
|
12
|
+
gem 'pry-byebug'
|
13
|
+
gem 'rubocop', '~> 1.7'
|
14
|
+
gem 'rubocop-performance', '~> 1.9'
|
15
|
+
gem 'rubocop-rake', '~> 0.5'
|
16
|
+
gem 'rubocop-rspec', '~> 2.1'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
skv_report (0.1.0)
|
5
|
+
money (~> 6.14)
|
6
|
+
valvat (~> 1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
akami (1.3.1)
|
14
|
+
gyoku (>= 0.4.0)
|
15
|
+
nokogiri
|
16
|
+
ast (2.4.1)
|
17
|
+
builder (3.2.4)
|
18
|
+
byebug (11.1.3)
|
19
|
+
coderay (1.1.3)
|
20
|
+
concurrent-ruby (1.1.7)
|
21
|
+
diff-lcs (1.4.4)
|
22
|
+
gyoku (1.3.1)
|
23
|
+
builder (>= 2.1.2)
|
24
|
+
httpi (2.4.5)
|
25
|
+
rack
|
26
|
+
socksify
|
27
|
+
i18n (1.8.7)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
method_source (1.0.0)
|
30
|
+
money (6.14.0)
|
31
|
+
i18n (>= 0.6.4, <= 2)
|
32
|
+
nokogiri (1.11.1-x86_64-darwin)
|
33
|
+
racc (~> 1.4)
|
34
|
+
nori (2.6.0)
|
35
|
+
parallel (1.20.1)
|
36
|
+
parser (3.0.0.0)
|
37
|
+
ast (~> 2.4.1)
|
38
|
+
pry (0.13.1)
|
39
|
+
coderay (~> 1.1)
|
40
|
+
method_source (~> 1.0)
|
41
|
+
pry-byebug (3.9.0)
|
42
|
+
byebug (~> 11.0)
|
43
|
+
pry (~> 0.13.0)
|
44
|
+
public_suffix (4.0.6)
|
45
|
+
racc (1.5.2)
|
46
|
+
rack (2.2.3)
|
47
|
+
rainbow (3.0.0)
|
48
|
+
rake (13.0.3)
|
49
|
+
regexp_parser (2.0.3)
|
50
|
+
rexml (3.2.4)
|
51
|
+
rspec (3.10.0)
|
52
|
+
rspec-core (~> 3.10.0)
|
53
|
+
rspec-expectations (~> 3.10.0)
|
54
|
+
rspec-mocks (~> 3.10.0)
|
55
|
+
rspec-core (3.10.1)
|
56
|
+
rspec-support (~> 3.10.0)
|
57
|
+
rspec-expectations (3.10.1)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.10.0)
|
60
|
+
rspec-mocks (3.10.1)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.10.0)
|
63
|
+
rspec-support (3.10.1)
|
64
|
+
rubocop (1.7.0)
|
65
|
+
parallel (~> 1.10)
|
66
|
+
parser (>= 2.7.1.5)
|
67
|
+
rainbow (>= 2.2.2, < 4.0)
|
68
|
+
regexp_parser (>= 1.8, < 3.0)
|
69
|
+
rexml
|
70
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
71
|
+
ruby-progressbar (~> 1.7)
|
72
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
73
|
+
rubocop-ast (1.3.0)
|
74
|
+
parser (>= 2.7.1.5)
|
75
|
+
rubocop-performance (1.9.1)
|
76
|
+
rubocop (>= 0.90.0, < 2.0)
|
77
|
+
rubocop-ast (>= 0.4.0)
|
78
|
+
rubocop-rake (0.5.1)
|
79
|
+
rubocop
|
80
|
+
rubocop-rspec (2.1.0)
|
81
|
+
rubocop (~> 1.0)
|
82
|
+
rubocop-ast (>= 1.1.0)
|
83
|
+
ruby-progressbar (1.10.1)
|
84
|
+
savon (2.12.1)
|
85
|
+
akami (~> 1.2)
|
86
|
+
builder (>= 2.1.2)
|
87
|
+
gyoku (~> 1.2)
|
88
|
+
httpi (~> 2.3)
|
89
|
+
nokogiri (>= 1.8.1)
|
90
|
+
nori (~> 2.4)
|
91
|
+
wasabi (~> 3.4)
|
92
|
+
socksify (1.7.1)
|
93
|
+
unicode-display_width (1.7.0)
|
94
|
+
valvat (1.1.0)
|
95
|
+
savon (>= 2.3.0)
|
96
|
+
wasabi (3.6.1)
|
97
|
+
addressable
|
98
|
+
httpi (~> 2.0)
|
99
|
+
nokogiri (>= 1.4.2)
|
100
|
+
|
101
|
+
PLATFORMS
|
102
|
+
x86_64-darwin-19
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
pry-byebug
|
106
|
+
rake (~> 13.0)
|
107
|
+
rspec (~> 3.0)
|
108
|
+
rubocop (~> 1.7)
|
109
|
+
rubocop-performance (~> 1.9)
|
110
|
+
rubocop-rake (~> 0.5)
|
111
|
+
rubocop-rspec (~> 2.1)
|
112
|
+
skv_report!
|
113
|
+
|
114
|
+
BUNDLED WITH
|
115
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 frdrkolsson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# SKVReport
|
2
|
+
|
3
|
+
Generate CSV-formatted string from specified data to be able to create a
|
4
|
+
[Periodisk Sammanställningsrapport](https://www.skatteverket.se/foretagochorganisationer/moms/deklareramoms/periodisksammanstallning.4.58d555751259e4d661680001093.html) file for Skatteverket.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'skv_report'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install skv_report
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Stripe
|
25
|
+
```ruby
|
26
|
+
# charges - array of charges in json-format from stripe
|
27
|
+
# period - for which period of the year this report should be for
|
28
|
+
# year - corresponding year for the period
|
29
|
+
# company_information - needs to contain the following information:
|
30
|
+
# {
|
31
|
+
# vat_number: String, # vat number of the selling company
|
32
|
+
# name: String, # contact name on selling company
|
33
|
+
# phone: String, # phone to contact on selling company
|
34
|
+
# email: String, # optional email to contact on selling company
|
35
|
+
# type_of_sales: String, # one of the following three
|
36
|
+
# ['wares', 'third_party', 'services']
|
37
|
+
# }
|
38
|
+
# rates - object containing exchange rates
|
39
|
+
|
40
|
+
SKVReport::Stripe.call(charges, period, year, company_information, rates)
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Exchange rates
|
50
|
+
|
51
|
+
Exchange rates needs to be passed.
|
52
|
+
[exchangerateapi](https://exchangeratesapi.io) gives us a JSON-object suited for
|
53
|
+
this gem.
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/standout/skv_report.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'skv_report'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
require 'pry'
|
12
|
+
Pry.start
|
13
|
+
|
14
|
+
# require 'irb'
|
15
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/skv_report.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'skv_report/version'
|
4
|
+
require_relative 'skv_report/stripe'
|
5
|
+
require_relative 'skv_report/exchange_rates'
|
6
|
+
|
7
|
+
# Generate CSV-formatted string for SKV report
|
8
|
+
module SKVReport
|
9
|
+
Money.default_currency = Money::Currency.new('SEK')
|
10
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
|
11
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module SKVReport
|
6
|
+
# Fetches relevant exchange rate for given date and given currency
|
7
|
+
class ExchangeRates
|
8
|
+
class NoRatesForDateError < StandardError; end
|
9
|
+
|
10
|
+
class NoRateForCurrencyError < StandardError; end
|
11
|
+
|
12
|
+
attr_reader :rates, :start_at, :base, :end_at
|
13
|
+
|
14
|
+
def initialize(rates = {})
|
15
|
+
@rates = rates['rates']
|
16
|
+
@base_currency = rates['base']
|
17
|
+
@start_at = Date.parse(rates['start_at'])
|
18
|
+
@end_at = Date.parse(rates['end_at'])
|
19
|
+
end
|
20
|
+
|
21
|
+
def rate_for(to_currency, date)
|
22
|
+
date_for_rate = find_previous_existing_date(Date.parse(date))
|
23
|
+
raise_no_rates_for_date_error(date) if date_for_rate.nil?
|
24
|
+
|
25
|
+
rate = rates.dig(date_for_rate.to_s, to_currency.upcase)
|
26
|
+
return rate unless rate.nil?
|
27
|
+
|
28
|
+
raise NoRateForCurrencyError, "currency: #{to_currency}\nrates: #{rates}"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Test number of times this recursive method is called?
|
34
|
+
def find_previous_existing_date(date)
|
35
|
+
return nil if date_outside_of_range?(date)
|
36
|
+
|
37
|
+
rates[date.to_s].nil? ? find_previous_existing_date(date - 1) : date
|
38
|
+
end
|
39
|
+
|
40
|
+
def date_outside_of_range?(date)
|
41
|
+
date < start_at || date > end_at
|
42
|
+
end
|
43
|
+
|
44
|
+
def raise_no_rates_for_date_error(date)
|
45
|
+
raise NoRatesForDateError,
|
46
|
+
"date: #{date}\nstart_at: #{start_at}\nend_at: #{end_at}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require 'skv_report/stripe_charge_row'
|
5
|
+
|
6
|
+
module SKVReport
|
7
|
+
# Generate SKV CSV string from Stripe charge
|
8
|
+
class Stripe
|
9
|
+
class NoTurnoverCountryError < StandardError; end
|
10
|
+
|
11
|
+
class UndefinedTypeOfSalesError < StandardError; end
|
12
|
+
|
13
|
+
attr_reader :charges, :period, :year, :company_information, :rates
|
14
|
+
|
15
|
+
#
|
16
|
+
# company_information needs to contain the following information
|
17
|
+
# {
|
18
|
+
# vat_number: String, # vat number of the selling company
|
19
|
+
# name: String, # contact name on selling company
|
20
|
+
# phone: String, # phone to contact on selling company
|
21
|
+
# email: String, # optional email to contact on selling company
|
22
|
+
# type_of_sales: String, # one of the following three
|
23
|
+
# ['wares', 'third_party', 'services']
|
24
|
+
# }
|
25
|
+
#
|
26
|
+
# Send rates to ImportExchangeRates, and send the object to stripe charge
|
27
|
+
# row, and then call rate for in there? Nah...
|
28
|
+
def initialize(charges, period, year, company_information = {}, rates = {})
|
29
|
+
@charges = charges
|
30
|
+
@company_information = company_information
|
31
|
+
@period = period
|
32
|
+
@year = year
|
33
|
+
@rates = rates
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.call(charges, period, year, company_information = {}, rates = {})
|
37
|
+
new(charges, period, year, company_information, rates).call
|
38
|
+
end
|
39
|
+
|
40
|
+
def call
|
41
|
+
CSV.generate(csv_options) do |csv|
|
42
|
+
csv << first_row
|
43
|
+
csv << second_row
|
44
|
+
generate_charge_rows(csv)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def first_row
|
51
|
+
['SKV574008']
|
52
|
+
end
|
53
|
+
|
54
|
+
def second_row
|
55
|
+
[company_information['vat_number'],
|
56
|
+
year_and_period,
|
57
|
+
company_information['name'][0...35],
|
58
|
+
sanitized_phone,
|
59
|
+
company_information['email']]
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_charge_rows(csv)
|
63
|
+
build_charge_rows.each { |row| csv << row }
|
64
|
+
end
|
65
|
+
|
66
|
+
def group_charge_rows
|
67
|
+
charge_rows = charges.map do |charge|
|
68
|
+
charge_row = SKVReport::StripeChargeRow.new(charge, exchange_rates)
|
69
|
+
next if charge_row.skippable?
|
70
|
+
|
71
|
+
charge_row
|
72
|
+
end.compact
|
73
|
+
|
74
|
+
charge_rows.group_by(&:buyer_vat_number)
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_charge_rows
|
78
|
+
group_charge_rows.map do |vat_number, charges|
|
79
|
+
sales_row(vat_number, charges)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def sales_row(vat_number, charges)
|
84
|
+
[vat_number].concat(evaluate_amount_position(charges))
|
85
|
+
end
|
86
|
+
|
87
|
+
def evaluate_amount_position(charges)
|
88
|
+
case company_information['type_of_sales']
|
89
|
+
when 'wares' then [charges.sum(&:sales_amount), nil, nil]
|
90
|
+
when 'third_party' then [nil, charges.sum(&:sales_amount), nil]
|
91
|
+
when 'services' then [nil, nil, charges.sum(&:sales_amount)]
|
92
|
+
else
|
93
|
+
raise UndefinedTypeOfSalesError,
|
94
|
+
"#{company_information['type_of_sales']} is not valid"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def csv_options
|
99
|
+
{ col_sep: column_separator, row_sep: row_separator }
|
100
|
+
end
|
101
|
+
|
102
|
+
def row_separator
|
103
|
+
";\r\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
def column_separator
|
107
|
+
';'
|
108
|
+
end
|
109
|
+
|
110
|
+
def year_and_period
|
111
|
+
"#{year_short}-#{period}"
|
112
|
+
end
|
113
|
+
|
114
|
+
def year_short
|
115
|
+
Date.new(year).strftime('%y')
|
116
|
+
end
|
117
|
+
|
118
|
+
def sanitized_phone
|
119
|
+
company_information['phone'].gsub(/[^0-9\-+]/, '')[0...17]
|
120
|
+
end
|
121
|
+
|
122
|
+
def exchange_rates
|
123
|
+
@exchange_rates ||= ExchangeRates.new(rates)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'money'
|
4
|
+
require 'valvat/local'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
module SKVReport
|
8
|
+
# Parse charge data from single Stripe charge
|
9
|
+
# Sales amount will not contain any cents, so we round
|
10
|
+
# All amounts should be handled as without vat
|
11
|
+
class StripeChargeRow
|
12
|
+
class AmountNotInSwedishKronorError < StandardError; end
|
13
|
+
|
14
|
+
attr_reader :charge, :buyer_vat_number, :exchange_rates
|
15
|
+
|
16
|
+
#
|
17
|
+
# charge: a stripe charge
|
18
|
+
# exchange_rates: a SKVReport::ExchangeRates object
|
19
|
+
#
|
20
|
+
def initialize(charge, exchange_rates)
|
21
|
+
@charge = charge
|
22
|
+
@buyer_vat_number = charge.dig('customer', 'tax_info', 'tax_id') || ''
|
23
|
+
@exchange_rates = exchange_rates
|
24
|
+
end
|
25
|
+
|
26
|
+
def sales_amount
|
27
|
+
Money.new(amount).dollars.to_f.round
|
28
|
+
end
|
29
|
+
|
30
|
+
def skippable?
|
31
|
+
swedish_buyer? || !valid_vat_number? || not_completed? || refunded?
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def swedish_buyer?
|
37
|
+
buyer_vat_number[0...2].casecmp?('SE')
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid_vat_number?
|
41
|
+
Valvat::Syntax.validate(buyer_vat_number)
|
42
|
+
end
|
43
|
+
|
44
|
+
def amount
|
45
|
+
currency = charge['currency']
|
46
|
+
return charge['amount'] if currency.casecmp?('sek')
|
47
|
+
|
48
|
+
date = Time.at(charge['created']).to_date.to_s
|
49
|
+
convert_amount_to_sek(exchange_rates.rate_for(currency, date))
|
50
|
+
end
|
51
|
+
|
52
|
+
def convert_amount_to_sek(exchange_rate)
|
53
|
+
(charge['amount'] * exchange_rate).round
|
54
|
+
end
|
55
|
+
|
56
|
+
def not_completed?
|
57
|
+
charge['status'] != 'succeeded'
|
58
|
+
end
|
59
|
+
|
60
|
+
def refunded?
|
61
|
+
charge['refunded']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/skv_report.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/skv_report/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'skv_report'
|
7
|
+
spec.version = SKVReport::VERSION
|
8
|
+
spec.authors = ['frdrkolsson']
|
9
|
+
spec.email = ['fredrik.olsson@standout.se']
|
10
|
+
|
11
|
+
spec.summary = 'Generates CSV complete string for Skatteverkets '\
|
12
|
+
'Periodisk Sammanfattning'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/standout/skv_report'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
24
|
+
# into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{\A(?:test|spec|features)/})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
# spec.add_dependency to register a new dependency of your gem
|
35
|
+
spec.add_dependency 'money', '~> 6.14'
|
36
|
+
spec.add_dependency 'valvat', '~> 1.1'
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, checkout our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skv_report
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- frdrkolsson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: money
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: valvat
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
description: Generates CSV complete string for Skatteverkets Periodisk Sammanfattning
|
42
|
+
email:
|
43
|
+
- fredrik.olsson@standout.se
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".github/workflows/gempush.yml"
|
49
|
+
- ".github/workflows/main.yml"
|
50
|
+
- ".gitignore"
|
51
|
+
- ".rspec"
|
52
|
+
- ".rubocop.yml"
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- bin/console
|
59
|
+
- bin/setup
|
60
|
+
- lib/skv_report.rb
|
61
|
+
- lib/skv_report/exchange_rates.rb
|
62
|
+
- lib/skv_report/stripe.rb
|
63
|
+
- lib/skv_report/stripe_charge_row.rb
|
64
|
+
- lib/skv_report/version.rb
|
65
|
+
- skv_report.gemspec
|
66
|
+
homepage: https://github.com/standout/skv_report
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata:
|
70
|
+
homepage_uri: https://github.com/standout/skv_report
|
71
|
+
source_code_uri: https://github.com/standout/skv_report
|
72
|
+
changelog_uri: https://github.com/standout/skv_report
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.5.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.2.3
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Generates CSV complete string for Skatteverkets Periodisk Sammanfattning
|
92
|
+
test_files: []
|