<commit_before>(function (E, $) {
  function getAllocatedInputAmountSum() {
    return $('input[type=number].allocation').toArray().reduce(((acc, e) => acc + parseFloat(e.value) || 0), 0)
  }

  function displayTotalSum() {
    $('.fieldset-fields .amount_allocated').find('span').text(totalSumRemainedToAllocate())
    onAmountChange()
  }

  function totalSumRemainedToAllocate() {
    return (Math.abs(balanceBetweenResultsAndCarryForward()) - getAllocatedInputAmountSum()).toFixed(2)
  }

  function fillAmountToAllocate() {
    const $amountAllocated = $('.fieldset-fields .amount_allocated')
    $amountAllocated.find('span').text(getAmountToAllocate())
    $amountAllocated.append(`<input type='number' name='sum' id='sum' value='${getAmountToAllocate()}' class='hidden credit_balance' step='any'>`)
  }

  function balanceBetweenResultsAndCarryForward() {
    const debitCarryForwardAmount = parseFloat($('.fieldset-fields .previous_debit_balance').val()) || 0
    const creditCarryForwardAmount = parseFloat($('.fieldset-fields .previous_credit_balance').val()) || 0
    const carryForwardAmount = (creditCarryForwardAmount - debitCarryForwardAmount)

    const exerciceResults = parseFloat($('.close-conditions .result').find('.result-amount').attr('data-exercice-results'))

    return (carryForwardAmount + exerciceResults).toFixed(2)
  }


  function getAmountToAllocate() {
    const exerciceResults = parseFloat($('.close-conditions .result').find('.result-amount').attr('data-exercice-results'))
    const creditCarryForward = parseFloat($('.fieldset-fields .amount_allocated--carry_forward').find('input').val()) || 0

    if ($('.previous_debit_balance').length) {
      return Math.abs(exerciceResults - creditCarryForward).toFixed(2)
    } else {
      return Math.abs(exerciceResults + creditCarryForward).toFixed(2)
    }
  }

  function onAmountChange() {
    $('.fieldset-fields .amount_allocated .allocated-budget').toggleClass('error', totalSumRemainedToAllocate() < 0)
    $('#close-btn').attr('disabled', (!$('#confirm-revised-accounts').prop('checked') || totalSumRemainedToAllocate() !== 0))
  }


  document.addEventListener('DomContentLoaded', function () {
    $('.lock-table #confirm-revised-accounts').on('change', function () {
      const lock_btn = $('#lock-btn')
      lock_btn.attr('disabled', !this.checked)
    })

    $('.close-table #confirm-revised-accounts').on('change', function () {
      if ($('.amount_allocated').length) {
        $('#close-btn').attr('disabled', !this.checked || (totalSumRemainedToAllocate() !== 0))
      } else {
        $('#close-btn').attr('disabled', !this.checked)
      }
    })

    $('.med-info .signature-trigger').on('click', function () {
      const signatureContainer = $(this).closest('.med-info')
      const signatureDetails = $(signatureContainer).find('.signature-details')
      const chevron = $(signatureContainer).find('.chevron')

      if ($(signatureDetails).is(":visible")) {
        $(chevron).css('transform', 'rotate(0deg)')
      } else {
        $(chevron).css('transform', 'rotate(90deg)')
      }

      $(signatureDetails).slideToggle()
    })

    $('.exercice_result_allocation').each(function () {
      fillAmountToAllocate()
      displayTotalSum()

      $(document).on('input', '.fieldset-fields .amount_allocated input', () => displayTotalSum())
    })
  })
}(ekylibre, jQuery))
<commit_msg>Move call to 'toFixed' that was messing with comparisons<commit_after>(function (E, $) {
  function getAllocatedInputAmountSum() {
    return $('input[type=number].allocation').toArray().reduce(((acc, e) => acc + parseFloat(e.value) || 0), 0)
  }

  function displayTotalSum() {
    $('.fieldset-fields .amount_allocated').find('span').text(totalSumRemainedToAllocate().toFixed(2))
    onAmountChange()
  }

  function totalSumRemainedToAllocate() {
    return (Math.abs(balanceBetweenResultsAndCarryForward()) - getAllocatedInputAmountSum())
  }

  function fillAmountToAllocate() {
    const $amountAllocated = $('.fieldset-fields .amount_allocated')
    $amountAllocated.find('span').text(getAmountToAllocate())
    $amountAllocated.append(`<input type='number' name='sum' id='sum' value='${getAmountToAllocate()}' class='hidden credit_balance' step='any'>`)
  }

  function balanceBetweenResultsAndCarryForward() {
    const debitCarryForwardAmount = parseFloat($('.fieldset-fields .previous_debit_balance').val()) || 0
    const creditCarryForwardAmount = parseFloat($('.fieldset-fields .previous_credit_balance').val()) || 0
    const carryForwardAmount = (creditCarryForwardAmount - debitCarryForwardAmount)

    const exerciceResults = parseFloat($('.close-conditions .result').find('.result-amount').attr('data-exercice-results'))

    return (carryForwardAmount + exerciceResults).toFixed(2)
  }


  function getAmountToAllocate() {
    const exerciceResults = parseFloat($('.close-conditions .result').find('.result-amount').attr('data-exercice-results'))
    const creditCarryForward = parseFloat($('.fieldset-fields .amount_allocated--carry_forward').find('input').val()) || 0

    if ($('.previous_debit_balance').length) {
      return Math.abs(exerciceResults - creditCarryForward).toFixed(2)
    } else {
      return Math.abs(exerciceResults + creditCarryForward).toFixed(2)
    }
  }

  function onAmountChange() {
    $('.fieldset-fields .amount_allocated .allocated-budget').toggleClass('error', totalSumRemainedToAllocate() < 0)
    $('#close-btn').attr('disabled', (!$('#confirm-revised-accounts').prop('checked') || totalSumRemainedToAllocate() !== 0))
  }


  document.addEventListener('DOMContentLoaded', function () {
    $('.lock-table #confirm-revised-accounts').on('change', function () {
      const lock_btn = $('#lock-btn')
      lock_btn.attr('disabled', !this.checked)
    })

    $('.close-table #confirm-revised-accounts').on('change', function () {
      if ($('.amount_allocated').length) {
        $('#close-btn').attr('disabled', !this.checked || (totalSumRemainedToAllocate() !== 0))
      } else {
        $('#close-btn').attr('disabled', !this.checked)
      }
    })

    $('.med-info .signature-trigger').on('click', function () {
      const signatureContainer = $(this).closest('.med-info')
      const signatureDetails = $(signatureContainer).find('.signature-details')
      const chevron = $(signatureContainer).find('.chevron')

      if ($(signatureDetails).is(":visible")) {
        $(chevron).css('transform', 'rotate(0deg)')
      } else {
        $(chevron).css('transform', 'rotate(90deg)')
      }

      $(signatureDetails).slideToggle()
    })

    $('.exercice_result_allocation').each(function () {
      fillAmountToAllocate()
      displayTotalSum()

      $(document).on('input', '.fieldset-fields .amount_allocated input', () => displayTotalSum())
    })
  })
}(ekylibre, jQuery))

{'fraction_non_alphanumeric': 0.1774405369910988, 'fraction_numerical': 0.00437764482708303, 'mean_word_length': 4.470071827613727, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 9, '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': '2006156', 'n_tokens_mistral': 2076, 'n_tokens_neox': 2004, 'n_words': 292}