Created
October 22, 2012 12:02
-
-
Save aalvesjr/3931221 to your computer and use it in GitHub Desktop.
Alterar esse trecho. [GVAR]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| // Substituir esse script: | |
| // https://github.com/kakobotasso/gvar/blob/master/app/views/financeiro/novo_pagamento.html.erb | |
| // | |
| // Depois colocar em um JS separado | |
| function get_tecla(e){ | |
| var tecla = (window.event) ? event.keyCode : e.which; | |
| return tecla; | |
| } | |
| function valida_numerico(tecla, permitidos){ | |
| var permitidos = permitidos || [], | |
| permitido = false; | |
| permitidos.concat([0,8]); // Sabe-se la deus porque... (né Kako) | |
| if( (tecla > 47 && tecla < 58) || ( permitidos.indexOf(tecla) =! -1) ) permitido = true; | |
| return permitido; | |
| } | |
| function somente_numero(e){ | |
| return valida_numerico(get_tecla(e)); | |
| } | |
| function numeros_com_separador(e){ | |
| return valida_numerico(get_tecla(e),[44,46]); | |
| } | |
| function formas_pagamento(id){ | |
| var formasPagamento = ''; | |
| formasPagamento += '<select class="select"'; | |
| formasPagamento += ' id="release_instalments_attributes_'+id+'_payment_id"'; | |
| formasPagamento += ' name="release[instalments_attributes]['+id+'][payment_id]">'; | |
| formasPagamento += ' <option value="0">Dinheiro</option>'; | |
| formasPagamento += ' <option value="1">Cheque</option>'; | |
| formasPagamento += ' <option value="2">Cheque-pre</option>'; | |
| formasPagamento += ' <option value="3">Cartão Debito</option>'; | |
| formasPagamento += ' <option value="4">Cartão Credito</option>'; | |
| formasPagamento += '</select>'; | |
| return formasPagamento; | |
| } | |
| function all_status(id){ | |
| var status = ''; | |
| status += '<select class="select"'; | |
| status += ' id="release_instalments_attributes_'+id+'_status_id"'; | |
| status += ' name="release[instalments_attributes]['+id+'][status_id]">'; | |
| status += ' <option value="0">Pendente</option>'; | |
| status += ' <option value="1">Quitado</option>'; | |
| status += ' <option value="2">Cancelado</option>'; | |
| status += ' <option value="3">Recebido</option>'; | |
| status += '</select>'; | |
| return status; | |
| } | |
| //numberParcelas | |
| $(function(){ | |
| var numero_parcelas = $("#numberParcelas").val(); | |
| $("#numberParcelas").keypress(somente_numero); | |
| $("#valorTotal").keypress(numeros_com_separador); | |
| $("#numberParcelas").blur(function(){ | |
| var valor, _tr = ""; | |
| valor = $("#valorTotal").val(); | |
| valor = valor + ""; // Transforma em string para usar o replace | |
| valor = valor.replace(".",""); // Caso a pessoa digite 1.500,00 | |
| valor = valor.replace(",","."); // Para deixar no formato 1500.00 | |
| if( numero_parcelas > 0 ){ | |
| if( valor > 0 ){ | |
| for( var i = 0; i < numero_parcelas; i++ ){ | |
| _tr += '<tr class="generated">'; | |
| _tr += ' <td width="14%"> <span>'+(i+1)+'/'+numero_parcelas+'</span> <input id="release_instalments_attributes_'+i+'_number" name="release[instalments_attributes]['+i+'][number]" type="hidden" value="'+(i+1)+'"> </td>'; | |
| _tr += ' <td width="14%"> <span>R$ <input class="inputMenor input soNumeros" id="release_instalments_attributes_'+i+'_amount" name="release[instalments_attributes]['+i+'][amount]" size="30" type="text" value="'+parseFloat(Math.round((valor/numero_parcelas)*100)/100).toFixed(2).replace(".",",")+'"></span> </td>'; | |
| _tr += ' <td width="14%"> <span><input class="inputMenor input" id="release_instalments_attributes_'+i+'_expiration_date" name="release[instalments_attributes]['+i+'][expiration_date]" size="30" type="text"></span> </td>'; | |
| _tr += ' <td width="14%"> <span><input class="inputMenor input" id="release_instalments_attributes_'+i+'_paid_at" name="release[instalments_attributes]['+i+'][paid_at]" size="30" type="text"></span> </td>'; | |
| _tr += ' <td width="14%"> <span><input class="inputMenor input soNumeros" id="release_instalments_attributes_'+i+'_amount_paid" name="release[instalments_attributes]['+i+'][amount_paid]" size="30" type="text"></span> </td>'; | |
| _tr += ' <td width="14%"> <span>'+formas_pagamento(i)+'</span> </td>'; | |
| _tr += ' <td width="14%"> <span>'+all_status(i)+'</span> </td>'; | |
| _tr += '</tr>'; | |
| } | |
| $("#guardaParcelasGeradas tr.generated").remove(); | |
| $("#guardaParcelasGeradas").append(_tr); | |
| $("#guardaParcelasGeradas").slideDown(500); | |
| }else{ | |
| alert("Digite um valor válido"); | |
| $("#valorTotal").focus(); | |
| } | |
| }else{ | |
| alert("Valor minimo para parcelas: 1"); | |
| $("#numberParcelas").focus(); | |
| } | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment