Class: RVista::POALineItem

Inherits:
Object
  • Object
show all
Defined in:
lib/rvista/poa_line_item.rb

Overview

represents a single line on the purchase order ack. Has attributes like price, qty and description

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#availability_dateObject

Returns the value of attribute availability_date.



15
16
17
# File 'lib/rvista/poa_line_item.rb', line 15

def availability_date
  @availability_date
end

#buying_locationObject

Returns the value of attribute buying_location.



13
14
15
# File 'lib/rvista/poa_line_item.rb', line 13

def buying_location
  @buying_location
end

#buying_location_nameObject

Returns the value of attribute buying_location_name.



13
14
15
# File 'lib/rvista/poa_line_item.rb', line 13

def buying_location_name
  @buying_location_name
end

#delivered_qtyObject

Returns the value of attribute delivered_qty.



13
14
15
# File 'lib/rvista/poa_line_item.rb', line 13

def delivered_qty
  @delivered_qty
end

#demand_qtyObject

Returns the value of attribute demand_qty.



14
15
16
# File 'lib/rvista/poa_line_item.rb', line 14

def demand_qty
  @demand_qty
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/rvista/poa_line_item.rb', line 11

def description
  @description
end

#discount_percentObject

Returns the value of attribute discount_percent.



14
15
16
# File 'lib/rvista/poa_line_item.rb', line 14

def discount_percent
  @discount_percent
end

#eanObject

Returns the value of attribute ean.



11
12
13
# File 'lib/rvista/poa_line_item.rb', line 11

def ean
  @ean
end

#line_numObject

Returns the value of attribute line_num.



11
12
13
# File 'lib/rvista/poa_line_item.rb', line 11

def line_num
  @line_num
end

#nett_unit_priceObject

Returns the value of attribute nett_unit_price.



12
13
14
# File 'lib/rvista/poa_line_item.rb', line 12

def nett_unit_price
  @nett_unit_price
end

#qty_innersObject

Returns the value of attribute qty_inners.



12
13
14
# File 'lib/rvista/poa_line_item.rb', line 12

def qty_inners
  @qty_inners
end

#rrpObject

Returns the value of attribute rrp.



14
15
16
# File 'lib/rvista/poa_line_item.rb', line 14

def rrp
  @rrp
end

#status_codeObject

Returns the value of attribute status_code.



14
15
16
# File 'lib/rvista/poa_line_item.rb', line 14

def status_code
  @status_code
end

#tax_rateObject

Returns the value of attribute tax_rate.



12
13
14
# File 'lib/rvista/poa_line_item.rb', line 12

def tax_rate
  @tax_rate
end

#textObject

Returns the value of attribute text.



15
16
17
# File 'lib/rvista/poa_line_item.rb', line 15

def text
  @text
end

Class Method Details

.load_from_array(data) ⇒ Object

returns a new RVista::POALineItem object using the data passed in as an array. The array should have exactly 14 items in it. Refer to the Vista standard to see what those 14 items should be.



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

def self.load_from_array(data)
  item = self.new
  raise InvalidLineItemError, 'incorrect number of data points' unless data.size == 20

  item.line_num = data[1].to_i
  item.ean = data[2]
  item.description = data[4]
  item.nett_unit_price = BigDecimal.new(data[5]) unless data[5].nil?
  item.qty_inners = data[7].to_i
  item.tax_rate = BigDecimal.new(data[8]) unless data[8].nil?
  item.buying_location = data[10]
  item.buying_location_name = data[11]
  item.delivered_qty = data[13].to_i
  item.status_code = data[14]
  item.demand_qty = data[15].to_i
  item.rrp = BigDecimal.new(data[16]) unless data[16].nil?
  item.discount_percent = BigDecimal.new(data[17]) unless data[17].nil?
  item.availability_date = data[18] # TODO: convert this to a Date?
  item.text = data[19]

  return item
end

Instance Method Details

#status_textObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rvista/poa_line_item.rb', line 43

def status_text
  case self.status_code.to_i
  when 1  then "Accepted: Title Shipped As Ordered"
  when 2  then "Accepted: Substitute Title Shipped As Ordered"
  when 3  then "Cancelled: Future Publication"
  when 4  then "Cancelled: Future Publication" # date available
  when 5  then "Backordered: Future Publication"
  when 6  then "Cancelled: Out of Stock"
  when 7  then "Backordered: Out of Stock"
  when 8  then "Cancelled: Out of Print"
  when 9  then "Partial Ship: Cancel Rest"
  when 10 then "Partial Ship: Backorder Rest"
  when 11 then "Cancelled: HB Out of Print, PB Available"
  when 12 then "Cancelled: PB Out of Print, HB Available"
  when 13 then "Cancelled: Out of Print, Alt. Edition Available"
  when 14 then "Backordered: Subtitute Title on BO."
  when 15 then "Cancelled: No Rights"
  when 16 then "Cancelled: Not our Publication"
  when 17 then "Accepted: Free Book"
  when 18 then "Cancelled: BO Expired"
  when 19 then "Cancelled: Subscription Only"
  when 20 then "Cancelled: Not Carried"
  when 21 then "Cancelled: Not Carried"
  when 22 then "Cancelled: Import Title"
  when 23 then "Cancelled: Not Available for Wholesale"
  when 24 then "Cancelled: Kits Not Available"
  when 25 then "Cancelled: Not Available"
  when 26 then "Cancelled: New Price From Publisher"
  when 27 then "Cancelled: ISBN Not Recognised"
  when 28 then "Cancelled: Out of Print"
  when 29 then "Backordered: At Customers Request"
  else
    "UNKNOWN"
  end
end

#to_sObject

output a string that represents this line item that meets the vista spec



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rvista/poa_line_item.rb', line 80

def to_s
  nil_numeric_values
  normalise_numeric_values

  msg = ""
  msg << "D,"
  msg << "#{line_num},"
  msg << "#{ean},"
  msg << ","
  msg << "#{description},"
  msg << "#{formatted_nett_unit_price},"
  msg << "1,"
  msg << "#{qty_inners},"
  msg << "#{formatted_tax_rate},"
  msg << ","
  msg << "#{buying_location},"
  msg << "#{buying_location_name},"
  msg << ","
  msg << "#{delivered_qty},"
  msg << "#{status_code},"
  msg << "#{demand_qty},"
  msg << "#{formatted_rrp},"
  msg << "#{formatted_discount_percent},"
  msg << "#{availability_date},"
  msg << "#{text}"
  return msg
end