Class: Vng::WorkOrder
Overview
Provides methods to interact with Vonigo work orders.
Constant Summary collapse
- PATH =
'/api/v1/data/WorkOrders/'
Instance Attribute Summary collapse
-
#discount ⇒ Object
readonly
Returns the value of attribute discount.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#scheduled_on ⇒ Object
readonly
Returns the value of attribute scheduled_on.
-
#tax ⇒ Object
readonly
Returns the value of attribute tax.
-
#tip ⇒ Object
readonly
Returns the value of attribute tip.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
- .create(lock_id:, client_id:, contact_id:, location_id:, duration:, summary:, line_items:) ⇒ Object
- .for_client_id(client_id) ⇒ Object
Instance Method Summary collapse
-
#initialize(id:, scheduled_on: nil, price: nil, discount: nil, tax: nil, tip: nil, duration: nil, total: nil) ⇒ WorkOrder
constructor
A new instance of WorkOrder.
-
#url ⇒ Object
Returns the URL to manage the work order in the Vonigo UI.
Constructor Details
#initialize(id:, scheduled_on: nil, price: nil, discount: nil, tax: nil, tip: nil, duration: nil, total: nil) ⇒ WorkOrder
Returns a new instance of WorkOrder.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vng/work_order.rb', line 10 def initialize(id:, scheduled_on: nil, price: nil, discount: nil, tax: nil, tip: nil, duration: nil, total: nil) @id = id @scheduled_on = scheduled_on @price = price @discount = discount @tax = tax @tip = tip @duration = duration @total = total end |
Instance Attribute Details
#discount ⇒ Object (readonly)
Returns the value of attribute discount.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def discount @discount end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def duration @duration end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def id @id end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def price @price end |
#scheduled_on ⇒ Object (readonly)
Returns the value of attribute scheduled_on.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def scheduled_on @scheduled_on end |
#tax ⇒ Object (readonly)
Returns the value of attribute tax.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def tax @tax end |
#tip ⇒ Object (readonly)
Returns the value of attribute tip.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def tip @tip end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
8 9 10 |
# File 'lib/vng/work_order.rb', line 8 def total @total end |
Class Method Details
.create(lock_id:, client_id:, contact_id:, location_id:, duration:, summary:, line_items:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vng/work_order.rb', line 21 def self.create(lock_id:, client_id:, contact_id:, location_id:, duration:, summary:, line_items:) body = { method: '3', serviceTypeID: '14', # only return items of serviceType 'Pet Grooming' lockID: lock_id, clientID: client_id, contactID: contact_id, locationID: location_id, Fields: [ { fieldID: 200, fieldValue: summary }, { fieldID: 186, fieldValue: duration.to_i }, { fieldID: 201, optionID: '9537' } # label: Online Tentative ], Charges: charges_for(line_items) } data = request path: PATH, body: body new id: data['WorkOrder']['objectID'] end |
.for_client_id(client_id) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vng/work_order.rb', line 42 def self.for_client_id(client_id) body = { clientID: client_id, isCompleteObject: 'true' } data = request path: PATH, body: body, returning: 'WorkOrders' data.filter_map do |body| next unless body['isActive'] id = body['objectID'] # scheduled_on is in the time zone of the franchise, not UTC scheduled_on = Time.at Integer(value_for_field body, 185), in: 'UTC' price = BigDecimal(value_for_field body, 813) discount = BigDecimal(value_for_field body, 809) tax = BigDecimal(value_for_field body, 811) tip = BigDecimal(value_for_field body, 810) duration = Integer(value_for_field body, 186) total = BigDecimal(value_for_field body, 9835) new id:, scheduled_on:, price:, discount:, tax:, tip:, duration:, total: end end |
Instance Method Details
#url ⇒ Object
Returns the URL to manage the work order in the Vonigo UI.
65 66 67 |
# File 'lib/vng/work_order.rb', line 65 def url "https://#{self.class.host}/Schedule/Job/Job_Main.aspx?woID=#{id}" end |