rvista 0.2 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
  require "rake/gempackagetask"
6
6
  require "rubygems"
7
7
 
8
- PKG_VERSION = "0.2"
8
+ PKG_VERSION = "0.5"
9
9
  PKG_NAME = "rvista"
10
10
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
11
 
@@ -53,7 +53,7 @@ spec = Gem::Specification.new do |spec|
53
53
  spec.extra_rdoc_files = %w{README COPYING LICENSE}
54
54
  spec.rdoc_options << '--title' << 'rvista Documentation' <<
55
55
  '--main' << 'README' << '-q'
56
- spec.add_dependency('fastercsv', '>= 0.2.1')
56
+ spec.add_dependency('fastercsv', '>= 1.2.1')
57
57
  spec.author = "James Healy"
58
58
  spec.email = "jimmy@deefa.com"
59
59
  spec.description = <<END_DESC
data/examples/test.rb ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + "/../lib/rvista"
4
+
5
+ #filename = File.dirname(__FILE__) + "/../test/data/seperate_delivery_location.txt"
6
+ filename = File.dirname(__FILE__) + "/../test/data/no_delivery_location.txt"
7
+ #filename = File.dirname(__FILE__) + "/../test/data/valid.txt"
8
+
9
+ msg = RVista::Message.load_from_file(filename)
10
+ if msg.delivery_location.nil?
11
+ puts "nil delivery location"
12
+ else
13
+ puts msg.delivery_location
14
+ end
@@ -0,0 +1,104 @@
1
+ require 'rubygems'
2
+ require 'fastercsv'
3
+
4
+ module RVista
5
+
6
+ # Represents a single Vista Invoice
7
+ class Invoice
8
+
9
+ attr_accessor :sender_id, :receiver_id, :doc_type, :description
10
+ attr_accessor :doc_number, :doc_date, :delivery_location, :currency
11
+ attr_accessor :items
12
+
13
+ # creates a new RVista::Invoice object
14
+ def initialize
15
+ @items = []
16
+ end
17
+
18
+ # reads a vista invoice file into memory. input should be a string
19
+ # that specifies the file path
20
+ def self.load_from_file(input)
21
+ raise InvalidFileError, 'Invalid file' unless File.exist?(input)
22
+ data = FasterCSV.read(input)
23
+ return self.build_message(data)
24
+ end
25
+
26
+ # creates a RVista::Invoice object from a string. Input should
27
+ # be a complete vista file as a string
28
+ def self.load_from_string(input)
29
+ data = FasterCSV.parse(input)
30
+ return self.build_message(data)
31
+ end
32
+
33
+ # print a string representation of this order that meets the spec
34
+ def to_s
35
+ # message header
36
+ msg = ""
37
+ msg << "H,"
38
+ msg << "#{sender_id},"
39
+ msg << "#{receiver_id},"
40
+ msg << "#{doc_type},"
41
+ msg << "#{description},"
42
+ msg << "#{doc_number},"
43
+ msg << "#{doc_date},"
44
+ msg << "#{delivery_location},"
45
+ msg << "#{currency}\n"
46
+
47
+ total_value = BigDecimal.new("0")
48
+ total_qty = BigDecimal.new("0")
49
+ total_gst = BigDecimal.new("0")
50
+
51
+ # message line items
52
+ @items.each do |item|
53
+ msg << item.to_s << "\n"
54
+ total_value += item.value
55
+ total_qty += item.qty
56
+ total_gst += item.gst
57
+ end
58
+
59
+ # message summary
60
+ msg << "S,"
61
+ msg << "#{@items.size.to_s},"
62
+ msg << sprintf("%.2f", total_value)
63
+ msg << ","
64
+ msg << sprintf("%.0f", total_qty)
65
+ msg << ","
66
+ msg << sprintf("%.2f", total_gst)
67
+ msg << "\n"
68
+
69
+ return msg
70
+ end
71
+
72
+ private
73
+
74
+ def self.build_message(data)
75
+ raise InvalidFileError, 'File appears to be too short' unless data.size >= 3
76
+ raise InvalidFileError, 'Missing header information' unless data[0][0].eql?("H")
77
+ raise InvalidFileError, 'Missing footer information' unless data[-1][0].eql?("S")
78
+
79
+ msg = self.new
80
+
81
+ # set message attributes
82
+ msg.sender_id = data[0][1]
83
+ msg.receiver_id = data[0][2]
84
+ msg.doc_type = data[0][3]
85
+ msg.description = data[0][4]
86
+ msg.doc_number = data[0][5]
87
+ msg.doc_date = data[0][6]
88
+ msg.delivery_location = data[0][7]
89
+ msg.currency = data[0][8]
90
+
91
+ # load each lineitem into the message
92
+ data[1,data.size - 2].each do |row|
93
+ raise InvalidLineItemError, 'Invalid line detected' unless row[0].eql?("D")
94
+ item = InvoiceLineItem.load_from_array(row)
95
+ msg.items << item
96
+ end
97
+
98
+ raise InvalidFileError, 'Line item count doesn\'t match footer' unless data[-1][1].to_i.eql?(msg.items.size)
99
+
100
+ # return the results
101
+ return msg
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,86 @@
1
+ require 'bigdecimal'
2
+
3
+ module RVista
4
+
5
+ # represents a single line on an invoice. Has attributes like
6
+ # price, qty and description
7
+ class InvoiceLineItem
8
+
9
+ attr_accessor :line_num, :po_number, :qualifier, :ean, :description
10
+ attr_accessor :qty, :unit_measure, :rrp, :discount_percent
11
+ attr_accessor :nett_unit_price, :gst_inclusive, :value
12
+ attr_accessor :discount_value, :nett_value, :gst, :firm_sale
13
+
14
+ # returns a new RVista::POALineItem object using the data passed in as an
15
+ # array. The array should have exactly 14 items in it. Refer to the Vista
16
+ # standard to see what those 14 items should be.
17
+ def self.load_from_array(data)
18
+ item = self.new
19
+ raise InvalidLineItemError, 'incorrect number of data points' unless data.size == 17
20
+
21
+ item.line_num = data[1].to_i
22
+ item.po_number = data[2]
23
+ item.qualifier = data[3]
24
+ item.ean = data[4]
25
+ item.description = data[5]
26
+ item.qty = data[6].to_i
27
+ item.unit_measure = data[7]
28
+ item.rrp = BigDecimal.new(data[8]) unless data[8].nil?
29
+ item.discount_percent = BigDecimal.new(data[9]) unless data[9].nil?
30
+ item.nett_unit_price = BigDecimal.new(data[10]) unless data[10].nil?
31
+ if data[11].eql?("Y")
32
+ item.gst_inclusive = true
33
+ else
34
+ item.gst_inclusive = false
35
+ end
36
+ item.value = BigDecimal.new(data[12]) unless data[12].nil?
37
+ item.discount_value = BigDecimal.new(data[13]) unless data[13].nil?
38
+ item.nett_value = BigDecimal.new(data[14]) unless data[14].nil?
39
+ item.gst = BigDecimal.new(data[15]) unless data[15].nil?
40
+ if data[16].eql?("F")
41
+ item.firm_sale = true
42
+ else
43
+ item.firm_sale = false
44
+ end
45
+
46
+ return item
47
+ end
48
+
49
+ # output a string that represents this line item that meets the vista spec
50
+ def to_s
51
+ msg = ""
52
+ msg << "D,"
53
+ msg << "#{line_num},"
54
+ msg << "#{po_number},"
55
+ msg << "#{qualifier},"
56
+ msg << "#{ean},"
57
+ msg << "#{description},"
58
+ msg << "#{qty},"
59
+ msg << "#{unit_measure},"
60
+ msg << sprintf("%.2f", rrp) unless rrp.nil?
61
+ msg << ","
62
+ msg << sprintf("%.2f", discount_percent) unless discount_percent.nil?
63
+ msg << ","
64
+ msg << sprintf("%.2f", nett_unit_price) unless nett_unit_price.nil?
65
+ msg << ","
66
+ if gst_inclusive
67
+ msg << "Y,"
68
+ else
69
+ msg << ","
70
+ end
71
+ msg << sprintf("%.2f", value) unless value.nil?
72
+ msg << ","
73
+ msg << sprintf("%.2f", discount_value) unless discount_value.nil?
74
+ msg << ","
75
+ msg << sprintf("%.2f", nett_value) unless nett_value.nil?
76
+ msg << ","
77
+ msg << sprintf("%.2f", gst) unless gst.nil?
78
+ msg << ","
79
+ if firm_sale
80
+ msg << "F"
81
+ end
82
+
83
+ return msg
84
+ end
85
+ end
86
+ end
@@ -1,12 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'fastercsv'
3
- require File.dirname(__FILE__) + '/line_item'
4
- require File.dirname(__FILE__) + '/errors'
5
3
 
