Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 9 commits
  • 21 files changed
  • 0 commit comments
  • 5 contributors
View
1 app/controllers/data_entry/loans.rb
@@ -5,6 +5,7 @@ class Loans < DataEntry::Controller
def new
if params[:client_id]
@client = Client.get(params[:client_id]) || Client.first(:name => params[:client_id]) || Client.first(:reference => params[:client_id])
+ raise NotFound unless @client
@center = @client.center
if params[:product_id] and @loan_product = LoanProduct.is_valid(params[:product_id])
View
7 app/controllers/insurance_products.rb
@@ -42,15 +42,16 @@ def create(insurance_product)
end
def update(id, insurance_product)
+ debugger
@insurance_product = InsuranceProduct.get(id)
raise NotFound unless @insurance_product
fees = []
if params[:fees]
- fees = params[:fees].map{ |k,v| Fee.get(k.to_i) }
+ fees = params[:fees].keys.map{ |k,v| Fee.get(k.to_i) }
end
+ @insurance_product.update_attributes(insurance_product)
@insurance_product.fees = fees
- @insurance_product.attributes = insurance_product
- if @insurance_product.save
+ if @insurance_product.save or @insurance_product.errors.empty?
redirect resource(@insurance_product)
else
display @insurance_product, :edit
View
1 app/controllers/journals.rb
@@ -222,5 +222,6 @@ def tally_download
private
def get_context
@branch = Branch.get(params[:branch_id]) if params[:branch_id] and params[:branch_id].to_i > 0
+ @journal_type = JournalType.get(params[:journal_type_id]) if params[:journal_type_id] and params[:journal_type_id].to_i > 0
end
end # Journals
View
39 app/controllers/loans.rb
@@ -43,33 +43,36 @@ def create
fee_params = params.delete(:fees)
@loan = klass.new(attrs)
@loan.loan_product = @loan_product
- if params.include?(:premium_as_fees) and fee_params[:premium_as_fees]
- @fee = Fee.get(fee_params[:fee_id])
- payable_models ||= Fee::PAYABLE.map{|m| [m[0], [m[1], m[2]]]}.to_hash
- method = payable_models[@fee.payable_on][1] if @fee
- end
msg = {}
if @loan.save
+ debugger
msg[:notice] = "Loan '#{@loan.id}' was successfully created"
- if @fee
- if params.include?(:fee_date)
- if params[:fee_date].empty?
- date = (@loan.insurance_policy.send(method) if @loan.insurance_policy.respond_to?(method))
- else
- date = (Date.strptime(params[:fee_date], Mfi.first.date_format))
+ params[:fees].keys.each do |fee_id|
+ debugger
+ @app_fee = []
+ @fee = Fee.get(fee_id)
+ if @fee
+ payable_models ||= Fee::PAYABLE.map{|m| [m[0], [m[1], m[2]]]}.to_hash
+ method = payable_models[@fee.payable_on][1] if @fee
+ if params.include?(:fee_date)
+ if params[:fee_date].empty?
+ date = (@loan.insurance_policy.send(method) if @loan.insurance_policy.respond_to?(method))
+ else
+ date = (Date.strptime(params[:fee_date], Mfi.first.date_format))
+ end
+ end
+ if date
+ @app_fees << ApplicableFee.new(:applicable_on => date, :amount => params[:insurance_policy][:premium], :fee => @fee,
+ :applicable_id => @loan.id, :applicable_type => 'Loan')
end
end
- if date
- @app_fee = ApplicableFee.new(:applicable_on => date, :amount => params[:insurance_policy][:premium], :fee => @fee,
- :applicable_id => @loan.id, :applicable_type => 'Loan')
- @fees_applied = @app_fee.save
- end
- msg[:error] = "However, insurance premium could not be applied as a fee" unless @fees_applied
+ result = @app_fees.map{|f| f.save}
+ msg[:error] = "However, #{result.select{|r| false}.count} insurance premium could not be applied as a fee" if result.include?[false]
end
redirect(params[:return] || resource(@branch, @center, @client), :message => msg)
else
set_insurance_policy(@loan_product)
- @loan.interest_rate *= 100
+ @loan.interest_rate *= 100 if @loan.interest_rate
render :new # error messages will be shown
end
end
View
6 app/helpers/global_helpers.rb
@@ -516,9 +516,11 @@ def paginate_on_weekdays(branch, selected=Date.today.weekday)
}.join(' | ')
end
- def select_accounts(name, branch=nil, attrs = {})
+ def select_accounts(name, branch=nil, journal_type=nil, attrs = {})
collection = []
- Account.all(:branch => branch).group_by{|a| a.account_type}.sort_by{|at, as| at.name}.each do |account_type, accounts|
+ @acc = Account.all(:branch => branch)
+ @acc = @acc.all(:account_category => ["Cash", "Bank"]) if journal_type == JournalType.get(4)
+ @acc.group_by{|a| a.account_type}.sort_by{|at, as| at.name}.each do |account_type, accounts|
collection << ['', "#{account_type.name}"]
accounts.sort_by{|a| a.name}.each{|a| collection << [a.id.to_s, "!!!!!!!!!#{a.name}"] }
end
View
5 app/models/journal.rb
@@ -12,6 +12,7 @@ class Journal
property :created_at, DateTime, :index => true
property :deleted_at, DateTime, :index => true
property :batch_id, Integer, :nullable => true
+ property :uuid, String, :nullable => false
belongs_to :batch
belongs_to :journal_type
has n, :postings
@@ -72,7 +73,8 @@ def self.create_transaction(journal_params, debit_accounts, credit_accounts)
journal = Journal.create(:comment => journal_params[:comment], :date => journal_params[:date]||Date.today,
:transaction_id => journal_params[:transaction_id],
- :journal_type_id => journal_params[:journal_type_id])
+ :journal_type_id => journal_params[:journal_type_id],
+ :uuid => UUID.generate)
amount = journal_params.key?(:amount) ? journal_params[:amount].to_i : nil
@@ -148,6 +150,7 @@ def self.xml_tally(hash={}, xml_file = nil)
x.NARRATION j.comment
x.VOUCHERTYPENAME j.journal_type.name
x.VOUCHERNUMBER j.id
+ x.REMOTEID j.uuid
credit_posting.each do |p|
x.tag! 'ALLLEDGERENTRIES.LIST' do
x.LEDGERNAME(p.account.name)
View
14 app/views/insurance_policies/_fields.html.haml
@@ -31,14 +31,18 @@
Premium
%td
= text_field :premium
- %tr
+ %tr{:style => "background-color:#fff370"}
%td
- = check_box(:name => "fees[premium_as_fees]", :value => 1)
Apply premium as
%td
- - fee_list = Fee.all.map{|x| [x.id, x.name] if x.payable_on.to_s =~ /policy/}
- - fee_list.delete(nil)
- = select(:name => "fees[fee_id]", :collection => fee_list, :prompt => "")
+ - @loan_product.insurance_product.fees.each do |f|
+ %ul
+ %li
+ = check_box(:name => "fee_#{f.id}", :checked => true)
+ = f.name
+ %tr{:style => "background-color:#fff370"}
+ %td
+ payable on
%td
= date_select :fee_date, nil
%tr
View
2 app/views/insurance_products/_fields.html.haml
@@ -17,6 +17,6 @@
%i No fees defined for insurance products
- else
- for fee in fees_for_insurance
- = check_box :name => "#{fee}", :checked => @insurance_product.fees.include?(fee)
+ = check_box :name => "fees[#{fee.id}]", :checked => @insurance_product.fees.include?(fee)
= fee.name
%br
View
4 app/views/journals/_account_amount.html.haml
@@ -3,12 +3,12 @@
%td
= account_type.to_s.camelcase(' ')
%td
- = select_accounts("#{account_type.to_s}[][account_id]", @branch, :selected => account[:account_id])
+ = select_accounts("#{account_type.to_s}[][account_id]", @branch, @journal_type, :selected => account[:account_id])
%td
Amount
%td
=text_field :name => "#{account_type.to_s}[][amount]", :value => account[:amount]
- if last_account
%td
- %a{:href => url(:controller => :journals, :action => :add_account, :account_type => account_type, :branch_id => (@branch ? @branch.id : "")), :class => "_remote_", :id => "account_row_#{random}"}
+ %a{:href => url(:controller => :journals, :action => :add_account, :account_type => account_type, :branch_id => (@branch ? @branch.id : ""), :journal_type_id => (@journal_type ? @journal_type.id : nil)), :class => "_remote_", :id => "account_row_#{random}"}
add another entry
View
7 app/views/journals/_fields.html.haml
@@ -1,11 +1,6 @@
%table
%tr
%td
- Voucher Type
- %td
- = select :journal_type_id, :collection => JournalType.all.map{|x| [x.id, x.name]}, :prompt=> "Select voucher"
- %tr
- %td
Date
%td
= date_select_for @journal, :date
@@ -29,5 +24,7 @@
Transaction ID
%td
=text_field :transaction_id
+ =text_field :journal_type_id, :value => @journal_type.nil? ? 1 : @journal_type.id, :hidden => true
+
%p
= submit "Create"
View
6 app/views/journals/new.html.haml
@@ -24,16 +24,20 @@
%form{:class => "_remote_", :method => "GET", :action => resource(:journals, :new, {:return => params[:return]})}
%b Select branch
= select :name => :branch_id, :collection => Branch.all.map{|x| [x.id, x.name]}, :prompt => "Head office accounts", :selected => params[:branch_id]
+ %b Journal Type
+ = select :name => :journal_type_id, :collection => JournalType.all.map{|x| [x.id, x.name]}, :selected => params[:journal_type_id]
%input{:type => :hidden, :name => "_target_", :value => "voucher_container"}
%input{:type => :hidden, :name => "return", :value => params[:return]}
= submit "GO"
+
- if @branch
%h2
= @branch.name
- = form_for(@journal, :action => resource(:journals, {:branch_id => (@branch ? @branch.id : nil), :return => params[:return]}), :method => :post) do
+ = form_for(@journal, :action => resource(:journals, {:branch_id => (@branch ? @branch.id : nil), :journal_type_id => @journal_type, :return => params[:return]}), :method => :post) do
= partial :fields
- else
%h2
HO journal entry
= form_for(@journal, :action => resource(:journals, {:return => params[:return]}), :method => :post) do
= partial :fields
+
View
4 bin/autospec
@@ -13,7 +13,7 @@ if File.directory?(gems_dir)
Gem.path.replace([File.expand_path(gems_dir)])
ENV["PATH"] = "#{File.dirname(__FILE__)}:#{ENV["PATH"]}"
- gem_file = File.join(gems_dir, "specifications", "rspec-*.gemspec")
+ gem_file = File.join(gems_dir, "specifications", "rspec-core-*.gemspec")
if local_gem = Dir[gem_file].last
version = File.basename(local_gem)[/-([\.\d]+)\.gemspec$/, 1]
@@ -27,5 +27,5 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
ARGV.shift
end
-gem 'rspec', version
+gem 'rspec-core', version
load 'autospec'
View
0 bin/rspec 100644 → 100755
File mode changed.
View
45 lib/automater/cluster.rb
@@ -1,45 +0,0 @@
-#This class is made for the application of k-mean clustering algorithm used in auto_simulation.rake
-
-class Cluster
- attr_accessor :center, :points
-
- # Constructor with a starting centerpoint
- def initialize(center)
- @center = center
- @points = []
- end
-
- # Recenters the centroid point and removes all of the associated points
- def recenter!
- lata = longa = 0
- old_center = @center
-
- # Sum up all x/y coords
- @points.each do |point|
- lata += point.lat
- longa += point.long
- end
-
- # Average out data
- lata /= @points.length
- longa /= @points.length
-
- # Reset center and return distance moved
- @center = Point.new("center", lata, longa)
- return old_center.dist_to(center)
- end
-
- def centerize
- min_dist = 1.0/0
- new_cent = nil
- @points.each{|point|
- dist = @center.dist_to(point)
- if dist < min_dist
- new_cent = point
- min_dist = dist
- end
- }
- @center = new_cent if new_cent
- @points = @points - [@center]
- end
-end
View
60 lib/automater/kmean.rb
@@ -1,60 +0,0 @@
-#This is used in auto_simulation.rake for clustering of locations
-
-def kmeans(data, k, delta=10.0)
- clusters = []
-
- # Assign intial values for all clusters
- (0...k).each do |i|
- index = (((i*1.0)/k)*data.length).to_i
-
- rand_point = data[index]
- c = Cluster.new(rand_point)
-
- clusters.push c
- end
-
- # Loop
- while true
- # Assign points to clusters
- data.each do |point|
- min_dist = 1.0/0
- min_cluster = nil
-
- # Find the closest cluster
- clusters.each do |cluster|
- dist = point.dist_to(cluster.center)
-
- if dist < min_dist
- min_dist = dist
- min_cluster = cluster
- end
- end
-
- # Add to closest cluster
- min_cluster.points.push point
- end
-
- # Check deltas
- max_delta = -100000000
-
- clusters.each do |cluster|
- next if cluster.points.length == 0
- dist_moved = cluster.recenter!
-
- # Get largest delta
- if dist_moved > max_delta
- max_delta = dist_moved
- end
- end
-
- # Check exit condition
- if max_delta < delta
- return clusters
- end
-
- # Reset points for the next iteration
- clusters.each do |cluster|
- cluster.points = []
- end
- end
-end
View
29 lib/automater/point.rb
@@ -1,29 +0,0 @@
-#This class is made for the application of k-mean clustering algorithm used in auto_simulation.rake
-
-class Point
- attr_accessor :name, :lat, :long
-
- # Constructor that takes in an x,y coordinate
- def initialize(name, lat, long)
- @name = name
- @lat = lat#[0..1].to_i + lat[3..4].to_i/60.0
- @long = long#[0..1].to_i + long[3..4].to_i/60.0
- end
-
- # Calculates the distance to Point p
- def dist_to(p)
- dlat = (@lat - p.lat) * Math::PI / 180
- dlon = (@long - p.long) * Math::PI / 180
- a = Math.sin(dlat/2) * Math.sin(dlat/2) + Math.cos(@lat * Math::PI/180) * Math.cos(p.lat * Math::PI / 180) * Math.sin(dlon/2) * Math.sin(dlon/2)
- c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
- return 6371.009 * c
- end
-
- # Return a String representation of the object
- def to_s
- return "#{@name} - (#{@lat}, #{@long})"
- end
-end
-
-#point = Point.new("Balliapal", "26*40`N", "87*17`E")
-#puts point.dist_to(Point.new("Ballia", "25*46`N", "84*12`E"))
View
262 lib/tasks/auto_simulation.rake
@@ -1,262 +0,0 @@
-# Add the local gems dir if found within the app root; any dependencies loaded
-# hereafter will try to load from the local gems before loading system gems.
-if (local_gem_dir = File.join(File.dirname(__FILE__), '..', '..', 'gems')) && $BUNDLE.nil?
- $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
-end
-
-require "merb-core"
-require "fastercsv"
-require "lib/automater/point.rb"
-require "lib/automater/cluster.rb"
-require "lib/automater/kmean.rb"
-require "pp"
-
-# this loads all plugins required in your init file so don't add them
-# here again, Merb will do it for you
-Merb.start_environment(:environment => ENV['MERB_ENV'] || 'development')
-
-namespace :mostfit do
- desc "Simulate the natural activity in a pattern"
- task :simulate do
- Merb.logger.info "Simulating the natural activity in a pattern"
- names = FasterCSV.parse(File.read("db/names.csv")).flatten
- len = names.length
- counter = 1
- user = User.first
-
- regions = FasterCSV.parse(File.read("db/in_lat_long.csv")).flatten
- nregions = regions.length/4
-
- areas = FasterCSV.parse(File.read("db/in_lat_long1.csv")).flatten
- nareas = areas.length/3
-
- dobs = FasterCSV.parse(File.read("db/date_of_births.csv")).flatten
- dob_len = dobs.length
-
- funders = FasterCSV.parse(File.read("db/funders.csv")).flatten
- funders.each{|f_name|
- funder = Funder.first(:name => f_name) || Funder.create(:name => f_name)
- funder.save unless funder.valid?
- (1..1+(rand()*4)).each {|x|
- funding_line = FundingLine.create(:funder => funder, :amount => x*100000, :interest_rate => 6+rand()*8, :disbursal_date => Date.today, :first_payment_date => Date.today+7, :last_payment_date => Date.today+365*5)
- funding_line.save unless funding_line.valid?
- }
- }
-
- fees = FasterCSV.parse(File.read("db/fees.csv")).flatten
- (0...fees.length/5).each {|i|
- fee = Fee.first(:name => fees[5*i], :percentage => fees[5*i+1].to_f) || Fee.create(:name => fees[5*i], :percentage => fees[5*i+1].to_f, :amount => fees[5*i+2].to_i, :min_amount => fees[5*i+3].to_i, :max_amount => fees[5*i+4].to_i, :payable_on => :loan_applied_on)
- fee.save unless fee.valid?
- }
-
- cts = FasterCSV.parse(File.read("db/client_types.csv")).flatten
- cts.each{|type|
- client_type = ClientType.first(:type => type) || ClientType.create(:type => type)
- client_type.save unless client_type.valid?
- }
-
- lps = FasterCSV.parse(File.read("db/loan_products.csv")).flatten
- (0...lps.length/10).each {|i|
- if(Date.parse(lps[10*i+9])>Date.today)
- loan_product = LoanProduct.first(:name => lps[10*i]) || LoanProduct.create(:name => lps[10*i], :max_amount => lps[10*i+1].to_i, :min_amount => lps[10*i+2].to_i, :max_interest_rate => lps[10*i+3].to_f, :min_interest_rate => lps[10*i+4].to_f,
- :installment_frequency => :weekly, :max_number_of_installments => lps[10*i+5].to_i, :min_number_of_installments => lps[10*i+6].to_i,
- :loan_type => "DefaultLoan", :valid_from => Date.parse(lps[10*i+8]), :valid_upto => Date.parse(lps[10*i+9]))
- loan_product.errors {|e| puts e}
- loan_product.save! unless loan_product.valid?
- end
- }
-
- occs = FasterCSV.parse(File.read("db/occupations.csv")).flatten
- occs.each {|occ|
- occupation = Occupation.first(:name => occ) || Occupation.create(:name => occ)
- occupation.save unless occupation.valid?
- }
-
- icompanies = FasterCSV.parse(File.read("db/insurance_companies.csv")).flatten
- icompanies.each {|company|
- insurance_company = InsuranceCompany.first(:name => company) || InsuranceCompany.create(:name => company)
- insurance_company.save unless insurance_company.valid?
- }
-
- iproducts = FasterCSV.parse(File.read("db/insurance_products.csv")).flatten
- (0...iproducts.length/2).each{|i|
- insurance_product = InsuranceProduct.first(:name => iproducts[2*i]) || InsuranceProduct.create(:name => iproducts[2*i], :insurance_company => InsuranceCompany.first(:name => "#{iproducts[2*i+1]}"))
- insurance_product.save unless insurance_product.valid?
- }
-
- if Region.all.empty?
- region_count, branch_count, center_count, ccount, n_center = 0, -1, 0, 0, 0
- else
- region_count = Region.count # total number of regions
- branch_count = Area.last.branches.count-1 # total number of branches in the last area - 1
- center_count = Branch.last.centers.count # total number of centers in the last branch
- center_manager = Branch.last.centers.last.manager
- ccount = Region.last.areas.last.branches.count + Region.last.areas.last.branches.centers.count
- raw_data = FasterCSV.parse(File.read("db/in_lat_long#{regions[regions.index(Region.last.name)-1]}.csv")).flatten
- n_center = raw_data.length/3
- data = []
- (0...raw_data.length/3).each {|i|
- point = Point.new(raw_data[3*i], raw_data[3*i+1].to_f, raw_data[3*i+2].to_f)
- data.push(point)
- }
- clusters = kmeans(data, n_center/25 + 1, 10.0)
- clusters.each{|cluster| cluster.centerize}
- end
-
- c_date = Date.today
- c_time = Time.now
- count = 0
- DAYS = [:monday, :tuesday, :wednesday, :thursday, :friday]
- CASTES = ['sc', 'st', 'obc', 'general']
- RELIGIONS = ['hindu', 'muslim', 'sikh', 'jain', 'buddhist', 'christian']
-
- while true
- region = Region.last if !Region.nil?
- area = Area.last if !Area.nil?
- if ccount >=n_center
- ccount = 0
- raw_data = FasterCSV.parse(File.read("db/in_lat_long#{regions[4*region_count]}.csv")).flatten
- n_center = raw_data.length/3
- data = []
- (0...raw_data.length/3).each {|i|
- point = Point.new(raw_data[3*i], raw_data[3*i+1].to_f, raw_data[3*i+2].to_f)
- data.push(point)
- }
- clusters = kmeans(data, n_center/25 + 1, 10.0)
- clusters.each{|cluster| cluster.centerize}
-
- regional_manager = StaffMember.create(:name => names[(rand()*len).to_i], :active => true, :creation_date => c_date)
- region = Region.create(:manager => regional_manager, :name => regions[region_count*4+1], :creation_date => c_date)
- region.save
-
- region_location = Location.create(:parent_id => region.id, :parent_type => "region", :latitude => regions[region_count*4+2].to_f, :longitude => regions[region_count*4+3].to_f)
- region_location.save
-
- area_manager = StaffMember.create(:name => names[(rand()*len).to_i], :active => true, :creation_date => c_date)
- area = Area.create(:name => areas[region_count*3], :region => region, :manager => area_manager, :creation_date => c_date)
- area.save
-
- area_location = Location.create(:parent_id => area.id, :parent_type => "area", :latitude => areas[region_count*3+1].to_f, :longitude => areas[region_count*3+2].to_f)
- area_location.save
-
- region_count += 1
- branch_count = -1
- end
-
- if branch_count==-1 or Branch.last.centers.length>=clusters[branch_count].points.length
- branch_count += 1
- center_count = 0
- branch_manager = StaffMember.create(:name => names[(rand()*len).to_i], :active => true, :creation_date => c_date)
- branch = Branch.create(:name => clusters[branch_count].center.name, :code => "R#{region.id}A#{area.id}B#{branch_count}", :area => area,
- :manager => branch_manager, :creation_date => c_date)
- branch.save
- ccount += 1
-
- branch_location = Location.create(:parent_id => branch.id, :parent_type => "branch", :latitude => clusters[branch_count].center.lat, :longitude => clusters[branch_count].center.long)
- branch_location.save
-
- if center_count%20==0
- center_manager = StaffMember.create(:name => names[(rand()*len).to_i], :active => true, :creation_date => c_date)
- end
- center = Center.create(:branch => branch, :manager => center_manager, :name => clusters[branch_count].points[center_count].name, :code => branch.code+"C#{center_count}",
- :meeting_day => DAYS[center_count%5], :meeting_time_hours => "#{7+center_count%5}", :meeting_time_minutes => 0,
- :creation_date => c_date)
- center.save!
-
- center_location = Location.create(:parent_id => center.id, :parent_type => "center", :latitude => clusters[branch_count].points[center_count].lat, :longitude => clusters[branch_count].points[center_count].long)
- center_location.save
-
- center_count = 1
- ccount = ccount + 1
-
- client_grp = ClientGroup.create(:name => "Group#{counter}", :code => "G#{counter}", :center => center)
- client_grp.save!
-
- joining_date = center.creation_date + rand()*30
- 5.times{|x|
- client = Client.create(:name => names[counter%len], :reference => "#{branch.code}#{center.code}#{client_grp.code}#{x}", :center => center, :created_by => user,
- :created_by_staff => center.manager, :date_joined => joining_date, :client_type => ClientType.all[(rand()*(ClientType.count)).to_i],
- :client_group => client_grp, :date_of_birth => Date.parse(dobs[counter%dob_len]),
- :caste => CASTES[(rand()*CASTES.length).to_i], :religion => RELIGIONS[(rand()*RELIGIONS.length).to_i])
- client.save
-
- counter = counter + 1
- date = client.date_joined + (rand()*10).to_i
- loan_pro = LoanProduct.all[(rand()*LoanProduct.count).to_i]
- amt = loan_pro.min_amount + (rand()*((loan_pro.max_amount-loan_pro.min_amount)/1000)).to_i*1000
- int_rate = (loan_pro.min_interest_rate + rand()*(loan_pro.max_interest_rate-loan_pro.min_interest_rate))/100
- ninstallments = loan_pro.min_number_of_installments + (rand()*((loan_pro.max_number_of_installments-loan_pro.min_number_of_installments))).to_i
- loan = DefaultLoan.create(:amount => amt, :amount_applied_for => amt, :amount_sanctioned => amt, :interest_rate => int_rate, :discriminator => DefaultLoan,
- :installment_frequency => :weekly, :funding_line => FundingLine.all[(rand()*(FundingLine.count)).to_i], :loan_product => loan_pro,
- :number_of_installments => ninstallments, :scheduled_disbursal_date => date+7, :scheduled_first_payment_date => date+14,
- :applied_on => date, :approved_on => date+3, :disbursal_date => date+7, :applied_by => center.manager, :created_by => user,
- :approved_by => center.branch.manager, :disbursed_by => center.manager, :client => client, :occupation => Occupation.all[(rand()*Occupation.count).to_i])
- loan.save unless loan.valid?
- }
- else
- branch = Branch.last
- if branch.centers.last.creation_date+14 <= c_date
- if center_count%20==0
- center_manager = StaffMember.create(:name => "R#{region.id}A#{area.id}B#{branch.id} Cen#{center_count} Manager", :active => true, :creation_date => c_date)
- center_manager.save!
- end
- center = Center.create(:branch => branch, :manager => center_manager, :name => clusters[branch_count].points[center_count].name, :code => branch.code+"C#{center_count}",
- :meeting_day => DAYS[center_count%5], :meeting_time_hours => "#{7+center_count%5}", :meeting_time_minutes => 0,
- :creation_date => c_date)
- center.save
-
- center_location = Location.create(:parent_id => center.id, :parent_type => "center", :latitude => clusters[branch_count].points[center_count].lat, :longitude => clusters[branch_count].points[center_count].long)
- center_location.save
- center_count = center_count+1
- ccount = count + 1
- center.save!
- end
-
- Branch.last.centers(:creation_date.gt => c_date-49).each {|center|
- if (c_date-center.creation_date).to_i%7==0
- client_grp = ClientGroup.create(:name => "Group#{counter}", :code => counter, :center => center)
- client_grp.save
-
- joining_date = center.creation_date + rand()*30
- 5.times{|x|
- client = Client.create(:name => names[counter%len], :reference => "#{branch.code}#{center.code}#{client_grp.code}#{x}", :center => center,
- :created_by => user, :created_by_staff => center.manager, :date_joined => joining_date,
- :client_type => ClientType.all[(rand()*(ClientType.count-1)).to_i], :client_group => client_grp, :date_of_birth => Date.parse(dobs[counter%dob_len]),
- :caste => CASTES[(rand()*CASTES.length).to_i], :religion => RELIGIONS[(rand()*RELIGIONS.length).to_i])
- client.save
- counter = counter + 1
- date = client.date_joined + (rand()*10).to_i
- loan_pro = LoanProduct.all[(rand()*LoanProduct.count).to_i]
- amt = loan_pro.min_amount + (rand()*((loan_pro.max_amount-loan_pro.min_amount)/1000)).to_i*1000
- int_rate = (loan_pro.min_interest_rate + rand()*(loan_pro.max_interest_rate-loan_pro.min_interest_rate))/100
- ninstallments = loan_pro.min_number_of_installments + (rand()*((loan_pro.max_number_of_installments-loan_pro.min_number_of_installments))).to_i
- loan = DefaultLoan.create(:amount => amt, :amount_applied_for => amt, :amount_sanctioned => amt, :interest_rate => int_rate, :discriminator => DefaultLoan,
- :installment_frequency => :weekly, :funding_line => FundingLine.all[(rand()*(FundingLine.count)).to_i], :loan_product => loan_pro,
- :number_of_installments => ninstallments, :scheduled_disbursal_date => date+7, :scheduled_first_payment_date => date+14,
- :applied_on => date, :approved_on => date+3, :disbursal_date => date+7, :applied_by => center.manager, :created_by => user,
- :approved_by => center.branch.manager, :disbursed_by => center.manager, :client => client, :occupation => Occupation.all[(rand()*Occupation.count).to_i])
- loan.save unless loan.valid?
- }
- center.save
- branch.save
- end
- }
- end
-
- LoanHistory.all(:date => c_date, :status => :outstanding, :principal_due.gt => 0).each {|loan_his|
- loan = loan_his.loan
- loan.payment_schedule.find_all{|pay| pay[0]==c_date}.each{|pay|
- loan.repay(pay[1][:principal]+pay[1][:interest], User.first, c_date, loan.client.client_group.center.manager, false, NORMAL_REPAYMENT_STYLE, :default)
- }
- }
-
- count = count+1
- c_time = c_time + 86400
- c_date = Date.new(c_time.year, c_time.month, c_time.day)
- Merb.logger.info "Current date -> #{c_date}\nNumber of regions -> #{Region.count}\nNumber of areas -> #{Area.count}\nNumber of branches -> #{Branch.count}\nNumber of centers -> #{Center.count}\nNumber of ClientGruops -> #{ClientGroup.count}\nNumber of Clients -> #{Client.count}\nNumber of loans -> #{Loan.count}\nNumber of payments made -> #{Payment.count}\nIteration count -> #{count}"
- Merb.logger.info "========================================================================================================================================================="
- sleep(86400)
- end
- end
-end
-
View
7 spec/models/fee_spec.rb
@@ -110,7 +110,7 @@
@f.fees_for(@loan).should == 1
end
-
+## start of loan fee spec
it "should return correct fee_schedule for loan" do
@f.percentage = 0.1
@loan_product.fees = [@f]
@@ -314,7 +314,9 @@
@loan.disbursed_by = nil
@loan.save
end
+ ### end of loan fee spec
+### start of client fee spec
it "should give correct fee schedule for client" do
@client_fee = Fee.new(:name => "client fee", :amount => 20, :payable_on => :client_date_joined)
@@ -409,4 +411,7 @@
@client.levy_fees
@client.fees_payable_on.should == {@fee1 => 20 - 5, @fee2 => 10}
end
+
+
+### client fees
end
View
1 spec/models/loan_spec.rb
@@ -781,6 +781,7 @@ class TestLoan < Loan; end
end
it "should repay properly" do
+ # this test is failing.
@loan = Loan.new(:amount => 1000, :interest_rate => 0.2, :installment_frequency => :weekly, :number_of_installments => 25,
:scheduled_first_payment_date => "2000-12-06",
:applied_on => "2000-02-01", :scheduled_disbursal_date => "2000-06-14",
View
1 spec/spec.opts
@@ -5,3 +5,4 @@
--format html:spec/spec_report.html
--loadby mtime
--reverse
+--debugger
View
1 spec/spec_failing_examples.txt
@@ -1 +0,0 @@
-Fee should repay correctly

No commit comments for this range

Something went wrong with that request. Please try again.