__________________________________________________ _________|
AÑO |MES |Nº DOC |DEBE |HABER |SALDO |
______|_____ |_______|_______|________|________|
2009 |11 | 2 | 6000| 6000| 0|
______|_____ |_______|_______|________|________|
2009 |12 | 1 | 8000| 0| 8000|
______|_____ |_______|_______|________|________|
2009 |TOTAL | 3 | 14000| 6000| 8000|
______|______|_______|_______|________|________|
2010 |1 | 2 | 11000| 0| 11000|
______|______|_______|_______|________|________|
2010 |TOTAL | 2 | 11000| 0| 11000|
______|______|_______|_______|________|________|
ahora bien coloque en rojo lo que esta malo, ya que enero debe tener el saldo que trae ese cliente del año anterior, y eso es lo que me a sacado canas verdesssssssssss porque no lo consigo hacerr hayyyyyyy voy a colocar el codigo a ver que me dicen ustedes que tengo malo
porrrfisssss ayudaaaaaaaaaaaaaaaa
Código PHP:
Ver original
$cSql=mysql_query("SELECT YEAR(FECHA) AS ANO, MONTH(FECHA) AS MES, COUNT(*) AS MOVIMIENTOS, SUM(IF(CXC= 1,NETO,0)) AS DEBE, SUM(IF(CXC=-1,NETO,0)) AS HABER, SUM(IF(CXC= 1,NETO,0))-SUM(IF(CXC=-1,NETO,0)) AS SALDO FROM CLIENTE WHERE CODIGO='0000000001' GROUP BY YEAR(FECHA),MONTH(FECHA) UNION ALL SELECT YEAR(FECHA) AS ANO, 'Total' AS MES, COUNT(*) AS MOVIMIENTOS, SUM(IF(CXC= 1,NETO,0)) AS DEBE, SUM(IF(CXC=-1,NETO,0)) AS HABER, SUM(IF(CXC= 1,NETO,0))-SUM(IF(CXC=-1,NETO,0)) AS SALDO FROM CLIENTE WHERE CODIGO='0000000001' GROUP BY YEAR(FECHA) ORDER BY ANO, MES") echo "<table width=150 border=1 align='center' bordercolor='#000000'>"; echo "<tr>"; echo "<td colspan=26 class=Estilo2>Año</td>"; echo "<td colspan=38 class=Estilo2>Mes</td>"; echo "<td colspan=30 class=Estilo2>Nº Docs</td>"; echo "<td colspan=40 class=Estilo2>Debe</td>"; echo "<td colspan=40 class=Estilo2>Haber</td>"; echo "<td colspan=40 class=Estilo2>Saldo</td>"; echo "</tr>"; $mes=$row["MES"]; if ($row["MES"]=='Total') { echo "<tr bgcolor=#cccccc>"; $debe+=$row["DEBE"]; $haber+=$row["HABER"]; $saldo+=$row["SALDO"]; $cuantos+=$row["CUANTOS"]; echo "<td colspan=26 class=Estilo2>".$row["ANO"]."</td>"; echo "<td colspan=38 class=Estilo2>".$mes."</td>"; echo "<td colspan=30 class=Estilo2 align='right'>".$row["CUANTOS"]."</td>"; echo "<td colspan=40 class=Estilo3 align='right'>".number_format($row["DEBE"], 2, ",", ".")."</td>"; echo "<td colspan=40 class=Estilo4 align='right'>".number_format($row["HABER"], 2, ",", ".")."</td>"; if ($row["SALDO"]==0){ echo "<td colspan=40 class=Estilo4 align='right'>".number_format($row["SALDO"], 2, ",", ".")."</td>"; }else { echo "<td colspan=40 class=Estilo3 align='right'>".number_format($row["SALDO"], 2, ",", ".")."</td>"; } echo "</tr>"; }//fin del if else { echo "<tr>"; echo "<td colspan=26 class=Estilo1>".$row["ANO"]."</td>"; echo "<td colspan=38 class=Estilo1>".$mes."</td>"; echo "<td colspan=30 class=Estilo1 align='right'>".$row["CUANTOS"]."</td>"; echo "<td colspan=40 class=Estilo3 align='right'>".number_format($row["DEBE"], 2, ",", ".")."</td>"; echo "<td colspan=40 class=Estilo4 align='right'>".number_format($row["HABER"], 2, ",", ".")."</td>"; if ($row["SALDO"]==0){ echo "<td colspan=40 class=Estilo4 align='right'>".number_format($row["SALDO"], 2, ",", ".")."</td>"; }else { echo "<td colspan=40 class=Estilo3 align='right'>".number_format($row["SALDO"], 2, ",", ".")."</td>"; } echo "</tr>"; }//fin del else }//fin del while echo "</table>";
ayudaaaaaaaaaaaaaaaaaaaaaaa