Tabela Dinamica com colunas mensais
Pessoal,
Preciso de uma ajuda. Sou iniciante em PHP e estou com o seguinte problema.
Tenho que montar um relatório vindo do mysql com uma tabela dinâmica, conforme abaixo:
Ele monta tudo certinho, só que as colunas da direita, devem apresentar o calculo da query "aprop" separado por mês/ano e de acordo com as parcelas que o associado tem, por ex:
MATRÍCULA NOME: CONTRATO/SEQ. DATA CONT. V.EMPR. JUROS TAXA PR-FAL V.TOTAL Q. PAR. V. P. JUL AGO SET OUT NOV DEZ JAN FEV 18765-9 JACIRO DE OLIVEIRA 12263/007 12/09/2016 750,00 30,00 30,00 16,40 826,40 4 206,60 15,00 15,00 15,00 15,00 838520-6 ROMEU MORAES BLOISE 12262/004 12/09/2016 600,00 24,00 24,00 16,40 664,40 4 166,10 12,00 12,00 12,00 12,00 874087-7 VERA MARIA LUCHESE 12265/029 06/06/2016 3.000,00 180,00 180,00 68,88 3.428,88 6 571,48 60,00 60,00 60,00 60,00 60,00 60,00 106460-5 ANNA MARIA REBELO 12264/019 07/06/2016 3.000,00 180,00 180,00 68,88 3.428,88 6 571,48 60,00 60,00 60,00 60,00 60,00 60,00 622210-9 MARCIA M M ´POLITI 12266/0114 08/06/2016 4.000,00 320,00 320,00 118,08 4.758,08 8 594,76 80,00 80,00 80,00 80,00 80,00 80,00 80,00 80,00 <?php require_once('../Connections/rs_con.php'); ?>
<?php
//preenchimento mês e ano
$sql = mysql_query("SELECT p.datavencimento, c.Matricula, c.Nome, p.contrato, c.DtContrato, c.VlrLiquido, c.VlrJuros, c.VlrTxServicos, c.VlrSeguro, (c.VlrLiquido + c.VlrJuros + c.VlrTxServicos + c.VlrSeguro) as Vtotal, c.QtdeParcelas, c.VlrParcela, (c.VlrJuros + c.VlrTxServicos)/c.QtdeParcelas as aprop FROM contratoemprestimo as c, parcemprestimo as p WHERE c.Id = p.contrato GROUP BY p.datavencimento ORDER BY p.datavencimento");
$linha = mysql_fetch_array($sql);
$totallinha = mysql_num_rows($sql);
// preenchimento da tabela
$sql2 = mysql_query("SELECT c.Matricula, c.Nome, c.Id, c.DtContrato, c.VlrLiquido, c.VlrJuros, c.VlrTxServicos, c.VlrSeguro, (c.VlrLiquido + c.VlrJuros + c.VlrTxServicos + c.VlrSeguro) as Vtotal, c.QtdeParcelas, c.VlrParcela, (c.VlrJuros + c.VlrTxServicos)/c.QtdeParcelas as aprop FROM contratoemprestimo as c, parcemprestimo as p WHERE c.Id = p.contrato GROUP BY p.matricula ");
$linha2 = mysql_fetch_array($sql2);
$totallinha2 = mysql_num_rows($sql2);
// preenchimento do calculo
$sql3 = mysql_query("SELECT p.datavencimento, (c.VlrJuros + c.VlrTxServicos)/c.QtdeParcelas as aprop FROM contratoemprestimo as c, parcemprestimo as p WHERE c.Id = p.contrato GROUP BY p.parcela ");
$linha3 = mysql_fetch_array($sql3);
$totallinha3 = mysql_num_rows($sql3);
echo "<table border='1'>";
echo "<th>". "Matrícula". "</th>";
echo "<th>". "Nome". "</th>";
echo "<th>". "Contrato". "</th>";
echo "<th>". "Dt Contr". "</th>";
echo "<th>". "V.Empr". "</th>";
echo "<th>". "Juros". "</th>";
echo "<th>". "Taxa". "</th>";
echo "<th>". "Fundo". "</th>";
echo "<th>". "VTotal". "</th>";
echo "<th>". "QtParc". "</th>";
echo "<th>". "V.Prest". "</th>";
while ($linha = mysql_fetch_array($sql)) {
echo "<th>". date('M/Y', strtotime($linha['datavencimento'])). "</th>";
//echo "<td>". $linha['aprop']. "</td>";
}
while ($linha2 = mysql_fetch_array($sql2)) {
echo "<tr><td>". $linha2['Matricula']. "</td>";
echo "<td>". $linha2['Nome']. "</td>";
echo "<td>". $linha2['Id']. "</td>";
echo "<td>". $linha2['DtContrato']. "</td>";
echo "<td>". $linha2['VlrLiquido']. "</td>";
echo "<td>". $linha2['VlrJuros']. "</td>";
echo "<td>". $linha2['VlrTxServicos']. "</td>";
echo "<td>". $linha2['VlrSeguro']. "</td>";
echo "<td>". $linha2['Vtotal']. "</td>";
echo "<td>". $linha2['QtdeParcelas']. "</td>";
echo "<td>". $linha2['VlrParcela']. "</td>";
echo "<td>". $linha2['aprop']. "</td></tr>";
}
echo "</table>";
?>
Ele está fazendo uma parte, mas não consigo plotar os valores nas células à direita, que seria o retorno do calculo de juros + taxa dividido pelas parcelas..
Alguém poderia ajudar ?
Discussão (0)
Carregando comentários...