class Colppy::Company
Constants
- ATTRIBUTES_MAPPER
- PROTECTED_DATA_KEYS
Attributes
id[R]
name[R]
Public Class Methods
all(client)
click to toggle source
# File lib/colppy/resources/company.rb, line 39 def all(client) list(client) end
get(client, id)
click to toggle source
# File lib/colppy/resources/company.rb, line 59 def get(client, id) response = client.call( :company, :read, client.session_params.merge({ idEmpresa: id }) ) if response[:success] new(response[:data].merge(client: client)) else response end end
list(client, parameters = {})
click to toggle source
# File lib/colppy/resources/company.rb, line 43 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
new(client: nil, **params)
click to toggle source
Calls superclass method
Colppy::Resource::new
# File lib/colppy/resources/company.rb, line 74 def initialize(client: nil, **params) @client = client if client && client.is_a?(Colppy::Client) @id = params.delete(:IdEmpresa) || params.delete(:id) @name = params.delete(:razonSocial) || params.delete(:name) super(params) end
Public Instance Methods
account_name(account_id)
click to toggle source
# File lib/colppy/resources/company.rb, line 166 def account_name(account_id) return if available_accounts.nil? || available_accounts.empty? if account = available_accounts.detect{ |a| a[:account_id].to_s == account_id.to_s } account[:name] end end
available_accounts()
click to toggle source
# File lib/colppy/resources/company.rb, line 147 def available_accounts return @available_accounts unless @available_accounts.nil? || @available_accounts.empty? response = @client.call( :inventory, :accounts_list, params.merge(@client.session_params) ) if response[:success] @available_accounts = response[:cuentas].map do |account| { id: account[:Id], account_id: account[:idPlanCuenta], full_name: account[:Descripcion], name: account[:Descripcion].split(' - ')[1] } end end end
customer_by_id(id)
click to toggle source
# File lib/colppy/resources/company.rb, line 91 def customer_by_id(id) ensure_client_valid! Customer.get(@client, self, id) end
Also aliased as: customer
customers(params = {})
click to toggle source
# File lib/colppy/resources/company.rb, line 82 def customers(params = {}) ensure_client_valid! if params.empty? Customer.all(@client, self) else Customer.list(@client, self, params) end end
params()
click to toggle source
# File lib/colppy/resources/company.rb, line 174 def params { idEmpresa: @id } end
product_by_code(code)
click to toggle source
# File lib/colppy/resources/company.rb, line 107 def product_by_code(code) ensure_client_valid! params = { filter: [ { field: "codigo", op: "=", value: code } ] } response = Product.list(@client, self, params) response[:results].last end
product_by_id(id)
click to toggle source
# File lib/colppy/resources/company.rb, line 118 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
Also aliased as: product
products(params = {})
click to toggle source
# File lib/colppy/resources/company.rb, line 98 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)
click to toggle source
# File lib/colppy/resources/company.rb, line 140 def sell_invoice_by_id(id) ensure_client_valid! SellInvoice.get(@client, self, id) end
Also aliased as: sell_invoice
sell_invoices(params = {})
click to toggle source
# File lib/colppy/resources/company.rb, line 131 def sell_invoices(params = {}) ensure_client_valid! if params.empty? SellInvoice.all(@client, self) else SellInvoice.list(@client, self, params) end end
Private Instance Methods
attr_inspect()
click to toggle source
# File lib/colppy/resources/company.rb, line 180 def attr_inspect [:id, :name] end