<?php
include 'header.php';
include 'connect.php';
include 'erpc_transportadora_toolbar.php';

$id = 0;

if(isset($_GET['id'])){
  $id_crip = $_GET['id'];
  $id = (int)base64_decode($id_crip);
}

$consulta = "select * from erpc_transportadoras where st_ativo=1 and id=$id";

$resultado = mysqli_query($conexao, $consulta) or die ($erro = mysqli_error($conexao));
if (mysqli_num_rows($resultado)>0) {
  while ($registro = mysqli_fetch_assoc($resultado)){

  $ds_codigo = trim($registro['ds_codigo']);
    $st_acao = trim($registro['st_acao']);
    $ds_razao = trim($registro['ds_razao']);
    $ds_fantasia = trim($registro['ds_fantasia']);
    $ds_cep = trim($registro['ds_cep']);
    $ds_endereco = trim($registro['ds_endereco']);
    $ds_bairro = trim($registro['ds_bairro']);
    $id_municipio = trim($registro['id_municipio']);
    $ds_cx_postal = trim($registro['ds_cx_postal']);
    $ds_cpf_cnpj = trim($registro['ds_cpf_cnpj']);
    $ds_rg = trim($registro['ds_rg']);
    $ds_ddi = trim($registro['ds_ddi']);
    $ds_ddd = trim($registro['ds_ddd']);
    $ds_telefone = trim($registro['ds_telefone']);
    $ds_fax = trim($registro['ds_fax']);
    $ds_ie = trim($registro['ds_ie']);
    $ds_im = trim($registro['ds_im']);
    $ds_email = trim($registro['ds_email']);
    $ds_departamento = trim($registro['ds_departamento']);
    $ds_homepage = trim($registro['ds_homepage']);
    $ds_telex = trim($registro['ds_telex']);
    $ds_complemento = trim($registro['ds_complemento']);
    $id_banco = trim($registro['id_banco']);
    $ds_conta_corrente = trim($registro['ds_conta_corrente']);
    $ds_natureza = trim($registro['ds_natureza']);
    $id_condicao_pagamento = trim($registro['id_condicao_pagamento']);
    $vl_maior_frete = trim($registro['vl_maior_frete']);
    $nr_media_atraso = trim($registro['nr_media_atraso']);
    $vl_maior_saldo = trim($registro['vl_maior_saldo']);
    $nr_entregas = trim($registro['nr_entregas']);
    $ds_observacao= trim($registro['ds_observacao']);


  }
}
?>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li role="presentation" class="active">
                          <a href="#form1" aria-controls="form1" role="tab" data-toggle="tab">Cadastro</a></li>
  <li role="presentation"><a href="#form2" aria-controls="form2" role="tab" data-toggle="tab">Adm/Fin.</a></li>
</ul>


<!-- Tab panes -->
<form id=validate_custom method=POST action="erpc_transportadora_ws.php">
<input name="id" id="id" value="<?echo $id?>" hidden/>