6
4
  module RVista
7
5
 
8
6
  # Represents a single Vista message (purchase order).
9
- class Message
7
+ class PO
10
8
 
11
9
  attr_accessor :sender_id, :receiver_id, :internal_control_number, :po_number
12
10
  attr_accessor :po_subset_code, :purpose_code, :purpose_desc, :date
@@ -78,7 +76,7 @@ module RVista
78
76
  raise InvalidFileError, 'Missing header information' unless data[0][0].eql?("H")
79
77
  raise InvalidFileError, 'Missing footer information' unless data[-1][0].eql?("S")
80
78
 
81
- msg = Message.new
79
+ msg = self.new
82
80
 
83
81
  # set message attributes
84
82
  msg.sender_id = data[0][1]
@@ -104,7 +102,7 @@ module RVista
104
102
  # load each lineitem into the message
105
103
  data[1,data.size - 2].each do |row|
106
104
  raise InvalidLineItemError, 'Invalid line detected' unless row[0].eql?("D")
107
- item = LineItem.load_from_array(row)
105
+ item = POLineItem.load_from_array(row)
108
106
  msg.items << item
109
107
  end
110
108
 
@@ -4,7 +4,7 @@ module RVista
4
4
 
5
5
  # represents a single line on the purchase order. Has attributes like
6
6
  # price, qty and description
7
- class LineItem
7
+ class POLineItem
8
8
 
9
9
  attr_accessor :line_num, :qualifier, :ean, :description
10
10
  attr_accessor :qty, :nett_unit_price, :unit_measure
@@ -55,7 +55,7 @@ module RVista
55
55
  if backorder == true
56
56
  msg << "Y,"
57
57
  else
