PHP - problema con SUM

 
Vista:
sin imagen de perfil

problema con SUM

Publicado por aldemir (51 intervenciones) el 18/11/2010 19:20:45
ESTOY TRATANDO DE SUMAR E IMPRIMIR LOS REGISTROS POR CADA FACTURA PERO NO LO ESTA HACIENDO, ESTO ESTA EN EL WHILE MAS INTERNO CON EL ARREGLO $SUMA
EN REALIDAD NO VEO EL ERROR, SI ALGUIEN PUDIERA AYUDARME, GRACIAS.
<?php
$conexion = pg_connect("host=localhost port=5432 dbname=administra user=postgres password=/*parW");
//define('./PDF/font/');
require('WriteTag.php');
$recibos = "SELECT * FROM vrecibo ORDER BY nombres,descripcion";
class PDF extends PDF_WriteTag
{
//Cabecera de página
function Header()
{
$this->Image('./imagenes/dibujo.JPG',55,10,100,20);
//Select Arial bold 15
$this->SetFont('Arial','B',15);

$this->Ln(25);

//Move to the right
$this->Cell(80);
//Framed title
$this->Cell(30,10,'Rxxxxx',1,0,'C');
$this->SetFont('Arial','B',8);
$this->Cell(95, 5, 'Fecha: '.date('d/m/Y'), 0, 0, 'R');
//Line break
$this->Ln(40);
$this->SetFont('Arial','B',8);
}

//Pie de página
function Footer()
{
//Posición: a 1,5 cm del final
$this->SetY(-12);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Número de página
$this->Cell(0,10,'Pag '.$this->PageNo(),0,0,'C');
}

}//--Fin de la Clase

//Creación del objeto de la clase heredada
$pdf=new PDF('P','mm','Letter');
//$pdf->Ln(20);

$nroapto = '';
$tot = $total = $totalmonto = 0;
$seleccionados = @pg_query($conexion,$recibos);

while($select2 = @pg_fetch_array($seleccionados)):
$nombres = $select2['nombres'];
$monto = $select2['monto'];
if ($select2['nroapto']!=$nroapto)
{
$pdf->AddPage();
$pdf->SetFont('Arial','B',8);
$pdf->Cell(20,4,'Cédula:');
$pdf->Cell(26,4,$select2['cedula'],0,1,'R');
$pdf->Cell(20,4,'Nombres:',0);
$pdf->Cell(26,4,$nombres,0,1,'R');
$pdf->Cell(20,4,'Apellidos:',0);
$pdf->Cell(26,4,$select2['apellidos'],0,1,'R');
$pdf->Cell(20,4,'Nro Apto:',0);
$pdf->Cell(26,4,$select2['nroapto'],0,1,'R');
$pdf->Cell(20,4,'Alícuota:',0);
$pdf->Cell(26,4,$select2['alicuota'],0,1,'R');
$pdf->Line($pdf->GetX(), $pdf->GetY(), 205, $pdf->GetY());
$pdf->Ln(8);
$pdf->Cell(45,4,'Gasto',0,'C');
$pdf->Cell(90,4,'Monto',0,1,'R');
$pdf->Ln(6);
}
$monto = $select2['monto'];
$totalgasto +=$monto;
$nroapto = $select2['nroapto'];
$pdf->SetFont('Arial','I',8);
$pdf->Cell(47,4,$select2['descripcion'],0,0,'L');
$pdf->Cell(90,4,number_format($monto,2,',','.'),0,1,'R');
$suma = "SELECT SUM(monto) AS tot FROM vrecibo GROUP BY nroapto,nombres";
$gastos = @pg_query($conexion,$suma);
while($select1 = @pg_fetch_array($gastos)):
$gasto = $select1['tot'];
$pdf->Cell(10,5,number_format($gasto,2,',','.'),0,1,'R');
endwhile;
endwhile;
$pdf->Cell(47,1,"Total--->",0,0);
$pdf->Cell(100,4,number_format($totalgasto,2,',','.'),0,1,'C');
$totalgasto = 0;
$pdf->Output();
$pdf->Close();
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder