@@ -1289,7 +1289,7 @@ def calculate_history
1289
1289
}
1290
1290
# {:date_field => [:status, :loan_property]}
1291
1291
{ :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 |
1293
1293
if date == self . send ( dt )
1294
1294
current_row [ action [ 0 ] ] = action [ 1 ] == :last_balance ? last_row [ :actual_outstanding_principal ] : self . send ( action [ 1 ] )
1295
1295
current_row [ "#{ action [ 0 ] . to_s } _count" . to_sym ] = 1
@@ -1299,6 +1299,9 @@ def calculate_history
1299
1299
end
1300
1300
end
1301
1301
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
+
1302
1305
@history_array << current_row
1303
1306
last_status = current_row [ :status ]
1304
1307
last_row = current_row
@@ -1313,34 +1316,15 @@ def calculate_history
1313
1316
@history_array
1314
1317
end
1315
1318
1316
- def _show_his ( arg = { } )
1319
+ def _show_his ( report_format_id = 1 , width = 8 , padding = 2 )
1317
1320
# pretty prints the loan history
1318
1321
# 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 ( "|" )
1342
1327
end
1343
- puts "Call with _show_his(:extended) to see more fields" if fields == [ :basic ]
1344
1328
false
1345
1329
end
1346
1330
0 commit comments