iif 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +22 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +7 -0
  6. data/CHANGELOG.md +48 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +189 -0
  10. data/Rakefile +6 -0
  11. data/bin/rake +16 -0
  12. data/config.ru +9 -0
  13. data/lib/riif.rb +6 -0
  14. data/lib/riif/dsl/accnt.rb +15 -0
  15. data/lib/riif/dsl/base.rb +51 -0
  16. data/lib/riif/dsl/bud.rb +14 -0
  17. data/lib/riif/dsl/ctype.rb +9 -0
  18. data/lib/riif/dsl/cust.rb +51 -0
  19. data/lib/riif/dsl/emp.rb +31 -0
  20. data/lib/riif/dsl/invitem.rb +32 -0
  21. data/lib/riif/dsl/invmemo.rb +9 -0
  22. data/lib/riif/dsl/klass.rb +9 -0
  23. data/lib/riif/dsl/othername.rb +25 -0
  24. data/lib/riif/dsl/paymeth.rb +9 -0
  25. data/lib/riif/dsl/shipmeth.rb +10 -0
  26. data/lib/riif/dsl/spl.rb +29 -0
  27. data/lib/riif/dsl/terms.rb +13 -0
  28. data/lib/riif/dsl/timeact.rb +17 -0
  29. data/lib/riif/dsl/timerhdr.rb +14 -0
  30. data/lib/riif/dsl/trns.rb +56 -0
  31. data/lib/riif/dsl/vend.rb +39 -0
  32. data/lib/riif/dsl/vtype.rb +9 -0
  33. data/lib/riif/iif.rb +60 -0
  34. data/lib/riif/rails/renderer.rb +15 -0
  35. data/lib/riif/rails/template_handler.rb +20 -0
  36. data/lib/riif/railtie.rb +17 -0
  37. data/lib/riif/version.rb +3 -0
  38. data/riif.gemspec +29 -0
  39. data/spec/controllers/invoices_controller_spec.rb +26 -0
  40. data/spec/fixtures/accnt.iif +2 -0
  41. data/spec/fixtures/bud.iif +2 -0
  42. data/spec/fixtures/ctype.iif +2 -0
  43. data/spec/fixtures/cust.iif +2 -0
  44. data/spec/fixtures/emp.iif +2 -0
  45. data/spec/fixtures/invitem.iif +2 -0
  46. data/spec/fixtures/invmemo.iif +2 -0
  47. data/spec/fixtures/klass.iif +2 -0
  48. data/spec/fixtures/mixed.iif +13 -0
  49. data/spec/fixtures/othername.iif +2 -0
  50. data/spec/fixtures/paymeth.iif +2 -0
  51. data/spec/fixtures/rails/invoices.iif +6 -0
  52. data/spec/fixtures/shipmeth.iif +2 -0
  53. data/spec/fixtures/terms.iif +2 -0
  54. data/spec/fixtures/timeact.iif +4 -0
  55. data/spec/fixtures/trns.iif +7 -0
  56. data/spec/fixtures/vend.iif +2 -0
  57. data/spec/fixtures/vtype.iif +2 -0
  58. data/spec/internal/app/controllers/invoices_controller.rb +10 -0
  59. data/spec/internal/app/views/invoices/index.iif.riif +27 -0
  60. data/spec/internal/config/database.yml +3 -0
  61. data/spec/internal/config/routes.rb +3 -0
  62. data/spec/internal/db/schema.rb +3 -0
  63. data/spec/internal/log/.gitignore +1 -0
  64. data/spec/internal/public/favicon.ico +0 -0
  65. data/spec/riif/dsl/accnt_spec.rb +22 -0
  66. data/spec/riif/dsl/bud_spec.rb +28 -0
  67. data/spec/riif/dsl/ctype_spec.rb +19 -0
  68. data/spec/riif/dsl/cust_spec.rb +20 -0
  69. data/spec/riif/dsl/emp_spec.rb +24 -0
  70. data/spec/riif/dsl/invitem_spec.rb +21 -0
  71. data/spec/riif/dsl/invmemo_spec.rb +19 -0
  72. data/spec/riif/dsl/klass_spec.rb +20 -0
  73. data/spec/riif/dsl/othername_spec.rb +23 -0
  74. data/spec/riif/dsl/paymeth_spec.rb +19 -0
  75. data/spec/riif/dsl/shipmeth_spec.rb +19 -0
  76. data/spec/riif/dsl/terms_spec.rb +23 -0
  77. data/spec/riif/dsl/timeact_spec.rb +35 -0
  78. data/spec/riif/dsl/trns_spec.rb +54 -0
  79. data/spec/riif/dsl/vend_spec.rb +21 -0
  80. data/spec/riif/dsl/vtype_spec.rb +19 -0
  81. data/spec/riif/iif_spec.rb +61 -0
  82. data/spec/spec_helper.rb +21 -0
  83. metadata +295 -0
