Sha256: 84b417fcf45a662f3d41d3deff33f7bf51158038989970a6d8ba5efc28ae440e

Contents?: true

Size: 1.7 KB

Versions: 10

Compression:

Stored size: 1.7 KB

Contents

$(document).on "ready page:load", ->
  if ($('#quotation.edit').size() > 0)
    sum_line = (line) ->
      q = line.find('input.line-quantity').val().replace(',', '.')
      up = line.find('input.line-unit_price').val().replace(',', '.')
      total =  q * up

    update_line_total = (line)->
      total = sum_line(line)
      display_euros(total, line.find('.line-total'))

    update_total = ->
      total_duty = 0
      vat_rate = parseFloat $('#quotation_vat_rate').val().replace(',', '.') || 0
      commercial_discount = parseFloat $('#quotation_commercial_discount').val().replace(',', '.') || 0

      $('.quotation-line').each (index, element)->
          remove_me = $(element).find('.remove-line input[type="hidden"]').val()
          total_duty += sum_line $(element) if remove_me == 'false'
      total_duty -= commercial_discount
      vat_amount = vat_rate * total_duty / 100.0

      display_euros(commercial_discount, $('#quotation-commercial_discount'))
      display_euros(total_duty, $('#quotation-total_duty'))
      display_euros(vat_amount, $('#quotation-vat_amount'))
      display_euros(vat_amount+total_duty, $('#quotation-total_all_taxes'))

    # Set listener on inputs
    $('#quotation-lines').on 'input', 'input.line-quantity, input.line-unit_price', (event) ->
      update_line_total $(event.currentTarget).parents('.quotation-line')
      update_total()
    $('#quotation').on 'input', 'input#quotation_commercial_discount, input#quotation_vat_rate', (event) ->
       update_total()
    $('#quotation').on 'cocoon:after-remove', (event) ->
       update_total()

    # Update values on page loading
    $('.quotation-line').each (index, element)->
      update_line_total $(element)
    update_total()

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dorsale-2.1.15 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.14 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.13 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.12 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.11 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.10 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.9 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.8 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.7 app/assets/javascripts/dorsale/billing_machine/quotations.coffee
dorsale-2.1.6 app/assets/javascripts/dorsale/billing_machine/quotations.coffee