Class: Colppy::SellInvoice
- Defined in:
- lib/colppy/resources/sell_invoice.rb
Constant Summary collapse
- VALID_RECEIPT_TYPES =
%w(4 6 8 NCV)
Constants inherited from Resource
Instance Attribute Summary collapse
-
#cae ⇒ Object
readonly
Returns the value of attribute cae.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#items ⇒ Object
Returns the value of attribute items.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#payments ⇒ Object
Returns the value of attribute payments.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .all(client, company) ⇒ Object
- .get(client, company, id) ⇒ Object
- .list(client, company, parameters = {}) ⇒ Object
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #editable? ⇒ Boolean
-
#initialize(client: nil, company: nil, customer: nil, **params) ⇒ SellInvoice
constructor
A new instance of SellInvoice.
- #new? ⇒ Boolean
- #save ⇒ Object
Methods inherited from Resource
Constructor Details
#initialize(client: nil, company: nil, customer: nil, **params) ⇒ SellInvoice
Returns a new instance of SellInvoice.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/colppy/resources/sell_invoice.rb', line 73 def initialize(client: nil, company: nil, customer: nil, **params) @client = client if client && client.is_a?(Colppy::Client) @company = company if company && company.is_a?(Colppy::Company) @customer = customer if customer && customer.is_a?(Colppy::Customer) @id = params.delete(:idFactura) @number = params.delete(:nroFactura) @cae = params.delete(:cae) @items = parse_items(params.delete(:items)) @payments = params.delete(:ItemsCobro) || [] @data = params @url = build_pdf_url end |
Instance Attribute Details
#cae ⇒ Object (readonly)
Returns the value of attribute cae.
3 4 5 |
# File 'lib/colppy/resources/sell_invoice.rb', line 3 def cae @cae end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/colppy/resources/sell_invoice.rb', line 3 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/colppy/resources/sell_invoice.rb', line 3 def id @id end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/colppy/resources/sell_invoice.rb', line 3 def items @items end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/colppy/resources/sell_invoice.rb', line 3 def number @number end |
#payments ⇒ Object
Returns the value of attribute payments.
4 5 6 |
# File 'lib/colppy/resources/sell_invoice.rb', line 4 def payments @payments end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/colppy/resources/sell_invoice.rb', line 3 def url @url end |
Class Method Details
.all(client, company) ⇒ Object
9 10 11 |
# File 'lib/colppy/resources/sell_invoice.rb', line 9 def all(client, company) list(client, company) end |
.get(client, company, id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/colppy/resources/sell_invoice.rb', line 30 def get(client, company, id) response = client.call( :sell_invoice, :read, extended_parameters(client, company, { idFactura: id }) ) if response[:success] new(extended_response(response, client, company)) else response end end |
.list(client, company, parameters = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/colppy/resources/sell_invoice.rb', line 13 def list(client, company, parameters = {}) call_parameters = base_params.merge(parameters) response = client.call( :sell_invoice, :list, extended_parameters(client, company, call_parameters) ) if response[:success] results = response[:data].map do |params| new(params.merge(client: client, company: company)) end parse_list_response(results, response[:total].to_i, call_parameters) else response end end |
Instance Method Details
#[]=(key, value) ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/colppy/resources/sell_invoice.rb', line 114 def []=(key, value) ensure_editability! key_sym = key.to_sym if protected_data_keys.include?(key_sym) raise ResourceError.new("You cannot change any of this values: #{protected_data_keys.join(", ")} manually") end @data[key_sym] = value end |
#editable? ⇒ Boolean
93 94 95 |
# File 'lib/colppy/resources/sell_invoice.rb', line 93 def editable? cae.nil? || cae.empty? end |
#new? ⇒ Boolean
89 90 91 |
# File 'lib/colppy/resources/sell_invoice.rb', line 89 def new? id.nil? || id.empty? end |
#save ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/colppy/resources/sell_invoice.rb', line 97 def save ensure_editability! && ensure_client_valid! && ensure_company_valid! && ensure_customer_valid! response = @client.call( :sell_invoice, :create, save_parameters ) binding.pry if response[:success] @id = response[:data][:idFactura] self else false end end |