<?php
require 'Conexao.php';
require 'dadosBoleto.php';
require_once 'tcpdf_barcodes_1d.php';
define("BASE_URL", "http://172.21.55.39/boleto2");

########################################################### TITULO ##########################################################################
$titulo = isset($_GET['titulo']) ? $_GET['titulo'] : null;
if (empty($titulo)){
    echo "TITULO NAO INFORMADO";
    exit;
}
########################################################### TITULO ##########################################################################

$Conexao = new Conexao();
$database = $Conexao->getConnection();

$boletoPf   = new dadosBoleto($database);
$topo       = $boletoPf->topoBoleto($titulo);
$corpo      = $boletoPf->corpoBoleto($titulo);
$codigo     = $boletoPf->codbarrasBoleto($titulo);

$barcodeobj = new TCPDFBarcode($codigo[0]['DIGITAVEL'], 'C128');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="pt-br">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<html>
	<head>

        <title>UNIMED SETE LAGOAS</title>

		<link rel="stylesheet" type="text/css" href="<?php echo BASE_URL; ?>/css/bootstrapv3.3.5.min.css" >
        <link href="<?php echo BASE_URL; ?>/css/imprMensa.css" rel="stylesheet" />

        <script src="js/jquery-3.4.1.min.js" crossorigin="anonymous"></script>
        <script src="js/image_to_data_url.js" crossorigin="anonymous"></script>
        <script src="js/html2canvas.js" crossorigin="anonymous"></script>
        <script src="js/jspdf.debug.js" crossorigin="anonymous"></script>

        <!-- <script src="js/jspdf.min.js"></script> -->
        <!-- <script src="js/FileReader.js" crossorigin="anonymous"></script> -->
        <!-- <script src="js/jspdf.js" crossorigin="anonymous"></script>
        <script src="js/base64.js" crossorigin="anonymous"></script>
        <script src="js/sprintf.js" crossorigin="anonymous"></script> -->
    </head>

    <style>
            @page { 
                size: auto;   /* auto is the initial value */
                /* margin: 0mm;  this affects the margin in the printer settings */
                margin-top: 3mm;
                margin-right: 5mm;
                margin-bottom: 0;
                margin-left: 5mm;
            }        
            @media print {
            .print-only { display: block; }
            
            body { 
                margin-top: 3mm;
                margin-right: 5mm;
                margin-bottom: 0;
                margin-left: 5mm;
                /* margin: 0; */
            }}
    </style>

