<commit_before>class Salary < Invoice
  # String
  def to_s(format = :default)
    "%s (%s / %s - %s)" % [title, company, duration_from ? I18n::localize(duration_from) : '', duration_to ? I18n::localize(duration_to) : '']
  end
  
  # Calculations
  def net_amount
    salary_invoice_booking = bookings.where(:debit_account_id => Account.find_by_code('2050').id).first
    return 0.0 unless salary_invoice_booking

    salary_invoice_booking.amount
  end
  
  # Assignment proxies
  def duration_from=(value)
    write_attribute(:duration_from, value)
    
    value_as_date = self.duration_from
    # Calculate value and due dates
    date = Date.new(value_as_date.year, value_as_date.month, 1).in(1.month).ago(1.day)
    self.value_date ||= date
    self.due_date   ||= date
  end
  
  # Bookings
  # ========
  def self.direct_account
    Account.find_by_code("5000")
  end

  # Build booking
  #
  # We use the value_date of the purchase invoice but our own amount.
  def build_booking(params = {}, template_code = nil)
    # Build and assign booking
    super(params, 'salary:employee:ahv_iv_eo').save
    super(params, 'salary:employer:ahv_iv_eo').save
    super(params, 'salary:employee:alv').save
    super(params, 'salary:employer:alv').save
    super(params, 'salary:employee:nbu').save
    super(params, 'salary:employer:nbu').save
    super(params, 'salary:employer:bu').save
    super(params, 'salary:employer:fak').save
    super(params, 'salary:employer:vkb').save
    
    super(params, 'salary:employee:ktg').save
    super(params.merge(:person_id => company.id), "salary:bvg").save
    super(params.merge(:person_id => company.id), "salary:kz").save
    super(params.merge(:person_id => company.id), "salary:social:kz").save

    super(params, 'salary:invoice').save
  end
end<commit_msg>Book salary invoice before "Kinderzulage".<commit_after>class Salary < Invoice
  # String
  def to_s(format = :default)
    "%s (%s / %s - %s)" % [title, company, duration_from ? I18n::localize(duration_from) : '', duration_to ? I18n::localize(duration_to) : '']
  end
  
  # Calculations
  def net_amount
    salary_invoice_booking = bookings.where(:debit_account_id => Account.find_by_code('2050').id).first
    return 0.0 unless salary_invoice_booking

    salary_invoice_booking.amount
  end
  
  # Assignment proxies
  def duration_from=(value)
    write_attribute(:duration_from, value)
    
    value_as_date = self.duration_from
    # Calculate value and due dates
    date = Date.new(value_as_date.year, value_as_date.month, 1).in(1.month).ago(1.day)
    self.value_date ||= date
    self.due_date   ||= date
  end
  
  # Bookings
  # ========
  def self.direct_account
    Account.find_by_code("5000")
  end

  # Build booking
  #
  # We use the value_date of the purchase invoice but our own amount.
  def build_booking(params = {}, template_code = nil)
    # Build and assign booking
    super(params, 'salary:employee:ahv_iv_eo').save
    super(params, 'salary:employer:ahv_iv_eo').save
    super(params, 'salary:employee:alv').save
    super(params, 'salary:employer:alv').save
    super(params, 'salary:employee:nbu').save
    super(params, 'salary:employer:nbu').save
    super(params, 'salary:employer:bu').save
    super(params, 'salary:employer:fak').save
    super(params, 'salary:employer:vkb').save
    
    super(params, 'salary:employee:ktg').save
    super(params.merge(:person_id => company.id), "salary:bvg").save

    super(params, 'salary:invoice').save

    super(params.merge(:person_id => company.id), "salary:kz").save
    super(params.merge(:person_id => company.id), "salary:social:kz").save
  end
end
{'fraction_non_alphanumeric': 0.1386600768808347, 'fraction_numerical': 0.009335529928610654, 'mean_word_length': 4.152758132956153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1507173', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1284, 'n_words': 227}