.widget .widget-body strong legend Cadastrar Itens da Dotação = simple_form_for(@orcamento_da_despesa_do_apostilamento, url: licitacao_atualizar_itens_do_orcamento_da_despesa_path(@orcamento_da_despesa_do_apostilamento), method: :patch) do |f| .row .col-sm-6 p strong Unidade Orçamentária: ==< @orcamento_da_despesa_do_apostilamento.unidade_orcamentaria.codigo_e_nome .col-sm-6 p strong Valor do Apostilamento: ==< @orcamento_da_despesa_do_apostilamento.valor.to_f.real_contabil .row .col-sm-6 p strong Proj/Atividade: ==< @orcamento_da_despesa_do_apostilamento.acao.codigo_e_nome .col-sm-6 p strong Elemento de Despesa: ==< @orcamento_da_despesa_do_apostilamento.elemento_de_despesa.codigo_e_descricao .row .col-sm-6 p strong Subelemento de Despesa: ==< @orcamento_da_despesa_do_apostilamento.sub_elemento_de_despesa.codigo_e_descricao .col-sm-6 p strong Fonte: ==< @orcamento_da_despesa_do_apostilamento.fonte_de_recursos.codigo_completo_e_descricao = error_for f.object, :base table.table.table-bordered.table-hover.table-responsive thead tr th width="30%" Item th width="15%" Qtd.Contrato th width="15%" Quantidade th width="15%" Vr unitário th width="15%" Total th width="10%" tbody#itens_do_orcamento_da_despesa = f.fields_for :itens_do_orcamento_da_despesa_do_apostilamento do |item_do_orcamento_da_despesa_do_apostilamento| = render 'item_do_orcamento_da_despesa_do_apostilamento_fields', f: item_do_orcamento_da_despesa_do_apostilamento tfoot tr td colspan="1" span Valor Total: span.bold.valor_total td.links.text-right colspan="5"align="right" = link_to_add_association ' Adicionar'.html_safe, f, :itens_do_orcamento_da_despesa_do_apostilamento, :"data-association-insertion-node" => "tbody#itens_do_orcamento_da_despesa", :"data-association-insertion-method" => "append", class: 'btn btn-primary btn-sm', id: 'btn-add-item-do-orcamento-da-despesa-por-aditivo' - if f.object.itens_do_orcamento_da_despesa_do_apostilamento.size < f.object.contrato.itens_do_contrato.size = link_to licitacao_editar_itens_do_orcamento_da_despesa_path(f.object, todos: true), class: 'btn btn-primary btn-sm', style: 'margin-left: 20px;' do span class="glyphicon glyphicon-plus-sign" | Adicionar Todos .form-actions .row .col-sm-12 = f.submit 'Salvar', class: 'btn btn-primary' = link_to 'Cancelar', @orcamento_da_despesa_do_apostilamento.apostilamento, class: 'btn btn-default' javascript: $(document).ready(function() { initAutoNumerics(); calculaNovoValorTotal(); }) $('body').on('change', '.item_do_contrato', function(){ var idItemDoContrato = $(this).val(); if(idItemDoContrato != ''){ var linha = $(this).closest("tr"); $.getJSON(`${root_url}pesquisas/${idItemDoContrato}/item_do_contrato` , function(data){ $('.quantidade_contrato', linha).text(data.quantidade_atual); $('.valor_unitario', linha).autoNumeric('set', data.valor_unitario); }); }; }); $('body').on('change', '.quantidade', function(){ preencheTotal($(this)); }); $('form').submit(function(){ var form = $(this); $('input').each(function(i){ var input = $(this); try{ var valorDoInput = input.autoNumeric('get'); input.autoNumeric('destroy'); input.val(valorDoInput); }catch(err){ } }); return true; }); function preencheTotal(objetoQuantidade){ var linha = objetoQuantidade.closest("tr"); var quantidade = parseFloat(objetoQuantidade.val()); var valorUnitario = $('.valor_unitario', linha).autoNumeric('get'); $('.total', linha).autoNumeric('set', quantidade * valorUnitario); calculaNovoValorTotal(); } function calculaNovoValorTotal(){ var total = 0; $('.total').each(function(){ var autoNumericTotal = $(this).autoNumeric('get') if (autoNumericTotal){ total += parseFloat(autoNumericTotal); } }) $('.valor_total').autoNumeric('set', total); } function initAutoNumerics(){ $('.valor_unitario, .total, .valor_total').autoNumeric('init', { 'aSep': '.', 'aDec': ',', 'aPad': true, 'vMin': 0, 'aSign': 'R$ ', 'mDec': 2 }); } $(function(){ $('form').on('cocoon:after-insert', function(e, insertedItem) { $('select.s2', insertedItem).select2(); $('select.s2').on('select2:select', function (evt) { $(this).focus(); }); initAutoNumerics(); }); });