Permalink
Browse files

preclosure row in loan history now captures only the preclosed amount

get_bulk_insert_sql now in alphabetical order of column names for better readability
  • Loading branch information...
Siddharth Sharma
Siddharth Sharma committed Dec 14, 2011
1 parent d8c1336 commit 206b5df413fe8fff275718c78777a8e6d25e4ba6
Showing with 27 additions and 27 deletions.
  1. +10 −26 app/models/loan.rb
  2. +16 −0 bin/rslurp
  3. +1 −1 lib/functions.rb
View
@@ -1289,7 +1289,7 @@ def calculate_history
}
# {:date_field => [:status, :loan_property]}
{:applied_on => [:applied, :amt_applied_for], :approved_on => [:approved, :amt_sanctioned], :rejected_on => [:rejected, :amount],
- :disbursal_date => [:disbursed, :amount], :written_off_on => [:written_off, :last_balance], :preclosed_on => [:preclosed, :last_balance]}.each do |dt, action|
+ :disbursal_date => [:disbursed, :amount], :written_off_on => [:written_off, :last_balance]}.each do |dt, action|
if date == self.send(dt)
current_row[action[0]] = action[1] == :last_balance ? last_row[:actual_outstanding_principal] : self.send(action[1])
current_row["#{action[0].to_s}_count".to_sym] = 1
@@ -1299,6 +1299,9 @@ def calculate_history
end
end
+ current_row[:preclosed] = (date == self.preclosed_on) ? current_row[:advance_principal_paid_today] : 0
+ current_row[:preclosed_count] = (date == self.preclosed_on) ? 1 : 0
+
@history_array << current_row
last_status = current_row[:status]
last_row = current_row
@@ -1313,34 +1316,15 @@ def calculate_history
@history_array
end
- def _show_his(arg = {})
+ def _show_his(report_format_id = 1, width = 8, padding = 2)
# pretty prints the loan history
# get extended info by saying _show_his(:extended)
- arg = {:fields => [:basic, :next]} if arg == :extended
- args = {:width => 10, :padding => 4, :fields => [:basic]}
- args = args.merge(arg) if arg.is_a? Hash
- width = args[:width]; padding = args[:padding]; fields = args[:fields]
-
- print_order = {:basic => {:titles => {:date => :date, :s_total => :scheduled_outstanding_total, :s_bal => :scheduled_outstanding_principal,
- :a_total => :actual_outstanding_total, :a_bal => :actual_outstanding_principal,
- :p_paid => :principal_paid, :p_due => :principal_due, :i_paid => :interest_paid, :i_due => :interest_due,
- :tot_p_pd => :total_principal_paid, :tot_i_pd => :total_interest_paid, :tot_p_due => :total_principal_due, :tot_i_due => :total_interest_due},
- :title_order => [:date, :s_total, :s_bal, :a_total, :a_bal, :p_paid, :p_due, :i_paid, :i_due, :tot_p_pd, :tot_p_due, :tot_i_pd, :tot_i_due]},
- :next => {:titles => {:date => :date, :tp_due => :total_principal_due, :tp_paid => :total_principal_paid, :ti_due => :total_interest_due,
- :ti_paid => :total_interest_paid, :adv_p => :advance_principal_paid, :adv_i => :advance_interest_paid, :def_p => :principal_in_default,
- :def_i => :interest_in_default, :b => :branch_id, :c => :center_id, :k => :composite_key},
- :title_order => [:date, :tp_due, :tp_paid, :ti_due, :ti_paid, :adv_p, :adv_i, :def_p, :def_i, :b, :c, :k]}}
- fields.each do |f|
- hist = calculate_history.sort_by{|x| x[:date]}
- title_order = print_order[f][:title_order]
- titles = print_order[f][:titles]
- puts title_order.map{|t| t.to_s.rjust(width - padding/2).ljust(width)}.join("|")
- hist.each do |h|
- puts (["#{h[:date]}"] + title_order[1..-1].map{|t| (h[titles[t]] || 0).round(2)}.map{|v| v.to_s}.map{|s| s.rjust(width - padding/2).ljust(width)}).join("|")
- end
-
+ hist = calculate_history.sort_by{|x| x[:date]}
+ keys = ReportFormat.get(report_format_id).keys
+ puts keys.map{|t| t.to_s.rjust(width - padding/2).ljust(width)}.join("|")
+ hist.each do |h|
+ puts (["#{h[:date]}"] + keys.map{|t| (h[t.to_sym] || 0).round(2)}.map{|v| v.to_s}.map{|s| s.rjust(width - padding/2).ljust(width)}).join("|")
end
- puts "Call with _show_his(:extended) to see more fields" if fields == [:basic]
false
end
View
@@ -0,0 +1,16 @@
+#! /usr/bin/env ruby
+require 'rubygems'
+require 'yaml'
+config = YAML.load_file(File.join('config', 'remote.yml')) rescue {}
+this_dir = `pwd`.split("/")[-1].chomp
+remote_directory = config['remote_directory'] || this_dir
+iname = config['remote_host'] || "#{this_dir}.mostfit.in"
+uname = config['remote_username'] || "mostfit"
+what = ARGV[0]
+# if there is a date, get the corresponding db dump, else dump one now
+date = Date.parse(ARGV[0]) rescue nil
+debugger
+unless date
+ status = `ssh -t #{uname}@#{iname} 'cd ~/mostfit_installations/#{iname};bin/dump.rb'`
+ puts status
+end
View
@@ -340,7 +340,7 @@ def url(params)
# Wow. It this supposed to be classless?
def get_bulk_insert_sql(table_name, data)
t = Time.now
- keys = data.first.keys
+ keys = data.first.keys.sort_by{|k| k.to_s}
sql = "INSERT INTO #{table_name}(#{keys.join(',')} )
VALUES "
values = []

0 comments on commit 206b5df

Please sign in to comment.