<div class="tab-content">
  <!--<form id=validate_custom method=POST action="erpc_produto_ws.php" >-->

  <!--  aba de dados cadastrais -->
  <div role="tabpanel" class="tab-pane fade in active" id="form1">
    <div class="block">
        <div class="content controls">
          <div class="form-row">
            <div class="col-md-2"><label>Código</label></div>
            <div class="col-md-2"><input type=number name="ds_codigo" id="ds_codigo" value="<?echo $ds_codigo?>" class="validate[required] form-control" maxlength="04" size=4/></div>
            <div class="col-md-1"><label>Status</label></div>
            <div class="col-md-1">
              <div class="checked inline"><label> <input type=radio class=validate[required] name=st_acao value="1" <?if($st_acao==1){echo "checked";}?>/> Ativo</label></div>
            </div>
            <div class="col-md-1">
              <div class="checked inline"><label> <input type=radio class=validate[required] name=st_acao value="0" <?if($st_acao==0){echo "checked";}?>/> Bloqueado </label></div>
            </div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Razão Social</label></div>
            <div class="col-md-10"><input name="ds_razao" id="ds_razao" value="<?echo $ds_razao?>" class="validate[required] form-control nocharespecial" maxlength="100"/></div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Nome Fantasia</label></div>
            <div class="col-md-6"><input name="ds_fantasia" id="ds_fantasia" value="<?echo $ds_fantasia?>" class="validate[required] form-control nocharespecial" maxlength="40"/></div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>CEP</label></div>
            <div class="col-md-2">
              <div class="input-group">
                <input name="ds_cep" id="ds_cep" maxlenght="8" size="4" class="mask_cep"  value="<?echo $ds_cep?>">
                <div class="input-group-addon">
                <a href="helper-cep.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="#ds_cep" data-description="#ds_endereco" data-title="Selecione:">
                <span class="fa fa-search"></span></a>
              </div>
              </div>
            </div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Endereço</label></div>
            <div class="col-md-10"><input name="ds_endereco" id="ds_endereco" value="<?echo $ds_endereco?>" class="validate[required] form-control" maxlength="100"/></div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Complemento</label></div>
            <div class="col-md-6"><input name="ds_complemento" id="ds_complemento" maxlength="100" value="<?echo $ds_complemento?>"/></div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Bairro</label></div>
            <div class="col-md-4"><input name="ds_bairro" id="ds_bairro" class="validate[required] form-control" maxlength="60"  value="<?echo $ds_bairro?>"/></div>
          </div>

        <div class="row clear">&nbsp;</div>
        <div class="form-row">
          <div class="col-md-2"><label>Município</label></div>
          <div class="col-md-2">
            <div class="input-group">
              <input type=number name="id_municipio" id="id_municipio" maxlenght="10" size="4"  value="<?echo $id_municipio?>">
                <div class="input-group-addon">
                <a href="erpc_municipios_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-parameter="" data-value="#id_municipio" data-description="#ds_municipio" data-title="Selecione:">
                <span class="fa fa-search"></span></a>
                </div>
             </div>
          </div>
          <div class="col-md-2"><input name="ds_municipio" id="ds_municipio" readonly></div>

        </div>


        <div class="form-row">
          <div class="col-md-2"><label>Cx.Postal</label></div>
          <div class="col-md-1"><input type=number name="ds_cx_postal" id="ds_cx_postal" value="<?echo $ds_cx_postal?>"/></div>
          <div class="col-md-3">&nbsp;</div>
          <div class="col-md-1"><label>Tipo</label></div>
          <div class="col-md-2">
                  <select name="tp_tipo" id="tp_tipo">
                    <option value="F">F - Fisico</option>
                    <option value="J">J - Juridico</option>
                    <option value="X">X - Outros</option>
                  </select>
          </div>
        </div>

        <div class="form-row">
          <div class="col-md-2"><label>CNPJ</label></div>
          <div class="col-md-4"><input name="ds_cpf_cnpj" id="ds_cpf_cnpj" class="mask_cnpj" value="<?echo $ds_cpf_cnpj?>"/></div>

          <div class="col-md-1"><label>RG</label></div>
          <div class="col-md-4"><input type=number name="ds_rg" id="ds_rg" value="<?echo $ds_rg?>"></div>
        </div>

        <div class="form-row">
          <div class="col-md-2"><label>DDI</label></div>
          <div class="col-md-1"><input type=number name="ds_ddi" id="ds_ddi" maxlength="02"  value="<?echo $ds_ddi?>"></div>
          <div class="col-md-2"><label>DDD</label></div>
          <div class="col-md-1"><input type=number name="ds_ddd" id="ds_ddd" maxlength="02" value="<?echo $ds_ddd?>"></div>
        </div>

        <div class="form-row">
          <div class="col-md-2"><label>Telefone</label></div>
          <div class="col-md-2"><input type=number name="ds_telefone" id="ds_telefone" maxlength="09" class="mask_nr_tel"  value="<?echo $ds_telefone?>"></div>

          <div class="col-md-2">&nbsp;</div>
          <div class="col-md-2"><label>Fax</label></div>
          <div class="col-md-2"><input name="ds_fax" id="ds_fax" class="mask_nr_tel"  value="<?echo $ds_fax?>"/></div>
        </div>

        <div class="form-row">
          <div class="col-md-2"><label>Insc. Estadual</label></div>
          <div class="col-md-3"><input type=text name="ds_ie" id="ds_ie" value="<?echo $ds_ie?>"/></div>

          <div class="col-md-1">&nbsp;</div>
          <div class="col-md-2"><label>Insc. Municipal</label></div>
          <div class="col-md-3"><input type=number name="ds_im" id="ds_im" value="<?echo $ds_im?>"/></div>
         </div>

         <div class="form-row">
           <div class="col-md-2"><label>E-mail</label></div>
           <div class="col-md-3"><input name="ds_email" id="ds_email" maxlength="40" value="<?echo $ds_email?>"/></div>

           <div class="col-md-1">&nbsp;</div>
           <div class="col-md-2"><label>Departamento</label></div>
           <div class="col-md-3"><input name="ds_departamento" id="ds_departamento" maxlength="40" value="<?echo $ds_departamento?>"/></div>
         </div>

        <div class="form-row">
          <div class="col-md-2"><label>Home Page</label></div>
          <div class="col-md-3"><input name="ds_homepage" id="ds_homepage" maxlength="100" value="<?echo $ds_homepage?>"/></div>

          <div class="col-md-1">&nbsp;</div>
          <div class="col-md-2"><label>Nr.Telex</label></div>
          <div class="col-md-1"><input type=number name="ds_telex" id="ds_telex" maxlength="20"  value="<?echo $ds_telex?>"/></div>
        </div>

        <!--
        <div class="form-row">
          <div class="col-md-2"><label>CBO</label></div>
          <div class="col-md-1"><input type=number name="id_cbo" id="id_cbo"  value="<?echo $id_cbo?>"/></div>

          <div class="col-md-1">&nbsp;</div>
          <div class="col-md-2"><label>CNAE</label></div>
          <div class="col-md-1"><input type=number name="id_cnae" id="id_cnae" value="<?echo $id_cnae?>"/></div>
        </div>
        -->

        <div class="form-row">
          <div class="col-md-2"><label>Observações</label></div>
          <div class="col-md-4"><input name="ds_observacao" id="ds_observacao" maxlength="255"  value="<?echo $ds_observacao?>"/></div>
        </div>

    </div>
    </div>
  </div> <!-- fim da seção abas cadastrais -->

  <!--  adm fin aba -->
  <div role="tabpanel" class  ="tab-pane fade" id="form2">
    <div class="block">
       <div class="content controls">
          <div class="form-row" id="form2">
            <div class="col-md-2"><label>Banco</label></div>
            <div class="col-md-2">
              <div class="input-group">
              <input name="id_banco" id="id_banco" type="number" min="0"  value="<?echo $id_banco?>"/>
              <div class="input-group-addon">
                <a href="helper-bancos.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="#id_banco" data-description="#ds_banco" data-title="Selecione:">
                <span class="fa fa-search"></span></a>
               </div>
               </div>
               </div>
            <div class="col-md-4"><input name="ds_banco" id="ds_banco"/></div>
          </div>

          <div class="form-row">
              <!--
              <div class="col-md-2"><label>Agência</label></div>
              <div class="col-md-1"><input name="nr_agencia" id="nr_agencia" type="number" min="0"  value="<?echo $nr_agencia?>"/></div>
            -->
            <div class="col-md-1">&nbsp;</div>
            <div class="col-md-1"><label>Conta</label></div>
            <div class="col-md-2"><input name="ds_conta_corrente" id="ds_conta_corrente" type="number" min="0" value="<?echo $ds_conta_corrente?>"/></div>
            <div class="col-md-1">&nbsp;</div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Natureza</label></div>
            <div class="col-md-2">
              <div class="input-group">
                <input name="ds_natureza" id="ds_natureza" type="number" min="0" value="<?echo $ds_natureza?>"/>
                <div class="input-group-addon">
                <a href="helper-plano-contas.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="#ds_natureza" data-description="#ds_natureza" data-title="Selecione:">
                <span class="fa fa-search"></span></a><br>
                </div>
                </div>
            </div>
            <div class="col-md-2"><input name="ds_natureza" id="ds_natureza" readonly/></div>
          </div>

            <div class="form-row">
            <div class="col-md-2"><label>Cond.Pagto</label></div>
            <div class="col-md-2">
              <div class="input-group">
              <input name="id_condicao_pagamento" id="id_condicao_pagamento"  value="<?echo $id_condicao_pagamento?>"/>
                <div class="input-group-addon">
                <a href="erpc_financeiro_plano_contas_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="#id_condicao_pagamento" data-description="#ds_pagto" data-title="Selecione:">
                <span class="fa fa-search"></span></a>
                </div>
              </div>
            </div>
            <div class="col-md-2"><input name="ds_pagto" id="ds_pagto" readonly/></div>
            </div>


        <div class="row clear">&nbsp;</div>
        <div class="content controls">
          <div class="form-row">
            <div class="col-md-2"><label>Maior Frete</label></div>
            <div class="col-md-2"><input name="vl_maior_frete" id="vl_maior_frete"  value="<?echo $vl_maior_frete?>" type="number" value="0.00" min="0" step="0.00" readonly/></div>
            <div class="col-md-1">&nbsp;</div>
            <div class="col-md-2"><label>Média Atraso</label></div>
            <div class="col-md-2"><input name="nr_media_atraso" id="nr_media_atraso"  value="<?echo $nr_media_atraso?>"type="number" value="0.00" min="0" step="0.00" readonly/></div>
          </div>
          <div class="form-row">
            <div class="col-md-2"><label>Maior Saldo</label></div>
            <div class="col-md-2"><input name="vl_maior_saldo" id="vl_maior_saldo"  value="<?echo $vl_maior_saldo?>"type="number"  value="0.00" min="0" step="0.00" readonly/></div>
            <div class="col-md-1">&nbsp;</div>
            <div class="col-md-2"><label>N.° Entregas</label></div>
            <div class="col-md-1"> <input name="nr_entregas" id="nr_entregas" value="<?echo $nr_entregas?>" type="number"  value="0.00" min="0" step="0" readonly/></div>
          </div>

          <div class="form-row">
            <div class="col-md-2"><label>Saldo Duplicatas</label></div>
            <div class="col-md-2"><input name="vl_saldo_duplicatas" id="vl_saldo_duplicatas"  value="<?echo $vl_saldo_duplicatas?>" type="number"  value="0.00" min="0" step="0.00" readonly/></div>
          </div>


        </div>
      </div>
    </div>

  </div> <!-- fim da tab bancos adm /fin -->

  <div class=footer>
      <div class="side pull-right">
        <div class=btn-group>

          <button class="btn btn-success" type="submit" value="editar" onClick="$('#validate_custom').validationEngine('hide');" name="editar">Editar</button>

          <button class="btn btn-default" type="button" onClick="window.history.go(-1)" value="Voltar">Voltar</button>

        </div>
      </div>
    </div>


</div>

</form>


<?php include 'footer.php'; ?>
<?php include 'inc/helper_modal_div.php'; ?>
<script type="text/javascript" src="js/acme.js"></script>
<script type="text/javascript" src="js/caracteres.js"></script>

<script type="text/javascript" >

    $("[name='ds_ie']").keyup(function(){
    	$(this).val($(this).val().replace(".", ""));
    });
    $("[name='ds_ie'").blur(function(){
    	$(this).val($(this).val().replace(".", ""));
    });
    
</script>