D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Views
/
Portal
/
Filename :
ViePtAcaoContratoCadastrar.php
back
Copy
<?php if (isset($this->Dados['form'])) { $valorForm = $this->Dados['form']; } if (isset($this->Dados['form'][0])) { $valorForm = $this->Dados['form'][0]; } //var_dump($this->Dados['select']['acao']); ?> <style> .form-group { font-size: 0.9rem; /* line-height: 1.0; */ } .form-row { line-height: 1.0; } .form-control { font-size: 0.9rem; line-height: 1.0; } .ff { width: 50px; } .fff { width: 300px; } .ffff { width: 350px; } .mm { width: 100px; } .mmm { width: 50px; } .mmmm { width: 150px; } input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } table .filial { border-collapse: collapse; max-width: 60%; } .inacao { border: 0; } table .mesesacao { border-collapse: collapse; max-width: 30%; overflow-y:auto; } .acoes { border-collapse: collapse; max-width:100%; } table th { position: -webkit-sticky; position: sticky; top: 0; } tbody { display:block; max-height:120px; max-width:100%; overflow-y:auto; } #resto{ line-height: 0.5; } </style> <div class="content p-1"> <div class="list-group-item"> <div class="d-flex"> <div class="mr-auto p-2"> <h2 class="display-4 titulo">Solicitar Ação de Trade </h2> </div> <?php if ($this->Dados['botao']['vol_contr']) { ?> <div id="voltar" class="p-2"> <a href="<?php echo URLADM . 'con-trade-acao-contrato/listar'?>" class="btn btn-outline-info btn-sm">Voltar</a> </div> <?php } ?> </div> <?php if (isset($_SESSION['msg'])) { echo $_SESSION['msg']; unset($_SESSION['msg']); } ?> <!-- Nav tabs --> <ul id="aba" class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-toggle="tab" href="#home" role="tab" onclick="javascript:habilitavolta()">Contrato</a> </li> <li class="nav-item"> <a class="nav-link" data-toggle="tab" href="#profile" role="tab" onclick="javascript:desabilitavolta()" >Ações</a> <!-- <a class="nav-link" data-toggle="tab" href="#profile" role="tab" onclick="javascript:teste()">Filiais</a> --> </li> <!--<li class="nav-item"> <a class="nav-link" data-toggle="tab" href="#settings" role="tab">Settings</a> </li>--> </ul> <!-- Tab panes --> <form method="POST" action="" enctype="multipart/form-data"> <input type="hidden" name="hoje" id="hoje" class="form-control" value="<?php echo date('Y-m-d'); ?>" > <input type="hidden" name="urladm" id="urladm" class="form-control" value="<?php echo URLADM; ?>" > <input type="hidden" name="upmarca" id="upmarca" class="form-control" value="S" > <input type="hidden" name="base_id" id="base_id" class="form-control" > <input type="hidden" name="abrangencia" id="abrangencia" class="form-control" > <input type="hidden" name="vigencia_num" id="vigencia_num" class="form-control" > <input type="hidden" name="base_sigla" id="base_sigla" class="form-control" > <input type="hidden" name="controla_prod" id="controla_prod" class="form-control" > <input type="hidden" name="qtde_lojas" id="qtde_lojas" class="form-control" > <input type="hidden" name="plano_nome" id="plano_nome" class="form-control" > <input type="hidden" name="contr_id" id="contr_id" class="form-control" > <div class="tab-content"> <div class="tab-pane active" id="home" role="tabpanel"> <div class="form-row"> <div class="form-group col-md-3"> <label><span class="text-danger">*</span>Marca:</label> <input id="gre_marca_aux" name="gre_marca_id_aux" list="ent" class="form-control col-sm-12" onchange="javascript:marca_con(this)" required> <datalist id="ent" > <?php foreach ($this->Dados['select']['marca'] as $sit) { extract($sit); $nome_marca = utf8_decode($nome_marca); echo "<option data-id='{$marca_id}' id='{$marca_id}' value='{$nome_marca}'></option>"; } ?> </datalist> <input type="hidden" name="marca_id" id="marca_id" > </div> <div class="form-group col-md-4"> <label><span class="text-danger">*</span>Razão Social:</label> <input name="razao_social" type="text" maxlength="60" id="razao_social" class="form-control" required height:10px; > </div> <div class="form-group col-md-2"> <label><span class="text-danger">*</span>CNPJ:</label> <input name="cnpj" id="cnpj" type="text" class="form-control" onblur="javascript:validarCNPJ(this.value)" required > </div> <div class="form-group col-md-2"> <label title="Se Zeros ou Branco utiliza valor da Tabela">Total do Investimento:</label> <input name="valor_investido" type="text" id="valor_investido" class="form-control" title="Se Zeros ou Branco utiliza valor da Tabela" onKeyPress="return(MascaraMoeda(this, '.', ',', event))" > </div> </div> <div id="resto"> <div class="form-row" > <div class="form-group col-md-2"> <label><span class="text-danger">*</span>Plano</label> <!--<select name="plano_id" id="plano_id" class="form-control" onblur="javascript:pega_prod()" onchange="javascript:qtdemeses(this.value)">--> <select name="plano_id" id="plano_id" class="form-control" onchange="javascript:qtdemeses(this.value)" required> <option value="">Selecione</option> <?php foreach ($this->Dados['select']['plano'] as $plano) { extract($plano); echo "<option value='$plano_id'>$plano_nome</option>"; } ?> </select> <input type="hidden" name="filial_controle" id="filial_controle" class="form-control" value="0" > </div> <div class="form-group col-md-3"> <label><span class="text-danger">* </span>Inicio Acordo</label> <input name="data_inicio" type="month" id="data_inicio" class="form-control" required onchange="javascript:checadata(this.value)"> </div> <div class="form-group col-md-2"> <label id="lmeses"><span class="text-danger">* </span>Qt Meses Acordo:</label> <input type="text" name="meses_vigencia" id="meses_vigencia" class="form-control" readonly onchange="javascript:checadata(this.value)" required> </div> <div class="form-group col-md-2"> <label><span class="text-danger">* </span>Vigencia Acordo</label> <input name="data_vigencia" type="text" id="data_vigencia" class="form-control" readonly required> </div> </div> </div> <div id="avulso"> <div class="form-row"> <div class="form-group col-md-2"> <label><span class="text-danger">*</span>Tipo</label> <select name="tipo_id" id="tipo_id" class="form-control" onchange="javascript:buscasubtipo(this.value)" required> <option value="">Selecione</option> <?php foreach ($this->Dados['select']['tipo'] as $tipo) { extract($tipo); echo "<option value='$tipo_id'>$tipo_nome</option>"; } ?> </select> </div> <div class="form-group col-md-3"> <label><span class="text-danger">*</span>Sub-Tipo</label> <select name="sub_tipo_id" id="sub_tipo_id" class="form-control" onchange="javascript:buscaacao(this.value)"> </select> </div> <div class="form-group col-md-3"> <label><span class="text-danger">*</span>Ação</label> <!-- <select name="acao_id" id="acao_id" list="qtde_disp" class="form-control" onchange="javascript:trade_disp(this.value)"> --> <select name="acao_id" id="acao_id" list="qtde_disp" class="form-control" onchange="javascript:pega_disp()"> </select> </div> <div id="dqtde" class="form-group col-md-2"> <label> Qtde Ações:</label> <input name="qtde" type="number" id="qtde" class="form-control" value="1"> </div> <div class="form-group col-md-2"> <label id="lptab">Preço Tabela:</label> <input name="preco_venda_tabela" type="text" id="preco_venda_tabela" class="form-control" readonly> </div> </div> </div> <div id="tabfil" class="form-row"> <div class="table-responsive col-md-6"> <table id="example-crm" class="filial" cellspacing="1" border="0" > </table> </div> <div id="tabmesacao" class="table-responsive col-md-2"> <table id="meses-acao" class="mesesacao" cellspacing="1" border="1" > <thead> </thead> <tbody> </tbody> </table> </div> </div> <!-- <div class="form-group col-md-2"> <label >Total Tabela:</label> <input name="total_tabela" type="text" id="total_tabela" class="form-control" readonly > </div> --> <div id="acao"> <div class="form-row"> <div class="form-group col-md-1"> <label></label> <!-- <input name="CadAcao" id="CadAcao" type="submit" class="btn btn-success" value="Incluir" > --> <input name="CadAcao" id="CadAcao" type='button' class="btn btn-primary" value="Incluir Ação do Acordo" onclick="javascript:inclui_acao(this.value)" > </div> </div> </div> <div class="form-row"> <div class="form-group col-md-2" id="qparcelas"> <label>Parcelas Pagto:</label> <input name="parcelas" type="number" class="form-control col-sm-8" id="parcelas" min="1" required> </div> <div class="form-group col-md-2"> <label><span class="text-danger">*</span>Contato Contratante:</label> <input name="contato" type="text" maxlength="30" id="contato" class="form-control" required > </div> <div class="form-group col-md-2"> <label><span class="text-danger">*</span>Celular Contratante:</label> <input name="celular_contratante" type="text" id="cel" class="form-control" required> </div> <div class="form-group col-md-6"> <label>Observações:</label> <input name="observacao" type="text" maxlength="600" id="observacao" class="form-control"> </div> </div> <div class="form-row"> <p> <span class="text-danger">*</span>Campo obrigatório </p> </div> <div class="form-row"> <div class="form-group col-md-1"> <input name="Limpar" id="Limpar" type="reset" class="btn btn-success" value="Limpar"> <!-- <div class="form-group col-md-0.5"> </div> <input name="CadEstResid" id="CadEstResid" type="submit" class="btn btn-warning" value="Salvar"> --> </div> <div class="form-group col-md-2"> <input name="CadContr" id="CadContr" type="submit" class="btn btn-warning" value="Incluir Contrato" > </div> </div> </div> <div class="tab-pane" id="profile" role="tabpanel"> <div class="table-responsive"> <table id="tabacoes" class="acoes" cellspacing="1" border="1" style="width:100%" > <thead> <tr> <td align='center' colspan="9"><font color="blue"><b>AVULSOS</b></td> </tr> <tr> <td align='center' style="width:50px" ><font color="blue"><b>#ID</b></td> <td align='center' style="width:50px" ><font color="blue"><b>Contr</b></td> <td align='center' style="width:250px" ><font color="blue"><b>Sub-Tipo</b></td> <td align='center' style="width:250px" ><font color="blue"><b>Ação</b></td> <td align='center' style="width:100px" ><font color="blue"><b>Unit Tabela</b></td> <td align='center' style="width:50px" ><font color="blue"><b>Meses</b></td> <td align='center' style="width:50px" ><font color="blue"><b>Lojas</b></td> <td align='center' style="width:70px" ><font color="blue"><b>Qt.Ações</b></td> <td align='center' style="width:100px" ><font color="blue"><b>Total</b></td> <td align='center' style="width:30px" ><font color="blue"><b></b></td> <!-- <td align='center' style="width:700px" ><b>Sub-Tipo</b></td> <td align='center' style="width:250px" ><font color="blue"><b></b></td> --> </tr> </thead> <tbody> </tbody> </table> </div> </div> </div> </form> </div> </div> <script> //document.getElementById("qtde").value = '1'; document.getElementById("CadAcao").disabled =true; document.getElementById("tabfil").style.display = 'none'; document.getElementById("tabacoes").style.display = 'none'; document.getElementById("meses-acao").style.display = 'none'; function habilitavolta(){ document.getElementById("voltar").style.display = 'block'; } function desabilitavolta(){ document.getElementById("voltar").style.display = 'none'; } function inclui_acao(){ if(document.getElementById("data_inicio").value == '') { alert("Mes do Inicio Obrigatorio!"); document.getElementById("data_inicio").focus(); exit; } var wacao = document.getElementById("acao_id").value; var wtipo = document.getElementById("tipo_id").value; var wsubtipo = document.getElementById("sub_tipo_id").value; var wbase = document.getElementById("base_id").value; var wprecotab = document.getElementById("preco_venda_tabela").value; var wvignum= document.getElementById("vigencia_num").value; var wsigla = document.getElementById("base_sigla").value; var wcontprod = document.getElementById("controla_prod").value; var fil_controle = document.getElementById("filial_controle").value; var wmesvig = document.getElementById("meses_vigencia").value; var wplanonome = document.getElementById("plano_nome").value; document.getElementById("tabacoes").style.display = 'block'; var resultado = document.getElementById("plano_id").value.split("-"); var endereco = document.getElementById("urladm").value; var data_inicial = document.getElementById("data_inicio").value+'-01'; var meses = document.getElementsByClassName('mesescheck'); var array_meses = meses; var newArraymeses = []; for(var x = 0; x <= array_meses.length; x++){ if(typeof array_meses[x] == 'object'){ if(array_meses[x].checked){ newArraymeses.push(array_meses[x].name); } } } if(newArraymeses.length == 0 && wmesvig > 1){ alert("Selecione um pelo menos UM MES DA AÇÃO!"); exit; } console.log(newArraymeses); // exit; if(document.getElementById("abrangencia").value !== 'L') { document.getElementById("qtde_lojas").value = 1; }else{ var ids = document.getElementsByClassName('editar'); var array_dados = ids; var newArray = []; for(var x = 0; x <= array_dados.length; x++){ if(typeof array_dados[x] == 'object'){ if(array_dados[x].checked){ newArray.push(array_dados[x].name); } } } if(newArray.length <= 0){ alert("Selecione pelo menos UMA FILIAL!"); exit; }else{ document.getElementById("qtde_lojas").value = newArray.length; var wqtlojas = document.getElementById("qtde_lojas").value; } } var qtde_acao = document.getElementById("qtde").value; $(document).ready(function() { var response = ''; var tab= document.getElementById("tabacoes"); var numLinhas = tab.rows.length; var parte = document.getElementById("data_inicio").value.split("-"); var mesi = parte[1]+'/'+parte[0]; $.ajax({ type: "POST", data : { plano_id :resultado[1], tipo_id : wtipo, sub_tipo_id : wsubtipo, acao_id : wacao, base_id : wbase, preco_venda_tabela: wprecotab, data_inicio : data_inicial, final_vigencia : wvignum, base_sigla: wsigla, controla_prod: wcontprod, qtde_lojas: wqtlojas, qtde_meses: wmesvig, plano_nome: wplanonome, arr_filial: newArray, arr_meses: newArraymeses, mesi: mesi, num_linha: numLinhas, qtde: qtde_acao, filial_controle: fil_controle }, url: endereco + "vendor/api/incluir_trade_acao.php", async: false, success: function(text) { response = text; // } }); adicionaLinha("tabacoes", response); }); document.getElementById("tipo_id").value = ""; document.getElementById("sub_tipo_id").value= ""; document.getElementById("acao_id").value = ""; document.getElementById("base_id").value = ""; document.getElementById("preco_venda_tabela").value = ""; // document.getElementById("preco_venda_negociado").value = ""; document.getElementById("base_sigla").value = ""; document.getElementById("controla_prod").value= ""; document.getElementById("qtde_lojas").value = ""; document.getElementById("CadAcao").disabled =true; document.getElementById("meses-acao").style.display = 'none'; document.getElementById("tabfil").style.display = 'none'; document.getElementById("tipo_id").focus(); document.getElementById("qtde").value = '1'; } /* function coletaIDs(dados) { // alert(dados); var array_dados = dados; var newArray = [ ]; var y =0; for(var x =0; x <= array_dados.length; x++) { if(array_dados[x].checked) { newArray.push(array_dados[x].id) } if(newArray.length <= 0) { alert ("Selecione pelo menos um item"); exit; }else{ newArray.length; // alert ("Seu novo array de IDs tem ["+newArray+" ]"); } } //alert('qtde = '+ qtde); } */ function adicionaLinha(idTabela, response) { var tabela = document.getElementById(idTabela); var nomes = response.split("#"); var numeroLinhas = tabela.rows.length; var linha = tabela.insertRow(numeroLinhas); var celula0 = linha.insertCell(0); var celula1 = linha.insertCell(1); var celula2 = linha.insertCell(2); var celula3 = linha.insertCell(3); var celula4 = linha.insertCell(4); var celula5 = linha.insertCell(5); var celula6 = linha.insertCell(6); var celula7 = linha.insertCell(7); var celula8 = linha.insertCell(8); var celula9 = linha.insertCell(9); //var celula7 = linha.insertCell(6); celula0.innerHTML = nomes[0]; celula1.innerHTML = nomes[1]; celula2.innerHTML = nomes[2]; celula3.innerHTML = nomes[3]; celula4.innerHTML = nomes[4]; celula5.innerHTML = nomes[5]; celula6.innerHTML = nomes[6]; celula7.innerHTML = nomes[7]; celula8.innerHTML = nomes[9]; document.getElementById("contr_id").value = nomes[1]; //document.getElementById("total_tabela").value = nomes[8]; celula9.innerHTML = "<button class='btn btn-danger' onclick='removeLinha(this)' >Remover</button>"; //alert(idTabela); $('#tipo_id').prop('required', false); $('#sub_tipo_id').prop('required', false); $('#acao_id').prop('required', false); } function removeLinha(linha) { var linhas = linha.parentNode.parentNode.children; var id_acao = linhas[0].innerText; var endereco = document.getElementById("urladm").value; var response = ''; $.ajax({ type: "POST", data : { acao_id : id_acao}, url: endereco + "vendor/api/excluir_trade_acao.php", async: false, success: function(text) { response = text; } }); var valores = document.querySelectorAll("tabacoes tr td "); var i=linha.parentNode.parentNode.rowIndex; document.getElementById('tabacoes').deleteRow(i); if(i == 1) { $('#tipo_id').prop('required', true); $('#sub_tipo_id').prop('required', true); $('#acao_id').prop('required', true); } alert(response); } function pega_filial_pacote() { var resultado = document.getElementById("plano_id").value.split("-"); // alert (resultado[0]); // alert (resultado[1]); var enderecoa = document.getElementById("urladm").value; $(document).ready(function() { var responsef = ''; $.ajax({ type: "POST", data : { plano_pacote : resultado[0], tipo_id : document.getElementById("tipo_id").value, sub_tipo_id : document.getElementById("sub_tipo_id").value, acao_id : document.getElementById("acao_id").value }, url: enderecoa + "vendor/api/pega_trade_filial_disp.php", async: false, success: function(text) { responsef = text; // console.log(responsef); document.getElementById("example-crm").innerHTML = responsef; } }); }); } function pega_disp() { busca_preco(document.getElementById("acao_id").value); var resultado = document.getElementById("plano_id").value.split("-"); var endereco = document.getElementById("urladm").value; var base_sigla = document.getElementById("base_sigla").value; if (base_sigla != 'U' ) { $(document).ready(function() { var response = ''; // document.getElementById("qtde").value = 1; document.getElementById("tabfil").style.display = 'block'; $.ajax({ type: "POST", data : { filial_controle : document.getElementById("filial_controle").value, plano_pacote :resultado[0], tipo_id : document.getElementById("tipo_id").value, sub_tipo_id : document.getElementById("sub_tipo_id").value, acao_id : document.getElementById("acao_id").value }, url: endereco + "vendor/api/pega_trade_filial_disp.php", async: false, success: function(text) { response = text; if(response != ''){ $('#example-crm').prop('border', true); } // alert(response); document.getElementById("example-crm").innerHTML = response; } }); }); }else{ document.getElementById("tabfil").style.display = 'none'; //alert(base_sigla); } } function pega_filial_disp() { var resultado = document.getElementById("plano_id").value.split("-"); // alert (resultado[0]); // alert (resultado[1]); var enderecoa = document.getElementById("urladm").value; $(document).ready(function() { var responsef = ''; $.ajax({ type: "POST", data : { filial_controle : document.getElementById("filial_controle").value, plano_pacote : resultado[0], tipo_id : document.getElementById("tipo_id").value, sub_tipo_id : document.getElementById("sub_tipo_id").value, acao_id : document.getElementById("acao_id").value }, url: enderecoa + "vendor/api/pega_trade_filial_disp.php", async: false, success: function(text) { responsef = text; document.getElementById("acoes").innerHTML = responsef; } }); }); } function qtdemeses(plano) { if(document.getElementById("marca_id").value == '') { alert ('Marca é OBRIGATORIO !!'); location.reload(); document.getElementById("gre_marca_aux").focus(); exit; } var resultado = plano.split("-"); var obj = <?php echo json_encode($this->Dados['select']['plano']); ?>; element = document.getElementById("qtde_mes"); for (var i = 0; i < obj.length; i++){ if (obj[i].plano_id === plano){ document.getElementById("plano_nome").value = obj[i].plano_nome; // document.getElementById("preco_venda_negociado").value = ""; document.getElementById("preco_venda_tabela").value = ""; if(resultado[0] === 'N'){ document.getElementById('lptab').innerHTML = "Preço Tabela:"; // document.getElementById('lpneg').innerHTML = "Preço Unit Negociado:"; document.getElementById("avulso").style.display = 'block'; document.getElementById("acao").style.display = 'block'; document.getElementById("data_inicio").value = ""; // document.getElementById("qtde_mes").value = "1"; document.getElementById("preco_venda_tabela").value = ""; $('#meses_vigencia').prop('readonly', false); document.getElementById("meses_vigencia").value = "1"; document.getElementById("parcelas").value = 1; }else{ document.getElementById("avulso").style.display = 'none'; document.getElementById("acao").style.display = 'none'; document.getElementById('lptab').innerHTML = "Valor Pacote:"; // document.getElementById('lpneg').innerHTML = "Valor Negociado:"; document.getElementById("qparcelas").style.display = 'block'; $('#tipo_id').prop('required', false); $('#sub_tipo_id').prop('required', false); $('#acao_id').prop('required', false); //document.getElementById("qtde_mes").value = obj[i].plano_qtde_meses; $('parcelas').prop('required', true); document.getElementById("preco_venda_tabela").value = obj[i].plano_preco_venda; document.getElementById("parcelas").value = obj[i].plano_qtde_meses; document.getElementById("data_vigencia").value = ""; document.getElementById("data_inicio").value = "mm/aaaa"; $('#meses_vigencia').prop('readonly', false); // alert(obj[i].plano_qtde_meses); document.getElementById("meses_vigencia").value = obj[i].plano_qtde_meses; $('#meses_vigencia').prop('readonly', true); pega_filial_pacote(); } } } } function checavalor (negociado){ if (document.getElementById("preco_venda_tabela").value === '' && negociado === '') { alert('Valor Negociado Obrigatório !!'); document.getElementById("preco_venda_negociado").value =""; document.getElementById("data_inicio").focus(); } if (document.getElementById("preco_venda_tabela").value === '' && negociado === '0,00') { alert('Valor Negociado não podem ser Zeros!!'); document.getElementById("preco_venda_negociado").value =""; document.getElementById("data_inicio").focus(); } if (document.getElementById("preco_venda_tabela").value === 'R$ 0,00' && negociado === '') { alert('Valor Negociado Obrigatório!!'); document.getElementById("preco_venda_negociado").value =""; document.getElementById("data_inicio").focus(); } if (document.getElementById("preco_venda_tabela").value === 'R$ 0,00' && negociado === '0,00') { alert('Valor Negociado não podem ser Zeros!!'); document.getElementById("preco_venda_negociado").value =""; document.getElementById("data_inicio").focus(); } } function buscasubtipo(tipo) { var obj = <?php echo json_encode($this->Dados['select']['sub_tipo']); ?>; element = document.getElementById("sub_tipo_id"); element.innerHTML = ''; var node = document.createElement("option"); var textnode = document.createTextNode('Selecione'); node.setAttribute("value", ""); node.appendChild(textnode); element.appendChild(node); for (var i = 0; i < obj.length; i++){ if (obj[i].tipo_id === tipo){ var node = document.createElement("option"); var textnode = document.createTextNode(obj[i].sub_tipo_nome); node.setAttribute("value", obj[i].sub_tipo_id); node.appendChild(textnode); element.appendChild(node); } } meses_acao(document.getElementById("vigencia_num").value); } function buscaacao(subtipo) { var enderecoa = document.getElementById("urladm").value; var contrato_id = document.getElementById("contr_id").value; var tipo_plano = document.getElementById("tipo_id").value; $(document).ready(function() { var responsef = ''; $.ajax({ type: "POST", data : { contr_id: contrato_id , tipo_id : tipo_plano, sub_tipo_id : subtipo }, url: enderecoa + "vendor/api/ler_acoes.php", async: false, success: function(text) { responsef = text; document.getElementById("acao_id").innerHTML = responsef; } }); }); } function marcacon(marca) { var cod_marca = document.getElementById("id").value; //alert(marca+cod_marca); } function checadata(meses) { //alert(meses); var plano = document.getElementById("plano_id").value.split("-"); var inicio = document.getElementById("data_inicio").value+'-01'; //alert(resultado[0]); if (inicio==''){ alert('Data Inicio Obrigatoria !!'); document.getElementById("data_inicio").focus(); exit; } var resultado = inicio.split('-'); var hoje = document.getElementById("hoje").value; //alert('hoje: '+hoje); //var data_base = resultado[1]+'/'+resultado[2]+'/'+resultado[0]; var ndata = new Date(resultado[0],resultado[1], resultado[2], 0, 0, 0, 0); var ndata_inicio = new Date(resultado[0],resultado[1], 1, 0, 0, 0, 0); if (document.getElementById("meses_vigencia").value == '') { var meses = document.getElementById("meses_vigencia").value; }else{ var meses = document.getElementById("meses_vigencia").value; } var a = parseInt(meses) - parseInt(1); ndata.setMonth(ndata.getMonth()+a); var dia = String(ndata.getDate()).padStart(2, '0'); var mes = String(ndata.getMonth() + 1).padStart(2, '0'); var ano = ndata.getFullYear(); var datavigreal = ano + mes + dia; //alert('datavigreal: '+datavigreal); //var meses = document.getElementById("meses_vigencia").value; var ano_lim = parseInt(resultado[0]) + parseInt(1); var datalim = ano_lim.toString() + '01'+ '31'; if (datavigreal > datalim ){ var vigencia_num = ano_lim.toString() + '-01'+ '-31'; var data_vigencia = 'janeiro de ' + ano_lim.toString(); // alert(data_vigencia); var d1Y = parseInt(resultado[0]); var d1m = resultado[1]; var d2Y = ano_lim; var calc_mes = ((parseInt(1)+(parseInt(12)*parseInt(d2Y)))) - ((parseInt(d1m) + (parseInt(12)*parseInt(d1Y)))); calc_mes = parseInt(calc_mes) + parseInt(1); document.getElementById("data_vigencia").value = data_vigencia; document.getElementById("meses_vigencia").value = calc_mes.toString(); document.getElementById("vigencia_num").value = vigencia_num; document.getElementById("parcelas").value = calc_mes.toString(); }else{ //var a = parseInt(document.getElementById("qtde_mes").value) - parseInt(2) ; var a = meses - parseInt(2) ; var month = ndata_inicio.getMonth(); var n_date = new Date(ndata_inicio.getFullYear(), eval(a+month), 1); var n_date = new Date(n_date.getFullYear(), n_date.getMonth() + 1, 0); var dia = String(n_date.getDate()).padStart(2, '0'); var mes = String(n_date.getMonth() + 1).padStart(2, '0'); var ano = n_date.getFullYear(); var vigencia_num = ano+'-'+mes+'-'+dia; if(plano[0]=='N') { if(document.getElementById("meses_vigencia").value > 1) { meses_acao(vigencia_num); }else{ document.getElementById("meses-acao").style.display = 'none'; } } if(mes=='01') { data_vigencia='janeiro de '+ano}; if(mes=='02') { data_vigencia='fevereiro de '+ano}; if(mes=='03') { data_vigencia='marco de '+ano}; if(mes=='04') { data_vigencia='abril de '+ano}; if(mes=='05') { data_vigencia='maio de '+ano}; if(mes=='06') { data_vigencia='junho de '+ano}; if(mes=='07') { data_vigencia='julho de '+ano}; if(mes=='08') { data_vigencia='agosto de '+ano}; if(mes=='09') { data_vigencia='setembro de '+ano}; if(mes=='10') { data_vigencia='outubro de '+ano}; if(mes=='11') { data_vigencia='novembro de '+ano}; if(mes=='12') { data_vigencia='dezembro de '+ano}; document.getElementById("data_vigencia").value = data_vigencia; document.getElementById("vigencia_num").value = vigencia_num; // document.getElementById("meses_vigencia").value = document.getElementById("qtde_mes").value; document.getElementById("parcelas").value = document.getElementById("qtde_mes").value; } } function meses_acao(vigencia) { // alert('meses_acao'); // document.getElementById("meses-acao").style.display = 'block'; var data_inicio = document.getElementById("data_inicio").value+'-01'; // alert('vigencia_num'+document.getElementById("vigencia_num").value); var data_fim = vigencia; // alert(data_inicio); // alert('vigencia:'+data_fim); const mes_ini = parseInt(data_inicio.substring(5, 7)); const ano_ini = parseInt(data_inicio.substring(0, 4)); const num_ini = (ano_ini * 12 + mes_ini); const mes_fim = parseInt(data_fim.substring(5, 7)); const ano_fim = parseInt(data_fim.substring(0, 4)); const num_fim = (ano_fim * 12 + mes_fim); const qtde_mes = (num_fim - num_ini) + 1; var enderecoa = document.getElementById("urladm").value; $(document).ready(function() { var responsef = ''; $.ajax({ type: "POST", data : { tipo: 'A', qtde : qtde_mes, data_inicio : data_inicio, data_fim : data_fim }, url: enderecoa + "vendor/api/monta_meses_meta.php", async: false, success: function(text) { responsef = text; // alert(responsef); // console.log(responsef); document.getElementById("meses-acao").innerHTML = responsef; if (qtde_mes > 1) { document.getElementById("meses-acao").style.display = 'block'; } } }); }); } function busca_preco() { var obj = <?php echo json_encode($this->Dados['select']['acao']); ?>; var plano = document.getElementById("plano_id").value; var tipo = document.getElementById("tipo_id").value; //alert(document.getElementById("plano_id").value); var sub_tipo = document.getElementById("sub_tipo_id").value; var acao = document.getElementById("acao_id").value; for (var i = 0; i < obj.length; i++){ if ( obj[i].tipo_id == tipo && obj[i].sub_tipo_id == sub_tipo && obj[i].acao_id == acao) { document.getElementById("preco_venda_tabela").value = 'R$ ' + obj[i].preco_venda; document.getElementById("base_id").value = obj[i].base_id; document.getElementById("base_sigla").value = obj[i].base_sigla; document.getElementById("controla_prod").value = obj[i].controla_prod; document.getElementById("filial_controle").value = obj[i].filial_controle; document.getElementById("abrangencia").value = obj[i].abrangencia; // console.log(obj[i].filial_controle); //alert(obj[i].preco_venda) } } if(document.getElementById("preco_venda_tabela").value === '') { //alert( document.getElementById("plano_id").value); if(document.getElementById("plano_id").value !== '9'){ alert('Não encontrei Preço cadastrado na tabela de preços !!'); document.getElementById("plano_id").focus(); exit; }else{ document.getElementById("preco_venda_negociado").focus(); exit; } } document.getElementById("CadAcao").disabled = false; document.getElementById("tabfil").style.display = 'none'; } function validarCNPJ(cnpj) { // alert(cnpj); cnpj = cnpj.replace(/[^\d]+/g,''); //alert(cnpj); /* if(cnpj == ''){ document.getElementById("cnpj").value = ""; document.getElementById("cnpj").focus(); alert('CNPJ Não digitado'); exit; } } if (cnpj.length != 14){ document.getElementById("cnpj").value = ""; document.getElementById("cnpj").focus(); alert('CNPJ Invalido menor 14'); exit; } */ // Elimina CNPJs invalidos conhecidos if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "77777777777777" || cnpj == "88888888888888" || cnpj == "99999999999999") { document.getElementById("cnpj").value = ""; document.getElementById("cnpj").focus(); alert('CNPJ Invalido *'); exit; } // Valida DVs tamanho = cnpj.length - 2 numeros = cnpj.substring(0,tamanho); digitos = cnpj.substring(tamanho); // alert(tamanho); soma = 0; pos = tamanho - 7; for (i = tamanho; i >= 1; i--) { soma += numeros.charAt(tamanho - i) * pos--; if (pos < 2) pos = 9; } resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; // alert('resultado1:' + digitos.charAt(0)); if (resultado != digitos.charAt(0)) { document.getElementById("cnpj").value = ""; document.getElementById("cnpj").focus(); alert('CNPJ Invalido'); exit; } tamanho = tamanho + 1; numeros = cnpj.substring(0,tamanho); soma = 0; pos = tamanho - 7; for (i = tamanho; i >= 1; i--) { soma += numeros.charAt(tamanho - i) * pos--; if (pos < 2) pos = 9; } resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; //alert('resultado= '+digitos.charAt(0)+digitos.charAt(1); // alert('resultado'+resultado); if (resultado != digitos.charAt(1)) { document.getElementById("cnpj").value = ""; document.getElementById("cnpj").focus(); alert('CNPJ Invalido'); exit; } document.getElementById("plano_id").focus(); //return true; } function exibe_mes($mes) { switch ($mes) { case "1": return "Janeiro"; break; case "2": return "Fevereiro"; break; case "3": return "Março"; break; case "4": return "Abril"; break; case "5": return "Maio"; break; case "6": return "Junho"; break; case "7": return "Julho"; break; case "8": return "Agosto"; break; case "9": return "Setembro"; break; case "10": return "Outubro"; break; case "11": return "Novembro"; break; case "12": return "Dezembro"; break; default: return ""; } } </script>