Class: Vng::WorkOrder

Inherits:
Resource show all
Defined in:
lib/vng/work_order.rb

Overview

Provides methods to interact with Vonigo work orders.

Constant Summary collapse

PATH =
'/api/v1/data/WorkOrders/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, scheduled_on: nil, price: nil, discount: nil, tax: nil, tip: nil, duration: nil, total: nil, route_id: nil) ⇒ WorkOrder



10
11
12
13
14
15
16
17
18
19
20
# 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, route_id: nil)
  @id = id
  @scheduled_on = scheduled_on
  @price = price
  @discount = discount
  @tax = tax
  @tip = tip
  @duration = duration
  @total = total
  @route_id = route_id
end

Instance Attribute Details

#discountObject (readonly)

Returns the value of attribute discount.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def discount
  @discount
end

#durationObject (readonly)

Returns the value of attribute duration.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def id
  @id
end

#priceObject (readonly)

Returns the value of attribute price.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def price
  @price
end

#route_idObject (readonly)

Returns the value of attribute route_id.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def route_id
  @route_id
end

#scheduled_onObject (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

#taxObject (readonly)

Returns the value of attribute tax.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def tax
  @tax
end

#tipObject (readonly)

Returns the value of attribute tip.



8
9
10
# File 'lib/vng/work_order.rb', line 8

def tip
  @tip
end

#totalObject (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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vng/work_order.rb', line 22

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vng/work_order.rb', line 43

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 active?(body)

    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)
    route_id = value_for_relation body, 'route'

    new id:, scheduled_on:, price:, discount:, tax:, tip:, duration:, total:, route_id:
  end
end

Instance Method Details

#urlObject

Returns the URL to manage the work order in the Vonigo UI.



67
68
69
# File 'lib/vng/work_order.rb', line 67

def url
  "https://#{self.class.host}/Schedule/Job/Job_Main.aspx?woID=#{id}"
end