Sha256: 432663621ca16e17d1c4b6b540ca286108897e3660f2f8616dff0ee69e4ca038

Contents?: true

Size: 655 Bytes

Versions: 4

Compression:

Stored size: 655 Bytes

Contents

namespace :brisk_bills do
  desc "Print an invoice to STDOUT as a csv file"
  
  task :invoice_as_csv => :environment do   
    require 'fastercsv'

    inv_id = $1.to_i if /^([\d]+)$/.match ENV['id']

    unless inv_id
       puts "Missing required id= parameter"
       exit
    end

    inv = Invoice.find inv_id

    unless inv
       puts "Invoice not found"
       exit
    end

    csv_out = FasterCSV.generate do |csv|
      csv << %w(Qty Rate Amount Item Date Description)

      inv.activities.find(:all, :order => 'occurred_on ASC').each do |a| 
        csv << a.sub_activity.as_legacy_ledger_row
      end

    end

    puts csv_out
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brisk-bills-0.8.2 lib/tasks/invoice_as_csv.rake
brisk-bills-0.8.1 lib/tasks/invoice_as_csv.rake
brisk-bills-0.7.0 lib/tasks/invoice_as_csv.rake
brisk-bills-0.6.0 lib/tasks/invoice_as_csv.rake