58
- "N,"
58
+ msg << "N,"
59
59
  end
60
60
  msg << "#{additional_discount},"
61
61
  msg << "#{firm_sale}"
data/lib/rvista/poa.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'rubygems'
2
+ require 'fastercsv'
3
+
4
+ module RVista
5
+
6
+ # Represents a single Vista Purchase Order Ack (POA).
7
+ class POA
8
+
9
+ attr_accessor :sender_id, :receiver_id, :po_number, :date
10
+ attr_accessor :supply_after, :supply_before, :delivery_location
11
+ attr_accessor :delivery_location_name
12
+ attr_accessor :items
13
+
14
+ # creates a new RVista::POA object
15
+ def initialize
16
+ @items = []
17
+ end
18
+
19
+ # reads a vista poa file into memory. input should be a string
20
+ # that specifies the file path
21
+ def self.load_from_file(input)
22
+ raise InvalidFileError, 'Invalid file' unless File.exist?(input)
23
+ data = FasterCSV.read(input)
24
+ return self.build_message(data)
25
+ end
26
+
27
+ # creates a RVista::POA object from a string. Input should
28
+ # be a complete vista file as a string
29
+ def self.load_from_string(input)
30
+ data = FasterCSV.parse(input)
31
+ return self.build_message(data)
32
+ end
33
+
34
+ # print a string representation of this order that meets the spec
35
+ def to_s
36
+ # message header
37
+ msg = ""
38
+ msg << "H,"
39
+ msg << "#{sender_id},"
40
+ msg << "#{receiver_id},"
41
+ msg << ","
42
+ msg << ","
43
+ msg << ","
44
+ msg << ","
45
+ msg << "#{po_number},"
46
+ msg << "#{date},"
47
+ msg << ","
48
+ msg << "#{supply_after},"
49
+ msg << "#{supply_before},"
50
+ msg << "SP,"
51
+ msg << "#{delivery_location},"
52
+ msg << "#{delivery_location_name}\n"
53
+
54
+ # message line items
55
+ @items.each { |item| msg << item.to_s << "\n"}
56
+
57
+ # message summary
58
+ msg << "S,#{@items.size.to_s},\n"
59
+
60
+
61
+ return msg
62
+ end
63
+
64
+ private
65
+
66
+ def self.build_message(data)
67
+ raise InvalidFileError, 'File appears to be too short' unless data.size >= 3
68
+ raise InvalidFileError, 'Missing header information' unless data[0][0].eql?("H")
69
+ raise InvalidFileError, 'Missing footer information' unless data[-1][0].eql?("S")
70
+
71
+ msg = self.new
72
+
73
+ # set message attributes
74
+ msg.sender_id = data[0][1]
75
+ msg.receiver_id = data[0][2]
76
+ msg.po_number = data[0][7]
77
+ msg.date = data[0][8]
78
+ msg.supply_after = data[0][10]
79
+ msg.supply_before = data[0][11]
80
+ msg.delivery_location = data[0][13]
81
+ msg.delivery_location_name = data[0][14]
82
+
83
+ # load each lineitem into the message
84
+ data[1,data.size - 2].each do |row|
85
+ raise InvalidLineItemError, 'Invalid line detected' unless row[0].eql?("D")
86
+ item = POALineItem.load_from_array(row)
87
+ msg.items << item
88
+ end
89
+
90
+ raise InvalidFileError, 'Line item count doesn\'t match footer' unless data[-1][1].to_i.eql?(msg.items.size)
91
+
92
+ # return the results
93
+ return msg
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,71 @@
1
+ require 'bigdecimal'
2
+
3
+ module RVista
4
+
5
+ # represents a single line on the purchase order ack. Has attributes like
6
+ # price, qty and description
7
+ class POALineItem
8
+
9
+ attr_accessor :line_num, :ean, :description
10
+ attr_accessor :nett_unit_price, :qty_inners, :tax_rate
11
+ attr_accessor :buying_location, :buying_location_name, :delivered_qty
12
+ attr_accessor :status_code, :demand_qty, :rrp, :discount_percent
13
+ attr_accessor :availability_date, :text
14
+
15
+ # returns a new RVista::POALineItem object using the data passed in as an
16
+ # array. The array should have exactly 14 items in it. Refer to the Vista
17
+ # standard to see what those 14 items should be.
18
+ def self.load_from_array(data)
19
+ item = self.new
20
+ raise InvalidLineItemError, 'incorrect number of data points' unless data.size == 20
21
+
22
+ item.line_num = data[1].to_i
23
+ item.ean = data[2]
24
+ item.description = data[4]
25
+ item.nett_unit_price = BigDecimal.new(data[5]) unless data[5].nil?
26
+ item.qty_inners = data[7].to_i
27
+ item.tax_rate = BigDecimal.new(data[8]) unless data[8].nil?
28
+ item.buying_location = data[10]
29
+ item.buying_location_name = data[11]
30
+ item.delivered_qty = data[13].to_i
31
+ item.status_code = data[14]
32
+ item.demand_qty = data[15].to_i
33
+ item.rrp = BigDecimal.new(data[16]) unless data[16].nil?
34
+ item.discount_percent = BigDecimal.new(data[17]) unless data[17].nil?
35
+ item.availability_date = data[18] # TODO: convert this to a Date?
36
+ item.text = data[19]
37
+
38
+ return item
39
+ end
40
+
41
+ # output a string that represents this line item that meets the vista spec
42
+ def to_s
43
+ msg = ""
44
+ msg << "D,"
45
+ msg << "#{line_num},"
46
+ msg << "#{ean},"
47
+ msg << ","
48
+ msg << "#{description},"
49
+ msg << sprintf("%.2f", nett_unit_price) unless nett_unit_price.nil?
50
+ msg << ","
51
+ msg << "1,"
52
+ msg << "#{qty_inners},"
53
+ msg << sprintf("%.2f", tax_rate) unless tax_rate.nil?
54
+ msg << ","
55
+ msg << ","
56
+ msg << "#{buying_location},"
57
+ msg << "#{buying_location_name},"
58
+ msg << ","
59
+ msg << "#{delivered_qty},"
60
+ msg << "#{status_code},"
61
+ msg << "#{demand_qty},"
62
+ msg << sprintf("%.2f", rrp) unless rrp.nil?
63
+ msg << ","
64
+ msg << sprintf("%.2f", discount_percent) unless discount_percent.nil?
65
+ msg << ","
66
+ msg << "#{availability_date},"
67
+ msg << "#{text}"
68
+ return msg
69
+ end
70
+ end
71
+ end
data/lib/rvista.rb CHANGED
@@ -1,7 +1,11 @@
1
1
 
