<commit_before>class FacturasDatatable
  delegate :params,:link_to, :h, to: :@view

  def initialize(view, place)
    @view = view
    @place = place
  end

  def as_json(options = {})
    {
      sEcho: params[:sEcho].to_i,
      iTotalRecords: facturas.count,
      iTotalDisplayRecords: facturas.total_entries,
      aaData: data
    }
  end

  private

  def data
    case @place
    when "venta"
    facturas.map do |factura|
      [
        (factura.cliente.nombre),
        (factura.numero),
        (factura.tipo),
        (factura.total),
        (factura.user.username),
        (link_to '', factura, :remote => true,  :rel => 'tooltip', 'data-toggle' =>  "modal", 'data-target' => '#myModal', :title => 'Modificar', class: "ttip fa fa-eye btn btn-info") + " " + 
        (link_to '', @view.anular_factura_path(factura), method: :post, data: { confirm: 'Esta seguro?' }, :rel => "tooltip", :title => 'Anular', class: "ttip fa fa-thumbs-down btn btn-danger")
        # (link_to 'Create PDF',factura, :format => :pdf)
      ]
    end
    when "anulada"
    facturas.map do |factura|
      [
        (factura.cliente.nombre),
        (factura.numero),
        (factura.tipo),
        (factura.total),
        (factura.user.username),
        (link_to '', factura, :remote => true, :rel => 'tooltip','data-toggle' =>  "modal", 'data-target' => '#myModal', :title => 'Mostrar', class: "ttip fa fa-eye btn btn-info")
      ]
    end 
    when "compra"
    facturas.map do |factura|
      [
        (factura.proveedor.nombre_o_razon_social),
        (factura.numero),
        (factura.total),
        (factura.user.username),
        (link_to '', factura, :remote => true, :rel =>'tooltip', 'data-toggle' =>  "modal", 'data-target' => '#myModal', :title => 'Mostar', class: "ttip fa fa-eye btn btn-info")
        # (link_to 'delete', factura, method: :delete, class: "cancel_button")
      ]
    end
    end
  end

  def facturas
    @facturas ||= fetch_facturas
  end

  def fetch_facturas
    case @place
    when "compra"  
      facturas = Factura.where(:tipo => "compra").order("#{sort_column} #{sort_direction}")
    when "anulada"
      facturas = Factura.where(:anulada => true).order("#{sort_column} #{sort_direction}")
    when "venta"
      facturas = Factura.where("tipo != 'compra' and anulada = false").order("#{sort_column} #{sort_direction}")
    end
    facturas = facturas.page(page).per_page(per_page)
    if params[:sSearch].present?
      facturas = facturas.where("tipo like :search or numero like :search", search: "%#{params[:sSearch]}%")
    end
    facturas
  end

  def page
    params[:iDisplayStart].to_i/per_page + 1
  end

  def per_page
    params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
  end

  def sort_column
    columns = %w[cliente_id numero tipo user_id total]
    columns[params[:iSortCol_0].to_i]
  end

  def sort_direction
    params[:sSortDir_0] == "desc" ? "desc" : "asc"
  end
end<commit_msg>cambiar el mostrar por modificar<commit_after>class FacturasDatatable
  delegate :params,:link_to, :h, to: :@view

  def initialize(view, place)
    @view = view
    @place = place
  end

  def as_json(options = {})
    {
      sEcho: params[:sEcho].to_i,
      iTotalRecords: facturas.count,
      iTotalDisplayRecords: facturas.total_entries,
      aaData: data
    }
  end

  private

  def data
    case @place
    when "venta"
    facturas.map do |factura|
      [
        (factura.cliente.nombre),
        (factura.numero),
        (factura.tipo),
        (factura.total),
        (factura.user.username),
        (link_to '', factura, :remote => true,  :rel => 'tooltip', 'data-toggle' =>  "modal", 'data-target' => '#myModal', :title => 'Mostrar', class: "ttip fa fa-eye btn btn-info") + " " + 
        (link_to '', @view.anular_factura_path(factura), method: :post, data: { confirm: 'Esta seguro?' }, :rel => "tooltip", :title => 'Anular', class: "ttip fa fa-thumbs-down btn btn-danger")
        # (link_to 'Create PDF',factura, :format => :pdf)
      ]
    end
    when "anulada"
    facturas.map do |factura|
      [
        (factura.cliente.nombre),
        (factura.numero),
        (factura.tipo),
        (factura.total),
        (factura.user.username),
        (link_to '', factura, :remote => true, :rel => 'tooltip','data-toggle' =>  "modal", 'data-target' => '#myModal', :title => 'Mostrar', class: "ttip fa fa-eye btn btn-info")
      ]
    end 
    when "compra"
    facturas.map do |factura|
      [
        (factura.proveedor.nombre_o_razon_social),
        (factura.numero),
        (factura.total),
        (factura.user.username),
        (link_to '', factura, :remote => true, :rel =>'tooltip', 'data-toggle' =>  "modal", 'data-target' => '#myModal', :title => 'Mostar', class: "ttip fa fa-eye btn btn-info")
        # (link_to 'delete', factura, method: :delete, class: "cancel_button")
      ]
    end
    end
  end

  def facturas
    @facturas ||= fetch_facturas
  end

  def fetch_facturas
    case @place
    when "compra"  
      facturas = Factura.where(:tipo => "compra").order("#{sort_column} #{sort_direction}")
    when "anulada"
      facturas = Factura.where(:anulada => true).order("#{sort_column} #{sort_direction}")
    when "venta"
      facturas = Factura.where("tipo != 'compra' and anulada = false").order("#{sort_column} #{sort_direction}")
    end
    facturas = facturas.page(page).per_page(per_page)
    if params[:sSearch].present?
      facturas = facturas.where("tipo like :search or numero like :search", search: "%#{params[:sSearch]}%")
    end
    facturas
  end

  def page
    params[:iDisplayStart].to_i/per_page + 1
  end

  def per_page
    params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
  end

  def sort_column
    columns = %w[cliente_id numero tipo user_id total]
    columns[params[:iSortCol_0].to_i]
  end

  def sort_direction
    params[:sSortDir_0] == "desc" ? "desc" : "asc"
  end
end
{'fraction_non_alphanumeric': 0.15648662291771834, 'fraction_numerical': 0.0020191822311963654, 'mean_word_length': 2.882429784454605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '3612171', 'n_tokens_mistral': 2111, 'n_tokens_neox': 2072, 'n_words': 455}