Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Problemas com relatório


carlosinss

Pergunta

Pessoal, preciso de uma ajuda, estou preparando um relatório que deve demonstrar o quantitativo de funcionários em cada situação por unidade de exercício. O primeiro select que fiz gera o total certo, usei o count no cpf e group by no setor de exercício, depois acresceitei situação no group by e a contagem vem certa porém a exibição repete a unidade de exercicio para cada situação e preciso que a exibição seja uma unidade de exercício por linha e as situações nas colunas.

Eis o codigo:

<?
   $x  = "SELECT cod_lot, cod_sitcad, COUNT(cpf) as cpf  FROM servativ GROUP BY cod_lot, cod_sitcad ORDER BY substring(cod_lot,3,2), cod_lot";
   $Rcpf = mysql_query($x);  
?>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#808040" width="100%" id="AutoNumber1">
    <tr>
      <td  align='center' style='font-family:verdana; font-size:12pt'><font face="Tahoma" size="4" color="#333300">SISGEP 
        - Sistema de Gestão de Pessoas</font></td>
    </tr>
    <tr> 
      <td width="100%"  align='center' style='font-family:verdana; font-size:12pt'><b><font size="2">Força 
        de Trabalho</font></b></td>
    </tr>
    <tr> 
      <td  align='center' style='font-family:verdana; font-size:12pt'> </td>
    </tr>
  </table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#F1F1E2" width="100%" id="AutoNumber1">
  <tr> 
  <table class="thin sortable draggable" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#F1F1E2" width="100%" id="AutoNumber2" >
    <tr bgcolor="#DBDBB7"> 
      <td width="10%"><div align="center"><strong>Lotação</strong></div></td>
      <td width="25%"> <strong>Descrição da lotação</strong></td>
      <td width="7%"><div align="center"><strong>Ativos</strong></div></td>
      <td width="7%" align='center'><div align="left"></div>
        <strong>Requisitados</strong> </td>
      <td width="7%" align='center'><strong>Nomeados</strong></td>
      <td width="7%" align='center'><strong>Ex. descentr.</strong></td>
      <td width="7%" align='center'><strong>Estagiários</strong></td>
      <td width="7%" align='center'><strong>Terceirizados</strong></td>
      <td width="7%" align='center'><strong>Militares</strong></td>
      <td width="11%" align='center'><strong>Total</strong></td>
    </tr>
    <?
      if (mysql_num_rows($Rcpf)>0)
       {
         while ($qcpf = mysql_fetch_array($Rcpf))
           {
             $tot = $qcpf['cpf'];
        
               $pesquisa = "SELECT descricao from tabsetor where codigo = '$qcpf[cod_lot]' ";
                                                 $result = mysql_query($pesquisa);
             $dlot = @mysql_result($result,0,0);
             
                      
             echo "
             <tr onmouseover='pinta(1,this)' onmouseout='pinta(2,this)' height='18'>
              <td align='center'><a href='pesservidor2.php?var1=$qcpf[cod_lot]'>$qcpf[cod_lot]</a></td>
              <td>$dlot</td>
              <td align='center'>$tot</td>
              <td align='center'></td>
              <td align='center'></td>
              <td align='center'></td>
              <td align='center'></td>
              <td align='center'></td>
                                                  <td align='center'></td>
              <td align='center'>$tot</td>             
              </tr>";
             } 
       }
       
    
      ?>

Editado por Jonathan Queiroz
Remover caixa alta do título e descrição conforme regra 3.7 e adicionar tag's (Jonathan)
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Pessoal, o colega Edinalvo conseguiu uma solução ficou assim o código.

// seleciona, agrupando, os codigos de situacao

$x = "SELECT cod_sitcad FROM servativ GROUP BY cod_sitcad ORDER BY cod_sitcad ";

$Rsitcad = mysql_query($x);

if ($Rsitcad)

{

$x = "SELECT excluido, cod_lot";

while ($dados = mysql_fetch_object($Rsitcad))

{

$cod = $dados->cod_sitcad;

$x .= ", SUM(IF(excluido = 'N' && cod_sitcad='$cod',1,0)) AS c$cod";

}

$x .= " FROM servativ GROUP BY cod_lot ORDER BY SUBSTRING(cod_lot,3,2), cod_lot, cod_sitcad ";

}

$Rcpf = mysql_query($x);

?>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

<html>

<head>

<title>SISGEP <? echo date("d/m/Y"); ?></title>

<meta name="generator" content="editplus">

<meta name="author" content="">

<meta name="keywords" content="">

<meta name="description" content="">

<link rel="stylesheet" type="text/css" href="estiloIE.css">

<script language="javascript" src="funcoes.js"></script>

<script src="sorttable.js"></script>

<script LANGUAGE="JavaScript">

<!--

function pinta(arg1, arg2)

{

if (arg1==1)

arg2.style.backgroundColor = '#FFD782';

else

arg2.style.backgroundColor = '#ffffff';

}