2
- require File.dirname(__FILE__) + '/rvista/message'
3
- require File.dirname(__FILE__) + '/rvista/line_item'
4
2
  require File.dirname(__FILE__) + '/rvista/errors'
3
+ require File.dirname(__FILE__) + '/rvista/invoice'
4
+ require File.dirname(__FILE__) + '/rvista/invoice_line_item'
5
+ require File.dirname(__FILE__) + '/rvista/po'
6
+ require File.dirname(__FILE__) + '/rvista/po_line_item'
7
+ require File.dirname(__FILE__) + '/rvista/poa'
8
+ require File.dirname(__FILE__) + '/rvista/poa_line_item'
5
9
 
6
10
  # Ruby module for reading Vista HDS order files
7
11
  #
@@ -0,0 +1,4 @@
1
+ H,1111111,2222222,IN,Invoice,5678,071011,2222222,
2
+ D,1,1234,EN,9781857230765,Eye of the World,2,EA,5.00,40.00,4.50,Y,10.00,6.00,9.50
3
+ D,2,1234,EN,9780744590104,Eye of the Wolf,3,EA,5.00,40.00,4.50,Y,15.00,9.00,9.50,1.50,F
4
+ S,2,25.00.00,5,3.00
@@ -0,0 +1,3 @@
1
+ H,1111111,2222222,IN,Invoice,5678,071011,2222222,
2
+ D,1,1234,EN,9781857230765,Eye of the World,2,EA,5.00,40.00,4.50,Y,10.00,6.00,9.50,1.00,F
3
+ D,2,1234,EN,9780744590104,Eye of the Wolf,3,EA,5.00,40.00,4.50,Y,15.00,9.00,9.50,1.50,F
@@ -0,0 +1,3 @@
1
+ D,1,1234,EN,9781857230765,Eye of the World,2,EA,5.00,40.00,4.50,Y,10.00,6.00,9.50,1.00,F
2
+ D,2,1234,EN,9780744590104,Eye of the Wolf,3,EA,5.00,40.00,4.50,Y,15.00,9.00,9.50,1.50,F
3
+ S,2,25.00.00,5,3.00
@@ -0,0 +1,4 @@
1
+ H,1111111,2222222,IN,Invoice,5678,071011,1111111,
2
+ D,1,1234,EN,9781857230765,Eye of the World,2,EA,5.00,40.00,4.50,Y,10.00,6.00,9.50,1.00,F
3
+ D,2,1234,EN,9780744590104,Eye of the Wolf,3,EA,5.00,40.00,4.50,Y,15.00,9.00,9.50,1.50,F
4
+ S,2,25.00,5,2.50
File without changes
@@ -0,0 +1,3 @@
1
+ H,9024298,9013725,,024/60152,,00,,070501,,000000,000000,,,,,,,,
2
+ D,1,EN,9780809142217,,175,,,,,,Y,,
3
+ S,1,,
@@ -0,0 +1,3 @@
1
+ H,9024298,9013725,,024/60152,,00,,070501,,000000,000000,,,,,,9013091,,
2
+ D,1,EN,9780809142217,,175,,,,,,Y,,
3
+ S,1,,
File without changes
@@ -0,0 +1,4 @@
1
+ H,1111111,2222222,,,,,1234,060915,,071010,071030,SP,1111111,Some Store
2
+ D,1,0701180358,,DIGGING TO AMERICA,10.00,1,0,,1111111,Some Store,,1,01,1,11.00,40,20071015,
3
+ D,2,071267344X,,THE LAST ENEMY,15.00,1,0,,1111111,Some Store,,7,02,5,16.50,50
4
+ S,2,,
@@ -0,0 +1,3 @@
1
+ H,1111111,2222222,,,,,1234,060915,,071010,071030,SP,1111111,Some Store
2
+ D,1,0701180358,,DIGGING TO AMERICA,10.00,1,0,,1111111,Some Store,,1,01,1,11.00,40,20071015,
3
+ D,2,071267344X,,THE LAST ENEMY,15.00,1,0,,1111111,Some Store,,7,02,5,16.50,50,20071015,
@@ -0,0 +1,3 @@
1
+ D,1,0701180358,,DIGGING TO AMERICA,10.00,1,0,,1111111,Some Store,,1,01,1,11.00,40,20071015,
2
+ D,2,071267344X,,THE LAST ENEMY,15.00,1,0,,1111111,Some Store,,7,02,5,16.50,50,20071015,
3
+ S,2,,
@@ -0,0 +1,4 @@
1
+ H,1111111,2222222,,,,,1234,060915,,071010,071030,SP,1111111,Some Store
2
+ D,1,0701180358,,DIGGING TO AMERICA,10.00,1,0,10.00,,1111111,Some Store,,1,01,1,11.00,40.00,20071015,
3
+ D,2,071267344X,,THE LAST ENEMY,15.00,1,0,10.00,,1111111,Some Store,,7,02,5,16.50,50.00,20071015,
4
+ S,2,
@@ -0,0 +1,71 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rvista'
5
+ require 'fastercsv'
6
+
7
+ class InvoiceLineItemTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @row = []
11
+ @row << "D"
12
+ @row << "1"
13
+ @row << "1234"
14
+ @row << "EN"
15
+ @row << "9781857230765"
16
+ @row << "Eye of the World"
17
+ @row << "5"
18
+ @row << "EA"
19
+ @row << "19.95"
20
+ @row << "40.00"
21
+ @row << "17.95"
22
+ @row << "Y"
23
+ @row << "89.75"
24
+ @row << "35.90"
25
+ @row << "53.85"
26
+ @row << "2.00"
27
+ @row << "F"
28
+ end
29
+
30
+ # ensure the load_from_array method works as expected
31
+ def test_load_from_array
32
+ item = RVista::InvoiceLineItem.load_from_array(@row)
33
+ assert_kind_of RVista::InvoiceLineItem, item
34
+
35
+ assert_equal item.line_num, 1
36
+ assert_equal item.po_number, "1234"
37
+ assert_equal item.qualifier, "EN"
38
+ assert_equal item.ean, "9781857230765"
39
+ assert_equal item.description, "Eye of the World"
40
+ assert_equal item.qty, 5
41
+ assert_equal item.unit_measure, "EA"
42
+ assert_equal item.rrp, 19.95
43
+ assert_equal item.discount_percent, 40.00
44
+ assert_equal item.nett_unit_price, 17.95
45
+ assert_equal item.gst_inclusive, true
46
+ assert_equal item.value, 89.75
47
+ assert_equal item.discount_value, 35.90
48
+ assert_equal item.nett_value, 53.85
49
+ assert_equal item.gst, 2.00
50
+ assert_equal item.firm_sale, true
51
+ end
52
+
53
+ # ensure the load_from_file method throws the correct exceptions
54
+ # when it encounters a problem
55
+ def test_product_validation
56
+ assert_raise(RVista::InvalidLineItemError) {
57
+ item = RVista::InvoiceLineItem.load_from_array(%w[D blah])
58
+ }
59
+ end
60
+
61
+ def test_to_s
62
+ item = RVista::InvoiceLineItem.load_from_array(@row)
63
+ str = item.to_s
64
+ arr = FasterCSV.parse(str).first
65
+
66
+ assert_equal 17, arr.size
67
+ end
68
+
69
+ end
70
+
71
+
@@ -0,0 +1,73 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rvista'
5
+
6
+ class InvoiceTest < Test::Unit::TestCase
7
+
8
+ VALID = File.dirname(__FILE__) + "/../data/invoice/valid.txt"
9
+ INVALID_MISSING_HEADER = File.dirname(__FILE__) + "/../data/invoice/invalid_missing_header.txt"
10
+ INVALID_MISSING_FOOTER = File.dirname(__FILE__) + "/../data/invoice/invalid_missing_footer.txt"
11
+ INVALID_LINE = File.dirname(__FILE__) + "/../data/invoice/invalid_line.txt"
12
+ INVALID_DOESNT_EXIST = File.dirname(__FILE__) + "/../data/blah.txt"
13
+
14
+ # ensure the load_from_file method works as expected
15
+ def test_load_from_file
16
+ msg = RVista::Invoice.load_from_file(VALID)
17
+ assert_kind_of RVista::Invoice, msg
18
+ assert_equal msg.items.size, 2
19
+
20
+ validate_msg(msg)
21
+ end
22
+
23
+ # ensure the load_from_file method works as expected
24
+ def test_load_from_string
25
+ msg = RVista::Invoice.load_from_string(File.read(VALID))
26
+ assert_kind_of RVista::Invoice, msg
27
+ assert_equal msg.items.size, 2
28
+
29
+ validate_msg(msg)
30
+ end
31
+
32
+ # ensure the load_from_file method throws the correct exceptions
33
+ # when it encounters a problem
34
+ def test_product_validation
35
+
36
+ assert_raise(RVista::InvalidFileError) {
37
+ msg = RVista::Invoice.load_from_file(INVALID_MISSING_HEADER)
38
+ }
39
+
40
+ assert_raise(RVista::InvalidFileError) {
41
+ msg = RVista::Invoice.load_from_file(INVALID_MISSING_FOOTER)
42
+ }
43
+
44
+ assert_raise(RVista::InvalidLineItemError) {
45
+ msg = RVista::Invoice.load_from_file(INVALID_LINE)
46
+ }
47
+
48
+ assert_raise(RVista::InvalidFileError) {
49
+ msg = RVista::Invoice.load_from_file(INVALID_DOESNT_EXIST)
50
+ }
51
+ end
52
+
53
+ def test_to_s
54
+ msg = RVista::Invoice.load_from_file(VALID)
55
+ content = File.read(VALID)
56
+ assert_equal content, msg.to_s
57
+ end
58
+
59
+ private
60
+
61
+ # ensures the properties of the supplied RVista::Invoice object
62
+ # match the properties specified in the VALID file
63
+ def validate_msg(msg)
64
+ assert_equal msg.sender_id, "1111111"
65
+ assert_equal msg.receiver_id, "2222222"
66
+ assert_equal msg.doc_type, "IN"
67
+ assert_equal msg.description, "Invoice"
68
+ assert_equal msg.doc_number, "5678"
69
+ assert_equal msg.doc_date, "071011"
70
+ assert_equal msg.delivery_location, "1111111"
71
+ assert_equal msg.currency, nil
72
+ end
73
+ end
@@ -2,8 +2,9 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rvista'
5
+ require 'fastercsv'
5
6
 
6
- class LineItemTest < Test::Unit::TestCase
7
+ class POLineItemTest < Test::Unit::TestCase
7
8
 
8
9
  def setup
9
10
  @row = []
@@ -21,12 +22,28 @@ class LineItemTest < Test::Unit::TestCase
21
22
  @row << "Y"
22
23
  @row << nil
23
24
  @row << nil
25
+
26
+ @row2 = []
27
+ @row2 << "D"
28
+ @row2 << "1"
29
+ @row2 << "IB"
30
+ @row2 << "0701180358"
31
+ @row2 << "DIGGING TO AMERICA"
32
+ @row2 << "3"
33
+ @row2 << "0.00"
34
+ @row2 << "EA"
35
+ @row2 << nil
36
+ @row2 << nil
37
+ @row2 << "43"
38
+ @row2 << "N"
39
+ @row2 << nil
40
+ @row2 << nil
24
41
  end
25
42
 
26
43
  # ensure the load_from_array method works as expected
27
44
  def test_load_from_array
28
- item = RVista::LineItem.load_from_array(@row)
29
- assert_kind_of RVista::LineItem, item
45
+ item = RVista::POLineItem.load_from_array(@row)
46
+ assert_kind_of RVista::POLineItem, item
30
47
 
31
48
  assert_equal item.line_num, 1
32
49
  assert_equal item.qualifier, "IB"
@@ -48,11 +65,25 @@ class LineItemTest < Test::Unit::TestCase
48
65
  def test_product_validation
49
66
 
50
67
  assert_raise(RVista::InvalidLineItemError) {
51
- item = RVista::LineItem.load_from_array(%w[D blah])
68
+ item = RVista::POLineItem.load_from_array(%w[D blah])
52
69
  }
53
70
 
54
71
  end
55
72
 
73
+ def test_to_s
74
+ item = RVista::POLineItem.load_from_array(@row)
75
+ str = item.to_s
76
+ arr = FasterCSV.parse(str).first
77
+
78
+ assert_equal 14, arr.size
79
+
80
+ item = RVista::POLineItem.load_from_array(@row2)
81
+ str = item.to_s
82
+ arr = FasterCSV.parse(str).first
83
+
84
+ assert_equal 14, arr.size
85
+ end
86
+
56
87
  end
57
88
 
58
89
 
@@ -3,18 +3,18 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
3
3
  require 'test/unit'
4
4
  require 'rvista'
5
5
 
6
- class MessageTest < Test::Unit::TestCase
6
+ class POTest < Test::Unit::TestCase
7
7
 
8
- VALID = File.dirname(__FILE__) + "/../data/valid.txt"
9
- INVALID_MISSING_HEADER = File.dirname(__FILE__) + "/../data/invalid_missing_header.txt"
10
- INVALID_MISSING_FOOTER = File.dirname(__FILE__) + "/../data/invalid_missing_footer.txt"
11
- INVALID_LINE = File.dirname(__FILE__) + "/../data/invalid_line.txt"
8
+ VALID = File.dirname(__FILE__) + "/../data/po/valid.txt"
9
+ INVALID_MISSING_HEADER = File.dirname(__FILE__) + "/../data/po/invalid_missing_header.txt"
10
+ INVALID_MISSING_FOOTER = File.dirname(__FILE__) + "/../data/po/invalid_missing_footer.txt"
11
+ INVALID_LINE = File.dirname(__FILE__) + "/../data/po/invalid_line.txt"
12
12
  INVALID_DOESNT_EXIST = File.dirname(__FILE__) + "/../data/blah.txt"
13
13
 
14
14
  # ensure the load_from_file method works as expected
15
15
  def test_load_from_file
16
- msg = RVista::Message.load_from_file(VALID)
17
- assert_kind_of RVista::Message, msg
16
+ msg = RVista::PO.load_from_file(VALID)
17
+ assert_kind_of RVista::PO, msg
18
18
  assert_equal msg.items.size, 38
19
19
 
