Class: Colppy::Company
- Defined in:
- lib/colppy/resources/company.rb
Constant Summary collapse
- ATTRIBUTES_MAPPER =
{ idPlan: :plan_id, activa: :active, fechaVencimiento: :expiration_date }.freeze
- PROTECTED_DATA_KEYS =
ATTRIBUTES_MAPPER.values
Constants included from Utils
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Resource
Class Method Summary collapse
Instance Method Summary collapse
- #account_name(account_id) ⇒ Object
- #available_accounts ⇒ Object
- #customer_by_id(id) ⇒ Object (also: #customer)
- #customers(params = {}) ⇒ Object
-
#initialize(client: nil, **params) ⇒ Company
constructor
A new instance of Company.
- #params ⇒ Object
- #product_by_code(code) ⇒ Object
- #product_by_id(id) ⇒ Object (also: #product)
- #products(params = {}) ⇒ Object
- #sell_invoice_by_id(id) ⇒ Object (also: #sell_invoice)
- #sell_invoices(params = {}) ⇒ Object
Methods inherited from Resource
Methods included from Utils
Constructor Details
#initialize(client: nil, **params) ⇒ Company
Returns a new instance of Company.
43 44 45 46 47 48 49 |
# File 'lib/colppy/resources/company.rb', line 43 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 |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/colppy/resources/company.rb', line 12 def id @id end |
#name ⇒ Object (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
22 23 24 |
# File 'lib/colppy/resources/company.rb', line 22 def all(client) list(client) end |
.list(client, parameters = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/colppy/resources/company.rb', line 26 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
#account_name(account_id) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/colppy/resources/company.rb', line 135 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 ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/colppy/resources/company.rb', line 116 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) ⇒ Object Also known as: customer
60 61 62 63 64 |
# File 'lib/colppy/resources/company.rb', line 60 def customer_by_id(id) ensure_client_valid! Customer.get(@client, self, id) end |
#customers(params = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/colppy/resources/company.rb', line 51 def customers(params = {}) ensure_client_valid! if params.empty? Customer.all(@client, self) else Customer.list(@client, self, params) end end |
#params ⇒ Object
143 144 145 |
# File 'lib/colppy/resources/company.rb', line 143 def params { idEmpresa: @id } end |
#product_by_code(code) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/colppy/resources/company.rb', line 76 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) ⇒ Object Also known as: product
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/colppy/resources/company.rb', line 87 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 |
#products(params = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/colppy/resources/company.rb', line 67 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
109 110 111 112 113 |
# File 'lib/colppy/resources/company.rb', line 109 def sell_invoice_by_id(id) ensure_client_valid! SellInvoice.get(@client, self, id) end |
#sell_invoices(params = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/colppy/resources/company.rb', line 100 def sell_invoices(params = {}) ensure_client_valid! if params.empty? SellInvoice.all(@client, self) else SellInvoice.list(@client, self, params) end end |