Giter Site home page Giter Site logo

riif's Introduction

Riif

A simple DSL to generate IIF file.

Build Status Gem Version Code Climate Coverage Status

Installation

Add this line to your application's Gemfile:

gem 'riif'

And then execute:

$ bundle

Or install it yourself as:

$ gem install riif

Limitation

You have to use klass for class and _1099 for 1099

Usage

With Rails

With a custom template handler, it works with Rails.

# invoices_controller.rb

class InvoicesController < ApplicationController
  def show
    respond_to do |format|
      format.iif { render iif: render_to_string, filename: 'batman'}
      format.html
    end
  end
end
# show.iif.riif

iif.trns do
  row do
    trnsid 123
    trnstype 'INVOICE'
    date '8/31/1988'
    accnt 'Accounts Receivable'
    name 'Customer'
    amount 20
    docnum invoice.id
    clear 'N'
    toprint 'N'
    addr1 'Baker'
    addr2 'Customer'
  end

  spl do
    row do
      splid '777'
      trnstype 'INVOICE'
      date '8/31/1988'
      accnt 'Income Account'
      amount '-20'
      clear 'N'
      qnty '-2'
      price 10
      invitem 'Sales Item'
      taxable 'N'
    end
  end

  spl do
    row do
      splid '888'
    end
  end
end

Without Rails

Riif::IIF.new do
  trns do
    row do
      trnsid 123
      trnstype 'INVOICE'
      date '8/31/1988'
      accnt 'Accounts Receivable'
      name 'Customer'
      amount 20
      docnum 1
      clear 'N'
      toprint 'N'
      addr1 'Baker'
      addr2 'Customer'
    end

    spl do
      row do
        splid '777'
        trnstype 'INVOICE'
        date '8/31/1988'
        accnt 'Income Account'
        amount '-20'
        clear 'N'
        qnty '-2'
        price 10
        invitem 'Sales Item'
        taxable 'N'
      end
    end

    spl do
      row do
        splid '888'
      end
    end
  end
end

Result:

!TRNS	TRNSID	TRNSTYPE	DATE	ACCNT	NAME	CLASS	AMOUNT	DOCNUM	MEMO	CLEAR	TOPRINT	ADDR1	ADDR2	ADDR3	ADDR4	ADDR5	DUEDATE	TERMS	PAID	SHIPDATE
!SPL	SPLID	TRNSTYPE	DATE	ACCNT	NAME	CLASS	AMOUNT	DOCNUM	MEMO	CLEAR	QNTY	PRICE	INVITEM	PAYMETH	TAXABLE	REIMBEXP	EXTRA
!ENDTRNS
TRNS	123	INVOICE	8/31/1988	Accounts Receivable	Customer		20	1		N	N	Baker	Customer
SPL	777	INVOICE	8/31/1988	Income Account			-20			N	-2	10	Sales Item		N
SPL	888
ENDTRNS

If you prefer, you can pass an argument along with your block:

Riif::IIF.new do |riif|
  riif.trns do |trns|
    trns.row do |row|
      row.trnsid 123
      row.trnstype 'INVOICE'
      row.date '8/31/1988'
      row.accnt 'Accounts Receivable'
      row.name 'Customer'
    end
  end
end

Editors

Vim

au BufWinEnter,BufRead,BufNewFile *.riif set filetype=ruby

Resources

Export or import Intuit Interchange Format (.IIF) files

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

🍻

https://github.com/linjunpop/riif/graphs/contributors

Changes

See CHANGELOG.md

riif's People

Contributors

ghiculescu avatar jaredmoody avatar johnnyb avatar jphpsf avatar krasnoukhov avatar linjunpop avatar mcelicalderon avatar montulli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

riif's Issues

Cannot pass instance variable from controller to iif.riif

Hi,

This gem looks great, however i'm having a hard time figuring out how to pass an instance variable from the controller to the iff.riff file. The idea is to cycle through an array of hashes, and the iif output should have the correct values.

Any help is appreciated.

Defining a class on a trns

How do I define a class on a trns? Looking through the code, it looks like I should do it like:

iif.trns do
  row do
    class "something"
  end
end

But that obviously throws syntax errors. I tried using 'klass' as the readme suggests, but there doesn't appear to be support for that. Any suggestions?

Quickbooks Desktop and Semicolons

I've noticed that when a field contains a semicolon, Quickbooks Desktop gives an error and does not import the IIF file. Since that seems like a character that just isn't allowed, it seems like it would be a nice feature to automatically strip semicolons from any text fields in this library. What do you think, I'm happy to submit a PR if you like the idea.

Tabs counts are off in final file

On OSX Quickbooks it seems to care how many tabs are in each row. Any idea how to fix?

If TRNS has X columns
ENDTRNS expects X Columns worth of tabs

Getting nil variable when generating file

Hi, for some reason I'm getting a nil variable here is my .iif.riif file:

iif.trns do
 @payments.each do |payment|
    row do
      trnsid payment.id
      trnstype 'PAYMENT'
      date payment.paid_at.strftime('%m/%d/%Y')
      name "#{ payment.client.get_initials }"
      amount payment.amount
      docnum payment.id
    end

    spl do
      row do
        splid payment.id
        trnstype 'PAYMENT'
        date payment.paid_at.strftime('%m/%d/%Y')
        amount "-#{ payment.amount }"
        name "#{ payment.client.get_initials }"
        docnum payment.id
      end
    end
 end
end

I'm setting @payments variable inside my action but could not find a way to make it work with this gem.

Will appreciate some directions here...

layout: false not being respected

thanks for the gem!
Im seeing an odd behaviour.
respond_to do |format| format.iif { render iif: render_to_string, filename: 'batman' } format.html end
downloads a "batman" file, but with the entire application.haml layout, along with the IIF data in teh yield section

So I tried to set layout:false

respond_to do |format| format.iif { render iif: render_to_string, filename: 'batman', layout: false } format.html end
Im still seeing the application.haml layout , with the IIF data in the yield. so in essence, its creating a .html page and downloading it as "batman.iif"

If I remove the iif: render_to_string

respond_to do |format| format.iif { render filename: 'batman', layout: false } format.html end
I get the expected file output, but now the filename is the ID of the record, not "batman".

So im wondering if the layout: false is necessary, as Im not seeing it anywhere in the docs or other users examples.

Thanks for any info.

klass throws undefined method error

iif.trns do           
        row do
            # print "rfield = #{r_field}"           
            # print "Addcolumn = #{addcolumns}"
            trnsid      ''          #B
            trnstype    "INVOICE"
            date        first_shift_date         #Date of First Shift within selected date range   D
            accnt       "Accounts Receivable"    #E
            name        "#{@city} "," #{@state}"        #Site’s City, State Abbreviation  F
            # klass       total_billed_hours
            amount      setting_invoice_val   #Invoice Number H
            docnum      ""          #I
            memo        "N"         #J
            clear       "Y"         #K
            toprint     "N"         #L
            addr1       site.hospital_name          #Site’s Hospital Name M
            addr2       @b_street         #Billing street address N
            addr3       "#{@city}"," #{@state}"," #{@zip}"          #Site’s City, State, Zip Code   O
            addr4       ""          #P
            addr5       ""          #Q
            saddr1      ""          #R
            saddr2      ""          #S
            saddr3      ""          #T
            saddr4      ""          #U
            saddr5      ""          #V            
            duedate     first_shift_date          #Date of First Shift within selected date range W
            terms       ""          #X
            paid        ""          #Y           
            paymeth     ""          #Z
            shipdate    ""          #AA            
            rep         ""          #AB              
        end
        ab.each do |addcolumns|
            @tim = addcolumns.end.to_time - addcolumns.start.to_time
            @total = @tim/3600
            spl do
                row do
                    splid       ''          #B
                    trnstype    "INVOICE"   #C
                    date        addcolumns.start.strftime("%d-%m-%Y")          #Shift’s start date  D
                    accnt       site.quickbooks_label          #Site’s QuickBooks Label E
                    name        ""          #F
                    # klass       @total          #-(Total # of hours billed for the specific shift) G
                    amount      ''          #Invoice Number H
                    docnum      addcolumns.title.split('-')[0]          #Provider’s Name I
                    memo        "N"         #J
                    clear       ((addcolumns.end - addcolumns.start) / 1.hour)          #Total # of shift hours K
                    qnty        addcolumns.custom_bill_rate          #Shift’s Bill Rate L
                    price       addcolumns.shift_type          #Shift’s Shift Type M
                    invitem     "N"         #N
                    paymeth     addcolumns.start.strftime("%I:%M%p")          #Shifts start time O
                    taxable     addcolumns.end.strftime("%I:%M%p")          #Shifts End Time P
                    reimbexp    addcolumns.start.strftime("%d-%m-%Y")          #Shifts Start Date,Q
                    extra       site.quickbooks_class          #Site’s Quickbooks Class R                    
                end
            end
        end

    end 

Also, I'm an idiot... so feel free to let me know if this is a dumb question.

klassror 1 1

Having problems to make this work with Rail 6.0.3.2

All was working fine in Rails 4, but I'm currently upgrading to Rails 6.0.3.2 (with Ruby 2.6.6), and riif v1.0.0 and now the line

    respond_to do |format|
      format.iif { render iif: render_to_string, filename: 'myfile' }
    end

gives me this error:
ArgumentError (Invalid formats: #<Mime::Type:0x00007fc16304ceb0 @synonyms=["application/qbookspro", "text/iif"], @symbol=:iif, @string="application/qbooks", @hash=4387365843056142794>):

So it's not that the MIME type did not get registered (otherwise Rails would not know about the application/qbookspro, but something else. I'm very much confused.

Deprecation warning on Rails 6.0.0.rc1

DEPRECATION WARNING: Single arity template handlers are deprecated. Template handlers must
now accept two parameters, the view object and the source for the view object.
Change:
  >> Riif::Rails::TemplateHandler.call(template)
To:
  >> Riif::Rails::TemplateHandler.call(template, source)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.