[[iii{ "spec/spec_helper.rb{: coverage[7: inferred;TTTT;;T;T;;;TTT;;;;;;;;;;;;;;;;;;;;;;;;;T;;;;;;;: counts[7iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii: lines[7"O# This file is copied to ~/spec when you run 'ruby script/generate rspec' "(# from the project root directory. "ENV["RAILS_ENV"] = "test" "Qrequire File.expand_path(File.dirname(__FILE__) + "/../config/environment") "require 'spec' "require 'spec/rails' " "# ADDED BY GREG "require 'spec/factory.rb' " "(Spec::Runner.configure do |config| "B # If you're not using ActiveRecord you should remove these "F # lines, delete config/database.yml and disable :active_record " # in your config/boot.rb "0 config.use_transactional_fixtures = true "1 config.use_instantiated_fixtures = false "< config.fixture_path = RAILS_ROOT + '/spec/fixtures/' " " # == Fixtures " # "D # You can declare fixtures for each example_group like this: " # describe "...." do ") # fixtures :table_a, :table_b " # "I # Alternatively, if you prefer to declare them only once, you can "P # do so right here. Just uncomment the next line and replace the fixture "# # names with your fixtures. " # "5 # config.global_fixtures = :table_a, :table_b " # "M # If you declare global fixtures, be aware that they will be declared "C # for all of your examples, even those that don't use them. " # "^ # You can also declare which fixtures to use (for example fixtures for test/fixtures): " # "> # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' " # " # == Mock Framework " # "L # RSpec uses it's own mocking framework by default. If you prefer to "D # use mocha, flexmock or RR, uncomment the appropriate line: " # " config.mock_with :mocha "$ # config.mock_with :flexmock " # config.mock_with :rr " # " # == Notes " # "[ # For more information take a look at Spec::Example::Configuration and Spec::Runner " end "lib/error.rb{;[;TTT;TFFFFFFF;[iiiiiiiiiiiii;[" "!class Error < RuntimeError " attr :developer_message " attr :severity " "9 def initialize(user, dev=nil, sev=Logger::FATAL) "_ super user # Use normal exception parameter for User Message "M @developer_message = dev || user # Set developer focused message " @severity = sev " end " " " end "app/models/person.rb{;[;;;;;;;;;;;TTT;;;[iiiiiiiiiiiiiiii;["# == Schema Information "&# Schema version: 20090105211321 "# "# Table name: people "# ":# id :integer(4) not null, primary key "-# name :string(255) not null "%# created_at :datetime "%# updated_at :datetime "# " "'class Person < ActiveRecord::Base "# validates_presence_of :name "% validates_uniqueness_of :name " " end " app/models/interest_rate.rb{;[;;;;;;;;;;;;;T;T;TT;;;[iiiiiiiiiiiiiiiiiiiii;["# == Schema Information "&# Schema version: 20090105211321 "# ""# Table name: interest_rates "# ":# id :integer(4) not null, primary key "-# start_date :date not null "-# rate :decimal(9, 2) not null "-# account_id :integer(4) not null "%# created_at :datetime "%# updated_at :datetime "# " "-class InterestRate < ActiveRecord::Base " " belongs_to :account " "4 validates_numericality_of :rate, :account_id "" validates_date :start_date " " end " app/models/bi_allocation.rb{;[;;;;;;;;;;;;;;TTTT;;[iiiiiiiiiiiiiiiiiii;["# == Schema Information "&# Schema version: 20090105211321 "# ""# Table name: bi_allocations "# "@# id :integer(4) not null, primary key "3# business_item_id :integer(4) not null "+# category_id :integer(4) "+# person_id :integer(4) "3# amount :decimal(9, 2) not null "+# created_at :datetime "+# updated_at :datetime "# " "-class BiAllocation < ActiveRecord::Base "! belongs_to :business_item " belongs_to :category " belongs_to :person " end "spec/factory.rb{;[9T;TTT;TFFF;TFFFF;TFF;TFFFFFFFF;TFFFFFF;TFFFFFF;TT;;;;[9iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[9"module Factory " " def self.included(base) " base.extend(self) " end " " def build(params = {}) "l raise "There are no default params for #{self.name}" unless self.respond_to?(self.name.underscore) "< new(self.send(self.name.underscore).merge(params)) " end " " def build!(params = {}) " obj = build(params) " obj.save! " obj " end " " def account " {:name => "test name"} " end " " def account_item " { "' :date => Time.now.to_date, "$ :description => "test", " :amount => 10.0, " :account_id => 1, " :balance => 100 " } " end " " def business_item " { "& :date => Time.now.to_date, "# :description => "test", " :amount => 10.0 " } " end " " def ai_automation_config " { " :regex => ".*test.*" " } " end " " end " "&ActiveRecord::Base.class_eval do " include Factory " end " " "app/models/account.rb{;[);;;;;;;;;;;;;;;;T;TTT;;T;;;TTTTTT;;;;[)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[)"# == Schema Information "&# Schema version: 20090105211321 "# "# Table name: accounts "# "C# id :integer(4) not null, primary key "6# name :string(255) not null ".# limit :decimal(9, 2) ".# offset_account_id :integer(4) ".# autolevel_source_id :integer(4) ".# autolevel_min :decimal(9, 2) ".# autolevel_max :decimal(9, 2) ".# created_at :datetime ".# updated_at :datetime "# " "(class Account < ActiveRecord::Base " " has_many :interest_rates "/ has_and_belongs_to_many :account_groups "% belongs_to :autolevel_source, "# :class_name => "Account", "/ :foreign_key => "autolevel_source_id" "# belongs_to :offset_account, "# :class_name => "Account", "- :foreign_key => "offset_account_id" " "# validates_presence_of :name "O validates_numericality_of :offset_account_id, :if => :offset_account_id "S validates_numericality_of :autolevel_source_id, :if => :autolevel_source_id "M validates_numericality_of :autolevel_min, :if => :autolevel_source_id "M validates_numericality_of :autolevel_max, :if => :autolevel_source_id "7 validates_numericality_of :limit, :if => :limit " " " end "script/spec{;[ ;TTTT;[ iiiii;[ "#!/usr/bin/env ruby "c$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) "require 'rubygems' "require 'spec' "dexit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT)) "&app/models/account_item/upload.rb{;[¤T;TFFTFFTFFTFFTFFTFFTFF;;;TFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;T;;TFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;[¤iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[¤"class AccountItem " "1 def self.upload_cba_misa(str_or_readable) "¹ self.generic_upload(4, nil, false, {:date_index => 0, :description_index => 2, :debit_index => nil, :credit_index => nil, :amount_index => 1, :balance_index => 3}, str_or_readable) " end "8 def self.upload_cba_streamlined(str_or_readable) "¹ self.generic_upload(5, nil, false, {:date_index => 0, :description_index => 2, :debit_index => nil, :credit_index => nil, :amount_index => 1, :balance_index => 3}, str_or_readable) " end "1 def self.upload_cba_loan(str_or_readable) "¹ self.generic_upload(7, nil, false, {:date_index => 0, :description_index => 2, :debit_index => nil, :credit_index => nil, :amount_index => 1, :balance_index => 3}, str_or_readable) " end "9 def self.upload_stgeorge_savings(str_or_readable) "¶ self.generic_upload(1, nil, true, {:date_index => 0, :description_index => 1, :debit_index => 2, :credit_index => 3, :amount_index => nil, :balance_index => 4}, str_or_readable) " end "5 def self.upload_stgeorge_loc(str_or_readable) "¶ self.generic_upload(6, nil, true, {:date_index => 0, :description_index => 1, :debit_index => 2, :credit_index => 3, :amount_index => nil, :balance_index => 4}, str_or_readable) " end "8 def self.upload_stgeorge_dragon(str_or_readable) "¶ self.generic_upload(3, nil, true, {:date_index => 0, :description_index => 1, :debit_index => 2, :credit_index => 3, :amount_index => nil, :balance_index => 4}, str_or_readable) " end "3 def self.upload_anz_credit(str_or_readable) "ä self.generic_upload(2, params[:upload_transaction][:closing_balance], true, {:date_index => 0, :description_index => 2, :debit_index => nil, :credit_index => nil, :amount_index => 1, :balance_index => nil}, str_or_readable) " end " " " # Upload CSV bank data "k def self.generic_upload(account_id, closing_balance, inverse_sign, column_indexes, str_or_readable) " "V # Validate balance - either closing balance OR there is valid balance column "F if !column_indexes[:balance_index] && closing_balance.blank? "k raise Error.new("Validation Error. Neither a balance column or closing balance was specified", " nil, "& Logger::Severity::ERROR) " end " "0 # Validate closing balance is a number " begin "N closing_balance = Kernel.Float(closing_balance) if closing_balance " rescue Exception => e "q raise Error.new("Closing balance was not a float. Error = #{e.to_str}", nil, Logger::Severity::ERROR) " end " " # Initialise parameter " @success_count = 0 " "# # Load Data from CSV File "V data, errors = self.load_data(str_or_readable, inverse_sign, column_indexes) " duplicates = [] " successes = [] " "0 # Order data chronologically ascending "< if (data[0][:date] > data[data.length - 1][:date]) " data.reverse! " end " "- # Check for need to update balances ", if !column_indexes[:balance_index] "1 # Need to calculate balances manually "- previous_amount = closing_balance "@ # Loop through each item (now in chronological order "$ data.reverse_each do |t| ": t[:balance] = previous_amount # + t[:amount] "8 previous_amount = t[:balance] - t[:amount] " end " end " "0 # Update Database - with a transaction "$ AccountItem.transaction do " data.each do |item| " begin "! # Duplicate Check "9 existing_match = AccountItem.find(:first, "} :conditions => ["date = ? AND description = ? AND amount = ?", item[:date], item[:description], item[:amount]] ) "! if existing_match ", duplicates << item.inspect " next " end " "! # Update Database "# t = AccountItem.new "$ t.date = item[:date] "2 t.description = item[:description] "( t.amount = item[:amount] "/ previous_amount = item[:amount] "* t.balance = item[:balance] ") t.account_id = account_id " t.save! "; successes << item.inspect + " - ID:#{t.id}" "# rescue Exception => e "= errors << [e.inspect + " - " + item.inspect ] " end " end " " if !errors.empty? "# error_str = "" "A# errors.each {|e| error_str += " - " + e + " - \n"} "Q# raise Error.new("Error loading #{str_or_readable} \n#{error_str}") " "4 #HOW DO I ROLLBACK ALL TRANSACTIONS??? "C ActiveRecord::Base.connection.rollback_db_transaction " " end " " end " ". return successes, duplicates, errors " " end " " private " "; # Loads CSV data into Array - returns data & errors "I def self.load_data(str_or_readable, inverse_sign, column_indexes) "B str_or_readable = File.expand_path(str_or_readable).to_s "f raise Error.new("Not a valid file path: #{str_or_readable}") if !File.file?(str_or_readable) "0 input_file = File.new(str_or_readable) " data = [] " errors = [] "X # parsed_file=CSV::Reader.parse(params[:upload_transaction][:file], ",", "\n") "> parsed_file=CSV::Reader.parse(input_file, ",", "\n") "$ parsed_file.each do |row| " begin " # Parse Row Data "; r_date_str = row[column_indexes[:date_index]] "0 r_date = Date.parse_au(r_date_str) "s r_description = row[column_indexes[:description_index]].strip # to ensure duplicates are identified " r_amount = nil "A use_amount = (column_indexes[:amount_index] != nil) " if use_amount "B r_amount = row[column_indexes[:amount_index]].to_f " else "H r_debit = (row[column_indexes[:debit_index]] ||= 0).to_f "J r_credit = (row[column_indexes[:credit_index]] ||= 0).to_f "- r_amount = r_debit - r_credit " if inverse_sign "& r_amount = -r_amount " end " end "/ if column_indexes[:balance_index] "% # Balance is provided "L r_balance = (row[column_indexes[:balance_index]] ||= 0).to_f " else "` # Balance is not provided - keep as nil as will be updated outside this function " r_balance = nil " end "! rescue Exception => e "7 errors << e.inspect + " - " + row.inspect " next " end " " h = { " :date => r_date, "" :amount => r_amount, ", :description => r_description, "# :balance => r_balance " } " data << h " end " " return data, errors " end " " " end " spec/models/account_spec.rb{;[T;TTFFF;TFFFF;[iiiiiiiiiiiii;["Jrequire File.expand_path(File.dirname(__FILE__) + '/../spec_helper') " "describe Account do " before(:each) do "3 @valid_attributes = {:name => "test name" " } " end " "C it "should create a new instance given valid attributes" do "? Account.new(@valid_attributes).valid?.should be_true ", Account.create!(@valid_attributes) " end " end "lib/core_ext/integer.rb{;[TT;TFF;TFF;TFFFF;;[iiiiiiiiiiiiiiiii;["class Integer "1 include ActionView::Helpers::NumberHelper " " def format_au "@ return ( "$" + number_with_delimiter(self, ",", ".") ) " end " "% def financial_year_start_date "( Date.civil(self - 1, 7, 1) " end " "# def financial_year_end_date "! Date.civil(self, 6, 30) " end " " end " ")lib/active_record/base_extensions.rb{;[$T;TTT;T;TFFFFFFFFF;TFFFFFFFFFFF;[$iiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[$"class ActiveRecord::Base " " def self.concerns(*args) " args.each do |concern| "> require_dependency "#{name.underscore}/#{concern}" " end " end " "/ def self.create_with_id(attributes=nil) "$ if attributes.is_a?(Array) "> attributes.collect { |attr| create_with_id(attr) } " else "$ object = new(attributes) ") object[:id] = attributes[:id] " object.save " object " end " end " "0 def self.create_with_id!(attributes=nil) "$ if attributes.is_a?(Array) "? attributes.collect { |attr| create_with_id!(attr) } " else "$ object = new(attributes) ") object[:id] = attributes[:id] " object.save! " object " end " end " "end"app/models/tax_item.rb{;[";;;;;;;;;;;T;TT;TT;;TFFFFFFFF;["iiiiiiiiiiiiiiiiiiiiiiiiiiiii;[""# == Schema Information "&# Schema version: 20090105211321 "# "# Table name: tax_items "# ":# id :integer(4) not null, primary key "-# title :string(255) not null "%# created_at :datetime "%# updated_at :datetime "# " "require("csv.rb") " "(class TaxItem < ActiveRecord::Base " has_many :categories " "$ validates_presence_of :title "& validates_uniqueness_of :title " " "% def self.populate_config_data "# TaxItem.delete_all "] parsed_file=CSV::Reader.parse(File.open("db/config_data/tax_items.csv"), ",", "\n") "# parsed_file.each do |row| "D TaxItem.create_with_id!(:id => row[0], :title => row[1]) " end " end " " end " app/models/category_type.rb{;[";;;;;;;;;;;TT;TT;TTT;TFFFFFFF;["iiiiiiiiiiiiiiiiiiiiiiiiiiiii;[""# == Schema Information "&# Schema version: 20090105211321 "# ""# Table name: category_types "# ":# id :integer(4) not null, primary key "%# title :string(255) "%# created_at :datetime "%# updated_at :datetime "# " "-class CategoryType < ActiveRecord::Base " has_many :categories " "$ validates_presence_of :title "& validates_uniqueness_of :title " " KEY_INCOME = 1 " KEY_EXPENSE = 2 " KEY_JOURNAL = 3 " "% def self.populate_config_data ""# CategoryType.delete_all "M CategoryType.create_with_id!(:id => KEY_INCOME, :title => "Income") "O CategoryType.create_with_id!(:id => KEY_EXPENSE, :title => "Expense") "O CategoryType.create_with_id!(:id => KEY_JOURNAL, :title => "Journal") " " end " end "lib/core_ext/date.rb{;[';T;TFFFFFFFF;TFFF;TFF;TFF;TFFFF;;;;['iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;['" "class Date " " def self.parse_au(str) " begin " # 1st try "* Date.strptime(str, '%d/%m/%Y') " rescue " # 2nd try "* Date.strptime(str, '%Y-%m-%d') " end " end " " def to_sql_date "0 #"'" + self.strftime("%Y-%m-%d") + "'" "# self.strftime("%Y-%m-%d") " end " " def financial_year_start "` Date.civil(year, 6, 30) < self ? Date.civil(year, 6, 30) : Date.civil(year - 1, 6, 30) " end " " def financial_year_end "] Date.civil(year, 7, 1) > self ? Date.civil(year, 7, 1) : Date.civil(year + 1, 7, 1) " end " " def financial_year "9 Date.civil(year, 7, 1) > self ? year : year + 1 " end " " end " " " " lib/core_ext/big_decimal.rb{;[TT;TFFFFF;;[iiiiiiiiii;["class BigDecimal "1 include ActionView::Helpers::NumberHelper " " def format_au "B # return ( "$" + number_with_delimiter(self, ",", ".") ) "\ return ( "$" + number_with_delimiter(self, :delimiter => ",", :separator => ".") ) " end " " end " "app/models/account_item.rb{;[>;;;;;;;;;;;;;;;;TT;TT;TTTTT;;;;;T;T;TFFF;TFFFFFFFFFFFFFFF;[>iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[>"# == Schema Information "&# Schema version: 20090105211321 "# "!# Table name: account_items "# ";# id :integer(4) not null, primary key ".# account_id :integer(4) not null ".# date :date not null ".# amount :decimal(9, 2) not null ".# balance :decimal(9, 2) not null ".# description :string(255) not null "&# notes :text "&# created_at :datetime "&# updated_at :datetime "# " ",class AccountItem < ActiveRecord::Base " concerns :upload " " has_many :ai_allocations "= has_many :business_items, :through => :ai_allocations " "% validates_presence_of :amount ") validates_numericality_of :amount "* validates_numericality_of :balance " validates_date :date "* validates_presence_of :description " "L # Leave out until multi-model spanning validation approach is sorted ", # validate :business_rule_validation " "j # TODO: May need to move "create_matching_business_item" from after_create to be invoked manually "3 after_create :create_matching_business_item " " private " "$ def business_rule_validation "9 # Rule 1 - Must have an associated Account Item "… errors.add_to_base("Account Item #{self.id} does NOT have a Business Item associated to it.") if self.business_items.length == 0 " end " ") def create_matching_business_item " begin "t bi = BusinessItem.create!(:date => self.date, :description => self.description, :amount => self.amount) "! AiAllocation.create!( ") :business_item_id => bi.id, "* :account_item_id => self.id, " :amount => self.id " ) " rescue Exception => e "A ActiveRecord::Base.connection.rollback_db_transaction "u raise Error.new( "Error creating associated business_item for a new account item. Rolling back all. " + "n "Account item:#{self.date.to_s} - #{self.description} = #{self.amount}. Error: #{e.inspect}") " end " end " " end "app/models/frequency.rb{;[,;;;;;;;;;;;;;TTTT;TTTTTTT;TFFFFFFFFFFFF;[,iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[,"# == Schema Information "&# Schema version: 20090105211321 "# "# Table name: frequencies "# "G# id :integer(4) not null, primary key ":# title :string(255) not null "2# avg_days :integer(4) "2# date_group_column_title :string(255) "2# created_at :datetime "2# updated_at :datetime "# " "*class Frequency < ActiveRecord::Base " has_many :recurrings "$ validates_presence_of :title "& validates_uniqueness_of :title " " INDEX_DAILY = 1 " INDEX_WEEKLY = 2 " INDEX_FORTNIGHTLY = 3 " INDEX_MONTHLY = 4 " INDEX_QUARTERLY = 5 " INDEX_YEARLY = 6 " INDEX_ONCEOFF = 7 " "% def self.populate_config_data "# Frequency.delete_all "\ Frequency.create_with_id!([:id => INDEX_DAILY, :title => "Daily", :avg_days => 1]) "„ Frequency.create_with_id!([:id => INDEX_WEEKLY, :title => "Weekly", :avg_days => 7, :date_group_column_title => "week_title" ]) "” Frequency.create_with_id!([:id => INDEX_FORTNIGHTLY, :title => "Fortnightly", :avg_days => 14, :date_group_column_title => "fortnight_title" ]) "ˆ Frequency.create_with_id!([:id => INDEX_MONTHLY, :title => "Monthly", :avg_days => 30, :date_group_column_title => "month_title" ]) "‘ Frequency.create_with_id!([:id => INDEX_QUARTERLY, :title => "Quarterly", :avg_days => 365/4, :date_group_column_title => "quarter_title" ]) "† Frequency.create_with_id!([:id => INDEX_YEARLY, :title => "Yearly", :avg_days => 365, :date_group_column_title => "year_title" ]) "c Frequency.create_with_id!([:id => INDEX_ONCEOFF, :title => "Once Off", :avg_days => nil]) " end " " " end " app/models/business_item.rb{;[M;;;;;;;;;;;;;;TTTTTT;TTT;;;;TFFFFFFFF;;;;;;;;;;;TFFFFFFFFFFFFFFFFFFFFFFF;[Miiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[M"# == Schema Information "&# Schema version: 20090105211321 "# ""# Table name: business_items "# ";# id :integer(4) not null, primary key ".# date :date not null ".# amount :decimal(9, 2) not null ".# description :string(255) not null "&# notes :text "&# created_at :datetime "&# updated_at :datetime "# " "-class BusinessItem < ActiveRecord::Base " has_many :ai_allocations " has_many :bi_allocations "< has_many :account_items, :through => :ai_allocations "9 has_many :categories, :through => :bi_allocations "5 has_many :people, :through => :bi_allocations " ") validates_numericality_of :amount " validates_date :date "* validates_presence_of :description " "L # Leave out until multi-model spanning validation approach is sorted ", # validate :business_rule_validation " "$ def business_rule_validation "9 # Rule 1 - Must have an associated Account Item "… errors.add_to_base("Business Item #{self.id} does NOT have an Account Item associated to it.") if self.account_items.length == 0 " "N # Rule 2 - Sum of AiAllocation amounts should equal BI amount itself "i sum_allocations = AiAllocation.sum('amount', :conditions => {:business_item_id => self.id}) "· # errors.add_to_base("Business Item #{self.id}'s amount of #{self.amount.format_au} does NOT equal sum of #{AiAllocation.count} AiAllocations") if self.amount != sum_allocations " " end " "L # Will split an existing business item into multiple business items "_ # Input: bus_items = Array of Hashes which specify :date, :amount, :description, :notes " # Processing Rules: "J # a) First hash item will use existing business item (i.e. self) "W # b) Business item must have only one existing association to an Account Item "A # c) Existing category & person allocations are dropped "A # d) Ensure initial amount = sum(amount's of final BIs) " # Output: "9 # a) If successful - Array of Business Item IDs "N # b) If fails - Rolls back all database changes and raises Exception "" def split(bus_items_array) "~ raise Error.new("bus_items array should contain at least two entries") if !bus_items_array || bus_items_array.length <= 1 " "% BusinessItem.transaction do "` default_attributes = self.attributes.slice('date', 'amount', 'description', 'notes') "@ bus_items_array.each_with_index do |bi_attrs, index| " if index == 0 "6 # Use existing BI record for the first "N self.update_attributes!( default_attributes.merge!(bi_attrs) ) " else "3 # Create the new BI and Allocations "R bi_new = BusinessItem.create!(default_attributes.merge!(bi_attrs)) ") ai_new = AiAllocation.new "- ai_new.business_item = bi_new "; ai_new.account_item = self.account_items[0] "2 ai_new.amount = bi_attrs[:amount] " ai_new.save! " end " end " end " " end " " end " app/models/ai_allocation.rb{;[);;;;;;;;;;;;;TTT;TT;T;TFFFFFFFFFFFFF;[)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[)"# == Schema Information "&# Schema version: 20090105211321 "# ""# Table name: ai_allocations "# "@# id :integer(4) not null, primary key "3# account_item_id :integer(4) not null "3# business_item_id :integer(4) not null "3# amount :decimal(9, 2) not null "+# created_at :datetime "+# updated_at :datetime "# " "-class AiAllocation < ActiveRecord::Base " belongs_to :account_item "! belongs_to :business_item " ") validate :validate_business_rules "J validates_presence_of :amount, :account_item_id, :business_item_id " " private " "# def validate_business_rules "y if AiAllocation.find_all_by_account_item_id_and_business_item_id(account_item_id, business_item_id).length != 0 "¬ errors.add_to_base("AiAllocation uniqueness error. There is an already existing record with AccountItemId=#{account_item_id} and BusinessItemId=#{business_item_id}") " end " "Z # if AccountItem.find(account_item_id) && BusinessItem.find(business_item_id) "t # raise Error.new("An existing AiAllocation already exists between account item #{account_item_id}" + "< # " and business item #{business_item_id}") " # end " " end " " " end " app/models/account_group.rb{;[;;;;;;;;;;;;TT;T;;[iiiiiiiiiiiiiiiii;["# == Schema Information "&# Schema version: 20090105211321 "# ""# Table name: account_groups "# "># id :integer(4) not null, primary key "1# name :string(255) not null "1# show_in_splash :boolean(1) not null ")# created_at :datetime ")# updated_at :datetime "# " "-class AccountGroup < ActiveRecord::Base ". has_and_belongs_to_many :bank_accounts " "# validates_presence_of :name " end "lib/core_ext/string.rb{;[T;TFFFFFFFFFFFFF;[iiiiiiiiiiiiiiii;["class String " " def to_range " case self.count('.') " when 2 "' elements = self.split('..') "@ return Range.new(elements[0].to_i, elements[1].to_i) " when 3 "( elements = self.split('...') "B return Range.new(elements[0].to_i, elements[1].to_i-1) " else "G raise ArgumentError.new("Couldn't convert to Range:#{str}") " end " end " " end "!app/models/category_group.rb{;[";;;;;;;;;;;TT;TT;;TFFFFFFFFFF;["iiiiiiiiiiiiiiiiiiiiiiiiiiiii;[""# == Schema Information "&# Schema version: 20090105211321 "# "## Table name: category_groups "# ":# id :integer(4) not null, primary key "-# title :string(255) not null "%# created_at :datetime "%# updated_at :datetime "# " ".class CategoryGroup < ActiveRecord::Base " has_many :categories " "$ validates_presence_of :title "& validates_uniqueness_of :title " " "% def self.populate_config_data "## CategoryGroup.delete_all " "E CategoryGroup.create_with_id!(:id => 1, :title => "Income") "P CategoryGroup.create_with_id!(:id => 2, :title => "Mandatory Expense") "T CategoryGroup.create_with_id!(:id => 3, :title => "Discretionary Expense") "o CategoryGroup.create_with_id!(:id => 4, :title => "Journal") # should I really include this here? "r CategoryGroup.create_with_id!(:id => 5, :title => "Investment") # should I really include this here? " " end " end "app/models/category.rb{;[;;;;;;;;;;;;;;;;;;T;TTT;TTTTT;TT;TFFFFFFFFFFFFFFFFFFFFF;[;iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii;[;"# == Schema Information "&# Schema version: 20090105211321 "# "# Table name: categories "# "A# id :integer(4) not null, primary key "4# title :string(255) not null ",# tax_item_id :integer(4) "4# category_group_id :integer(4) not null ",# category_type_id :integer(4) ",# category_id :integer(4) "4# active :integer(4) not null ",# created_at :datetime ",# updated_at :datetime "# " " "require("csv.rb") " ")class Category < ActiveRecord::Base " has_many :bi_allocations "= has_many :business_items, :through => :bi_allocations " " has_many :categories "" belongs_to :category_group "! belongs_to :category_type " belongs_to :category " belongs_to :tax_item " "8 validates_presence_of :title, :category_group_id "4 validates_numericality_of :category_group_id " "% def self.populate_config_data "" # Category.delete_all "^ parsed_file=CSV::Reader.parse(File.open("db/config_data/categories.csv"), ",", "\n") "# parsed_file.each do |row| " begin "' Category.create_with_id!( " :id => row[0], "! :title => row[1], "> :tax_item_id => row[4] == '\N' ? nil : row[4], "- :category_group_id => row[5], ", :category_type_id => row[6], "> :category_id => row[7] == '\N' ? nil : row[7], "! :active => row[8] " ) "# rescue Exception => exc "b raise Error.new("Error loading category configuration data. Error: #{exc.inspect}") " end " end " end " " " end "'app/models/ai_automation_config.rb{;[T;;[ii;["3class AiAutomationConfig < ActiveRecord::Base " end "&app/helpers/application_helper.rb{;[;T;;[iii;["[# Methods added to this helper will be available to all templates in the application. "module ApplicationHelper " end "#app/controllers/application.rb{;[;;;TTTTTT;;TT;;;T;;;;;;;[iiiiiiiiiiiiiiiiiiiiiii;["U# Filters added to this controller apply to all controllers in the application. "N# Likewise, all the methods added will be available for all controllers. " "0require 'active_record/base_extensions.rb' " require 'core_ext/date.rb' ""require 'core_ext/string.rb' "#require 'core_ext/integer.rb' "'require 'core_ext/big_decimal.rb' "require 'error.rb' " " ":class ApplicationController < ActionController::Base "7 helper :all # include all helpers, all the time " "D # See ActionController::RequestForgeryProtection for details "L # Uncomment the :secret if you're not using the cookie session store "L protect_from_forgery # :secret => 'd2c4207f7c1793897e1658033c9a7c3f' " "1 # See ActionController::Base for details "V # Uncomment this to filter the contents of submitted sensitive data parameters "[ # from your application log (in this case, all fields with names like "password"). ", # filter_parameter_logging :password " end