<commit_before>module C2po
  module FacilityAccountsControllerExtension
    extend ActiveSupport::Concern


    module ClassMethods
      def billing_access_checked_actions
        [:credit_cards, :update_credit_cards, :purchase_orders, :update_purchase_orders, :accounts_receivable, :show_statement]
      end
    end

    def account_class_params
      params[:account] || params[:credit_card_account] || params[:purchase_order_account] || params[:nufs_account]
    end

    def configure_new_account(account)
      case account
        when PurchaseOrderAccount
          account.expires_at = parse_usa_date(account.expires_at).end_of_day
        when CreditCardAccount
          begin
            account.expires_at = Date.civil(account.expiration_year.to_i, account.expiration_month.to_i).end_of_month.end_of_day
          rescue => e
             account.errors.add(:base, e.message)
          end
        else
          super
      end
    end

    # GET /facilities/:facility_id/accounts/credit_cards
    def credit_cards
      @accounts = CreditCardAccount.need_reconciling(current_facility)
      render_account_reconcile
    end

    #POST /facilities/:facility_id/accounts/update_credit_cards
    def update_credit_cards
      update_account(CreditCardAccount, credit_cards_facility_accounts_path)
    end

    # GET /facilities/:facility_id/accounts/purchase_orders
    def purchase_orders
      @accounts = PurchaseOrderAccount.need_reconciling(current_facility)
      render_account_reconcile
    end

    # POST /facilities/:facility_id/accounts/update_purchase_orders
    def update_purchase_orders
      update_account(PurchaseOrderAccount, purchase_orders_facility_accounts_path)
    end

    private

    def set_selected_account_and_order_details
      @selected = get_selected_account(params[:selected_account])
      @unreconciled_details = get_unreconciled_details
    end

    def render_account_reconcile
      set_billing_navigation
      set_selected_account_and_order_details if @accounts.present?
      render 'c2po/reconcile'
    end

    def set_billing_navigation # TODO potential before_filter: only: [:credit_cards, :purchase_orders]
      @subnav = 'billing_nav'
      @active_tab = 'admin_billing'
    end

    def get_selected_account(selected_id)
      if selected_id.present?
        @accounts.find { |account| account.id == selected_id.to_i }
      else
        @accounts.first
      end
    end

    def get_unreconciled_details
      OrderDetail
        .order([:account_id, :statement_id, :order_id, :id])
        .account_unreconciled(current_facility, @selected)
        .paginate(page: params[:page])
    end<commit_msg>Set nav instance variables in a before_filter<commit_after>module C2po
  module FacilityAccountsControllerExtension
    extend ActiveSupport::Concern

    included do
      before_filter :set_billing_navigation, only: [:credit_cards, :purchase_orders]
    end

    module ClassMethods
      def billing_access_checked_actions
        [:credit_cards, :update_credit_cards, :purchase_orders, :update_purchase_orders, :accounts_receivable, :show_statement]
      end
    end

    def account_class_params
      params[:account] || params[:credit_card_account] || params[:purchase_order_account] || params[:nufs_account]
    end

    def configure_new_account(account)
      case account
        when PurchaseOrderAccount
          account.expires_at = parse_usa_date(account.expires_at).end_of_day
        when CreditCardAccount
          begin
            account.expires_at = Date.civil(account.expiration_year.to_i, account.expiration_month.to_i).end_of_month.end_of_day
          rescue => e
             account.errors.add(:base, e.message)
          end
        else
          super
      end
    end

    # GET /facilities/:facility_id/accounts/credit_cards
    def credit_cards
      @accounts = CreditCardAccount.need_reconciling(current_facility)
      render_account_reconcile
    end

    #POST /facilities/:facility_id/accounts/update_credit_cards
    def update_credit_cards
      update_account(CreditCardAccount, credit_cards_facility_accounts_path)
    end

    # GET /facilities/:facility_id/accounts/purchase_orders
    def purchase_orders
      @accounts = PurchaseOrderAccount.need_reconciling(current_facility)
      render_account_reconcile
    end

    # POST /facilities/:facility_id/accounts/update_purchase_orders
    def update_purchase_orders
      update_account(PurchaseOrderAccount, purchase_orders_facility_accounts_path)
    end

    private

    def set_selected_account_and_order_details
      @selected = get_selected_account(params[:selected_account])
      @unreconciled_details = get_unreconciled_details
    end

    def render_account_reconcile
      set_selected_account_and_order_details if @accounts.present?
      render 'c2po/reconcile'
    end

    def set_billing_navigation
      @subnav = 'billing_nav'
      @active_tab = 'admin_billing'
    end

    def get_selected_account(selected_id)
      if selected_id.present?
        @accounts.find { |account| account.id == selected_id.to_i }
      else
        @accounts.first
      end
    end

    def get_unreconciled_details
      OrderDetail
        .order([:account_id, :statement_id, :order_id, :id])
        .account_unreconciled(current_facility, @selected)
        .paginate(page: params[:page])
    end
{'fraction_non_alphanumeric': 0.06550055824339412, 'fraction_numerical': 0.000744324525493115, 'mean_word_length': 3.373474369406021, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3836520', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1623, 'n_words': 270}