Class: Centralpos::Batch
- Inherits:
-
Object
- Object
- Centralpos::Batch
- Includes:
- Utils
- Defined in:
- lib/centralpos/batch.rb
Instance Attribute Summary collapse
-
#card ⇒ Object
readonly
Returns the value of attribute card.
-
#card_id ⇒ Object
readonly
Returns the value of attribute card_id.
-
#commerce_number ⇒ Object
readonly
Returns the value of attribute commerce_number.
-
#date_since ⇒ Object
readonly
Returns the value of attribute date_since.
-
#date_until ⇒ Object
readonly
Returns the value of attribute date_until.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#processed_date ⇒ Object
readonly
Returns the value of attribute processed_date.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_id ⇒ Object
readonly
Returns the value of attribute status_id.
Instance Method Summary collapse
- #add_transaction(transaction) ⇒ Object
- #can_process?(date_when = nil) ⇒ Boolean
- #get_transaction(transaction) ⇒ Object
- #has_transaction?(transaction) ⇒ Boolean
-
#initialize(account: nil, **params) ⇒ Batch
constructor
A new instance of Batch.
- #process ⇒ Object
- #remove_transaction(transaction) ⇒ Object
- #transactions ⇒ Object
- #update_transaction(transaction) ⇒ Object
Methods included from Utils
#ensure_array, #in_time_zone, #inspect
Constructor Details
#initialize(account: nil, **params) ⇒ Batch
Returns a new instance of Batch.
6 7 8 9 10 |
# File 'lib/centralpos/batch.rb', line 6 def initialize(account: nil, **params) @account = account if account && account.is_a?(Centralpos::Account) @id = params.delete(:id) || params.delete(:id_presentacion) process_data(params) end |
Instance Attribute Details
#card ⇒ Object (readonly)
Returns the value of attribute card.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def card @card end |
#card_id ⇒ Object (readonly)
Returns the value of attribute card_id.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def card_id @card_id end |
#commerce_number ⇒ Object (readonly)
Returns the value of attribute commerce_number.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def commerce_number @commerce_number end |
#date_since ⇒ Object (readonly)
Returns the value of attribute date_since.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def date_since @date_since end |
#date_until ⇒ Object (readonly)
Returns the value of attribute date_until.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def date_until @date_until end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def id @id end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def period @period end |
#processed_date ⇒ Object (readonly)
Returns the value of attribute processed_date.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def processed_date @processed_date end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def status @status end |
#status_id ⇒ Object (readonly)
Returns the value of attribute status_id.
4 5 6 |
# File 'lib/centralpos/batch.rb', line 4 def status_id @status_id end |
Instance Method Details
#add_transaction(transaction) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/centralpos/batch.rb', line 29 def add_transaction(transaction) ensure_account_valid! && ensure_transaction_valid!(transaction) response = @account.gateway.call(:add_registro, batch_params.merge(transaction.to_add_params)) if response[:success] && response[:error].nil? { transaction: transaction.to_hash } else response end end |
#can_process?(date_when = nil) ⇒ Boolean
69 70 71 72 73 74 |
# File 'lib/centralpos/batch.rb', line 69 def can_process?(date_when = nil) date_when = Time.now if date_when.nil? || !date_when.is_a?(DateTime) date_when_utc = date_when.utc (@date_since.utc <= date_when_utc) && (date_when_utc <= @date_until.utc) end |
#get_transaction(transaction) ⇒ Object
63 64 65 66 67 |
# File 'lib/centralpos/batch.rb', line 63 def get_transaction(transaction) return unless has_transaction?(transaction) { transaction: transactions_by_id.fetch(transaction.owner_id) } end |
#has_transaction?(transaction) ⇒ Boolean
59 60 61 |
# File 'lib/centralpos/batch.rb', line 59 def has_transaction?(transaction) transactions_by_id.key?(transaction.owner_id) end |
#process ⇒ Object
76 77 78 79 80 |
# File 'lib/centralpos/batch.rb', line 76 def process ensure_account_valid! @account.gateway.call(:put_procesa_presentacion, batch_params) end |
#remove_transaction(transaction) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/centralpos/batch.rb', line 41 def remove_transaction(transaction) ensure_account_valid! && ensure_transaction_valid!(transaction) response = @account.gateway.call(:del_registro, batch_params.merge(transaction.to_remove_params)) if response[:success] && response[:error].nil? { transaction: transaction.to_hash } else response end end |
#transactions ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/centralpos/batch.rb', line 12 def transactions ensure_account_valid! response = @account.gateway.call(:list_registros, batch_params) if response[:success] && response[:error].nil? return [] if response[:result][:lista_registros].nil? entries = ensure_array(response[:result][:lista_registros][:registro]) entries.map do |entries_data| Centralpos::Transaction.load_it(entries_data.merge(batch: self)) end else response end end |
#update_transaction(transaction) ⇒ Object
53 54 55 56 57 |
# File 'lib/centralpos/batch.rb', line 53 def update_transaction(transaction) ensure_account_valid! && ensure_transaction_valid!(transaction) remove_transaction(transaction) add_transaction(transaction) end |