@@ -0,0 +1,51 @@
1
+ module Riif::DSL
2
+ class Cust < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :baddr1,
6
+ :baddr2,
7
+ :baddr3,
8
+ :baddr4,
9
+ :baddr5,
10
+ :saddr1,
11
+ :saddr2,
12
+ :saddr3,
13
+ :saddr4,
14
+ :saddr5,
15
+ :phone1,
16
+ :phone2,
17
+ :faxnum,
18
+ :cont1,
19
+ :cont2,
20
+ :ctype,
21
+ :terms,
22
+ :taxable,
23
+ :limit,
24
+ :resalenum,
25
+ :rep,
26
+ :taxitem,
27
+ :notepad,
28
+ :salutation,
29
+ :companyname,
30
+ :firstname,
31
+ :midinit,
32
+ :lastname,
33
+ :custfld1,
34
+ :custfld2,
35
+ :custfld3,
36
+ :custfld4,
37
+ :custfld5,
38
+ :custfld6,
39
+ :custfld7,
40
+ :jobdesc,
41
+ :jobtype,
42
+ :jobstatus,
43
+ :jobstart,
44
+ :jobprojend,
45
+ :jobend,
46
+ :note
47
+ ]
48
+ START_COLUMN = 'CUST'
49
+ END_COLUMN = ''
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ module Riif::DSL
2
+ class Emp < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :init,
6
+ :addr1,
7
+ :addr2,
8
+ :addr3,
9
+ :addr4,
10
+ :addr5,
11
+ :ssno,
12
+ :phone1,
13
+ :phone2,
14
+ :notepad,
15
+ :firstname,
16
+ :midinit,
17
+ :lastname,
18
+ :salutation,
19
+ :custfld1,
20
+ :custfld2,
21
+ :custfld3,
22
+ :custfld4,
23
+ :custfld5,
24
+ :custfld6,
25
+ :custfld7,
26
+ :note
27
+ ]
28
+ START_COLUMN = 'EMP'
29
+ END_COLUMN = ''
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ module Riif::DSL
2
+ class Invitem < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :invitemtype,
6
+ :desc,
7
+ :purchasedesc,
8
+ :accnt,
9
+ :assetaccnt,
10
+ :cogsaccnt,
11
+ :price,
12
+ :cost,
13
+ :taxable,
14
+ :paymeth,
15
+ :taxvend,
16
+ :taxdist,
17
+ :toprint,
18
+ :prefvend,
19
+ :reorderpoint,
20
+ :extra,
21
+ :custfld1,
22
+ :custfld2,
23
+ :custfld3,
24
+ :custfld4,
25
+ :custfld5,
26
+ :dep_type,
27
+ :ispassedthru
28
+ ]
29
+ START_COLUMN = 'INVITEM'
30
+ END_COLUMN = ''
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module Riif::DSL
2
+ class Invmemo < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'INVMEMO'
7
+ END_COLUMN = ''
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Riif::DSL
2
+ class Klass < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'CLASS'
7
+ END_COLUMN = ''
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module Riif::DSL
2
+ class Othername < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :baddr1,
6
+ :baddr2,
7
+ :baddr3,
8
+ :baddr4,
9
+ :baddr5,
10
+ :phone1,
11
+ :phone2,
12
+ :faxnum,
13
+ :cont1,
14
+ :notepad,
15
+ :salutation,
16
+ :companyname,
17
+ :firstname,
18
+ :midinit,
19
+ :lastname,
20
+ :note
21
+ ]
22
+ START_COLUMN = 'OTHERNAME'
23
+ END_COLUMN = ''
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Riif::DSL
2
+ class Paymeth < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'PAYMETH'
7
+ END_COLUMN = ''
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Riif::DSL
2
+ class Shipmeth < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'SHIPMETH'
7
+ END_COLUMN = ''
8
+ end
9
+ end
10
+
@@ -0,0 +1,29 @@
1
+ module Riif::DSL
2
+ class Spl < Base
3
+ HEADER_COLUMNS = [
4
+ :splid,
5
+ :trnstype,
6
+ :date,
7
+ :accnt,
8
+ :name,
9
+ :class,
10
+ :amount,
11
+ :docnum,
12
+ :memo,
13
+ :clear,
14
+ :qnty,
15
+ :price,
16
+ :invitem,
17
+ :paymeth,
18
+ :taxable,
19
+ :reimbexp,
20
+ :extra
21
+ ]
22
+ START_COLUMN = 'SPL'
23
+ END_COLUMN = ''
24
+
25
+ def headers
26
+ []
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Riif::DSL
2
+ class Terms < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :duedays,
6
+ :discper,
7
+ :discdays,
8
+ :termstype,
9
+ ]
10
+ START_COLUMN = 'TERMS'
11
+ END_COLUMN = ''
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Riif::DSL
2
+ class Timeact < Base
3
+ HEADER_COLUMNS = [
4
+ :date,
5
+ :job,
6
+ :emp,
7
+ :item,
8
+ :pitem,
9
+ :duration,
10
+ :proj,
11
+ :note,
12
+ :billingstatus
13
+ ]
14
+ START_COLUMN = 'TIMEACT'
15
+ END_COLUMN = ''
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Riif::DSL
2
+ class Timerhdr < Base
3
+ HEADER_COLUMNS = [
4
+ :ver,
5
+ :rel,
6
+ :companyname,
7
+ :importedbefore,
8
+ :fromtimer,
9
+ :companycreatetime
10
+ ]
11
+ START_COLUMN = 'TIMERHDR'
12
+ END_COLUMN = ''
13
+ end
14
+ end
@@ -0,0 +1,56 @@
1
+ module Riif::DSL
2
+ class Trns < Base
3
+ HEADER_COLUMNS = [
4
+ :trnsid,
5
+ :trnstype,
6
+ :date,
7
+ :accnt,
8
+ :name,
9
+ :class,
10
+ :amount,
11
+ :docnum,
12
+ :memo,
13
+ :clear,
14
+ :toprint,
15
+ :addr1,
16
+ :addr2,
17
+ :addr3,
18
+ :addr4,
19
+ :addr5,
20
+ :saddr1,
21
+ :saddr2,
22
+ :saddr3,
23
+ :saddr4,
24
+ :saddr5,
25
+ :duedate,
26
+ :terms,
27
+ :paid,
28
+ :paymeth,
29
+ :shipdate,
30
+ :rep,
31
+ :ponum,
32
+ :invtitle,
33
+ :invmemo
34
+ ]
35
+ START_COLUMN = 'TRNS'
36
+ END_COLUMN = 'ENDTRNS'
37
+
38
+ def headers
39
+ [
40
+ ["!#{START_COLUMN}"].concat(HEADER_COLUMNS.map(&:upcase)),
41
+ ["!SPL"].concat(Spl::HEADER_COLUMNS.map(&:upcase)),
42
+ ["!#{END_COLUMN}"]
43
+ ]
44
+ end
45
+
46
+ def rows
47
+ @rows << [END_COLUMN]
48
+ end
49
+
50
+ def spl(&block)
51
+ Spl.new.build(&block)[:rows].each do |row|
52
+ @rows << row
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ module Riif::DSL
2
+ class Vend < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :printas,
6
+ :addr1,
7
+ :addr2,
8
+ :addr3,
9
+ :addr4,
10
+ :addr5,
11
+ :vtype,
12
+ :cont1,
13
+ :phone1,
14
+ :phone2,
15
+ :faxnum,
16
+ :note,
17
+ :taxid,
18
+ :limit,
19
+ :terms,
20
+ :notepad,
21
+ :salutation,
22
+ :companyname,
23
+ :firstname,
24
+ :midinit,
25
+ :lastname,
26
+ :custfld1,
27
+ :custfld2,
28
+ :custfld3,
29
+ :custfld4,
30
+ :custfld5,
31
+ :custfld6,
32
+ :custfld7,
33
+ :_1099,
34
+ :note
35
+ ]
36
+ START_COLUMN = 'VEND'
37
+ END_COLUMN = ''
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module Riif::DSL
2
+ class Vtype < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'VTYPE'
7
+ END_COLUMN = ''
8
+ end
9
+ end
@@ -0,0 +1,60 @@
1
+ require 'csv'
2
+
3
+ require 'riif/dsl/base'
4
+
5
+ require 'riif/dsl/accnt'
6
+ require 'riif/dsl/bud'
7
+ require 'riif/dsl/ctype'
8
+ require 'riif/dsl/cust'
9
+ require 'riif/dsl/emp'
10
+ require 'riif/dsl/invitem'
11
+ require 'riif/dsl/invmemo'
12
+ require 'riif/dsl/klass'
13
+ require 'riif/dsl/othername'
14
+ require 'riif/dsl/paymeth'
15
+ require 'riif/dsl/shipmeth'
16
+ require 'riif/dsl/spl'
17
+ require 'riif/dsl/terms'
18
+ require 'riif/dsl/timeact'
19
+ require 'riif/dsl/timerhdr'
20
+ require 'riif/dsl/trns'
21
+ require 'riif/dsl/vend'
22
+ require 'riif/dsl/vtype'
23
+
24
+ module Riif
25
+ class IIF
26
+ def initialize(&block)
27
+ @output = {}
28
+ if block_given?
29
+ if block.arity == 1
30
+ yield(self)
31
+ else
32
+ instance_eval(&block)
33
+ end
34
+ end
35
+ end
36
+
37
+ def output
38
+ CSV.generate(col_sep: "\t") do |tsv|
39
+
40
+ @output.each do |_, list|
41
+ list[:headers].uniq.each do |header|
42
+ tsv << header
43
+ end
44
+ list[:rows].each do |row|
45
+ tsv << row
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def method_missing(method_name, *args, &block)
52
+ result = eval("::Riif::DSL::#{method_name.capitalize}").new.build(&block)
53
+
54
+ @output[method_name] ||= { headers: [], rows: [] }
55
+
56
+ @output[method_name][:headers].concat(result[:headers])
57
+ @output[method_name][:rows].concat(result[:rows])
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,15 @@
1
+ module Riif
2
+ module Rails
3
+ class Renderer
4
+ ActionController::Renderers.add :iif do |iif_string, options|
5
+ filename = options[:filename] || options[:template]
6
+ send_data(
7
+ iif_string,
8
+ filename: "#{filename}.iif",
9
+ type: Mime[:iif],
10
+ disposition: 'attachment'
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end