class Colppy::Invoice::Item
Constants
- ATTRIBUTES_MAPPER
- DATA_KEYS_SETTERS
- PROTECTED_DATA_KEYS
Attributes
data[R]
id[R]
Public Class Methods
new(params, company = nil)
click to toggle source
# File lib/colppy/resources/invoice.rb, line 91 def initialize(params, company = nil) @company = company if company.is_a?(Colppy::Company) @id = params.delete(:id) @product = params.delete(:product) @data = rename_params_hash(params, ATTRIBUTES_MAPPER, DATA_KEYS_SETTERS) if @product && @product.is_a?(Colppy::Product) @data[:product_id] = @product.id else @product = nil end end
Public Instance Methods
charged()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 133 def charged if (percentage = discount_percentage.to_f) > 0 unit_price * ((100 - percentage) / 100) else unit_price end end
code()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 155 def code (@data[:code] || product.code || "") end
comment()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 167 def comment (@data[:comment] || "#{product.name}, #{product.detail}" || "") end
inspect()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 192 def inspect "#<#{self.class.name} product_id:#{@data[:product_id]} >" end
item_type()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 152 def item_type (@data[:item_type] || product.item_type || "P") end
measure_unit()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 161 def measure_unit (@data[:measure_unit] || product.measure_unit || "u") end
minimum_stock()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 149 def minimum_stock (@data[:minimum_stock] || product.minimum_stock || 0) end
name()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 158 def name (@data[:name] || product.name || "") end
product()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 118 def product @product ||= @company.product(@data[:product_id]) end
product_id()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 126 def product_id @data[:product_id] end
product_id=(value)
click to toggle source
# File lib/colppy/resources/invoice.rb, line 122 def product_id=(value) @product = nil @data[:product_id] = value end
quantity()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 143 def quantity @data[:quantity] || 0 end
sales_account_id()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 164 def sales_account_id (@data[:sales_account_id] || product.sales_account || "") end
save_parameters()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 171 def save_parameters { idItem: product_id.to_s, minimo: minimum_stock.to_s, tipoItem: item_type, codigo: code, Descripcion: name, ccosto1: unhandle_data[:ccosto1] || "", ccosto2: unhandle_data[:ccosto2] || "", almacen: unhandle_data[:almacen] || "", unidadMedida: measure_unit, Cantidad: quantity, ImporteUnitario: unit_price.round(2), porcDesc: discount_percentage || 0, IVA: tax.to_s, subtotal: total_charged, idPlanCuenta: sales_account_id, Comentario: comment } end
tax()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 130 def tax (@data[:tax] || product.tax || 21).to_f end
total_charged()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 146 def total_charged ( charged * quantity ).round(2) end
unhandle_data()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 114 def unhandle_data @data[:unhandle] || {} end
unit_price()
click to toggle source
# File lib/colppy/resources/invoice.rb, line 140 def unit_price (@data[:unit_price] || product.sell_price || 0).to_f end