I want to generate the total amount of the invoice after the sales list. When I try, total amount displays with only one row of sales or not displaying anything as the image.
Below is my code:
// Set font for column headings
$pdf->SetXY(50,80);
$pdf->Cell(95,10,'Item Name','B',0,'L',1);
$pdf->Cell(30,10,'Qty','B',0,'L',1);
$pdf->Cell(30,10,'Unit Cost','B',0,'L',1);
$pdf->Cell(20,10,'Amount','B',0,'L',1);
$y_axis = $y_axis_initial + $row_height;
$result=mysqli_query($connection,'select item_name,qty,unit_price,amount,staff,date,receipt_no,SUM(amount) from sales_temp');
if (!$result) {
printf(" Errormessage: %s\n", mysqli_error($connection));
}
//initialize counter
$i = 0;
//Set maximum rows per page
$max = 35;
//Set Row Height
$row_height = 6;
while($row = mysqli_fetch_array($result))
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
$pdf->AddPage();
// Set font for report subject (new page)
$pdf->SetXY(20,45);
$pdf->SetFont('Helvetic','',10);
//$pdf->Cell(40,10,'Sales Receipt',0);
// Set font for column headings (new page)
$pdf->SetY(60);
$pdf->SetX(20);
$pdf->Cell(15,6,'Item Name','B',0,'L',0);
$pdf->Cell(30,6,'Qty','B',0,'L',0);
$pdf->Cell(20,6,'Unit Price','B',0,'L',0);
$pdf->Cell(20,6,'Amount','B',0,'L',0);
//Go to next row
$y_axis = $y_axis_initial + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$item_name = $row['item_name'];
$qty = $row['qty'];
$unit_price = $row['unit_price'];
$amount = $row['amount'];
$pdf->SetY($y_axis);
$pdf->SetX(50);
$pdf->Cell(95,42,$item_name,0,0,'L',0);
$pdf->Cell(30,42,$qty,0,0,'L',0);
$pdf->Cell(30,42,$unit_price,0,0,'L',0);
$pdf->Cell(15,42,$amount,0,0,'L',0);
$staff = $row['staff'];
$date = $row['date'];
$receipt_no = $row['receipt_no'];
$pdf->SetXY(20,65);
$pdf->Cell(30,5,'Date:',0,0,'C',1);
$pdf->Cell(75,5,$date,0,0,'L',0);
$pdf->Cell(30,5,'Operator:',0,0,'C',1);
$pdf->Cell(55,5,$staff,0,0,'L',0);
$pdf->Cell(30,5,'Receipt No:',0,0,'C',1);
$pdf->Cell(45,5,$receipt_no,0,0,'L',0);
$pdf->SetXY(160,90);
$pdf->Cell(50,92,'Gross Total',0,0,'L',0);
//$pdf->Cell(65,92,SUM($amount),0,0,'L',0);
$pdf->SetY($y_axis);
$pdf->SetX(50);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;}
mysqli_close($connection);
//Send file
$pdf->Output();
Appreciate any help on this.