Class: RVista::POLineItem

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

Overview

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

Direct Known Subclasses

LineItem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#additional_discount ⇒ Object

Returns the value of attribute additional_discount.



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

def additional_discount
  @additional_discount
end

#backorder ⇒ Object

Returns the value of attribute backorder.



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

def backorder
  @backorder
end

#description ⇒ Object

Returns the value of attribute description.



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

def description
  @description
end

#discount ⇒ Object

Returns the value of attribute discount.



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

def discount
  @discount
end

#ean ⇒ Object

Returns the value of attribute ean.



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

def ean
  @ean
end

#firm_sale ⇒ Object

Returns the value of attribute firm_sale.



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

def firm_sale
  @firm_sale
end

#line_num ⇒ Object

Returns the value of attribute line_num.



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

def line_num
  @line_num
end

#nett_unit_price ⇒ Object

Returns the value of attribute nett_unit_price.



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

def nett_unit_price
  @nett_unit_price
end

#qty ⇒ Object

Returns the value of attribute qty.



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

def qty
  @qty
end

#qualifier ⇒ Object

Returns the value of attribute qualifier.



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

def qualifier
  @qualifier
end

#retail_unit_price ⇒ Object

Returns the value of attribute retail_unit_price.



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

def retail_unit_price
  @retail_unit_price
end

#unit_measure ⇒ Object

Returns the value of attribute unit_measure.



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

def unit_measure
  @unit_measure
end

#was_unit_price ⇒ Object

Returns the value of attribute was_unit_price.



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

def was_unit_price
  @was_unit_price
end

Class Method Details

.load_from_array(data) ⇒ Object

returns a new RVista::LineItem 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.



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

def self.load_from_array(data)
  item = self.new
  raise InvalidLineItemError, "incorrect number of data points (#{data.inspect})" unless data.size == 14

  item.line_num = data[1].to_i
  item.qualifier = data[2]
  item.ean = data[3]
  item.description = data[4]
  item.qty = data[5].to_i
  item.nett_unit_price = BigDecimal.new(data[6]) unless data[6].nil?
  item.unit_measure = data[7]
  item.retail_unit_price = BigDecimal.new(data[8]) unless data[8].nil?
  item.was_unit_price = BigDecimal.new(data[9]) unless data[9].nil?
  item.discount = data[10].to_i unless data[10].nil?
  item.backorder = data[11] == "N" ? false : true
  item.additional_discount = data[12]
  item.firm_sale = data[13]

  return item
end

Instance Method Details

#to_s ⇒ Object

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



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

def to_s
  msg = ""
  msg << "D," 
  msg << "#{line_num.to_s},"
  msg << "#{qualifier},"
  msg << "#{ean},"
  msg << "#{description},"
  msg << "#{qty.to_s},"
  msg << sprintf("%.2f", nett_unit_price) unless nett_unit_price.nil?
  msg << ","
  msg << "#{unit_measure},"
  msg << sprintf("%.2f", retail_unit_price) unless retail_unit_price.nil?
  msg << ","
  msg << sprintf("%.2f", was_unit_price) unless was_unit_price.nil?
  msg << ","
  msg << "#{discount.to_s},"
  if backorder == true
    msg << "Y,"
  else
    msg << "N,"
  end
  msg << "#{additional_discount},"
  msg << "#{firm_sale}"
  return msg
end