= javascript_include_tag 'patrimonio/recebimentos_de_bens/form' .alert.alert-warning[role="alert" id="alert-content" style="display: none;"] span#alert-message = simple_form_for(@recebimento_de_bem) do |f| = f.error_notification = f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? = f.hidden_field :extraorcamentario, value: @outros - if logado_no_patrimonio? && @recebimento_de_bem.new_record? && @outros == false = f.hidden_field :criado_no_patrimonio, value: true fieldset legend strong = @recebimento_de_bem.new_record? ? 'Cadastrar' : 'Editar' ' Registro de Bem .form-inputs .row .col-sm-2 = f.input :data_do_recebimento, label: 'Data do Registro', as: :string, wrapper: :calendar_field, input_html: { class: 's2', autocomplete: "off" } - if @recebimento_de_bem.recebimento_de_material.present? .col-sm-4 = f.input :unidade_orcamentaria_id, label: 'Unidade Orçamentária', collection: @unidades_orcamentarias, label_method: :codigo_e_nome_e_exercicio, disabled: true .col-sm-2 = f.input :classificacao, label: 'Classificação', collection: Patrimonio::RecebimentoDeBem.classificacoes_i18n, disabled: true .div id="section_doador" style="display: none;" .col-sm-3 = f.input :doador_id, label: 'Doador', collection: @doadores, label_method: :nome_e_cpf_ou_cnpj, disabled: true - else .col-sm-4 = f.input :unidade_orcamentaria_id, label: 'Unidade Orçamentária', collection: @unidades_orcamentarias, label_method: :codigo_e_nome_e_exercicio, include_blank: 'Selecione...', input_html: { class: 'form-control s2'} - unless @outros == 'false' .col-sm-2 = f.input :classificacao, label: 'Classificação', collection: @classificacoes, include_blank: 'Selecione...', input_html: { class: 'form-control s2', id: 'classificacao' } .div id="section_doador" style="display: none;" .col-sm-3 = f.input :doador_id, label: 'Doador/Compromissário', collection: @doadores, label_method: :nome_e_cpf_ou_cnpj, include_blank: 'Selecione...', input_html: { class: 'form-control s2 doador'} .row - if @recebimento_de_bem.recebimento_de_material.present? .col-sm-3 = f.input :sub_elemento_de_despesa_id, label: 'Detalhamento', collection: @sub_elementos_de_despesa_permanente, label_method: :codigo_formatado_e_descricao, disabled: true - else .col-sm-3 = f.input :sub_elemento_de_despesa_id, label: 'Detalhamento', collection: @sub_elementos_de_despesa_permanente, label_method: :codigo_formatado_e_descricao, include_blank: 'Selecione...', input_html: { class: 'form-control s2'} .col-sm-2 = f.input :numero_da_nota, label: 'Nº da Nota' .col-sm-2 = f.input :serie, label: 'Série' .col-sm-2 = f.input :data_de_emissao, label: 'Data da Emissão', as: :string, wrapper: :calendar_field, input_html: { class: 's2', autocomplete: "off" } .row .col-sm-3 = f.input :fornecedor_id, label: 'Fornecedor', collection: @fornecedores, label_method: :nome_e_cpf_ou_cnpj, include_blank: 'Selecione...', input_html: { class: 'form-control s2 fornecedor'} - if @outros == false = f.hidden_field :classificacao, value: 'compra' .col-sm-2 .checkbox.checkbox-circle.checkbox_multiplos = f.check_box :multiplos_empenhos, class: 'multiplos_empenhos' = f.label 'Múltiplos Empenhos?' .div id='mostra_ano_empenho' .col-sm-3 = f.input :ano_empenho_vinculado, label: 'Ano do empenho', collection: @orcamento, label_method: :exercicio, include_blank: 'Selecione...', input_html: { class: 'form-control s2', id: 'ano_do_empenho' } - if @outros.present? .col-sm-3 = f.input :origem_de_recurso_patrimonial_id, label: 'Origem de Recurso Patrimonial', collection: @origem_de_recurso, label_method: :nome, include_blank: 'Selecione...', input_html: { class: 'form-control s2 origem_de_recurso'} .div id='mostra_tabela_de_itens' table.table.table-bordered.table-hover.table-responsive thead tr th Empenho th.text-center Valor Atual th.text-center Valor th.text-center Opções tbody#empenhos_do_recebimento = f.fields_for :empenhos_do_recebimento, @recebimento_de_bem.empenhos_do_recebimento do |empenho_do_recebimento| = render 'empenho_do_recebimento_fields', f: empenho_do_recebimento tfoot tr td.text-right colspan="5" = link_to_add_association ' Adicionar'.html_safe, f, :empenhos_do_recebimento, :"data-association-insertion-node" => "tbody#empenhos_do_recebimento", :"data-association-insertion-method" => "append", class: 'btn btn-primary btn-sm', id: 'btn-add-empenhos-do-recebimento' / .div id="section_fornecedor" style="display: none;" / legend / strong / ' Dados do Fornecedor / .form-group / .row / .col-sm-8 / label Fornecedor / = popup_pesquisa_pessoa_com_id_button id: "busca_fornecedor", module: "patrimonio_recebimento_de_bem", field: "fornecedor_id", url: pesquisa_base_pessoas_path, show_value: @recebimento_de_bem.fornecedor.try(:cpf_ou_cnpj_e_nome), hidden_value: @recebimento_de_bem.fornecedor_id, title: "Pesquisar Fornecedor" / = error_for @recebimento_de_bem, :fornecedor_id / .div id="section_doador" style="display: none;" / legend / strong / ' Dados do Doador / .form-group / .row / .col-sm-8 / label Doador / = popup_pesquisa_pessoa_com_id_button id: "busca_doador", module: "patrimonio_recebimento_de_bem", field: "doador_id", url: pesquisa_base_pessoas_path, show_value: @recebimento_de_bem.doador.try(:cpf_ou_cnpj_e_nome), hidden_value: @recebimento_de_bem.doador_id, title: "Pesquisar Doador" / = error_for @recebimento_de_bem, :doador_id .form-group .row .col-sm-12 = f.input :observacao, label: 'Observação', as: :text, input_html: { rows: '5' } .form-actions .row .col-sm-12 - if @recebimento_de_bem.new_record? = f.submit 'Salvar e ir para itens', class: "btn btn-success" - if @outros == true = link_to "Cancelar", patrimonio_recebimentos_de_bens_path(flag: true), class: "btn btn-default" - else = link_to "Cancelar", patrimonio_recebimentos_de_bens_path, class: "btn btn-default" - else = f.submit "Salvar", class: "btn btn-primary" = link_to "Cancelar", patrimonio_recebimento_de_bem_path(@recebimento_de_bem.id), class: "btn btn-default" / = popup_pesquisa_pesasoa title: "Pesquisa Pessoa" - content_for :js do javascript: $(function(){ inicia(); $('form').on('cocoon:after-insert', inicia) $('form').on('cocoon:before-remove', function (e, removedItem) { $('input[data-autonumeric]', removedItem).val('0'); $('input[type="hidden"][id$="_item_id"]', removedItem).val('0'); }); $('#patrimonio_recebimento_de_bem_multiplos_empenhos').change(function(){ if ($(this).is(":checked")){ $("#mostra_ano_empenho").show(); }else{ $("#mostra_ano_empenho").hide(); } }); $('#ano_do_empenho').change(function(){ let unidade = $('#patrimonio_recebimento_de_bem_unidade_orcamentaria_id') if ($(this).val() != undefined && $(this).val() != '' && unidade.val() != undefined && unidade.val() != '' ){ busca_empenhos_de_bens_permanentes($(this).val()); $("#mostra_tabela_de_itens").show(); } }); $('form').on('submit', function(e){ $('.valor_atual').each(function(){ $(this).autoNumeric('update', {aSign: '', aDec: '.', aSep: ''});; }); }); }) function busca_empenhos_de_bens_permanentes() { let unidade = $('#patrimonio_recebimento_de_bem_unidade_orcamentaria_id').val(); let ano = $('#ano_do_empenho').val(); $.ajax({ type: "GET", beforeSend: function(){ LoadingInterface("Aguarde..."); }, url : root_url + "/pesquisas/empenhos_por_ano?ano=" + ano + "&unidade_orcamentaria=" + unidade, success: function(data,status,xhr){ $(".empenho").each(function (e){ var linha = $(this).closest('.refer'); var box_selecionado_empenho = ($('.empenho', linha)); if ( $(box_selecionado_empenho).val() != undefined && $(box_selecionado_empenho).val() != '' ){ }else{ select_box_empenhos = limpaSelectBox(box_selecionado_empenho, linha); $.each(data, function (i, empenho) { option = new Option(empenho.numero_e_fornecedor, empenho.id, true, true); select_box_empenhos.append(option); }); populaSelectBox(select_box_empenhos); }; }); } }) }; function carrega_valor_atual() { var empenho_id = $(this).val(); var linha = $(this).closest('.refer'); if ( $(this).val() != undefined && $(this).val() != '' ) { $.getJSON(ROOT_PATH + "pesquisas/" + empenho_id + "/dados_do_empenho", function(dados) { $('.valor_atual', linha).autoNumeric('set', dados.saldo_para_recebimento_multiplos); }); }; }; function inicia() { $('select.s2').select2(); $('.valor_atual').autoNumeric('init', { 'aSep': '.', 'aDec': ',', 'aPad': true, 'vMin': 0, 'vMax': 999999999.99, 'aSign': 'R$ ' }); $('.valor').autoNumeric('init', { 'aSep': '.', 'aDec': ',', 'aPad': true, 'vMin': 0, 'vMax': 999999999.99, 'aSign': 'R$ ' }); $("#btn-add-empenhos-do-recebimento").click(busca_empenhos_de_bens_permanentes); $(".empenho").change(carrega_valor_atual); $(document).trigger('refresh_autonumeric'); if ( $('#patrimonio_recebimento_de_bem_multiplos_empenhos').is(":checked") ){ $("#mostra_ano_empenho").show(); $("#mostra_tabela_de_itens").show(); }else{ $("#mostra_ano_empenho").hide(); $("#mostra_tabela_de_itens").hide(); } } function limpaSelectBox(id) { $(id).empty().trigger('change') select_box = $(id).select2({ placeholder: "Selecione", allowClear: true }) return (select_box); } function populaSelectBox(select_box) { select_box.prepend(new Option('Selecione', '', true, true)); select_box.trigger('change'); }