ahi lo pude ahcer :P
pongo el codigo para futuros novatos como yo ajaja
.. falta arreglar los subtotales no mas...
Código PHP:
<style type="text/css">
<!--
.Estilo1 {
font-family: Tahoma;
font-size: 12px;
color: #333;
font-weight: bold;
}
.Estilo2 {
font-family:"Courier New";
font-size: 12px;
color: #333;
font-weight:normal;
}
.subtotales {
font-family:"Courier New";
font-size: 13px;
color: #000000;
font-weight:bold;
border-bottom:1px #E1E1E1 solid;
border-top:1px #E1E1E1 solid;
background-color:#E1E1E1;
}
.encabezado_subdiario {
font-family:"Tahoma";
font-size: 12px;
color: #000000;
font-weight:bold;
}
-->
</style>
<!-- Cabecera -->
<table width="100%" border="0" cellpadding="0" cellspacing="0" height="50" >
<tr>
<td colspan="2" style=" height:25px;" valign="middle" align="center"><div class="Estilo1">Electromecánica Tacuar</div> </td>
</tr>
<tr>
<td style=" height:25px;" valign="middle"> <div class="Estilo1">Sub-diario de ventas</div></td>
<td style=" height:25px;" valign="middle"> <div class="Estilo1" align="right" style="padding-right:10px;">Fecha: xx/xx/xx</div></td>
</tr>
</table>
<!-- Fin Cabecera -->
<div style="height:5px; border-bottom:#000000 2px solid;"> </div>
<!-- detalles -->
<table width="100%" border="0" cellpadding="0" cellspacing="0" height="50" >
<tr>
<td width="11%" valign="top" style=" height:25px;"> <div class="Estilo1">Fecha</div></td>
<td width="19%" valign="top" style=" height:25px;"> <div class="Estilo1" align="left" >Nro.Comprobante</div></td>
<td width="10%" valign="top" style=" height:25px;"> <div class="Estilo1">Código</div></td>
<td width="36%" valign="top" style=" height:25px;"> <div class="Estilo1" align="left" >Detalle</div></td>
<td width="12%" valign="top" style=" height:25px;"> <div class="Estilo1">DEBE</div></td>
<td width="12%" valign="top" style=" height:25px;"> <div class="Estilo1" align="left">HABER</div></td>
</tr>
<?
$sql_maxGrupos = "SELECT subdiario_ventas1.Emp_cta_deudores
FROM
`db_tacuar`.`subdiario_ventas` subdiario_ventas1 INNER JOIN `db_tacuar`.`cuentas` cuentas1 ON subdiario_ventas1.`Emp_cta_deudores` = cuentas1.`Cta_codigo`
GROUP BY `Emp_cta_deudores`";
$result_maxGrupos = mysql_query($sql_maxGrupos);
$maximo_grupos = mysql_num_rows($result_maxGrupos);
$sql = "
SELECT
subdiario_ventas1.`Id_venta`,
subdiario_ventas1.`Fecha`,
subdiario_ventas1.`Cte_codigo`,
subdiario_ventas1.`tipo_fac`,
subdiario_ventas1.`Suc_factura`,
subdiario_ventas1.`nro_factura`,
subdiario_ventas1.`Id_cliente`,
subdiario_ventas1.`empresa`,
subdiario_ventas1.`Emp_cta_deudores`,
subdiario_ventas1.`Importe`,
subdiario_ventas1.`Item`,
cuentas1.`Cta_detalle`
FROM
`db_tacuar`.`subdiario_ventas` subdiario_ventas1 INNER JOIN `db_tacuar`.`cuentas` cuentas1 ON subdiario_ventas1.`Emp_cta_deudores` = cuentas1.`Cta_codigo`
WHERE
subdiario_ventas1.Fecha BETWEEN '2009-05-01' AND '2009-05-31'
GROUP BY Cte_codigo, tipo_fac, nro_factura, Id_cliente, Cta_detalle
#GROUP BY Cta_detalle
ORDER BY
subdiario_ventas1.`Fecha` ASC, subdiario_ventas1.`tipo_fac` ASC, subdiario_ventas1.`Suc_factura` ASC, subdiario_ventas1.`nro_factura` ASC, subdiario_ventas1.`Id_venta` ASC, subdiario_ventas1.`Item` ASC
#limit 23
";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$Cte_codigo_ante = $Cte_codigo;
$tipo_fac_ante = $tipo_fac;
$nro_factura_ante = $nro_factura;
$Id_cliente_ante = $Id_cliente;
$Cta_detalle_ante = $Cta_detalle;
$Emp_cta_deudores_ante = $Emp_cta_deudores;
$id_venta_ante = $id_venta;
$Cte_codigo = $row['Cte_codigo'];
$tipo_fac = $row['tipo_fac'];
$nro_factura = $row['nro_factura'];
$Id_cliente = $row['Id_cliente'];
$Cta_detalle = $row['Cta_detalle'];
$Emp_cta_deudores = $row['Emp_cta_deudores'];
$id_venta = $row['Id_venta'];
if ($row[Importe]>0) { // DEBE
#$debe = number_format(abs($row[Importe]),2,",",".");
$haber = 0;
$debe = $row[Importe];
$subtotal_debe = 0;
$subtotal_debe = $subtotal_debe + $debe;
$total_debe = $total_debe + $subtotal_debe;
}
if ($row[Importe]<0) { // HABER
$debe = 0;
$haber = abs($row[Importe]); //number_format($row[Importe],2,",",".");
$subtotal_haber = 0;
$subtotal_haber = $subtotal_haber + $haber;
$total_haber = $total_haber + $subtotal_haber;
}
?>
<?
// $tipo_fac_ante <> $tipo_fac or $nro_factura_ante <> $nro_factura or $Id_cliente_ante <> $Id_cliente or $Cte_codigo_ante <> $Cte_codigo
if ($id_venta_ante != $id_venta) {
?>
<tr>
<td width="11%" valign="top" style=" height:25px;"> <div class="encabezado_subdiario"><?=cambia_fecha_a_normal($row[Fecha])?></div></td>
<td width="19%" valign="top" style=" height:25px;"> <div class="encabezado_subdiario" align="left" ><?=$row[Cte_codigo]?> <?=$row[tipo_fac]?> <?=$row[nro_factura]?></div></td>
<td width="10%" valign="top" style=" height:25px;"> <div class="encabezado_subdiario"><?=$row[Id_cliente] //." ".$nro_factura_ante ?></div></td>
<td width="36%" valign="top" style=" height:25px;"> <div class="encabezado_subdiario" align="left" ><?=$row[empresa]?></div></td>
<td width="12%" valign="top" style=" height:25px;"> <div class="encabezado_subdiario"><? //=$suma_debe?></div></td>
<td width="12%" valign="top" style=" height:25px;"> <div class="encabezado_subdiario"><? ?></div></td>
</tr>
<?
}
?>
<tr>
<td width="11%" valign="top" style=" height:25px;"><div class="Estilo2"> </div></td>
<td width="19%" valign="top" style=" height:25px;"><div class="Estilo2" align="left" > </div></td>
<td width="10%" valign="top" style=" height:25px;"><div class="Estilo2"><?=$row[Emp_cta_deudores] //." ".$nro_factura_ante?></div></td>
<td width="36%" valign="top" style=" height:25px;"><div class="Estilo2" align="left" ><?=$row[Cta_detalle]?></div></td>
<td width="12%" valign="top" style=" height:25px;"><div class="Estilo2"><?=number_format($debe,2,",",".")?></div></td>
<td width="12%" valign="top" style=" height:25px;"><div class="Estilo2"><?=number_format($haber,2,",",".")?></div></td>
</tr>
<?
//echo $nro_factura_ante;
//$c=0;
$c=$c+1;
//while ($c >= 3 ) {
while ($c == $maximo_grupos) {
echo '
<tr>
<td width="76%" valign="middle" align="center" colspan="4" style=" height:25px;"><div class="subtotales" align="center" > </div></td>
<td width="12%" valign="middle" style=" height:25px;"><div class="subtotales">$'.$subtotal_debe.'</div></td>
<td width="12%" valign="middle" style=" height:25px;"><div class="subtotales">$'.$subtotal_haber.'</div></td>
</tr>
';
$c=0;
//}
}
?>
<?
} // FIN ... while($row = mysql_fetch_array($result)) {
?>
<!-- TOTAL GENERAL -->
<tr>
<td width="76%" valign="middle" align="center" colspan="4" style=" height:25px;"><div class="subtotales" align="center" > Totales</div></td>
<td width="12%" valign="middle" style=" height:25px;"><div class="subtotales"><?=$total_debe?></div></td>
<td width="12%" valign="middle" style=" height:25px;"><div class="subtotales"><?=$total_haber?></div></td>
</tr>
</table>