Class: EInvoice::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/e_invoice/payload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, serial, encrypt) ⇒ Payload

Returns a new instance of Payload.



5
6
7
8
9
# File 'lib/e_invoice/payload.rb', line 5

def initialize(type, serial, encrypt)
  @serial = serial
  @encrypt = encrypt
  @type = type
end

Instance Attribute Details

#encryptObject (readonly)

Returns the value of attribute encrypt.



3
4
5
# File 'lib/e_invoice/payload.rb', line 3

def encrypt
  @encrypt
end

#serialObject (readonly)

Returns the value of attribute serial.



3
4
5
# File 'lib/e_invoice/payload.rb', line 3

def serial
  @serial
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/e_invoice/payload.rb', line 3

def type
  @type
end

Instance Method Details

#fetch_datetime(invoice_date) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/e_invoice/payload.rb', line 34

def fetch_datetime(invoice_date)
  year = (invoice_date["year"].to_i + 1911).to_s
  month = invoice_date["month"].to_s
  date = invoice_date["date"].to_s
  hours = invoice_date["hours"].to_s
  minutes = invoice_date["minutes"].to_s
  seconds = invoice_date["seconds"].to_s
  date_time = DateTime.parse(year + "/" + month + "/" + date + " " +
                             hours + ":" + minutes + ":" + seconds)
  [date_time.strftime("%Y/%m/%d"), date_time.strftime("%H:%M:%S")]
end

#get_invoices(start_date, end_date) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/e_invoice/payload.rb', line 11

def get_invoices(start_date, end_date)
  result = []
  month_endpoints = Duration.new(start_date, end_date).endpoints
  month_endpoints.each do |m|
    header_details = request_header(m[:endpoint_begin],
                                    m[:endpoint_end]).details
    header_details.each do |h|
      result += request_info(h).details
    end unless header_details.nil?
  end
  result
end

#request_header(start_date, end_date) ⇒ Object



24
25
26
# File 'lib/e_invoice/payload.rb', line 24

def request_header(start_date, end_date)
  Header.new(self, start_date, end_date).request
end

#request_info(header) ⇒ Object



28
29
30
31
32
# File 'lib/e_invoice/payload.rb', line 28

def request_info(header)
  invoice_number = header["invNum"]
  invoice_date, invoice_time = fetch_datetime(header["invDate"])
  Info.new(self, invoice_number, invoice_date, invoice_time).request
end