Class: Colppy::Company

Inherits:
Resource show all
Defined in:
lib/colppy/resources/company.rb

Constant Summary

Constants inherited from Resource

Resource::VALID_INVOICE_TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#inspect

Constructor Details

#initialize(client: nil, **params) ⇒ Company

Returns a new instance of Company.



36
37
38
39
40
41
# File 'lib/colppy/resources/company.rb', line 36

def initialize(client: nil, **params)
  @client = client if client && client.is_a?(Colppy::Client)
  @id = params.delete(:IdEmpresa)
  @name = params.delete(:razonSocial)
  @extras = params
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/colppy/resources/company.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/colppy/resources/company.rb', line 12

def name
  @name
end

Class Method Details

.all(client) ⇒ Object



15
16
17
# File 'lib/colppy/resources/company.rb', line 15

def all(client)
  list(client)
end

.list(client, parameters = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/colppy/resources/company.rb', line 19

def list(client, parameters = {})
  response = client.call(
    :company,
    :list,
    parameters.merge(client.session_params)
  )
  if response[:success]
    results = response[:data].map do |params|
      new(params.merge(client: client))
    end
    parse_list_response(results, response[:total].to_i, parameters)
  else
    response
  end
end

Instance Method Details

#customer_by_id(id) ⇒ Object Also known as: customer



53
54
55
56
57
# File 'lib/colppy/resources/company.rb', line 53

def customer_by_id(id)
  ensure_client_valid!

  Customer.get(@client, self, id)
end

#customers(params = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/colppy/resources/company.rb', line 43

def customers(params = {})
  ensure_client_valid!

  if params.empty?
    Customer.all(@client, self)
  else
    Customer.list(@client, self, params)
  end
end

#paramsObject



112
113
114
# File 'lib/colppy/resources/company.rb', line 112

def params
  { idEmpresa: @id }
end

#product_by_id(id) ⇒ Object Also known as: product



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/colppy/resources/company.rb', line 82

def product_by_id(id)
  ensure_client_valid!

  params = {
    filter: [
      { field: "idItem", op: "=", value: id }
    ]
  }
  response = Product.list(@client, self, params)
  response[:results].last
end

#product_by_sku(sku) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/colppy/resources/company.rb', line 70

def product_by_sku(sku)
  ensure_client_valid!

  params = {
    filter: [
      { field: "codigo", op: "=", value: sku }
    ]
  }
  response = Product.list(@client, self, params)
  response[:results].last
end

#products(params = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/colppy/resources/company.rb', line 59

def products(params = {})
  ensure_client_valid!

  if params.empty?
    Product.all(@client, self)
  else
    Product.list(@client, self, params)
  end
end

#sell_invoice_by_id(id) ⇒ Object Also known as: sell_invoice



105
106
107
108
109
# File 'lib/colppy/resources/company.rb', line 105

def sell_invoice_by_id(id)
  ensure_client_valid!

  SellInvoice.get(@client, self, id)
end

#sell_invoices(params = {}) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/colppy/resources/company.rb', line 95

def sell_invoices(params = {})
  ensure_client_valid!

  if params.empty?
    SellInvoice.all(@client, self)
  else
    SellInvoice.list(@client, self, params)
  end
end