sunat_books 0.0.4 → 0.1.0
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 +4 -4
- data/README.mkd +6 -1
- data/lib/sunat_books/csv/base.rb +1 -3
- data/lib/sunat_books/ple/base.rb +28 -57
- data/lib/sunat_books/ple/buys.rb +2 -26
- data/lib/sunat_books/ple/layouts/{buys.yml → buys-8.1.yml} +11 -4
- data/lib/sunat_books/ple/layouts/buys-8.2.yml +36 -0
- data/lib/sunat_books/ple/layouts/buys-8.3.yml +31 -0
- data/lib/sunat_books/ple/layouts/sales-14.1.yml +33 -0
- data/lib/sunat_books/ple/layouts/{sales.yml → sales-14.2.yml} +0 -0
- data/lib/sunat_books/ple/sales.rb +2 -10
- data/lib/sunat_books/ple/utils.rb +69 -0
- data/sunat_books.gemspec +1 -1
- data/test/ple/buys_test.rb +15 -5
- data/test/ple/sales_test.rb +20 -0
- data/test/ple/{base_test.rb → utils_test.rb} +8 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efd1903840f068f411f75c6c1f8fae4899ffe48fc28a803785a3831203e81ba4
|
4
|
+
data.tar.gz: f1365594c65b1a0b1c13858cfdb3b65db727e7b566120619e124fa54f3702841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f349ce044cc13391c2b67f7aab70edf73952c3a8159b5282697d8c935171bf73f16c0a0b34aaaa5d4912a68f94031d37a0a8cd5e84c463b839341ecfc95b9b83
|
7
|
+
data.tar.gz: b8ba1d475126a7ac3e5883df8146bfd9ca01a96149a8e30dbcce37b99c4892eb0f15651370e6256dd1bf2aedf669259818d1e460a44c3c5a532bb331007032ea
|
data/README.mkd
CHANGED
@@ -31,9 +31,14 @@ pdf.render
|
|
31
31
|
to get the txt file for electronic books
|
32
32
|
|
33
33
|
```ruby
|
34
|
-
ple = SunatBooks::Ple::Buys.new(ruc, tickets, month, year)
|
34
|
+
ple = SunatBooks::Ple::Buys.new(ruc, tickets, month, year, options)
|
35
35
|
```
|
36
36
|
|
37
|
+
Currently allowed options are:
|
38
|
+
- `yml`: path location to a custom layout file
|
39
|
+
- `layout`: a hash to define method names to replace in layout
|
40
|
+
- `book_format`: book format to use
|
41
|
+
|
37
42
|
[rubygems-image]: https://badge.fury.io/rb/sunat_books.svg
|
38
43
|
[rubygems-url]: https://badge.fury.io/rb/sunat_books
|
39
44
|
[travis-image]: https://travis-ci.org/ccarruitero/sunat_books.svg?branch=master
|
data/lib/sunat_books/csv/base.rb
CHANGED
@@ -15,9 +15,7 @@ module SunatBooks
|
|
15
15
|
# options
|
16
16
|
# - layout => Array of strings used to get data for csv
|
17
17
|
# - filename
|
18
|
-
if options[:layout].nil?
|
19
|
-
raise SunatBooks::Csv::OptionError, "Layout option is required"
|
20
|
-
end
|
18
|
+
raise SunatBooks::Csv::OptionError, "Layout option is required" if options[:layout].nil?
|
21
19
|
|
22
20
|
filename = options[:filename] || "#{tmp_path}book.csv"
|
23
21
|
fields = options[:layout]
|
data/lib/sunat_books/ple/base.rb
CHANGED
@@ -2,74 +2,45 @@
|
|
2
2
|
|
3
3
|
require "csv"
|
4
4
|
require_relative "../common_utils"
|
5
|
+
require_relative "./utils"
|
5
6
|
|
6
7
|
module SunatBooks
|
7
8
|
module Ple
|
8
9
|
class Base
|
9
10
|
include SunatBooks::CommonUtils
|
11
|
+
include Utils
|
10
12
|
|
11
13
|
attr_accessor :file
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
attr_reader :book_format
|
15
|
+
|
16
|
+
# ruc => company's ruc in string format
|
17
|
+
# tickets => an array of objects that respond to a layout's methods
|
18
|
+
# month => a number that represent a month
|
19
|
+
# year => a number that represent a year
|
20
|
+
# options =>
|
21
|
+
# :yml => to define a custom layout file
|
22
|
+
# :layout => to define a custom name for a specific layout method
|
23
|
+
# :book_format => to define ple book format to use
|
24
|
+
def initialize(ruc, tickets, month, year, options = {})
|
25
|
+
@book_format = options[:book_format]
|
26
|
+
yml_path = options[:yml] || default_yml(book_format)
|
27
|
+
fields = YAML.load_file(yml_path)
|
28
|
+
check_layout(options, fields)
|
29
|
+
content = !tickets.empty? ? 1 : 0
|
30
|
+
|
31
|
+
name = ple_book_name(book_format, ruc, month, year, nil, content)
|
32
|
+
filename = "#{path}#{name}.txt"
|
33
|
+
get_file(tickets, fields, filename)
|
21
34
|
end
|
22
35
|
|
23
|
-
|
24
|
-
dir = File.dirname(__FILE__)
|
25
|
-
path = "#{dir}/book_codes.csv"
|
26
|
-
code = ""
|
27
|
-
CSV.foreach(path) do |row|
|
28
|
-
if row[0] == uid
|
29
|
-
code = row[2]
|
30
|
-
break
|
31
|
-
end
|
32
|
-
end
|
33
|
-
code
|
34
|
-
end
|
36
|
+
private
|
35
37
|
|
36
|
-
|
38
|
+
# get default yml file according book format given
|
39
|
+
# book_format => ple book format
|
40
|
+
def default_yml(book_format)
|
41
|
+
book_name = self.class.name.downcase.sub("sunatbooks::ple::", "")
|
37
42
|
dir = File.dirname(__FILE__)
|
38
|
-
|
39
|
-
Dir.mkdir(tmp_path) unless Dir.exist?(tmp_path)
|
40
|
-
tmp_path
|
41
|
-
end
|
42
|
-
|
43
|
-
def get_file(tickets, fields, filename)
|
44
|
-
FileUtils.touch(filename.to_s)
|
45
|
-
|
46
|
-
send("file=", filename)
|
47
|
-
|
48
|
-
tickets.each_with_index do |ticket, i|
|
49
|
-
ticket_data = get_value(fields, ticket)
|
50
|
-
|
51
|
-
mode = (i.zero? ? "w+" : "a+")
|
52
|
-
File.open(filename.to_s, mode) do |txt|
|
53
|
-
txt.puts(ticket_data)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def get_value(fields, ticket)
|
59
|
-
data = ""
|
60
|
-
fields.each do |field|
|
61
|
-
value = available_value?(ticket, field)
|
62
|
-
data << "#{value}|"
|
63
|
-
end
|
64
|
-
data
|
65
|
-
end
|
66
|
-
|
67
|
-
def check_layout(options, fields)
|
68
|
-
options[:layout]&.each do |key, value|
|
69
|
-
i = fields.index(key.to_s)
|
70
|
-
fields.delete(key.to_s)
|
71
|
-
fields.insert(i, value)
|
72
|
-
end
|
43
|
+
"#{dir}/layouts/#{book_name}-#{book_format}.yml"
|
73
44
|
end
|
74
45
|
end
|
75
46
|
end
|
data/lib/sunat_books/ple/buys.rb
CHANGED
@@ -6,32 +6,8 @@ module SunatBooks
|
|
6
6
|
module Ple
|
7
7
|
class Buys < Base
|
8
8
|
def initialize(ruc, tickets, month, year, options = {})
|
9
|
-
|
10
|
-
|
11
|
-
# month => a number that represent a month
|
12
|
-
# year => a number that represent a year
|
13
|
-
# options =>
|
14
|
-
# :yml => to define a custom layout file
|
15
|
-
# :layout => to define a custom name for a specific layout method
|
16
|
-
|
17
|
-
book_name = self.class.name.downcase.sub("sunatbooks::ple::", "")
|
18
|
-
dir = File.dirname(__FILE__)
|
19
|
-
yml_path = options[:yml] || "#{dir}/layouts/#{book_name}.yml"
|
20
|
-
fields = YAML.load_file(yml_path)
|
21
|
-
check_layout(options, fields)
|
22
|
-
content = !tickets.empty? ? 1 : 0
|
23
|
-
name = ple_book_name("8.1", ruc, month, year, nil, content)
|
24
|
-
|
25
|
-
filename = "#{path}#{name}.txt"
|
26
|
-
get_file(tickets, fields, filename)
|
27
|
-
end
|
28
|
-
|
29
|
-
def insert_layout_fields(options, fields)
|
30
|
-
options[:layout].each do |key, value|
|
31
|
-
i = fields.index(key.to_s)
|
32
|
-
fields.delete(key.to_s)
|
33
|
-
fields.insert(i, value)
|
34
|
-
end
|
9
|
+
options[:book_format] = options[:book_format] || "8.1"
|
10
|
+
super(ruc, tickets, month, year, options)
|
35
11
|
end
|
36
12
|
end
|
37
13
|
end
|
@@ -21,14 +21,21 @@
|
|
21
21
|
- documentn_isc
|
22
22
|
- document_other_tax
|
23
23
|
- document_total
|
24
|
-
-
|
24
|
+
- currency_code
|
25
|
+
- exchange_rate # 1 entero, 3 decimales
|
25
26
|
- modified_document_date
|
26
27
|
- modified_document_type # 2
|
27
28
|
- modified_document_serial
|
28
29
|
- modified_document_aduanas_dependency
|
29
30
|
- modified_document_number
|
30
|
-
- foreign_document_number
|
31
31
|
- detraction_date
|
32
32
|
- detraction_number
|
33
|
-
-
|
34
|
-
-
|
33
|
+
- apply_retention? # retention ? '1'
|
34
|
+
- clasification_goods_services_adquired
|
35
|
+
- contract_or_project
|
36
|
+
- inconsistent_exchange
|
37
|
+
- inconsistent_provider_inactive
|
38
|
+
- inconsistent_provider_igv_exoneration
|
39
|
+
- inconsistent_dni_buy_liquidation
|
40
|
+
- payment_method
|
41
|
+
- anotation_oportunity
|
@@ -0,0 +1,36 @@
|
|
1
|
+
- period
|
2
|
+
- cuo
|
3
|
+
- correlative
|
4
|
+
- operation_date
|
5
|
+
- document_type
|
6
|
+
- document_serial
|
7
|
+
- document_number
|
8
|
+
- document_bi
|
9
|
+
- other_concepts
|
10
|
+
- document_total
|
11
|
+
- document_type_tax_credit
|
12
|
+
- document_serial_tax_credit
|
13
|
+
- dua_year_emition
|
14
|
+
- document_tax_pay
|
15
|
+
- retention_amount
|
16
|
+
- currency_code
|
17
|
+
- exchange_rate
|
18
|
+
- not_domiciled_residence_country
|
19
|
+
- not_domiciled_name
|
20
|
+
- not_domiciled_address
|
21
|
+
- not_domiciled_document_number
|
22
|
+
- payment_beneficiary_tax_document_number
|
23
|
+
- payment_beneficiary_name
|
24
|
+
- payment_beneficiary_residence_country
|
25
|
+
- economic_link_type
|
26
|
+
- gross_income
|
27
|
+
- deduction
|
28
|
+
- net_income
|
29
|
+
- retention_rate
|
30
|
+
- retention_tax
|
31
|
+
- double_taxation_agreement
|
32
|
+
- exoneration
|
33
|
+
- income_type
|
34
|
+
- service_mode
|
35
|
+
- art_76
|
36
|
+
- anotation_oportunity
|
@@ -0,0 +1,31 @@
|
|
1
|
+
- period
|
2
|
+
- cuo
|
3
|
+
- correlative
|
4
|
+
- operation_date
|
5
|
+
- pay_date
|
6
|
+
- document_type
|
7
|
+
- document_serial
|
8
|
+
- document_number
|
9
|
+
- total_diary_operation_non_credit
|
10
|
+
- provider_document_type
|
11
|
+
- provider_document_number
|
12
|
+
- provider_name
|
13
|
+
- document_bi
|
14
|
+
- document_igv
|
15
|
+
- document_other_concept
|
16
|
+
- document_total
|
17
|
+
- currency_code
|
18
|
+
- exchange_rate
|
19
|
+
- modified_document_date
|
20
|
+
- modified_document_type # 2
|
21
|
+
- modified_document_serial
|
22
|
+
- modified_document_number
|
23
|
+
- detraction_date
|
24
|
+
- detraction_number
|
25
|
+
- apply_retention?
|
26
|
+
- clasification_goods_services_adquired
|
27
|
+
- inconsistent_exchange
|
28
|
+
- inconsistent_provider_inactive
|
29
|
+
- inconsistent_provider_igv_exoneration
|
30
|
+
- payment_method
|
31
|
+
- anotation_oportunity
|
@@ -0,0 +1,33 @@
|
|
1
|
+
- period
|
2
|
+
- cuo
|
3
|
+
- correlative
|
4
|
+
- operation_date
|
5
|
+
- pay_date
|
6
|
+
- document_type
|
7
|
+
- document_serial
|
8
|
+
- initial_document_number
|
9
|
+
- final_document_number
|
10
|
+
- client_document_type
|
11
|
+
- client_document_number
|
12
|
+
- client_name
|
13
|
+
- bi_exported_operation
|
14
|
+
- bi_taxable_operation
|
15
|
+
- bi_discount
|
16
|
+
- igv_tax
|
17
|
+
- igv_discount
|
18
|
+
- exempt
|
19
|
+
- non_taxable
|
20
|
+
- isc_tax
|
21
|
+
- bi_ivap
|
22
|
+
- ivap_tax
|
23
|
+
- other_concept
|
24
|
+
- total_operation
|
25
|
+
- currency_code
|
26
|
+
- exchange_rate
|
27
|
+
- original_document_date
|
28
|
+
- original_document_type
|
29
|
+
- original_document_serial
|
30
|
+
- original_document_number
|
31
|
+
- contract_uid
|
32
|
+
- payment_way
|
33
|
+
- anotation_oportunity
|
File without changes
|
@@ -6,16 +6,8 @@ module SunatBooks
|
|
6
6
|
module Ple
|
7
7
|
class Sales < Base
|
8
8
|
def initialize(ruc, tickets, month, year, options = {})
|
9
|
-
|
10
|
-
|
11
|
-
yml_path = options[:yml] || "#{dir}/layouts/#{book_name}.yml"
|
12
|
-
fields = YAML.load_file(yml_path)
|
13
|
-
check_layout(options, fields)
|
14
|
-
content = !tickets.empty? ? 1 : 0
|
15
|
-
|
16
|
-
name = ple_book_name("14.2", ruc, month, year, nil, content)
|
17
|
-
@filename = "#{path}#{name}.txt"
|
18
|
-
get_file(tickets, fields, @filename)
|
9
|
+
options[:book_format] = options[:book_format] || "14.2"
|
10
|
+
super(ruc, tickets, month, year, options)
|
19
11
|
end
|
20
12
|
end
|
21
13
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
module SunatBooks
|
4
|
+
module Ple
|
5
|
+
module Utils
|
6
|
+
def ple_book_name(uid, ruc, month, year, *args)
|
7
|
+
code = book_code(uid)
|
8
|
+
code_oportunity = "00" # TODO: case for 'inventarios y balances'
|
9
|
+
operations_state = args[0] || 1 # 0, 1, 2
|
10
|
+
content = args[1] || 1 # 1 ,0
|
11
|
+
currency = args[2] || 1 # 1, 2
|
12
|
+
name = "LE#{ruc}#{year}#{month}00#{code}#{code_oportunity}"
|
13
|
+
name << "#{operations_state}#{content}#{currency}1"
|
14
|
+
end
|
15
|
+
|
16
|
+
def book_code(uid)
|
17
|
+
dir = File.dirname(__FILE__)
|
18
|
+
path = "#{dir}/book_codes.csv"
|
19
|
+
code = ""
|
20
|
+
CSV.foreach(path) do |row|
|
21
|
+
if row[0] == uid
|
22
|
+
code = row[2]
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
code
|
27
|
+
end
|
28
|
+
|
29
|
+
def path
|
30
|
+
dir = File.dirname(__FILE__)
|
31
|
+
tmp_path = "#{dir}/tmp/"
|
32
|
+
Dir.mkdir(tmp_path) unless Dir.exist?(tmp_path)
|
33
|
+
tmp_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_file(tickets, fields, filename)
|
37
|
+
FileUtils.touch(filename.to_s)
|
38
|
+
|
39
|
+
send("file=", filename)
|
40
|
+
|
41
|
+
tickets.each_with_index do |ticket, i|
|
42
|
+
ticket_data = get_value(fields, ticket)
|
43
|
+
|
44
|
+
mode = (i.zero? ? "w+" : "a+")
|
45
|
+
File.open(filename.to_s, mode) do |txt|
|
46
|
+
txt.puts(ticket_data)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_value(fields, ticket)
|
52
|
+
data = ""
|
53
|
+
fields.each do |field|
|
54
|
+
value = available_value?(ticket, field)
|
55
|
+
data << "#{value}|"
|
56
|
+
end
|
57
|
+
data
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_layout(options, fields)
|
61
|
+
options[:layout]&.each do |key, value|
|
62
|
+
i = fields.index(key.to_s)
|
63
|
+
fields.delete(key.to_s)
|
64
|
+
fields.insert(i, value)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/sunat_books.gemspec
CHANGED
data/test/ple/buys_test.rb
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
require_relative "../helper"
|
4
4
|
|
5
|
-
|
5
|
+
def ple_buys(opts = {})
|
6
6
|
tickets = [{}]
|
7
7
|
ruc = "102392839213"
|
8
|
-
|
8
|
+
SunatBooks::Ple::Buys.new(ruc, tickets, 10, 2013, opts)
|
9
9
|
end
|
10
10
|
|
11
11
|
test "generate txt file" do
|
12
|
-
assert File.exist?(
|
12
|
+
assert File.exist?(ple_buys.file)
|
13
13
|
end
|
14
14
|
|
15
15
|
test "tickets empty" do
|
16
|
-
|
17
|
-
assert File.exist?(
|
16
|
+
ple = SunatBooks::Ple::Buys.new("10293827481", {}, 10, 2011)
|
17
|
+
assert File.exist?(ple.file)
|
18
18
|
end
|
19
19
|
|
20
20
|
scope "custom layout" do
|
@@ -47,3 +47,13 @@ scope "custom layout" do
|
|
47
47
|
assert txt.include?("20/10/2015")
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
scope "book_format" do
|
52
|
+
test "without book_format option" do
|
53
|
+
assert_equal ple_buys.book_format, "8.1"
|
54
|
+
end
|
55
|
+
|
56
|
+
test "with book_format option" do
|
57
|
+
assert_equal ple_buys(book_format: "8.2").book_format, "8.2"
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../helper"
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@tickets = [{}]
|
7
|
+
@ruc = "102392839213"
|
8
|
+
end
|
9
|
+
|
10
|
+
test "generate txt file" do
|
11
|
+
ple = SunatBooks::Ple::Sales.new(@ruc, @tickets, 10, 2013)
|
12
|
+
assert File.exist?(ple.file)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "allow define book format" do
|
16
|
+
options = { book_format: "14.1" }
|
17
|
+
ple = SunatBooks::Ple::Sales.new(@ruc, @tickets, 10, 2013, options)
|
18
|
+
assert File.exist?(ple.file)
|
19
|
+
assert ple.book_format, "14.1"
|
20
|
+
end
|
@@ -2,8 +2,15 @@
|
|
2
2
|
|
3
3
|
require_relative "../helper"
|
4
4
|
|
5
|
+
class TestPle
|
6
|
+
include SunatBooks::Ple::Utils
|
7
|
+
include SunatBooks::CommonUtils
|
8
|
+
|
9
|
+
attr_accessor :file
|
10
|
+
end
|
11
|
+
|
5
12
|
setup do
|
6
|
-
@base =
|
13
|
+
@base = TestPle.new
|
7
14
|
end
|
8
15
|
|
9
16
|
test "book_code" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunat_books
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- César Carruitero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -171,9 +171,13 @@ files:
|
|
171
171
|
- lib/sunat_books/ple/base.rb
|
172
172
|
- lib/sunat_books/ple/book_codes.csv
|
173
173
|
- lib/sunat_books/ple/buys.rb
|
174
|
-
- lib/sunat_books/ple/layouts/buys.yml
|
175
|
-
- lib/sunat_books/ple/layouts/
|
174
|
+
- lib/sunat_books/ple/layouts/buys-8.1.yml
|
175
|
+
- lib/sunat_books/ple/layouts/buys-8.2.yml
|
176
|
+
- lib/sunat_books/ple/layouts/buys-8.3.yml
|
177
|
+
- lib/sunat_books/ple/layouts/sales-14.1.yml
|
178
|
+
- lib/sunat_books/ple/layouts/sales-14.2.yml
|
176
179
|
- lib/sunat_books/ple/sales.rb
|
180
|
+
- lib/sunat_books/ple/utils.rb
|
177
181
|
- sunat_books.gemspec
|
178
182
|
- test/csv/base_test.rb
|
179
183
|
- test/fixtures/base.rb
|
@@ -187,8 +191,9 @@ files:
|
|
187
191
|
- test/pdf/pages_utils_test.rb
|
188
192
|
- test/pdf/sales_test.rb
|
189
193
|
- test/pdf/utils_test.rb
|
190
|
-
- test/ple/base_test.rb
|
191
194
|
- test/ple/buys_test.rb
|
195
|
+
- test/ple/sales_test.rb
|
196
|
+
- test/ple/utils_test.rb
|
192
197
|
homepage: https://github.com/ccarruitero/sunat_books
|
193
198
|
licenses:
|
194
199
|
- MPL
|