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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a72408c02aa2786474dcb216588ecae777f3ff35
4
+ data.tar.gz: 361da7c46da4e400982fa90f2a05f9403bbd5a62
5
+ SHA512:
6
+ metadata.gz: f4197b94a9c4f5b509a16ea075da462b79eac3eb3ae9adb5ccc34a91f56abdd48b35d165aab452c97f05abde21bf15449cff256cd533a73dd642b45ef1a72cc5
7
+ data.tar.gz: fc0c627b4c8da4c52a1cd4dc39ebb6a31cbc0890b2952ac1b6fab4ba5cf93ebc0ea77696d80c8043d3c3e974267823d0b9ff5b698b9c739722aa5a720cff194f
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rbenv-gemsets
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ spec/dummy/log/*.log
21
+ spec/dummy/tmp/
22
+ spec/dummy/.sass-cache
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format Fuubar
3
+
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ script: "bundle exec rspec spec"
3
+ rvm:
4
+ - 2.2.6
5
+ - 2.3.3
6
+ - 2.4.0
7
+ - ruby-head
@@ -0,0 +1,48 @@
1
+ # CHANGELOG
2
+
3
+ ## NEXT (unreleased)
4
+
5
+ ## 0.6.0
6
+
7
+ * #10 Add option to pass an argument to `Riif.new`. [@ghiculescu](https://github.com/ghiculescu)
8
+
9
+ ## 0.5.0
10
+
11
+ * #9 Implement TIMERHDR. [@ghiculescu](https://github.com/ghiculescu)
12
+
13
+ ## 0.4.0
14
+
15
+ * #7 Add missing paymeth to transaction type. [@jphpsf](https://github.com/jphpsf)
16
+
17
+ ## 0.3.0
18
+
19
+ * #6 by [@jphpsf](https://github.com/jphpsf)
20
+ * Shipping address (SADDR1 to SADDR5)
21
+ * Sales rep (rep)
22
+ * Invoice title and memo (INVTITLE and INVMEMO)
23
+ * Purchase order number (PONUM)
24
+
25
+ ## 0.2.0
26
+ * #4 - Add support to customize filename
27
+ * #5 - Separate different lists into groups
28
+
29
+ ## 0.1.0
30
+ * #2 - Implement Mixed document in one IIF file. (DSL had been changed)
31
+
32
+ ## 0.0.1
33
+ * Implement OTHERNAME
34
+ * Implement TIMEACT
35
+ * Implement TERMS
36
+ * Implement VEND
37
+ * Implement VTYPE
38
+ * Implement SHIPMETH
39
+ * Implement PAYMETH
40
+ * Implement INVMEMO
41
+ * Implement INVITEM
42
+ * Implement CTYPE
43
+ * Implement CLASS
44
+ * Implement ACCNT
45
+ * Implement EMP
46
+ * Implement CUST
47
+ * Implement TRNS and SPL
48
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in riif.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Jun Lin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,189 @@
1
+ # Riif
2
+
3
+ A simple DSL to generate IIF file.
4
+
5
+ [![Build Status](https://travis-ci.org/linjunpop/riif.png?branch=master)](https://travis-ci.org/linjunpop/riif)
6
+ [![Gem Version](https://badge.fury.io/rb/riif.png)](http://badge.fury.io/rb/riif)
7
+ [![Code Climate](https://codeclimate.com/github/linjunpop/riif.png)](https://codeclimate.com/github/linjunpop/riif)
8
+ [![Coverage Status](https://coveralls.io/repos/linjunpop/riif/badge.png?branch=master)](https://coveralls.io/r/linjunpop/riif)
9
+ [![endorse](http://api.coderwall.com/linjunpop/endorsecount.png)](http://coderwall.com/linjunpop)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'riif'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install riif
24
+
25
+
26
+ ## Limitation
27
+
28
+ You have to use `klass` for `class` and `_1099` for `1099`
29
+
30
+ ## Usage
31
+
32
+ ### With Rails
33
+
34
+ With a custom template handler, it works with Rails.
35
+
36
+ ```ruby
37
+ # invoices_controller.rb
38
+
39
+ class InvoicesController < ApplicationController
40
+ def show
41
+ respond_to do |format|
42
+ format.iif { render iif: render_to_string, filename: 'batman'}
43
+ format.html
44
+ end
45
+ end
46
+ end
47
+ ```
48
+
49
+ ```ruby
50
+ # show.iif.riif
51
+
52
+ iif.trns do
53
+ row do
54
+ trnsid 123
55
+ trnstype 'INVOICE'
56
+ date '8/31/1988'
57
+ accnt 'Accounts Receivable'
58
+ name 'Customer'
59
+ amount 20
60
+ docnum invoice.id
61
+ clear 'N'
62
+ toprint 'N'
63
+ addr1 'Baker'
64
+ addr2 'Customer'
65
+ end
66
+
67
+ spl do
68
+ row do
69
+ splid '777'
70
+ trnstype 'INVOICE'
71
+ date '8/31/1988'
72
+ accnt 'Income Account'
73
+ amount '-20'
74
+ clear 'N'
75
+ qnty '-2'
76
+ price 10
77
+ invitem 'Sales Item'
78
+ taxable 'N'
79
+ end
80
+ end
81
+
82
+ spl do
83
+ row do
84
+ splid '888'
85
+ end
86
+ end
87
+ end
88
+ ```
89
+
90
+ ### Without Rails
91
+
92
+ ```ruby
93
+ Riif::IIF.new do
94
+ trns do
95
+ row do
96
+ trnsid 123
97
+ trnstype 'INVOICE'
98
+ date '8/31/1988'
99
+ accnt 'Accounts Receivable'
100
+ name 'Customer'
101
+ amount 20
102
+ docnum 1
103
+ clear 'N'
104
+ toprint 'N'
105
+ addr1 'Baker'
106
+ addr2 'Customer'
107
+ end
108
+
109
+ spl do
110
+ row do
111
+ splid '777'
112
+ trnstype 'INVOICE'
113
+ date '8/31/1988'
114
+ accnt 'Income Account'
115
+ amount '-20'
116
+ clear 'N'
117
+ qnty '-2'
118
+ price 10
119
+ invitem 'Sales Item'
120
+ taxable 'N'
121
+ end
122
+ end
123
+
124
+ spl do
125
+ row do
126
+ splid '888'
127
+ end
128
+ end
129
+ end
130
+ end
131
+ ```
132
+
133
+ Result:
134
+
135
+ ```
136
+ !TRNS TRNSID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR TOPRINT ADDR1 ADDR2 ADDR3 ADDR4 ADDR5 DUEDATE TERMS PAID SHIPDATE
137
+ !SPL SPLID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR QNTY PRICE INVITEM PAYMETH TAXABLE REIMBEXP EXTRA
138
+ !ENDTRNS
139
+ TRNS 123 INVOICE 8/31/1988 Accounts Receivable Customer 20 1 N N Baker Customer
140
+ SPL 777 INVOICE 8/31/1988 Income Account -20 N -2 10 Sales Item N
141
+ SPL 888
142
+ ENDTRNS
143
+ ```
144
+
145
+ If you prefer, you can pass an argument along with your block:
146
+
147
+ ```ruby
148
+ Riif::IIF.new do |riif|
149
+ riif.trns do |trns|
150
+ trns.row do |row|
151
+ row.trnsid 123
152
+ row.trnstype 'INVOICE'
153
+ row.date '8/31/1988'
154
+ row.accnt 'Accounts Receivable'
155
+ row.name 'Customer'
156
+ end
157
+ end
158
+ end
159
+ ```
160
+
161
+ ## Editors
162
+
163
+ ### Vim
164
+
165
+ ```VimL
166
+ au BufWinEnter,BufRead,BufNewFile *.riif set filetype=ruby
167
+ ```
168
+
169
+ ## Resources
170
+
171
+ [Use Intuit Interchange Format (.iif) files](http://support.quickbooks.intuit.com/support/articles/HOW12778)
172
+
173
+ ## Contributing
174
+
175
+ 1. Fork it
176
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
177
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
178
+ 4. Push to the branch (`git push origin my-new-feature`)
179
+ 5. Create new Pull Request
180
+
181
+ ## Contributors
182
+
183
+ :beers:
184
+
185
+ https://github.com/linjunpop/riif/graphs/contributors
186
+
187
+ ## Changes
188
+
189
+ See [CHANGELOG.md](CHANGELOG.md)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :development
5
+
6
+ require 'riif'
7
+
8
+ Combustion.initialize! :action_controller, :action_view
9
+ run Combustion::Application
@@ -0,0 +1,6 @@
1
+ require 'riif/version'
2
+ require 'riif/iif'
3
+ require 'riif/railtie' if defined?(Rails)
4
+
5
+ module Riif
6
+ end
@@ -0,0 +1,15 @@
1
+ module Riif::DSL
2
+ class Accnt < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :accnttype,
6
+ :obamount,
7
+ :desc,
8
+ :scd,
9
+ :accnum,
10
+ :extra
11
+ ]
12
+ START_COLUMN = 'ACCNT'
13
+ END_COLUMN = ''
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ module Riif::DSL
2
+ class Base
3
+
4
+ def initialize
5
+ @rows = []
6
+ @current_row = []
7
+ end
8
+
9
+ def build(&block)
10
+
11
+ instance_eval(&block)
12
+
13
+ output
14
+ end
15
+
16
+ def row(&block)
17
+ @current_row = [self.class::START_COLUMN]
18
+
19
+ instance_eval(&block)
20
+
21
+ @rows << @current_row
22
+ end
23
+
24
+ def output
25
+ {
26
+ headers: headers,
27
+ rows: rows
28
+ }
29
+ end
30
+
31
+ def headers
32
+ [
33
+ ["!#{self.class::START_COLUMN}"].concat(
34
+ self.class::HEADER_COLUMNS.map(&:upcase)
35
+ )
36
+ ]
37
+ end
38
+
39
+ def rows
40
+ @rows
41
+ end
42
+
43
+ def method_missing(method_name, *args, &block)
44
+ if self.class::HEADER_COLUMNS.include?(method_name)
45
+ @current_row[self.class::HEADER_COLUMNS.index(method_name) + 1] = args[0]
46
+ else
47
+ super
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ module Riif::DSL
2
+ class Bud < Base
3
+ HEADER_COLUMNS = [
4
+ :accnt,
5
+ :period,
6
+ :amount,
7
+ :startdate,
8
+ :class,
9
+ :customer
10
+ ]
11
+ START_COLUMN = 'BUD'
12
+ END_COLUMN = ''
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Riif::DSL
2
+ class Ctype < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'CTYPE'
7
+ END_COLUMN = ''
8
+ end
9
+ end