hmrc-moss-return 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eff0991cebfdb5e330d0cc55114f0305d2cd5909
4
+ data.tar.gz: 8adcaaa419baf2acf5e005974211dd144abe3be4
5
+ SHA512:
6
+ metadata.gz: 1d1734cb2217184dcf1183f91acb917d8bb33695749fadf71148818145d7e2fd58fd2961411aede6f20c6a10cf54eac27152d189384d91bec1b838f85faead67
7
+ data.tar.gz: 0918be37fc925b527d2e8809e2718187895466c25556ebedbf895e48f16b91e48b27404bea07acbcd07c2fd8a75a0533bfd250be552d63aac83180065b1ff00c
@@ -0,0 +1 @@
1
+ require 'hmrc_moss/return'
@@ -0,0 +1,27 @@
1
+ require 'hmrc_moss/supply'
2
+
3
+ module HMRCMOSS
4
+ class NonUKSupply < Supply
5
+
6
+ def initialize(vat_number, country, attributes = {})
7
+ attributes[:vat_number] = vat_number
8
+ attributes[:country] = country
9
+ super(attributes)
10
+ end
11
+
12
+ def vat_number
13
+ @attributes[:vat_number].to_s
14
+ end
15
+
16
+ class DSL
17
+ def initialize(moss_return)
18
+ @moss_return = moss_return
19
+ end
20
+
21
+ def line(*args)
22
+ @moss_return.supplies_from_outside_uk << NonUKSupply.new(*args)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ require 'zip'
2
+
3
+ module HMRCMOSS
4
+ class ODSFile
5
+
6
+ def initialize(moss_return)
7
+ @moss_return = moss_return
8
+ end
9
+
10
+ def content
11
+ @template_content ||= Zip::File.open(self.class.path_to_template) { |z| z.read('content.xml') }
12
+ end
13
+
14
+ def add_return_data
15
+ content.gsub!("{{uk:period}}", @moss_return.period)
16
+ content.gsub!("{{f:period}}", @moss_return.period)
17
+ (1..150).each do |i|
18
+ return_line = @moss_return.supplies_from_uk[i - 1]
19
+ content.gsub! "{{uk:taxsupp}}", "Yes" if return_line
20
+ content.gsub! "{{uk:state:#{i}}}", return_line ? return_line.country.to_s : ''
21
+ content.gsub! "{{uk:ratetype:#{i}}}", return_line ? return_line.rate_type.to_s : ''
22
+ content.gsub! "{{uk:rate:#{i}}}", return_line ? return_line.rate.to_s : ''
23
+ content.gsub! "{{uk:value:#{i}}}", return_line ? return_line.total_sales.to_s : ''
24
+ content.gsub! "{{uk:amount:#{i}}}", return_line ? return_line.vat_due.to_s : ''
25
+ content.gsub! "{{uk:taxsupp}}", "No"
26
+
27
+ return_line = @moss_return.supplies_from_outside_uk[i - 1]
28
+ content.gsub! "{{f:taxsupp}}", "Yes" if return_line
29
+ content.gsub! "{{f:number:#{i}}}", return_line ? return_line.vat_number.to_s : ''
30
+ content.gsub! "{{f:state:#{i}}}", return_line ? return_line.country.to_s : ''
31
+ content.gsub! "{{f:ratetype:#{i}}}", return_line ? return_line.rate_type.to_s : ''
32
+ content.gsub! "{{f:rate:#{i}}}", return_line ? return_line.rate.to_s : ''
33
+ content.gsub! "{{f:value:#{i}}}", return_line ? return_line.total_sales.to_s : ''
34
+ content.gsub! "{{f:amount:#{i}}}", return_line ? return_line.vat_due.to_s : ''
35
+ content.gsub! "{{f:taxsupp}}", "No"
36
+ end
37
+ end
38
+
39
+ def create_ods_file(path)
40
+ FileUtils.cp(self.class.path_to_template, path)
41
+ Zip::File.open(path) do |zip|
42
+ zip.get_output_stream('content.xml') do |io|
43
+ io.write(content)
44
+ end
45
+ end
46
+ end
47
+
48
+ def save(path)
49
+ add_return_data
50
+ create_ods_file(path)
51
+ end
52
+
53
+ def self.path_to_template
54
+ File.expand_path(File.join('..', '..', '..', 'template.ods'), __FILE__)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,41 @@
1
+ require 'hmrc_moss/uk_supply'
2
+ require 'hmrc_moss/non_uk_supply'
3
+
4
+ module HMRCMOSS
5
+ class Return
6
+
7
+ def initialize(period)
8
+ @period = period
9
+ end
10
+
11
+ def period
12
+ @period
13
+ end
14
+
15
+ def supplies_from_uk(&block)
16
+ if block_given?
17
+ dsl = HMRCMOSS::UKSupply::DSL.new(self)
18
+ dsl.instance_eval(&block)
19
+ supplies_from_uk
20
+ else
21
+ @supplies_from_uk ||= []
22
+ end
23
+ end
24
+
25
+ def supplies_from_outside_uk(&block)
26
+ if block_given?
27
+ dsl = HMRCMOSS::NonUKSupply::DSL.new(self)
28
+ dsl.instance_eval(&block)
29
+ supplies_from_outside_uk
30
+ else
31
+ @supplies_from_outside_uk ||= []
32
+ end
33
+ end
34
+
35
+ def ods_file
36
+ require 'hmrc_moss/ods_file'
37
+ ODSFile.new(self)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ module HMRCMOSS
2
+ class Supply
3
+
4
+ def initialize(attributes = {})
5
+ @attributes = attributes
6
+ end
7
+
8
+ def country
9
+ @attributes[:country].to_s
10
+ end
11
+
12
+ def rate_type
13
+ @attributes[:rate_type].to_s
14
+ end
15
+
16
+ def rate
17
+ numeric_value(@attributes[:rate].to_f)
18
+ end
19
+
20
+ def total_sales
21
+ numeric_value(@attributes[:total_sales])
22
+ end
23
+
24
+ def vat_due
25
+ numeric_value(@attributes[:vat_due])
26
+ end
27
+
28
+ private
29
+
30
+ def numeric_value(value)
31
+ "%.2f" % value.to_f
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'hmrc_moss/supply'
2
+
3
+ module HMRCMOSS
4
+ class UKSupply < Supply
5
+
6
+ def initialize(country, attributes = {})
7
+ attributes[:country] = country
8
+ super(attributes)
9
+ end
10
+
11
+ class DSL
12
+ def initialize(moss_return)
13
+ @moss_return = moss_return
14
+ end
15
+
16
+ def line(*args)
17
+ @moss_return.supplies_from_uk << UKSupply.new(*args)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module HMRCMOSS
2
+ VERSION = '1.0.0'
3
+ end
Binary file
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hmrc-moss-return
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ description: A Ruby library for generating a HMRC VAT MOSS return document
34
+ email:
35
+ - me@adamcooke.io
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - lib/hmrc_moss.rb
41
+ - lib/hmrc_moss/non_uk_supply.rb
42
+ - lib/hmrc_moss/ods_file.rb
43
+ - lib/hmrc_moss/return.rb
44
+ - lib/hmrc_moss/supply.rb
45
+ - lib/hmrc_moss/uk_supply.rb
46
+ - lib/hmrc_moss/version.rb
47
+ - template.ods
48
+ homepage: https://github.com/adamcooke/hmrc-moss-return
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.5
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: A Ruby library for generating a HMRC VAT MOSS return document
72
+ test_files: []