if ($linhastomador == 0) {
    $pdf->MultiCell(0, 6, 'SEM VALORES NA RETENÇÃO COMO TOMADOR TOMADOR LANÇADOS', 0, "J", 1);
} else {
    $pdf->Cell(3, 1, "RETENÇÃO COMO TOMADOR: ", 0, 0, "L", 1);
}
$pdf->Ln(3);
$pdf->SetFont($Letra, '', 8);
if ($linhastomador != 0) {
    $total = 0;
    $totali = 0;
    $totalvp = 0;
    for ($t = 0; $t < $linhastomador; $t++) {
        db_fieldsmemory($resulttomador, $t);
        $pdf->SetFillColor(200);
        $pdf->Cell(26, 6, 'Mês: ' . db_mes($w08_mes), 1, 0, "L", 1);
        $pdf->Cell(50, 6, 'CPF ou CNPJ: ' . db_cgccpf($w08_cnpj), 1, 0, "L", 1);
        $pdf->Cell(114, 6, 'Nome ou Razão Social: ' . $w08_nome, 1, 1, "L", 1);
        $pdf->SetFillColor(235);
        $pdf->Cell(114, 6, 'Serviço: ' . $w08_servico, 1, 0, "L", 0);
        $pdf->Cell(38, 6, 'Nota: ' . $w08_nota, 1, 0, "L", 0);
        $pdf->Cell(38, 6, 'Serie: ' . $w08_serie, 1, 1, "L", 0);
        $pdf->Cell(38, 6, 'Valor: ' . db_formatar($w08_valreceita, 'f'), 1, 0, "L", 0);
        $pdf->Cell(38, 6, 'Alíquota: ' . $w08_aliquota . " %", 1, 0, "L", 0);
        $pdf->Cell(38, 6, 'Imposto: ' . db_formatar($w08_imposto, 'f'), 1, 0, "L", 0);
        $pdf->Cell(38, 6, 'Data do pagto: ' . ($w09_dtpaga != '' ? db_formatar($w09_dtpaga, 'd') : 'não efetuado'), 1, 0, "L", 0);
        $pdf->Cell(38, 6, 'Valor pago: ' . ($w09_valpago != '' ? db_formatar($w09_valpago, 'f') : 'nâo efetuado'), 1, 1, "L", 0);
        $total += $w08_valreceita;
        $totali += $w08_imposto;
        //if ($w09_valpago!='')
        $totalvp += $w09_valpago;
    }
if (isset($planilha)) {
    if ($planilha != "" || $planilha != 0) {
        $sql = "select *,\n\t\t\t\t\t\t\t\t\t\tcase when q21_tipolanc = 1 then 'Tomado' \n\t\t\t\t\t\t\t\t\t\t\t\telse 'Prestado' \n\t\t\t\t\t\t\t\t\t\tend as tipolanc\n\t\t\t\t\t\t\t\t\tfrom issplanit \n\t\t\t\t\t\t\t\t\tleft join issplanitinscr on q21_sequencial=q31_issplanit \n\t\t\t\t\t\t\t\t\twhere q21_planilha= {$planilha} and q21_status = 1\n\t\t\t\t\t\t\t\t\torder by q21_tipolanc,q21_datanota";
        //monta_tabela($sql,$parametro);
        //die($sql);
        $resultx = db_query($sql);
        $linhax = pg_num_rows($resultx);
        // db_msgbox("nnnnnnnnnnn".$int_max." lin=".$linhax);
        if ($linhax > 0) {
            if ($linhax > $int_max) {
                db_msgbox("Voce deve criar outra planilha");
                echo "<script> document.form1.grava.style.visibility='hidden';\n\t\t\t\t\t    </script>";
            }
            for ($x = 0; $x < $linhax; $x++) {
                db_fieldsmemory($resultx, $x);
                echo "\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'center'>{$tipolanc}</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'center'>{$q31_inscr}</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'left'>" . db_cgccpf($q21_cnpj) . "</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'left'>{$q21_nome}</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'center'>{$q21_nota}</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'center'>{$q21_serie}</td>\n\t\t\t\t\t\t\t\t";
                if ($q21_datanota != "") {
                    echo "<td align= 'center'>" . db_formatar($q21_datanota, "d") . "</td>";
                } else {
                    echo "<td align= 'center'></td>";
                }
                echo "\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'right'>" . db_formatar($q21_valorbase, 'f') . "</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'center'>{$q21_aliq}%</td>\n\t\t\t\t\t\t\t\t\t\t\t<td align= 'right'>" . db_formatar($q21_valor, 'f') . "</td>\n\t\t\t\t\t\t\t\t\t\t\t<td width= '150px'>\n\t\t\t\t\t\t\t      \t  <input class=\"botao\" name=\"alterar teste\" type=\"button\" value=\"Alterar\" onClick=\"js_alterar('{$q31_sequencial}','{$q31_inscr}','{$q21_sequencial}','{$q21_planilha}','{$q21_cnpj}','{$q21_nome}','{$q21_servico}','{$q21_nota}','{$q21_serie}','{$q21_valorser}','{$q21_aliq}','{$q21_valor}','{$q21_tipolanc}','{$q21_situacao}','{$q21_valordeducao}','{$q21_valorbase}','{$q21_retido}','{$q21_obs}','{$q21_valorimposto}', '" . db_formatar($q21_datanota, "d") . "')\">\n\t\t\t\t\t\t\t\t\t\t  \t<input class=\"botao\" name=\"excluir\" type=\"submit\" value=\"Excluir\" onClick=\"js_excluir('{$q21_sequencial}','{$q31_sequencial}')\">\n\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\n";
            }
        }
    }
    echo "<script> document.form1.proximo.style.visibility='visible'; </script>";
}
if (isset($z01_numcgm) and $z01_numcgm != "") {
    echo "<script> document.form1.z01_numcgm.value = {$z01_numcgm};</script>";
}
?>
 if (!$cabec) {
     $pdf->Cell(0, 21, '', "TB", 0, 'C');
     $pdf->Text($X, $Y, "Numcgm:");
     $pdf->Text($X + 40, $Y, $outros);
     $pdf->Text($X, $Y + 4, "Nome:");
     $pdf->Text($X, $Y + 8, "CNPJ/CPF:");
     $pdf->Text($X + 45, $Y + 8, "Identidade:");
     $pdf->Text($X, $Y + 12, "Endereço:");
     $pdf->Text($X + 110, $Y + 12, "Número:");
     $pdf->Text($X + 155, $Y + 12, "Complemento:");
     $pdf->Text($X, $Y + 16, "Município:");
     $pdf->Text($X + 55, $Y + 16, "UF:");
     $pdf->SetFont('Arial', 'I', 8);
     $pdf->Text($X + 18, $Y, pg_result($dados, 0, "z01_numcgm"));
     $pdf->Text($X + 18, $Y + 4, pg_result($dados, 0, "z01_nome"));
     $pdf->Text($X + 18, $Y + 8, db_cgccpf(pg_result($dados, 0, "z01_cgccpf")));
     $pdf->Text($X + 18 + 45, $Y + 8, pg_result($dados, 0, "z01_ident"));
     $pdf->Text($X + 18, $Y + 12, pg_result($dados, 0, "z01_ender"));
     $pdf->Text($X + 130, $Y + 12, pg_result($dados, 0, "z01_numero"));
     $pdf->Text($X + 180, $Y + 12, pg_result($dados, 0, "z01_compl"));
     $pdf->Text($X + 18, $Y + 16, pg_result($dados, 0, "z01_munic"));
     $pdf->Text($X + 18 + 45, $Y + 16, pg_result($dados, 0, "z01_uf"));
     $pdf->SetXY(5, 60);
     $cabec = true;
 }
 $pdf->SetFont('arial', 'B', 6);
 $pdf->Cell(2, 5, " ", 0, 0, "C", 0);
 $pdf->Cell($TamNumpar, 5, "P", 1, 0, "C", 0);
 $pdf->Cell($TamNumtot, 5, "T", 1, 0, "C", 0);
 $pdf->Cell(13, 5, "OPER.", 1, 0, "C", 0);
 $pdf->Cell(13, 5, "VENC.", 1, 0, "C", 0);
				</th>
				<th>
					Data de emissão
				</th>
				<th>
					
				</th>
				
			</tr>
			
<?php 
$result = $cldb_dairetido->sql_record($cldb_dairetido->sql_query("", "*", "w15_mes", "w15_dai = {$codigo}"));
$linhas = $cldb_dairetido->numrows;
for ($i = 0; $i < $linhas; $i++) {
    db_fieldsmemory($result, $i);
    echo "\n\t\t\t\t<tr class=\"texto\">\n\t\t\t\t<td>\n\t\t\t\t\t" . db_mes($w15_mes) . "\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t" . db_cgccpf($w15_cnpj) . " \n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t{$w15_nota}\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t{$w15_serie}\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t" . db_formatar($w15_valreceita, 'f') . "\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t" . ($w15_data != "" ? db_formatar($w15_data, 'd') : 'não efetuado') . "\n";
    if ($w15_data != "") {
        $data = split("-", $w15_data);
        $diadt[$i] = $data[2];
        $mesdt[$i] = $data[1];
        $anodt[$i] = $data[0];
    }
    echo "\t\t\t\t\t\n\t\t\t\t</td>\n\t\t\t\t<td width= \"140px\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t    <input name=\"alterar\" type=\"button\" value=\"Alterar\" onClick=\"js_alterar('{$w15_sequencial}','{$w15_mes}','{$w15_valreceita}','{$w15_nota}','{$w15_serie}','{$w15_cnpj}','{$diadt[$i]}','{$mesdt[$i]}','{$anodt[$i]}')\">\n\t\t\t\t\t\t\n\t\t\t\t\t<input name=\"excluir\" type=\"submit\" value=\"Excluir\" onClick=\"js_excluir('{$w15_sequencial}')\">\n   \t\t\t      \n\t\t\t\t  \t\t\t\t\t  \n\t\t\t\t</td>\n\t\t\t</tr>\n";
}
//do for
?>
		</table>
	</td>
</tr>

</table>