Class: Bsale::Invoices
- Inherits:
-
Object
- Object
- Bsale::Invoices
- Defined in:
- lib/sale/invoices.rb
Instance Method Summary collapse
- #create(codeSii:, emissionDate:, expirationDate:, declareSii:, priceListId:, officeId: nil, clientId: nil, client: nil, details: nil, payments: nil) ⇒ Object
-
#get_pdf(url) ⇒ Object
actions.
-
#initialize(client) ⇒ Invoices
constructor
A new instance of Invoices.
- #mark_declared(id) ⇒ Object
- #remove(id:, office_id:) ⇒ Object
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:, 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 |
# File 'lib/sale/invoices.rb', line 20 def create(codeSii:, emissionDate:, expirationDate:, declareSii:, priceListId:, \ officeId: nil, clientId: nil, client: nil, details: nil, payments: nil) body = { codeSii: codeSii, # we could also use "documentTypeId" declareSii: declareSii, emissionDate: emissionDate, expirationDate: expirationDate } 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
47 48 49 50 |
# File 'lib/sale/invoices.rb', line 47 def mark_declared(id) body = { id: id, informedSii: 1 } request(:put, 'documents/set_sii_state.json', body) end |
#remove(id:, office_id:) ⇒ Object
52 53 54 |
# File 'lib/sale/invoices.rb', line 52 def remove(id:, office_id:) request(:delete, "documents/#{id}.json?officeid=#{office_id}") end |