# Arquitetura e Tecnologias

<div class="pw" id="bkmrk-"><div class="ph"></div></div>Stack técnico, hierarquia de classes, dependências e conexões com bancos de dados.

## Diagrama de componentes

<div class="pw" id="bkmrk-fullstore-http-post-"><figure id="bkmrk-fullstore-componentes" style="margin: 1.25em 0;"><svg aria-label="Componentes e fluxo de dados da integração FullStore" font-family="system-ui, Segoe UI, Roboto, sans-serif" role="img" style="max-width: 100%; height: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;" viewbox="0 0 1080 310" xmlns="http://www.w3.org/2000/svg"> <defs> <marker id="bkmrk--1" markerheight="10" markerwidth="10" orient="auto" refx="9" refy="3"> <path d="M0,0 L10,3 L0,6 z" fill="#334155"></path> </marker> </defs> <rect fill="#e0f2fe" height="92" rx="10" stroke="#0284c7" stroke-width="1.5" width="170" x="24" y="92"></rect> <text fill="#0c4a6e" font-size="16" font-weight="700" x="44" y="124">FullStore</text> <text fill="#075985" font-size="12" x="44" y="148">HTTP POST</text> <text fill="#075985" font-size="12" x="44" y="166">getVendas</text> <rect fill="#f1f5f9" height="120" rx="10" stroke="#64748b" stroke-width="1.5" width="210" x="302" y="78"></rect> <text fill="#1e293b" font-size="16" font-weight="700" x="326" y="110">isnapp</text> <text fill="#334155" font-size="12" x="326" y="134">controle.php</text> <text fill="#334155" font-size="12" x="326" y="152">PHP 7.3</text> <text fill="#334155" font-size="12" x="326" y="170">setSubmit()</text> <rect fill="#dcfce7" height="92" rx="10" stroke="#16a34a" stroke-width="1.5" width="190" x="654" y="28"></rect> <text fill="#14532d" font-size="16" font-weight="700" x="678" y="60">MySQL OSK</text> <text fill="#166534" font-size="12" x="678" y="84">PDV, Trocas</text> <text fill="#166534" font-size="12" x="678" y="102">Omni, filiais</text> <rect fill="#fef3c7" height="92" rx="10" stroke="#d97706" stroke-width="1.5" width="230" x="654" y="186"></rect> <text fill="#78350f" font-size="16" font-weight="700" x="678" y="218">SQL Server Linx/BI</text> <text fill="#92400e" font-size="12" x="678" y="242">LX\_ZERO\_300</text> <text fill="#92400e" font-size="12" x="678" y="260">W\_BI\_FAT\_VENDEDOR...</text> <line marker-end="url(#arr-cap02-comp)" stroke="#334155" stroke-width="2.2" x1="194" x2="298" y1="138" y2="138"></line> <text fill="#475569" font-size="11" x="210" y="124">CNPJ + periodo</text> <path d="M 512 120 L 650 75" fill="none" marker-end="url(#arr-cap02-comp)" stroke="#334155" stroke-width="2.2"></path> <text fill="#475569" font-size="11" x="540" y="82">CTEs + filiais</text> <path d="M 512 158 L 650 232" fill="none" marker-end="url(#arr-cap02-comp)" stroke="#334155" stroke-width="2.2"></path> <text fill="#475569" font-size="11" x="536" y="214">prepared statement</text> <path d="M 302 184 C 220 246, 94 238, 72 186" fill="none" marker-end="url(#arr-cap02-comp)" stroke="#334155" stroke-width="2"></path> <text fill="#475569" font-size="11" x="116" y="248">JSON success / message / data</text> <text fill="#64748b" font-size="12" x="24" y="296">Figura 1 - Componentes e fluxo de dados da integracao.</text> </svg></figure></div>## Stack

<div class="pw" id="bkmrk-camada-tecnologia-de"><div class="tw"><table><thead><tr><th>Camada</th><th>Tecnologia</th><th>Detalhe</th></tr></thead><tbody><tr><td>Linguagem</td><td>PHP **7.3**</td><td>Namespaces, PDO, Traits</td></tr><tr><td>Framework</td><td>CodeIgniter (`MY_Controller`)</td><td>Base do backend</td></tr><tr><td>Banco operacional</td><td>MySQL / PDO</td><td>PDV, Omni, Trocas</td></tr><tr><td>Banco E-commerce</td><td>SQL Server / PDO `sqlsrv:`</td><td>Linx `LX_ZERO_300`</td></tr><tr><td>Resposta</td><td>JSON via `setSubmit()`</td><td>Envelope padrão `success / message / data`</td></tr></tbody></table>

