Skip to content

Commit 206b5df

Browse files
author
Siddharth Sharma
committedDec 14, 2011
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
1 parent d8c1336 commit 206b5df

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed
 

‎app/models/loan.rb

+10-26
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ def calculate_history
12891289
}
12901290
# {:date_field => [:status, :loan_property]}
12911291
{:applied_on => [:applied, :amt_applied_for], :approved_on => [:approved, :amt_sanctioned], :rejected_on => [:rejected, :amount],
1292-
:disbursal_date => [:disbursed, :amount], :written_off_on => [:written_off, :last_balance], :preclosed_on => [:preclosed, :last_balance]}.each do |dt, action|
1292+
:disbursal_date => [:disbursed, :amount], :written_off_on => [:written_off, :last_balance]}.each do |dt, action|
12931293
if date == self.send(dt)
12941294
current_row[action[0]] = action[1] == :last_balance ? last_row[:actual_outstanding_principal] : self.send(action[1])
12951295
current_row["#{action[0].to_s}_count".to_sym] = 1
@@ -1299,6 +1299,9 @@ def calculate_history
12991299
end
13001300
end
13011301

1302+
current_row[:preclosed] = (date == self.preclosed_on) ? current_row[:advance_principal_paid_today] : 0
1303+
current_row[:preclosed_count] = (date == self.preclosed_on) ? 1 : 0
1304+
13021305
@history_array << current_row
13031306
last_status = current_row[:status]
13041307
last_row = current_row
@@ -1313,34 +1316,15 @@ def calculate_history
13131316
@history_array
13141317
end
13151318

1316-
def _show_his(arg = {})
1319+
def _show_his(report_format_id = 1, width = 8, padding = 2)
13171320
# pretty prints the loan history
13181321
# get extended info by saying _show_his(:extended)
1319-
arg = {:fields => [:basic, :next]} if arg == :extended
1320-
args = {:width => 10, :padding => 4, :fields => [:basic]}
1321-
args = args.merge(arg) if arg.is_a? Hash
1322-
width = args[:width]; padding = args[:padding]; fields = args[:fields]
1323-
1324-
print_order = {:basic => {:titles => {:date => :date, :s_total => :scheduled_outstanding_total, :s_bal => :scheduled_outstanding_principal,
1325-
:a_total => :actual_outstanding_total, :a_bal => :actual_outstanding_principal,
1326-
:p_paid => :principal_paid, :p_due => :principal_due, :i_paid => :interest_paid, :i_due => :interest_due,
1327-
:tot_p_pd => :total_principal_paid, :tot_i_pd => :total_interest_paid, :tot_p_due => :total_principal_due, :tot_i_due => :total_interest_due},
1328-
: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]},
1329-
:next => {:titles => {:date => :date, :tp_due => :total_principal_due, :tp_paid => :total_principal_paid, :ti_due => :total_interest_due,
1330-
:ti_paid => :total_interest_paid, :adv_p => :advance_principal_paid, :adv_i => :advance_interest_paid, :def_p => :principal_in_default,
1331-
:def_i => :interest_in_default, :b => :branch_id, :c => :center_id, :k => :composite_key},
1332-
:title_order => [:date, :tp_due, :tp_paid, :ti_due, :ti_paid, :adv_p, :adv_i, :def_p, :def_i, :b, :c, :k]}}
1333-
fields.each do |f|
1334-
hist = calculate_history.sort_by{|x| x[:date]}
1335-
title_order = print_order[f][:title_order]
1336-
titles = print_order[f][:titles]
1337-
puts title_order.map{|t| t.to_s.rjust(width - padding/2).ljust(width)}.join("|")
1338-
hist.each do |h|
1339-
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("|")
1340-
end
1341-
1322+
hist = calculate_history.sort_by{|x| x[:date]}
1323+
keys = ReportFormat.get(report_format_id).keys
1324+
puts keys.map{|t| t.to_s.rjust(width - padding/2).ljust(width)}.join("|")
1325+
hist.each do |h|
1326+
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("|")
13421327
end
1343-
puts "Call with _show_his(:extended) to see more fields" if fields == [:basic]
13441328
false
13451329
end
13461330

‎bin/rslurp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/env ruby
2+
require 'rubygems'
3+
require 'yaml'
4+
config = YAML.load_file(File.join('config', 'remote.yml')) rescue {}
5+
this_dir = `pwd`.split("/")[-1].chomp
6+
remote_directory = config['remote_directory'] || this_dir
7+
iname = config['remote_host'] || "#{this_dir}.mostfit.in"
8+
uname = config['remote_username'] || "mostfit"
9+
what = ARGV[0]
10+
# if there is a date, get the corresponding db dump, else dump one now
11+
date = Date.parse(ARGV[0]) rescue nil
12+
debugger
13+
unless date
14+
status = `ssh -t #{uname}@#{iname} 'cd ~/mostfit_installations/#{iname};bin/dump.rb'`
15+
puts status
16+
end

‎lib/functions.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def url(params)
340340
# Wow. It this supposed to be classless?
341341
def get_bulk_insert_sql(table_name, data)
342342
t = Time.now
343-
keys = data.first.keys
343+
keys = data.first.keys.sort_by{|k| k.to_s}
344344
sql = "INSERT INTO #{table_name}(#{keys.join(',')} )
345345
VALUES "
346346
values = []

0 commit comments

Comments
 (0)
Please sign in to comment.