Class: Bsale::Invoices

Inherits:
Object
  • Object
show all
Defined in:
lib/sale/invoices.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Invoices

Returns a new instance of Invoices.



5
6
7
# File 'lib/sale/invoices.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(codeSii: nil, documentTypeId: nil, emissionDate:, expirationDate:, declareSii:, priceListId:, officeId: nil, clientId: nil, client: nil, details: nil, payments: nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sale/invoices.rb', line 20

def create(codeSii: nil, documentTypeId: nil, emissionDate:, expirationDate:, declareSii:, priceListId:, \
  officeId: nil, clientId: nil, client: nil, details: nil, payments: nil)

  body = {
    declareSii: declareSii,
    emissionDate: emissionDate,
    expirationDate: expirationDate
  }

  if documentTypeId
    body[:documentTypeId] = documentTypeId
  elsif codeSii
    body[:codeSii] = codeSii
  else
    raise ArgumentError, "Either codeSii or documentTypeId required"
  end

  body[:officeId] = officeId if officeId
  body[:priceListId] = priceListId if priceListId

  if clientId
    body[:clientId] = clientId
  elsif client
    body[:client] = client
  elsif [33, 34].include?(codeSii.to_i) # facturas requiren clientId
    raise 'clientId or client required'
  end

  body[:details]  = details  if details
  body[:payments] = payments if payments

  post("documents.json", body.to_json)
end

#get_pdf(url) ⇒ Object

actions



11
12
13
14
15
16
17
18
# File 'lib/sale/invoices.rb', line 11

def get_pdf(url)
  resp = request(:get, url)
  if resp.success?
    StringIO.new(resp.body, 'rb')
  else
    nil
  end
end

#mark_declared(id) ⇒ Object



54
55
56
57
# File 'lib/sale/invoices.rb', line 54

def mark_declared(id)
  body = { id: id, informedSii: 1 }
  request(:put, 'documents/set_sii_state.json', body)
end

#remove(id:, office_id:) ⇒ Object



59
60
61
# File 'lib/sale/invoices.rb', line 59

def remove(id:, office_id:)
  request(:delete, "documents/#{id}.json?officeid=#{office_id}")
end