Module: SunatBooks::Ple::Utils

Included in:
Base
Defined in:
lib/sunat_books/ple/utils.rb

Instance Method Summary collapse

Instance Method Details

#book_code(uid) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sunat_books/ple/utils.rb', line 16

def book_code(uid)
  dir = File.dirname(__FILE__)
  path = "#{dir}/book_codes.csv"
  code = ""
  CSV.foreach(path) do |row|
    if row[0] == uid
      code = row[2]
      break
    end
  end
  code
end

#check_layout(options, fields) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/sunat_books/ple/utils.rb', line 60

def check_layout(options, fields)
  options[:layout]&.each do |key, value|
    i = fields.index(key.to_s)
    fields.delete(key.to_s)
    fields.insert(i, value)
  end
end

#get_file(tickets, fields, filename) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sunat_books/ple/utils.rb', line 36

def get_file(tickets, fields, filename)
  FileUtils.touch(filename.to_s)

  send("file=", filename)

  tickets.each_with_index do |ticket, i|
    ticket_data = get_value(fields, ticket)

    mode = (i.zero? ? "w+" : "a+")
    File.open(filename.to_s, mode) do |txt|
      txt.puts(ticket_data)
    end
  end
end

#get_value(fields, ticket) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/sunat_books/ple/utils.rb', line 51

def get_value(fields, ticket)
  data = ""
  fields.each do |field|
    value = available_value?(ticket, field)
    data << "#{value}|"
  end
  data
end

#pathObject



29
30
31
32
33
34
# File 'lib/sunat_books/ple/utils.rb', line 29

def path
  dir = File.dirname(__FILE__)
  tmp_path = "#{dir}/tmp/"
  Dir.mkdir(tmp_path) unless Dir.exist?(tmp_path)
  tmp_path
end

#ple_book_name(uid, ruc, month, year, *args) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/sunat_books/ple/utils.rb', line 6

def ple_book_name(uid, ruc, month, year, *args)
  code = book_code(uid)
  code_oportunity = "00" # TODO: case for 'inventarios y balances'
  operations_state = args[0] || 1 # 0, 1, 2
  content = args[1] || 1 # 1 ,0
  currency = args[2] || 1 # 1, 2
  name = "LE#{ruc}#{year}#{month}00#{code}#{code_oportunity}"
  name << "#{operations_state}#{content}#{currency}1"
end