<commit_before>class TransactionHistoryController < ApplicationController
  #layout 'application'
  #layout 'two_column', :except => [:my_history, :account_history]
  admin_tab     :all
  customer_tab :my_history, :account_history
  
  include DateHelper
  before_filter :authenticate_user!
  before_filter :check_acting_as
  
  before_filter :remove_ugly_params
   
  def my_history
    @accounts = session_user.accounts
    @facilities = Facility.active
    
    @search_fields = params.merge({
      :accounts => get_allowed_accounts(@accounts, params[:accounts])
    })
    do_search(@search_fields)
    add_optimizations
    @order_details = @order_details.paginate(:page => params[:page])
  end
  
  def account_history
    @account = Account.find(params[:account_id])
    @accounts = [@account]
    @facilities = @account.facilities
    
    @search_fields = params.merge({
      :accounts => [@account]
    })
    do_search(@search_fields)
    add_optimizations
    @order_details = @order_details.paginate(:page => params[:page])
    
  end
  
  def facility_history
    find_with_facility
    @order_details = @order_details.paginate(:page => params[:page])
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
    
  def in_review
    find_with_facility
    @order_details = @order_details.in_review(@facility)
    @order_details = @order_details.reorder(:reviewed_at)
    @order_detail_action = :mark_as_reviewed
    #@warning_method = Proc.new { |helper, order_detail| helper.needs_reconcile_warning?(order_detail) }
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  def mark_as_reviewed
    #TODO mark as reviewed
    flash[:notice] = "Marking as reviewed not yet implemented"
    redirect_to :action => :in_review
  end
  
  def notifications
    find_with_facility
    @order_details = @order_details.need_notification(@facility)
    @order_detail_action = :send_notifications
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  def send_notifications
    #TODO send notifications
    flash[:notice] = "Sending notifications not yet implemented"
    redirect_to :action => :notifications
  end
  
  def statements
    find_with_facility
    @accounts = @accounts.where("type in (?)", ['CreditCardAccount', 'PurchaseOrderAccount'])
    @order_details = @order_details.need_statement(@facility)
    @order_detail_action = :send_statements
    #@warning_method = Proc.new { |helper, order_detail| helper.needs_reconcile_warning?(order_detail) }
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  
  def send_statements
    #TODO send statements
    flash[:notice] = "Sending statements not yet implemented"
    redirect_to :action => "statements"
  end
  
  def journals
    find_with_facility
    @accounts = @accounts.where("type in (?)", ['NufsAccount'])
    @order_details = @order_details.need_journal(@facility)
    @order_detail_action = 'create_journal'
    #@warning_method = Proc.new { |helper, order_detail| helper.needs_reconcile_warning?(order_detail) }
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  
  def create_journal
    #TODO create journal
    flash[:notice] = "Creating journals not yet implemented"
    redirect_to :action => "journals"
  end
  
  def find_with_facility
    @current_facility = @facility = Facility.find_by_url_name(params[:facility_id])
    raise ActiveRecord::RecordNotFound unless @facility
    @facilities = [@facility]
    @accounts = Account.for_facility(@facility)
    
    @search_fields = params.merge({<commit_msg>only select certain fields in the account find because it saves time<commit_after>class TransactionHistoryController < ApplicationController
  #layout 'application'
  #layout 'two_column', :except => [:my_history, :account_history]
  admin_tab     :all
  customer_tab :my_history, :account_history
  
  include DateHelper
  before_filter :authenticate_user!
  before_filter :check_acting_as
  
  before_filter :remove_ugly_params
   
  def my_history
    @accounts = session_user.accounts
    @facilities = Facility.active
    
    @search_fields = params.merge({
      :accounts => get_allowed_accounts(@accounts, params[:accounts])
    })
    do_search(@search_fields)
    add_optimizations
    @order_details = @order_details.paginate(:page => params[:page])
  end
  
  def account_history
    @account = Account.find(params[:account_id])
    @accounts = [@account]
    @facilities = @account.facilities
    
    @search_fields = params.merge({
      :accounts => [@account]
    })
    do_search(@search_fields)
    add_optimizations
    @order_details = @order_details.paginate(:page => params[:page])
    
  end
  
  def facility_history
    find_with_facility
    @order_details = @order_details.paginate(:page => params[:page])
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
    
  def in_review
    find_with_facility
    @order_details = @order_details.in_review(@facility)
    @order_details = @order_details.reorder(:reviewed_at)
    @order_detail_action = :mark_as_reviewed
    #@warning_method = Proc.new { |helper, order_detail| helper.needs_reconcile_warning?(order_detail) }
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  def mark_as_reviewed
    #TODO mark as reviewed
    flash[:notice] = "Marking as reviewed not yet implemented"
    redirect_to :action => :in_review
  end
  
  def notifications
    find_with_facility
    @order_details = @order_details.need_notification(@facility)
    @order_detail_action = :send_notifications
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  def send_notifications
    #TODO send notifications
    flash[:notice] = "Sending notifications not yet implemented"
    redirect_to :action => :notifications
  end
  
  def statements
    find_with_facility
    @accounts = @accounts.where("type in (?)", ['CreditCardAccount', 'PurchaseOrderAccount'])
    @order_details = @order_details.need_statement(@facility)
    @order_detail_action = :send_statements
    #@warning_method = Proc.new { |helper, order_detail| helper.needs_reconcile_warning?(order_detail) }
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  
  def send_statements
    #TODO send statements
    flash[:notice] = "Sending statements not yet implemented"
    redirect_to :action => "statements"
  end
  
  def journals
    find_with_facility
    @accounts = @accounts.where("type in (?)", ['NufsAccount'])
    @order_details = @order_details.need_journal(@facility)
    @order_detail_action = 'create_journal'
    #@warning_method = Proc.new { |helper, order_detail| helper.needs_reconcile_warning?(order_detail) }
    @active_tab = 'admin_transactions'
    render :layout => 'two_column'
  end
  
  def create_journal
    #TODO create journal
    flash[:notice] = "Creating journals not yet implemented"
    redirect_to :action => "journals"
  end
  
  def find_with_facility
    @current_facility = @facility = Facility.find_by_url_name(params[:facility_id])
    raise ActiveRecord::RecordNotFound unless @facility
    @facilities = [@facility]
    # only select a few fields. This speeds up the load when there get to be a lot of accounts
    @accounts = Account.for_facility(@facility).select("id, description, account_number, type")
    
    @search_fields = params.merge({
{'fraction_non_alphanumeric': 0.0989010989010989, 'fraction_numerical': 0.0, 'mean_word_length': 4.193458594293667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1783424', 'n_tokens_mistral': 2357, 'n_tokens_neox': 2308, 'n_words': 482}