<commit_before>require 'csv'

class CsvGenerator
  def self.invoices_csv(user)
    CSV.generate do |csv|
      csv << [
        :id,
        :project,
        :date_start,
        :date_end,
        :total_hours,
        :total_bill,
        :num_work_entries,
        :is_sent,
        :is_paid,
        :created_at,
        :updated_at
      ]

      user.invoices.order(:created_at).each do |i|
        csv << [
          i.id,
          i.project.name,
          i.date_start,
          i.date_end,
          i.total_hours,
          i.total_bill.format,
          i.work_entries.count,
          i.is_sent,
          i.is_paid,
          i.created_at,
          i.updated_at
        ]
      end
    end
  end

  def self.work_entries_csv(user)
    CSV.generate do |csv|
      csv << [
        :id,
        :project,
        :date,
        :duration,
        :will_bill,
        :is_billed,
        :invoice_id,
        :invoice_notes,
        :admin_notes,<commit_msg>Invoices download: order most recent at top<commit_after>require 'csv'

class CsvGenerator
  def self.invoices_csv(user)
    CSV.generate do |csv|
      csv << [
        :id,
        :project,
        :date_start,
        :date_end,
        :total_hours,
        :total_bill,
        :num_work_entries,
        :is_sent,
        :is_paid,
        :created_at,
        :updated_at
      ]

      user.invoices.order("created_at DESC").each do |i|
        csv << [
          i.id,
          i.project.name,
          i.date_start,
          i.date_end,
          i.total_hours,
          i.total_bill.format,
          i.work_entries.count,
          i.is_sent,
          i.is_paid,
          i.created_at,
          i.updated_at
        ]
      end
    end
  end

  def self.work_entries_csv(user)
    CSV.generate do |csv|
      csv << [
        :id,
        :project,
        :date,
        :duration,
        :will_bill,
        :is_billed,
        :invoice_id,
        :invoice_notes,
        :admin_notes,
{'fraction_non_alphanumeric': 0.10090817356205853, 'fraction_numerical': 0.0, 'mean_word_length': 1.3439716312056738, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '785785', 'n_tokens_mistral': 700, 'n_tokens_neox': 679, 'n_words': 114}