<body> <!--  onload="window.print();ClosePrint();"> -->

    <div id="printableArea" >
        <table>
            <tr>
                <td> 
                    <table id="table-form2">
                        <tbody>
                            <tr>
                            <?php foreach($topo as $item): ?> 
                                <td style="width: 150px; border: none;" rowspan="3">
                                    <img src="<?php echo BASE_URL; ?>/img/unimed.png" alt="UNIMED SETE LAGOAS" width="150px" height="50px">
                                    <img src="<?php echo BASE_URL; ?>/img/ans.png" alt="UNIMED SETE LAGOAS" width="150px" height="35px">
                                </td>
                                <td style="border: none;" colspan="4" rowspan="3">
                                    <h1><b>UNIMED SETE LAGOAS COOPERATIVA DE TRABALHO MÉDICO</b></h1>
                                    <h2>RUA CORONEL RANDOLFO SIMÕES 281</h2>
                                    <h2>BOA VISTA - SETE LAGOAS - MG - CEP: 35700102</h2>
                                    <h2>Tel.: 31-2106-1900</h2>
                                    <h2>CNPJ: 24.014.235/0001-09 Insc. Municipal: 03.21118-5 </h2>
                                </td>
                                <td style="width: 8%;"><h3>Contrato: <br></h3><?php echo $item['CONTRATO'];?></td>
                                <td style="width: 8%;"><h3>Competência: </h3><?php echo $item['COMPETENCIA'];?></td>
                                <td style="width: 16%;" colspan="2"><h3>Emissão: </h3><?php echo date("d/m/Y", strtotime($item['EMISSAO']));?></td>
                            </tr>
                            <tr>
                                <td style="width: 8%;"><h3>Vencimento: </h3><?php echo date("d/m/Y", strtotime($item['VENCIMENTO']));?></td>
                                <td style="width: 8%;"><h3>Nº Fatura: </h3><?php echo $item['FATURA'];?></td>
                                <td style="width: 8%;"><h3>Nº Título: </h3><?php echo $item['TITULO'];?></td>
                                <td style="width: 8%;"><h3>Página:</h3>1</td>
                            </tr>
                            <tr>
                                <td style="width: 10%;" colspan="2"><h3>Agência/Código Cedente:</h3> <?php echo $item['AGENC_CEDENTE'];?></td>
                                <td style="width: 8%;"> <h3>Carteira:</h3> <?php echo $item['CARTEIRA'];?></td>
                                <td style="width: 10%;"><h3>Nosso Número:</h3> <?php echo $item['NOSSO_NUMERO'];?></td>
                            </tr>
                        </tbody>
                    </table>

                    <table id="table-form3">
                        <tbody>
                            <tr>
                                <td style="width: 5%;"><h4>Sacado:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['SACADO'];?></td>
                                <td style="width: 5%;"><h4>Telefone:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['TELEFONE'];?></td>
                            </tr>
                            <tr>
                                <td style="width: 5%;"><h4>Endereço:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['ENDERECO'];?></td>
                                <td style="width: 5%;"><h4>Bairro:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['BAIRRO'];?></td>
                            </tr>
                            <tr>
                                <td style="width: 5%;"><h4>Município:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['CIDADE'];?></td>
                                <td style="width: 5%;"><h4>Estado:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['ESTADO'];?></td>
                            </tr>
                            <tr>
                                <td style="width: 5%;"><h4>CNPJ:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['CNPJ'];?></td>
                                <td style="width: 5%;"><h4>Inscr.Estadual:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['JINSC_ESTADUAL'];?></td>
                            </tr>
                            <tr>
                                <td style="width: 5%;"><h4>Lotação:</h4></td>
                                <td colspan="2" style="width: 35%;"><?php echo $item['LOTACAO'];?></td>
                                <td style="width: 5%;"></td>
                                <td colspan="2" style="width: 35%;text-align: right;">RECIBO DO SACADO</td>
                                <?php endforeach;?>
                            </tr>
                        </tbody>
                    </table>     

                    <table id="table-form4">
                        <tbody>
                            <tr>
                                <td colspan="3" style="width: 150px;"><h4>DESCRIÇÃO</h4></td>
                                <td style="width: 50px;"><h4>VLR. UNITÁRIO</h4></td>
                                <td style="width: 50px;"><h4>VLR. TOTAL</h4></td>
                            </tr>

                            <tr>
                                <td  colspan="3" style="width: 150px; height:350px;border-bottom-color:white;">
                                    <?php foreach($corpo as $item): ?>
                                    <table id="table-form6">
                                            <?php echo '<tr><td style="font-size:11px;">'.$item['QTD'].' - ';?>
                                            <?php echo ' '.$item['DESCICAO_ITEM'].'</td></tr>';?>
                                    </table>
                                    <?php endforeach;?> 
                                    <table id="table-form6">
                                        <tr><td style="font-size:11px;"><strong>TOTAL</strong></td></tr>
                                    </table>
                                </td>
                                <td style="width: 50px; border-bottom-color:white;">
                                     <?php foreach($corpo as $item): ?>
                                     <table id="table-form6">
                                          <?php echo '<tr><td style="font-size:11px;"> R$ '.number_format($item['VALOR_UNIT'],2,',','.').'</td></tr>';?>
                                    </table>
                                     <?php endforeach;?>
                                </td>
                                <td style="width: 50px;border-bottom-color:white;">
                                    <?php foreach($corpo as $item): ?>
                                    <table id="table-form6">
                                        <?php echo '<tr><td style="font-size:11px;"> R$ '.number_format($item['VALOR_TOTAL'],2,',','.').'</td></tr>';?>
                                    </table>
                                    <?php endforeach;?>

                                   <?php foreach($corpo as $item): ?>
                                   <table id="table-form6">
                                        <strong><?php echo '<tr><td style="font-size:11px;"> R$ '.number_format($item['VALOR_TOTAL'],2,',','.').'</td></tr>';?></strong>
                                    </table>
                                   <?php endforeach;?>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3" style="width: 150px; border-top-color:white;border-bottom-color:white;">
                                    <h5>Valor aproximado dos tributos: PIS 0,65% COFINS 4% ISSQN 3%, com base na Lei 12.741/2012 e no Decreto 8.264/2014.</h5>
                                    <h5>Não reter CSLL conforme IN SRF nº 459, art. 5º de 18.10.2004.</h5>
                                </td>
                                <td style="width: 50px;white;border-bottom-color:white;"><h4></h4></td>
                                <td style="width: 50px;white;border-bottom-color:white;"><h4></h4></td>
                            </tr>
                            <tr>
                                <td style="width: 150px;height:100px; border-top-color:white;border-right-color:white;"><h4><strong>Tributo</strong></h4></td>
                                <td style="width: 15%;border-top-color:white;border-right-color:white;"><h4><strong>Base de Cálculo</strong></h4></td>
                                <td style="width: 15%;border-top-color:white;"><h4><strong>Percentual</strong></h4></td>
                                <td style="width: 15%;border-top-color:white;"><h4></h4></td>
                                <td style="width: 15%;border-top-color:white;"><h4></h4></td>
                            </tr>
                            <tr>
                                <td colspan="3" style="width: 150px;border-top-color:black; border-top:1px solid black;"><h4><strong>VALOR TOTAL</strong></h4></td>
                                <td style="width: 50px;"></td>
                                <td style="width: 50px;"><strong><?php foreach($corpo as $item): ?><?php echo " R$ " . number_format($item['VALOR_TOTAL'],2,',','.');?></BR> <?php endforeach;?></strong></td>
                            </tr>

                        </tbody>
                    </table>

                    <hr size="1" style="border:1px dashed black;">

                    <table id="table-form5">
                        <tbody>
                            <tr>
                                <td style="width: 25%;border-bottom:2px solid black;border-right:2px solid black;"><h3>BANCO SANTANDER</h3></td>
                                <td style="width: 7%;border-bottom:2px solid black;border-right:2px solid black;"><h3>033-7&emsp;</h3></td>
                                <td colspan="6" style="width:70%;border-right-color:white;border-bottom:2px solid black;"><h6 style="text-align:center"><?php foreach($topo as $item): ?><?php echo $item['DIGITAVEL'];?> <?php endforeach;?></h6></td>
                            </tr>
                            <tr>
                                <td colspan="7" style="width: 70%;"><h5>Local de Pagamento</h5><h3>Pagável em qualquer banco até o vencimento</h3></td>
                                <td style="width: 29.9%;"><h5>Vencimento</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo date("d/m/Y", strtotime($item['VENCIMENTO']));?> <?php endforeach;?></h4></td>
                            </tr>
                            <tr>
                                <td colspan="7"><h5>Beneficiário</h5><h3>UNIMED SETE LAGOAS COOPERATIVA DE TRABALHO MÉDICO CNPJ: 24.014.235/0001-09</h3></td>
                                <td><h5>Agência/Código Beneficiário</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo $item['AGENC_CEDENTE'];?> <?php endforeach;?></h4></td>
                            </tr>
                        </tbody>
                    </table>

                    <table id="table-form5">
                        <tbody>
                            <tr>
                                <td style="width: 8%;"><h5>Data do Documento</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo date("d/m/Y", strtotime($item['EMISSAO']));?> <?php endforeach;?></h4></td>
                                <td colspan="2" style="width: 16%;"><h5>Nº do Documento</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo $item['FATURA'];?> <?php endforeach;?></h4></td>
                                <td style="width: 3%;"><h5>Espécie Doc.</h5><h4 style="text-align:center;">DM</h4></td>
                                <td style="width: 3%;"><h5>Aceite</h5><h4 style="text-align:center;">N</h4></td>
                                <td style="width: 8.6%;"><h5>Data do Processamento</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo date("d/m/Y", strtotime($item['EMISSAO']));?> <?php endforeach;?></td>
                                <td style="width: 15.3%;"><h5>Nosso Número</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo $item['NOSSO_NUMERO'];?> <?php endforeach;?></td>

                            </tr>
                            <tr>
                                <td ><h5>Uso do Banco</h5><h4 style="text-align:center;">CNAB 400</h4></td>
                                <td ><h5>Carteira</h5><h4 style="text-align:center;"><?php foreach($topo as $item): ?><?php echo $item['CARTEIRA'];?> <?php endforeach;?></h4></td>
                                <td ><h5>Espécie</h5><h4 style="text-align:center;">R$</h4></td>
                                <td  colspan="2" ><h5>Quantidade</h5></td>
                                <td ><h5>Valor</h5></td>
                                <td><h5>(=)Valor do documento</h5><h4 style="text-align:center;">   
                                   <?php foreach($corpo as $item): ?><strong><?php echo number_format($item['VALOR_TOTAL'],2,',','.');?></BR> <?php endforeach;?></strong></h4></td>
                            </tr>
                        </tbody>
                    </table>

                    <table id="table-form5">
                        <tbody>
                            <tr>
                                <td rowspan="5" style="width: 30%;">
                                    <h5>Instruções:</h4>
                                    <h4>APÓS O VENCIMENTO COBRAR JUROS DE 0,03% AO DIA + MULTA DE 2%.</h4>
                                    <h4>ATÉ O VENCIMENTO PAGÁVEL EM QUALQUER AGÊNCIA BANCÁRIA OU CASA LOTÉRICA.</h4>
                                    <h4>APÓS O VENCIMENTO DIRIGIR-SE A AGÊNCIA DO SANTANDER.</h4>
                                    <h4>2ª VIA DESTE, DISPONÍVEL NO SITE: WWW.SANTANDER.COM.BR</h4>
                                    <h4></h4>
                                    <h4>Competência</h4>
                                </td>
                                <td style="width: 11.7%; height:40px;"><h5>(-)Desconto/Abatimento</h5></td>
                                
                            </tr>
                            <tr>
                                <td style="width: 11.5%; height:40px;"><h5>(-)Outras Deduções</h5></td>
                            </tr>
                            <tr>
                                <td style="width: 11.5%; height:40px;"><h5>(+)Mora/Multa</h5></td>
                            </tr>
                            <tr>
                                <td style="width: 11.5%; height:40px;"><h5>(+)Outros Acréscimos</h5></td>
                            </tr>
                            <tr>
                                <td style="width: 11.5%; height:40px;"><h5>(=)Valor Cobrado</h5></td>
                            </tr>
                        </tbody>
                    </table>
                    <table id="table-form5">
                        <tbody>
                            <tr>
                                <td rowspan="3" style="width: 5%;border-bottom:2px solid black;border-right:0px solid black;"><h4>Pagador:</h4></td>
                                <td style="border-right:0px solid black;border-bottom:0px solid black;"><h5 style="text-align:left;"><?php foreach($topo as $item): ?><?php echo $item['CONTRATO']."  ".$item['SACADO'];?> <?php endforeach;?></h5></td>
                                <td style="border-right:0px solid black;border-bottom:0px solid black;"><h5>CNPJ:</h5></td>
                            </tr>
                            <tr>
                                <td style="border-right:0px solid black;border-bottom:0px solid black;"><h5 style="text-align:left;"><?php foreach($topo as $item): ?><?php echo $item['ENDERECO']."      -       ".$item['BAIRRO'];?> <?php endforeach;?></h5></td>
                                <td style="border-right:0px solid black;border-bottom:0px solid black;"><h5></h5></td>
                            </tr>
                            <tr>
                                <td style="border-bottom:2px solid black;border-right:0px solid black;"><h5 style="text-align:left;"><?php foreach($topo as $item): ?><?php echo $item['CEP']."  ".$item['CIDADE'];?> <?php endforeach;?></h5></td>
                                <td style="border-bottom:2px solid black;border-right:0px solid black;font-weight: bold;"><h5>(145.<?=$item['CONTRATO']?>)</h5></td>
                            </tr>
                        </tbody>
                    </table>

                    <table id="table-form6">
                        <tbody>
                            <tr>
                                <td rowspan="2"><h5><div class="barras"><?=$barcodeobj->getBarcodeHTML(1.5, 60, 'black')?></div> </td>
                                <td><h5 style="font-size:11px;font-weight: bolder;"> Autenticação Mecânica</h5></td>
                            </tr>
                            <tr>
                                <td><h4 style="font-size:20px;font-weight: bolder;">Ficha de Compensação</h4></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>

