A fatal MySQL error occured.\n
Query: " . $qry . "
\nError: (" . mysql_errno() . ") " . mysql_error());
$inv = mysql_fetch_array($result);
$cqry = "SELECT * FROM ".$opts['cu']." WHERE customerid = ".$inv["customerid"];
$cresult = mysql_query($cqry) or die("A fatal MySQL error occured.\n
Query: " . $cqry . "
\nError: (" . mysql_errno() . ") " . mysql_error());
$customer = mysql_fetch_array($cresult);
// Check if we need to compute VAT
// Yes by default
$includevat = true;
if(!empty($customer["vatnr"])) {
if(!is_numeric(substr($customer["vatnr"],0,2)) && (strtoupper(substr($customer["vatnr"],0,2)) != "NL")) {
$includevat = false;
}
}
$pdf=new PDF();
$fontname="Arial";
$alternatefontname="Times";
$pdf->AliasNbPages();
$pdf->AddPage();
$leftmargin = 15;
// Create customer address box
$pdf->SetFont($fontname,'',12);
$pdf->SetY(45);
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$customer["customername"]);
$pdf->Ln();
if(!empty($customer["attn"])) {
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$strings[$customer["language"]]["attn"].$customer["attn"]);
$pdf->Ln();
}
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$customer["street"]);
$pdf->Ln();
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$customer["zipcode"]." ".$customer["city"]);
$pdf->Ln();
if(!empty($customer["country"])) {
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$customer["country"]);
$pdf->Ln();
}
// Date and reference
$nicedate = strtolower(date("j-M-Y", strtotime($inv["invoicelinedate"])));
$pdf->SetY(80);
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$strings[$customer["language"]]["date"].$nicedate);
$pdf->Ln();
$pdf->Cell($leftmargin);
$pdf->Cell(80,6,$strings[$customer["language"]]["subject"].$inv["invoiceid"]);
$pdf->Ln();
$pdf->Ln();
// Introductory text
$pdf->Cell($leftmargin);
$pdf->MultiCell(170,6,$strings[$customer["language"]]["pretext"]);
$pdf->Ln();
// Header row
$pdf->SetFont($alternatefontname,'',10);
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,"#");
$pdf->Cell(120,6,"");
$pdf->Cell(20,6,$strings[$customer["language"]]["itemprice"],0,0,'R');
$pdf->Cell(20,6,$strings[$customer["language"]]["linetotal"],0,0,'R');
$pdf->Ln();
// Build the table with invoiceable items
mysql_data_seek($result, 0);
$total = 0;
$pdf->SetFont($fontname,'',10);
while ($invoiceline = mysql_fetch_array($result)) {
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,$invoiceline["amount"]);
$pdf->Cell(120,6,$invoiceline["description"]);
$pdf->Cell(20,6,EURO." ".number_format($invoiceline["charge"],2,",",""),0,0,'R');
$pdf->Cell(20,6,EURO." ".number_format($invoiceline["amount"]*$invoiceline["charge"],2,",",""),0,0,'R');
$pdf->Ln();
$total += $invoiceline["amount"]*$invoiceline["charge"];
}
// Summation, VAT
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,"",'T');
$pdf->Cell(120,6,$strings[$customer["language"]]["invtotal"],'T');
$pdf->Cell(20,6,"",'T');
$pdf->Cell(20,6,EURO." ".number_format($total,2,",",""),'T',0,'R');
$pdf->Ln();
if($includevat) {
$vat = $total*($VATpct/100);
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,"");
$pdf->Cell(120,6,"$VATpct% ".$strings[$customer["language"]]["vat"]);
$pdf->Cell(20,6,"");
$pdf->Cell(20,6,EURO." ".number_format($vat,2,",",""),0,0,'R');
$pdf->Ln();
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,"",'T');
$pdf->Cell(120,6,$strings[$customer["language"]]["invoiceable"],'T');
$pdf->Cell(20,6,"",'T');
$pdf->Cell(20,6,EURO." ".number_format($total+$vat,2,",",""),'T',0,'R');
$pdf->Ln();
} else {
if(!empty($customer["vatnr"])) {
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,"");
$pdf->Cell(120,6,$strings[$customer["language"]]["your"]." ".$strings[$customer["language"]]["vat"]."nr: ".$customer["vatnr"]);
$pdf->Ln();
}
$pdf->Cell($leftmargin);
$pdf->Cell(10,6,"",'T');
$pdf->Cell(120,6,$strings[$customer["language"]]["invoiceable"],'T');
$pdf->Cell(20,6,"",'T');
$pdf->Cell(20,6,EURO." ".number_format($total,2,",",""),'T',0,'R');
$pdf->Ln();
}
// Finalisation text
$pdf->SetFont($fontname,'',12);
$pdf->Ln();
$pdf->Cell($leftmargin);
$pdf->MultiCell(170,6,$strings[$customer["language"]]["posttext"]);
$pdf->Ln();
$pdf->Cell($leftmargin);
$pdf->MultiCell(170,6,$strings[$customer["language"]]["signature"]);
$pdf->Ln();
$filename = $inv["invoiceid"]." ".$customer["customername"]." ".$inv["invoicelinedate"].".pdf";
$pdf->Output(str_replace(" ", "_", $filename), "I");
?>