<?php 
require_once 'connect.php';
require_once 'inc/usuario.php';

$id_pedido = 90;

$user = getLoggedUser();
$id_unid = $user['unidade'];

$sql    = " select	 ds_razao_social
                    ,ds_fantasia
                    ,ds_cnpj
                    ,ds_ie
                    ,ds_im
                    ,ds_cep
                    ,ds_endereco
                    ,ds_numero
                    ,ds_bairro
                    ,ds_municipio
                    ,ds_pais
                    ,ds_complemento
                    ,ds_logo
                    ,ds_regime
                    from erpc_unidades u
                        inner join erpc_dom_regime_tributario t
                        on u.id_regime = t.id
                        inner join erpc_municipios m
                        on u.id_municipio = m.id
                        inner join erpc_paises p
                        on m.id_pais = p.id
                    where u.id = $id_unid";

$result = mysqli_query($conexao, $sql);
if(mysqli_num_rows($result) > 0){
    while($row = mysqli_fetch_assoc($result)){
        $ds_razao = $row['ds_razao_social'];
        $ds_fantasia = $row['ds_fantasia'];
        $ds_logo  = $row['ds_logo'];
        $ds_cnpj  = $row['ds_cnpj'];
        $ds_ie    = $row['ds_ie'];
        $ds_im    = $row['ds_im'];
        $ds_cep   = $row['ds_cep'];
        $ds_endereco = $row['ds_endereco'];
        $ds_numero   = $row['ds_numero'];
        $ds_bairro   = $row['ds_bairro'];
        $ds_municipio = $row['ds_municipio'];
        $ds_uf       = $row['ds_uf'];
        $ds_cep      = $row['ds_cep'];
        $ds_pais     = $row['ds_pais'];
        $ds_complemento = $row['ds_complemento'];
        $ds_regime   = $row['ds_regime'];   
    }
}
?>

<!DOCTYPE html>
<html lang="pt">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">  

  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  
  <link rel="stylesheet" type="text/css" href="css/ficha_cadastral.css">
  <link rel="stylesheet" href="css/print_style.css" type="text/css" />
  
</head>
<body>
    <page size="A4">
        <table class="table table-sm borderless" >
            <tr>
                <td width=50%>
                <?php
                    //echo substr($ds_logo, 5);
                    if (substr($ds_logo, -3)=='jpg' || substr($ds_logo, -3)=='png' || substr($ds_logo, -3)=='gif') {
                        $prefix = substr($ds_logo, 5) =='http: ' || substr($ds_logo, 6) == 'https:' ? '' : '';
                        echo "<img src='$prefix$ds_logo' width='320px'><br>";
                    }
                ?>
                </td>
                
            </tr>
        </table><br>
        
        <div class="border" align="center"><h6><b>Empresa</b></h6></div>
        <div class="border">
            <div class="row col-sm-12">
                <div class="row col-sm-3">
                    <h6><b>Razão Social:</b></h6>
                </div>
                <div class="row col-sm-9">
                    <h6><?=$ds_razao; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-3">
                    <h6><b>Nome Fantasia:</b></h6>
                </div>
                <div class="row col-sm-9">
                    <h6><?=$ds_fantasia; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-3">
                    <h6><b>CNPJ:</b></h6>
                </div>
                <div class="row col-sm-3">
                    <h6><?=$ds_cnpj; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-3">
                    <h6><b>Inscrição Estadual:</b></h6>
                </div>
                <div class="row col-sm-3">
                    <h6><?=$ds_ie; ?></h6>
                </div>
                <div class="row col-sm-3">
                    <h6><b>Inscrição Municipal:</b></h6>
                </div>
                <div class="row col-sm-3">
                    <h6><?=$ds_im; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-3">
                    <h6><b>Regime Tributário:</b></h6>
                </div>
                <div class="row col-sm-9">
                    <h6><?=$ds_regime; ?></h6>
                </div>
            </div>
        </div>

        <br><br><br>
        <div class="border" align="center"><h6><b>Endereço</b></h6></div>
        <div class="border">
            <div class="row col-sm-12">
                <div class="row col-sm-2">
                    <h6><b>Logradouro:</b></h6>
                </div>
                <div class="row col-sm-7">
                    <h6><?=$ds_endereco; ?></h6>
                </div>
                <div class="row col-sm-1">
                    <h6><b>Nº:</b></h6>
                </div>
                <div class="row col-sm-2">
                    <h6><?=$ds_numero; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-2">
                    <h6><b>Bairro:</b></h6>
                </div>
                <div class="row col-sm-7">
                    <h6><?=$ds_bairro; ?></h6>
                </div>
                <div class="row col-sm-1">
                    <h6><b>Cep:</b></h6>
                </div>
                <div class="row col-sm-2">
                    <h6><?=$ds_cep; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-2">
                    <h6><b>Município:</b></h6>
                </div>
                <div class="row col-sm-7">
                    <h6><?=$ds_municipio; ?></h6>
                </div>
                <div class="row col-sm-1">
                    <h6><b>Estado:</b></h6>
                </div>
                <div class="row col-sm-2">
                    <h6><?=$ds_uf; ?></h6>
                </div>
                
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-2">
                    <h6><b>País:</b></h6>
                </div>
                <div class="row col-sm-9">
                    <h6><?=$ds_pais; ?></h6>
                </div>
            </div>
            <div class="row col-sm-12">
                <div class="row col-sm-2">
                    <h6><b>Complemento:</b></h6>
                </div>
                <div class="row col-sm-10">
                    <h6><?=$ds_complemento; ?></h6>
                </div>
            </div>
           
        </div>

    </page>
</body>
</html>