</div></div>## Hierarquia de classes

<div class="pw" id="bkmrk-biblioteca-base-do-l"><figure id="bkmrk-fullstore-classes" style="margin: 1.25em 0;"><svg aria-label="Hierarquia de classes e dependências do endpoint FullStore" font-family="system-ui, Segoe UI, Roboto, sans-serif" role="img" style="max-width: 100%; height: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;" viewbox="0 0 1080 360" xmlns="http://www.w3.org/2000/svg"> <defs> <marker id="bkmrk--2" markerheight="10" markerwidth="10" orient="auto" refx="9" refy="3"> <path d="M0,0 L10,3 L0,6 z" fill="#334155"></path> </marker> </defs> <rect fill="#f1f5f9" height="62" rx="10" stroke="#64748b" stroke-width="1.5" width="200" x="34" y="30"></rect> <text fill="#1e293b" font-size="14" font-weight="700" x="54" y="58">biblioteca</text> <text fill="#475569" font-size="11" x="54" y="76">base do loader</text> <rect fill="#e0f2fe" height="70" rx="10" stroke="#0284c7" stroke-width="1.5" width="220" x="34" y="146"></rect> <text fill="#0c4a6e" font-size="14" font-weight="700" x="54" y="176">fullStoreService</text> <text fill="#075985" font-size="11" x="54" y="195">carrega classe por UUID/token</text> <rect fill="#f1f5f9" height="62" rx="10" stroke="#64748b" stroke-width="1.5" width="200" x="344" y="30"></rect> <text fill="#1e293b" font-size="14" font-weight="700" x="364" y="58">utilOsk</text> <text fill="#475569" font-size="11" x="364" y="76">PDO MySQL OSK</text> <rect fill="#ede9fe" height="82" rx="10" stroke="#7c3aed" stroke-width="1.5" width="288" x="344" y="146"></rect> <text fill="#4c1d95" font-size="14" font-weight="700" x="364" y="176">WOSK\\fullStoreService\\WebService</text> <text fill="#5b21b6" font-size="11" x="364" y="196">valida, consulta canais e monta resposta</text> <rect fill="#dcfce7" height="70" rx="10" stroke="#16a34a" stroke-width="1.5" width="250" x="704" y="42"></rect> <text fill="#14532d" font-size="14" font-weight="700" x="724" y="72">WOSK\\Commons\\WebService</text> <text fill="#166534" font-size="11" x="724" y="91">trait: setSubmit(), logs</text> <rect fill="#fef3c7" height="70" rx="10" stroke="#d97706" stroke-width="1.5" width="220" x="704" y="186"></rect> <text fill="#78350f" font-size="14" font-weight="700" x="724" y="216">db\_sqlserver</text> <text fill="#92400e" font-size="11" x="724" y="235">PDO sqlsrv para e-commerce</text> <line marker-end="url(#arr-cap02-class)" stroke="#334155" stroke-width="2" x1="134" x2="134" y1="92" y2="142"></line> <line marker-end="url(#arr-cap02-class)" stroke="#334155" stroke-width="2" x1="444" x2="444" y1="92" y2="142"></line> <path d="M 632 176 C 664 136, 688 98, 700 82" fill="none" marker-end="url(#arr-cap02-class)" stroke="#334155" stroke-width="2"></path> <text fill="#475569" font-size="11" x="636" y="132">usa trait</text> <path d="M 632 204 C 662 214, 680 220, 700 220" fill="none" marker-end="url(#arr-cap02-class)" stroke="#334155" stroke-width="2"></path> <text fill="#475569" font-size="11" x="636" y="236">instancia</text> <text fill="#334155" font-size="13" font-weight="700" x="34" y="314">Cadeia principal</text> <text fill="#475569" font-size="12" x="34" y="336">biblioteca -&gt; fullStoreService / utilOsk -&gt; WOSK\\fullStoreService\\WebService -&gt; trait + db\_sqlserver</text> </svg></figure></div>## Arquivos required

Em `controle.php`, carregamos três dependências via `require_once(APPPATH . '...')`:

<div class="pw" id="bkmrk-uuid-arquivo-fornece"><div class="tw"><table style="width: 100%;"><thead><tr><th style="width: 13.8292%;">UUID</th><th style="width: 15.253%;">Arquivo</th><th style="width: 70.9178%;">Fornece</th></tr></thead><tbody><tr><td style="width: 13.8292%;">`4cb18a6c-...`</td><td style="width: 15.253%;">`wosk_webservice.php`</td><td style="width: 70.9178%;">Trait `WOSK\Commons\WebService` — formata JSON (`setSubmit`), valida campos e salva logs no MySQL</td></tr><tr><td style="width: 13.8292%;">`592ccfa0-...`</td><td style="width: 15.253%;">`utilOsk.php`</td><td style="width: 70.9178%;">Classe pai — conecta ao MySQL OSK e expõe `$this->conexao` (PDO)</td></tr><tr><td style="width: 13.8292%;">`0670acec-...`</td><td style="width: 15.253%;">`db_sqlserver.php`</td><td style="width: 70.9178%;">Gerencia conexão PDO com SQL Server (driver `sqlsrv:`)</td></tr></tbody></table>

</div></div>## Conexão MySQL

<div class="pw" id="bkmrk-como-configuramos"><div class="card"><div class="ct">Como configuramos</div></div></div>A classe `utilOsk` chama `getConfiguracao('db_osk_prod')` — credenciais armazenadas em Base64 na tabela de configuração do sistema. Em seguida, `_setConexao()` cria a conexão PDO:

```
// connection string:
"mysql:host={host};port={porta};dbname={banco}"
// PDO::ATTR_PERSISTENT  = true   (conexão persistente)
// PDO::ATTR_TIMEOUT     = 120    (timeout em segundos)
// charset               = UTF-8
```

## Conexão SQL Server

<div class="pw" id="bkmrk-instanciamos-em-busc"><div class="card"><div class="ct">Instanciamos em buscarDadosEcommercePorLoja()</div></div></div>```
$sqlserver = new \db_sqlserver(false, 'LX_ZERO_300', true);
// false  = produção (não homologação)
// 'LX_ZERO_300' = banco Linx
// true   = conecta imediatamente
```

<div class="pw" id="bkmrk-ambiente-host-porta-"><div class="card"></div><div class="tw"><table><thead><tr><th>Ambiente</th><th>Host</th><th>Porta</th><th>Banco</th></tr></thead><tbody><tr><td>**Produção**</td><td>`<HOST_SQLSERVER_PROD>`</td><td>`<PORTA_PROD>`</td><td>`LX_ZERO_300`</td></tr><tr><td>Homologação</td><td>`<HOST_SQLSERVER_HML>`</td><td>`<PORTA_HML>`</td><td>`LINX_HMLG`</td></tr></tbody></table>

</div><div class="db">**Credenciais hardcoded** As credenciais do SQL Server ficam em `db_sqlserver.php`. </div></div>## Tabelas MySQL utilizadas

<div class="pw" id="bkmrk-tabela-alias-o-que-f"><div class="tw"><table><thead><tr><th>Tabela</th><th>Alias</th><th>O que fornece</th></tr></thead><tbody><tr><td>`movimentacao`</td><td>m</td><td>Cabeçalho da transação (tipo, data, situação, módulo)</td></tr><tr><td>`movimentacao_detalhe`</td><td>md</td><td>Itens da venda (produto, qtde, preço)</td></tr><tr><td>`movimentacao_nfe`</td><td>nf / nfe</td><td>Número, série e situação da NF-e</td></tr><tr><td>`movimentacao_movimentacao`</td><td>mm</td><td>Vínculos entre movimentações (troca↔venda, omni↔orçamento)</td></tr><tr><td>`pessoa`</td><td>v</td><td>Nome e código do vendedor</td></tr><tr><td>`entidade`</td><td>e</td><td>Código da filial / loja</td></tr><tr><td>`juridica`</td><td>j</td><td>CNPJ da empresa</td></tr></tbody></table>

</div></div>## Objetos SQL Server utilizados

<div class="pw" id="bkmrk-objeto-tipo-o-que-fo"><div class="tw"><table><thead><tr><th>Objeto</th><th>Tipo</th><th>O que fornece</th></tr></thead><tbody><tr><td>`W_BI_FAT_VENDEDOR_VDK_OMNI_V0`</td><td>View BI</td><td>Pedidos e-commerce por vendedor: NF, valor, CPF, filial, pedido site/WMS</td></tr><tr><td>`FILIAIS`</td><td>Tabela</td><td>Cadastro de filiais — usamos para excluir franquias (`TIPO_FILIAL <> 'FRANQUIA'`)</td></tr></tbody></table>

</div>  
</div>