20
20
  validate_msg(msg)
@@ -23,8 +23,8 @@ class MessageTest < Test::Unit::TestCase
23
23
 
24
24
  # ensure the load_from_file method works as expected
25
25
  def test_load_from_string
26
- msg = RVista::Message.load_from_string(File.read(VALID))
27
- assert_kind_of RVista::Message, msg
26
+ msg = RVista::PO.load_from_string(File.read(VALID))
27
+ assert_kind_of RVista::PO, msg
28
28
  assert_equal msg.items.size, 38
29
29
 
30
30
  validate_msg(msg)
@@ -35,32 +35,32 @@ class MessageTest < Test::Unit::TestCase
35
35
  def test_product_validation
36
36
 
37
37
  assert_raise(RVista::InvalidFileError) {
38
- msg = RVista::Message.load_from_file(INVALID_MISSING_HEADER)
38
+ msg = RVista::PO.load_from_file(INVALID_MISSING_HEADER)
39
39
  }
40
40
 
41
41
  assert_raise(RVista::InvalidFileError) {
42
- msg = RVista::Message.load_from_file(INVALID_MISSING_FOOTER)
42
+ msg = RVista::PO.load_from_file(INVALID_MISSING_FOOTER)
43
43
  }
44
44
 
45
45
  assert_raise(RVista::InvalidLineItemError) {
46
- msg = RVista::Message.load_from_file(INVALID_LINE)
46
+ msg = RVista::PO.load_from_file(INVALID_LINE)
47
47
  }
48
48
 
49
49
  assert_raise(RVista::InvalidFileError) {
50
- msg = RVista::Message.load_from_file(INVALID_DOESNT_EXIST)
50
+ msg = RVista::PO.load_from_file(INVALID_DOESNT_EXIST)
51
51
  }
52
52
 
53
53
  end
54
54
 
55
55
  def test_to_s
56
- msg = RVista::Message.load_from_file(VALID)
56
+ msg = RVista::PO.load_from_file(VALID)
57
57
  content = File.read(VALID)
58
58
  assert_equal content, msg.to_s
59
59
  end
60
60
 
61
61
  private
62
62
 
63
- # ensures the properties of the supplied RVista::Message object
63
+ # ensures the properties of the supplied RVista::PO object
64
64
  # match the properties specified in the VALID file
65
65
  def validate_msg(msg)
66
66
  assert_equal msg.sender_id, "1111111"
@@ -0,0 +1,75 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rvista'
5
+ require 'fastercsv'
6
+
7
+ class POALineItemTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @row = []
11
+ @row << "D"
12
+ @row << "1"
13
+ @row << "0701180358"
14
+ @row << nil
15
+ @row << "DIGGING TO AMERICA"
16
+ @row << "10.00"
17
+ @row << "1"
18
+ @row << "0"
19
+ @row << "10.00"
20
+ @row << nil
21
+ @row << "1111111"
22
+ @row << "Some Store"
23
+ @row << nil
24
+ @row << "1"
25
+ @row << "01"
26
+ @row << "1"
27
+ @row << "11.00"
28
+ @row << "40.00"
29
+ @row << "20071015"
30
+ @row << nil
31
+ end
32
+
33
+ # ensure the load_from_array method works as expected
34
+ def test_load_from_array
35
+ item = RVista::POALineItem.load_from_array(@row)
36
+ assert_kind_of RVista::POALineItem, item
37
+
38
+ assert_equal item.line_num, 1
39
+ assert_equal item.ean, "0701180358"
40
+ assert_equal item.description, "DIGGING TO AMERICA"
41
+ assert_equal item.nett_unit_price, 10.00
42
+ assert_equal item.qty_inners, 0
43
+ assert_equal item.tax_rate, 10.00
44
+ assert_equal item.buying_location, "1111111"
45
+ assert_equal item.buying_location_name, "Some Store"
46
+ assert_equal item.delivered_qty, 1
47
+ assert_equal item.status_code, "01"
48
+ assert_equal item.demand_qty, 1
49
+ assert_equal item.rrp, 11.00
50
+ assert_equal item.discount_percent, 40.00
51
+ assert_equal item.availability_date, "20071015"
52
+ assert_equal item.text, nil
53
+ end
54
+
55
+ # ensure the load_from_file method throws the correct exceptions
56
+ # when it encounters a problem
57
+ def test_product_validation
58
+
59
+ assert_raise(RVista::InvalidLineItemError) {
60
+ item = RVista::POALineItem.load_from_array(%w[D blah])
61
+ }
62
+
63
+ end
64
+
65
+ def test_to_s
66
+ item = RVista::POALineItem.load_from_array(@row)
67
+ str = item.to_s
68
+ arr = FasterCSV.parse(str).first
69
+
70
+ assert_equal 20, arr.size
71
+ end
72
+
73
+ end
74
+
75
+
@@ -0,0 +1,78 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rvista'
5
+
6
+ class POATest < Test::Unit::TestCase
7
+
8
+ VALID = File.dirname(__FILE__) + "/../data/poa/valid.txt"
9
+ INVALID_MISSING_HEADER = File.dirname(__FILE__) + "/../data/poa/invalid_missing_header.txt"
10
+ INVALID_MISSING_FOOTER = File.dirname(__FILE__) + "/../data/poa/invalid_missing_footer.txt"
11
+ INVALID_LINE = File.dirname(__FILE__) + "/../data/poa/invalid_line.txt"
12
+ INVALID_DOESNT_EXIST = File.dirname(__FILE__) + "/../data/blah.txt"
13
+
14
+ # ensure the load_from_file method works as expected
15
+ def test_load_from_file
16
+ msg = RVista::POA.load_from_file(VALID)
17
+ assert_kind_of RVista::POA, msg
18
+ assert_equal msg.items.size, 2
19
+
20
+ validate_msg(msg)
21
+
22
+ end
23
+
24
+ # ensure the load_from_file method works as expected
25
+ def test_load_from_string
26
+ msg = RVista::POA.load_from_string(File.read(VALID))
27
+ assert_kind_of RVista::POA, msg
28
+ assert_equal msg.items.size, 2
29
+
30
+ validate_msg(msg)
31
+ end
32
+
33
+ # ensure the load_from_file method throws the correct exceptions
34
+ # when it encounters a problem
35
+ def test_product_validation
36
+
37
+ assert_raise(RVista::InvalidFileError) {
38
+ msg = RVista::POA.load_from_file(INVALID_MISSING_HEADER)
39
+ }
40
+
41
+ assert_raise(RVista::InvalidFileError) {
42
+ msg = RVista::POA.load_from_file(INVALID_MISSING_FOOTER)
43
+ }
44
+
45
+ assert_raise(RVista::InvalidLineItemError) {
46
+ msg = RVista::POA.load_from_file(INVALID_LINE)
47
+ }
48
+
49
+ assert_raise(RVista::InvalidFileError) {
50
+ msg = RVista::POA.load_from_file(INVALID_DOESNT_EXIST)
51
+ }
52
+
53
+ end
54
+
55
+ def test_to_s
56
+ msg = RVista::POA.load_from_file(VALID)
57
+ content = File.read(VALID)
58
+ assert_equal content, msg.to_s
59
+ end
60
+
61
+ private
62
+
63
+ # ensures the properties of the supplied RVista::POA object
64
+ # match the properties specified in the VALID file
65
+ def validate_msg(msg)
66
+ assert_equal msg.sender_id, "1111111"
67
+ assert_equal msg.receiver_id, "2222222"
68
+ assert_equal msg.po_number, "1234"
69
+ assert_equal msg.date, "060915"
70
+ assert_equal msg.supply_after, "071010"
71
+ assert_equal msg.supply_before, "071030"
72
+ assert_equal msg.delivery_location, "1111111"
73
+ assert_equal msg.delivery_location_name, "Some Store"
74
+ end
75
+
76
+ end
77
+
78
+
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rvista
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.2"
7
- date: 2006-11-19 00:00:00 +11:00
6
+ version: "0.5"
7
+ date: 2007-10-11 00:00:00 +10:00
8
8
  summary: A small library for reading Vista HDS order files
