<commit_before>class ClosedLoanReport < Report
  attr_accessor :from_date,:to_date, :branch, :branch_id

  def initialize(params, dates, user)
    @from_date = (dates and dates[:from_date]) ? dates[:from_date] : Date.today - 7
    @to_date   = (dates and dates[:to_date]) ? dates[:to_date] : Date.today
    @name   = "Report for #{@from_date} to #{@to_date}"
    get_parameters(params, user)
  end
  
  def name
    "Loan Closed Report for #{@from_date} to #{@to_date}"
  end

  def self.name
    "Loan Closed Report"
  end
  
  def generate
    data = {}
    @branch.each{|branch|
      data[branch] ||= {}
    }

    LoanHistory.all(:branch => @branch, :status => [:repaid, :written_off], :date.gte => @from_date, :date.lte => @to_date).each{|lh|
      status = if lh.status == :repaid and lh.amount_in_default < 0
                 'Foreclosure'
               elsif lh.status == :repaid
                 'Repaid'
               elsif lh.status == :written_off
                 'Written off'
               else
                 status = lh.status.to_s
               end
      data[lh.branch][lh.center] ||= []
      data[lh.branch][lh.center].push([lh.loan_id, lh.client_group.name, lh.client.name, lh.loan.amount, status])
    }    

    # claim settlement
    client_ids = Claim.all(:claim_submission_date.gte => @from_date, :claim_submission_date.lte => @to_date, :order => [:id]).aggregate(:client_id)
    
    Loan.all(:client_id => client_ids, "client.center.branch_id" => @branch.map{|b| b.id}).each{|loan|
      center = loan.client.center
      branch = center.branch
      data[branch][center] ||= []
      data[branch][center].push([loan.id, loan.client.client_group.name, loan.client.name, loan.amount, loan.client.inactive_reason.camelcase(' ')])<commit_msg>fixed Bug #607 No method error in Loan closed report<commit_after>class ClosedLoanReport < Report
  attr_accessor :from_date,:to_date, :branch, :branch_id

  def initialize(params, dates, user)
    @from_date = (dates and dates[:from_date]) ? dates[:from_date] : Date.today - 7
    @to_date   = (dates and dates[:to_date]) ? dates[:to_date] : Date.today
    @name   = "Report for #{@from_date} to #{@to_date}"
    get_parameters(params, user)
  end
  
  def name
    "Loan Closed Report for #{@from_date} to #{@to_date}"
  end

  def self.name
    "Loan Closed Report"
  end
  
  def generate
    data = {}
    @branch.each{|branch|
      data[branch] ||= {}
    }

    LoanHistory.all(:branch => @branch, :status => [:repaid, :written_off], :date.gte => @from_date, :date.lte => @to_date).each{|lh|
      status = if lh.status == :repaid and lh.amount_in_default < 0
                 'Foreclosure'
               elsif lh.status == :repaid
                 'Repaid'
               elsif lh.status == :written_off
                 'Written off'
               else
                 status = lh.status.to_s
               end
      data[lh.branch][lh.center] ||= []
      data[lh.branch][lh.center].push([lh.loan_id, lh.client_group != nil ? lh.client_group.name : "no group", lh.client.name, lh.loan.amount, status])

    }    

    # claim settlement
    client_ids = Claim.all(:claim_submission_date.gte => @from_date, :claim_submission_date.lte => @to_date, :order => [:id]).aggregate(:client_id)
    
    Loan.all(:client_id => client_ids, "client.center.branch_id" => @branch.map{|b| b.id}).each{|loan|
      center = loan.client.center
      branch = center.branch
      data[branch][center] ||= []
      data[branch][center].push([loan.id, loan.client.client_group.name, loan.client.name, loan.amount, loan.client.inactive_reason.camelcase(' ')])
{'fraction_non_alphanumeric': 0.14994487320837926, 'fraction_numerical': 0.0019294377067254685, 'mean_word_length': 2.752843846949328, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3856263', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1239, 'n_words': 241}