//-->

</SCRIPT>

</head>

<body topmargin=0 >

<script language=JavaScript src="frames_body_array.js" type=text/javascript></script>

<script language=JavaScript src="mmenu.js" type=text/javascript></script>

<form action="" method="post" AUTOCOMPLETE="OFF">

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#808040" width="100%" id="AutoNumber1">

<tr>

<td align='center' style='font-family:verdana; font-size:12pt'><font face="Tahoma" size="4" color="#333300">SISGEP

- Sistema de Gest&atilde;o de Pessoas</font></td>

</tr>

<tr>

<td width="100%" align='center' style='font-family:verdana; font-size:12pt'><b><font size="2">For&ccedil;a

de Trabalho</font></b></td>

</tr>

<tr>

<td align='center' style='font-family:verdana; font-size:12pt'>&nbsp;</td>

</tr>

</table>

<tr>

<table class="thin sortable draggable" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#F1F1E2" width="100%" id="AutoNumber2" >

<tr bgcolor="#DBDBB7">

<td width="8%"><div align="center"><strong>Lotação</strong></div></td>

<td width="25%"> <strong>Descri&ccedil;&atilde;o da lota&ccedil;&atilde;o</strong></td>

<td width="6%"><div align="center"><strong>Ativos</strong></div></td>

<td width="6%"><div align="center"><strong>Cedidos</strong></div></td>

<td width="6%" align='center'><div align="left"></div><strong>Requisitados</strong> </td>

<td width="6%" align='center'><strong>Nomeados</strong></td>

<td width="6%" align='center'><strong>Ex. descentr.</strong></td>

<td width="6%" align='center'><strong>Estagi&aacute;rios</strong></td>

<td width="6%" align='center'><strong>Terceirizados</strong></td>

<td width="6%" align='center'><strong>Militares</strong></td>

<td width="11%" align='center'><strong>Total</strong></td>

</tr>

<?

if (mysql_num_rows($Rcpf)>0)

{

//

$sitTotal = array();

$sitTotal['c01'] = 0; // ativos

$sitTotal['c08'] = 0; // cedidos

$sitTotal['c03'] = 0; // requisitados

$sitTotal['c14'] = 0; // requisitados

$sitTotal['c04'] = 0; // nomeados

$sitTotal['c18'] = 0; // exercicio descentralizado

$sitTotal['c66'] = 0; // estagiarios

$sitTotal['c99'] = 0; // terceirizados

$sitTotal['c35'] = 0; // militares

while ($qcpf = mysql_fetch_array($Rcpf))

{

$sitTotal['c01'] += $qcpf['c01']; // ativos

$sitTotal['c08'] += $qcpf['c08']; // cedidos

$sitTotal['c03'] += $qcpf['c03']; // requisitados

$sitTotal['c14'] += $qcpf['c14']; // requisitados

$sitTotal['c04'] += $qcpf['c04']; // nomeados

$sitTotal['c18'] += $qcpf['c18']; // exercicio descentralizado

$sitTotal['c66'] += $qcpf['c66']; // estagiarios

$sitTotal['c99'] += $qcpf['c99']; // terceirizados

$sitTotal['c35'] += $qcpf['c35']; // militares

$tot = $qcpf['c01'] + $qcpf['c08'] + $qcpf['c03'] + $qcpf['c04'] + $qcpf['c14'] + $qcpf['c18'] + $qcpf['c66'] + $qcpf['c99'] + $qcpf['c35'];

$tot_geral += $tot;

$pesquisa = "SELECT descricao from tabsetor where codigo = '$qcpf[cod_lot]' ";

$result = mysql_query($pesquisa);

$dlot = @mysql_result($result,0,0);

echo "

<tr onmouseover=pinta(1,this)' onmouseout='pinta(2,this)' height='18'>

<td align='center'><a href='pesservidor2.php?var1=$qcpf[cod_lot]'>$qcpf[cod_lot]</a></td>

<td>$dlot</td>

<td width='8%' align='center'>".number_format($qcpf['c01],0,',','.')."</td>

<td width='8%' align='center'>".number_format($qcpf['c08'],0,',','.')."</td>

<td width=8%' align='center'>".number_format(($qcpf['c03]+$qcpf['c14']),0,',','.')."</td>

<td width=8%' align='center'>".number_format($qcpf['c04],0,',','.')."</td>

<td width='8%' align='center'>".number_format($qcpf['c18'],0,',','.')."</td>

<td width=8%' align='center'>".number_format($qcpf['c66],0,',','.')."</td>

<td width='8%' align='center'>".number_format($qcpf['c99'],0,',','.')."</td>

<td width=8%' align='center'>".number_format($qcpf['c35],0,',','.')."</td>

<td width='12%' align='center'>".number_format($tot,0,',','.')."</td>

</tr>";

}

}

?>

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...