= javascript_include_tag 'bomcobox' = javascript_include_tag 'totalizando' = stylesheet_link_tag "inputs_select2" = javascript_include_tag "funcoes_lodash" = javascript_include_tag "select2_com_input" = javascript_include_tag 'gestao_de_estoque/recebimento_de_materiais/adicionar_informacoes' ol.breadcrumb li = link_to "Recebimento de Materiais", gestao_de_estoque_recebimento_de_material_path, class: "link_breadcrumb" li = link_to "#{@recebimento_de_material.codigo}", gestao_de_estoque_recebimento_de_material_path(@recebimento_de_material), class: "link_breadcrumb" li.active Itens do Recebimento de Materiais .widget .widget-body = form_for(@item_do_recebimento, url: gestao_de_estoque_atualiza_informacoes_extras_path(id: @recebimento_de_material.id, item_do_recebimento_id: @item_do_recebimento.id), html: { class: "form-vertical", method: "post" }, role: "form" ) do |f| fieldset legend strong |#{@item_do_recebimento.item.descricao_do_item} = error_for @item_do_recebimento, :base div style="margin-top: 10px;" .row .col-sm-3.pull-right p span.bold Quantidade Total Itens: span.quantidade_total | #{@item_do_recebimento.quantidade} p span.bold Quantidade Preenchida: span.quantidade_preenchida | #{@item_do_recebimento.informacoes_extras.map(&:quantidade).compact.sum.to_f} p span.bold Quantidade a Preencher: span.quantidade_a_preencher | #{@item_do_recebimento.quantidade.to_d - @item_do_recebimento.informacoes_extras.map(&:quantidade).compact.sum.to_f} table.table.table-bordered.table-hover.table-responsive thead tr th.text-center width="25%" Quantidade th.text-center width="25%" Validade th.text-center width="40%" Aspecto Geral th.text-center Lote de Fabricação th.text-center width="5%" Perecível th tbody#itens_do_recebimento_de_materiais = f.fields_for :informacoes_extras, @item_do_recebimento.informacoes_extras do |informacao_extra| = render 'informacao_extra_fields', f: informacao_extra tfoot tr td.text-right colspan="10" = link_to_add_association ' Adicionar'.html_safe, f, :informacoes_extras, :"data-association-insertion-node" => "tbody#itens_do_recebimento_de_materiais", :"data-association-insertion-method" => "append", class: 'btn btn-primary btn-sm', id: 'btn-add-itens-do-recebimento-de-materiais' .form-group h6 ' (*) Campos Obrigatórios .form-actions .row .col-sm-12 = f.submit "Salvar", class: "btn btn-primary" = link_to "Cancelar", gestao_de_estoque_recebimento_de_material_path(@recebimento_de_material), class: "btn btn-default" javascript: $(document).ready(function(){ preparaAutonumeric(); atualizaLabelsQuantidades(); }) $("body").on("change", ".quantidade_informacao_extra", function(){ atualizaLabelsQuantidades(); }) $(function(){ $('form').on('cocoon:after-insert', function(e, insertedItem) { $('select.s2', insertedItem).select2(); $('select.s2').on('select2:select', function (evt) { $(this).focus() }) }) }) function atualizaLabelsQuantidades(campoQuantidade){ var totalPreenchido = 0 $(".quantidade_informacao_extra").each(function(){ if(isNaN(parseFloat($(this).autoNumeric('get'))) == false){ totalPreenchido += parseFloat($(this).autoNumeric('get')) } }) var quantidadeRestante = defineQuantidadeRestante($(".quantidade_total").autoNumeric('get') ,totalPreenchido); $(".quantidade_preenchida").autoNumeric("set", totalPreenchido) $(".quantidade_total").autoNumeric("set", $(".quantidade_total").autoNumeric('get')) $(".quantidade_a_preencher").autoNumeric("set", quantidadeRestante) } function defineQuantidadeRestante(quantidadeTotal, quantidadePreenchida){ if( isNaN(quantidadePreenchida) ){ quantidadePreenchida = 0; } if(quantidadeTotal - quantidadePreenchida > 0){ return quantidadeTotal - quantidadePreenchida }else{ return 0; } } function preparaAutonumeric(){ $(".quantidade_total").autoNumeric("init",{ 'aSep': '.', 'aDec': ',', 'vMin': 0, 'vMax': 999999999.99, }) $(".quantidade_informacao_extra").autoNumeric("init",{ 'aSep': '.', 'aDec': ',', 'vMin': 0, 'vMax': 999999999.99 }) $(".quantidade_preenchida").autoNumeric("init",{ 'aSep': '.', 'aDec': ',', 'vMin': 0, 'vMax': 999999999.99 }) $(".quantidade_a_preencher").autoNumeric("init",{ 'aSep': '.', 'aDec': ',', 'vMin': 0, 'vMax': 999999999.99 }) }