9
9
  require_paths:
10
10
  - lib
@@ -25,22 +25,45 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - James Healy
30
31
  files:
32
+ - examples/test.rb
31
33
  - lib/rvista
32
- - lib/rvista.rb
33
34
  - lib/rvista/errors.rb
34
- - lib/rvista/message.rb
35
- - lib/rvista/line_item.rb
35
+ - lib/rvista/poa.rb
36
+ - lib/rvista/po.rb
37
+ - lib/rvista/po_line_item.rb
38
+ - lib/rvista/poa_line_item.rb
39
+ - lib/rvista/invoice_line_item.rb
40
+ - lib/rvista/invoice.rb
41
+ - lib/rvista.rb
36
42
  - test/unit
37
- - test/data
38
43
  - test/unit/message_test.rb
39
44
  - test/unit/line_item_test.rb
40
- - test/data/valid.txt
41
- - test/data/invalid_missing_footer.txt
42
- - test/data/invalid_line.txt
43
- - test/data/invalid_missing_header.txt
45
+ - test/unit/poa_test.rb
46
+ - test/unit/poa_line_item_test.rb
47
+ - test/unit/invoice_line_item_test.rb
48
+ - test/unit/invoice_test.rb
49
+ - test/data
50
+ - test/data/poa
51
+ - test/data/poa/invalid_line.txt
52
+ - test/data/poa/valid.txt
53
+ - test/data/poa/invalid_missing_footer.txt
54
+ - test/data/poa/invalid_missing_header.txt
55
+ - test/data/invoice
56
+ - test/data/invoice/invalid_line.txt
57
+ - test/data/invoice/valid.txt
58
+ - test/data/invoice/invalid_missing_header.txt
59
+ - test/data/invoice/invalid_missing_footer.txt
60
+ - test/data/po
61
+ - test/data/po/invalid_line.txt
62
+ - test/data/po/invalid_missing_footer.txt
63
+ - test/data/po/invalid_missing_header.txt
64
+ - test/data/po/no_delivery_location.txt
65
+ - test/data/po/valid.txt
66
+ - test/data/po/seperate_delivery_location.txt
44
67
  - Rakefile
45
68
  - README
46
69
  - COPYING
@@ -71,5 +94,5 @@ dependencies:
71
94
  requirements:
72
95
  - - ">="
73
96
  - !ruby/object:Gem::Version
74
- version: 0.2.1
97
+ version: 1.2.1
75
98
  version: