<?php require_once('../Connections/t77_connect.php'); ?>
<?php
error_reporting(2047);
set_time_limit(1800);
$colname_bills = "12";
if (isset($_GET['id'])) {
$colname_bills = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_bills = sprintf("SELECT * FROM t77_bill_bills WHERE t77_bill_bills.bill_id = %s", $colname_bills);
$bills = mysql_query($query_bills, $t77_connect) or die(mysql_error());
$row_bills = mysql_fetch_assoc($bills);
$totalRows_bills = mysql_num_rows($bills);
$colname_items = "1";
if (isset($_GET['id'])) {
$colname_items = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_items = sprintf("SELECT * FROM t77_bill_items WHERE t77_bill_items.bill_id = %s ORDER BY t77_bill_items.item_order", $colname_items);
$items = mysql_query($query_items, $t77_connect) or die(mysql_error());
$row_items = mysql_fetch_assoc($items);
$totalRows_items = mysql_num_rows($items);
$colname_contact = $row_bills['bill_contact'];
if (isset($row_bills['bill_contact'])) {
$colname_contact = (get_magic_quotes_gpc()) ? $row_bills['bill_contact'] : addslashes($row_bills['bill_contact']);
}
$contactSelect = $row_bills['bill_contact'];
$subtotal = 0;
$colname_contacts = "1";
if (isset($contactSelect)) {
$colname_contacts = (get_magic_quotes_gpc()) ? $contactSelect : addslashes($contactSelect);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_contacts = sprintf("SELECT * FROM t77_bill_contacts, t77_bill_companies WHERE t77_bill_contacts.contact_company_name = t77_bill_companies.company_id AND t77_bill_contacts.contact_id = %s", $colname_contacts);
$contacts = mysql_query($query_contacts, $t77_connect) or die(mysql_error());
$row_contacts = mysql_fetch_assoc($contacts);
$totalRows_contacts = mysql_num_rows($contacts);
$typeVar = $row_bills['bill_type'];
$colname_types = "1";
if (isset($typeVar)) {
$colname_types = (get_magic_quotes_gpc()) ? $typeVar : addslashes($typeVar);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_types = sprintf("SELECT * FROM t77_bill_types WHERE t77_bill_types.bill_type = %s", $colname_types);
$types = mysql_query($query_types, $t77_connect) or die(mysql_error());
$row_types = mysql_fetch_assoc($types);
$totalRows_types = mysql_num_rows($types);
mysql_select_db($database_t77_connect, $t77_connect);
$query_settings = "SELECT * FROM t77_bill_settings";
$settings = mysql_query($query_settings, $t77_connect) or die(mysql_error());
$row_settings = mysql_fetch_assoc($settings);
$totalRows_settings = mysql_num_rows($settings);
include './class.ezpdf.php';
// define a clas extension to allow the use of a callback to get the table of contents, and to put the dots in the toc
class Creport extends Cezpdf {
var $reportContents = array();
function Creport($p,$o){
$this->Cezpdf($p,$o);
}
function rf($info){
// this callback records all of the table of contents entries, it also places a destination marker there
// so that it can be linked too
$tmp = $info['p'];
$lvl = $tmp[0];
$lbl = rawurldecode(substr($tmp,1));
$num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber());
$this->reportContents[] = array($lbl,$num,$lvl );
$this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']);
}
function dots($info){
// draw a dotted line over to the right and put on a page number
$tmp = $info['p'];
$lvl = $tmp[0];
$lbl = substr($tmp,1);
$xpos = 520;
switch($lvl){
case '1':
$size=16;
$thick=1;
break;
case '2':
$size=12;
$thick=0.5;
break;
}
$this->saveState();
$this->setLineStyle($thick,'round','',array(0,10));
$this->line($xpos,$info['y'],$info['x']+5,$info['y']);
$this->restoreState();
$this->addText($xpos+5,$info['y'],$size,$lbl);
}
}
// I am in NZ, so will design my page for A4 paper.. but don't get me started on that.
// (defaults to legal)
// this code has been modified to use ezpdf.
//$pdf = new Cezpdf('a4','portrait');
$pdf = new Creport('a4','portrait');
$all = $pdf->openObject();
$pdf->saveState();
$pdf->addPngFromFile('logo.png',355,$pdf->y-70,180,0);
$pdf->restoreState();
$pdf->closeObject();
$pdf->addObject($all,'all');
$pdf -> ezSetMargins(120,70,70,50);
$mainFont = './fonts/Helvetica.afm';
$codeFont = './fonts/Courier.afm';
// select a font
$pdf->selectFont($mainFont);
//$pdf->openHere('Fit');
// try adding the faq's to the document, this will not work for people re-building the file from the
// download as I am not going to put in the faq file with tha
$pdf->ezStartPageNumbers(500,28,10,'','{PAGENUM} van {TOTALPAGENUM}',1);
$size=7;
$height = $pdf->getFontHeight($size);
$collecting=0;
$code='';
// content
$data1 = "<b>" . $row_contacts['company_name'] . "</b>\nt.a.v. " . $row_contacts['contact_title'] . " " . $row_contacts['contact_person'] . "\n" . $row_contacts['contact_company_address'] . "\n" . $row_contacts['contact_company_zip'] . " " . $row_contacts['contact_company_city'] . "\n" . $row_contacts['contact_country'] . "\n";
$data2 = ' ';
$data3 = "<b>" . $row_settings['company_name'] . "</b>\n" . $row_settings['company_address'] . "\n" . $row_settings['company_zip'] . " " . $row_settings['company_city'] . "\n" . "Tel : " . $row_settings['company_tel'] . "\n" . "email: " . $row_settings['company_email'] . "\n" . $row_settings['company_bank']. "\n" . $row_settings['company_COC_nr'] . "\n" . $row_settings['company_VAT_nr'];
$data = array(array('row1'=>$data1,'row2'=>$data2,'row3'=>$data3));
$pdf->ezTable($data,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0));
$pdf->ezSetDy(-40);
$pdf->saveState();
$pdf->setStrokeColor(0,0,0,1);
$pdf->setLineStyle(0.1);
$pdf->line(70,$pdf->y,535,$pdf->y);
$pdf->restoreState();
$pdf->ezSetDy(-2);
$header1 = "<b>Betreft: </b>\n" . $row_bills['bill_name'] . "\n\n" . "<b>Ordernummer: </b>\n" . $row_bills['order_number'];
$header2 = "<b>Behandeld door: </b>\n" . $row_settings['contact_name'] . "\n\n" . "<b>Type: </b>\n" . $row_types['type_description'];
$header3 = "<b>Datum: </b>\n" . DateAndTime($row_bills['bill_date']);
$header0 = array(array('row1'=>$header1,'row2'=>$header2,'row3'=>$header3));
$pdf->ezTable($header0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0));
$pdf->ezSetDy(-5);
$pdf->saveState();
$pdf->setStrokeColor(0,0,0,1);
$pdf->setLineStyle(0.1);
$pdf->line(70,$pdf->y,535,$pdf->y);
$pdf->restoreState();
$pdf->ezSetDy(-20);
do {
$subtotal = $subtotal + $row_items['item_price'];
$item1 = "<b>" . $row_items['item_name'] . "</b>\n\n" . strip_tags(str_replace("B>","b>", str_replace("I>","1>",str_replace("U>","u>",str_replace(" "," ",str_replace("H1>","b>",str_replace("STRONG>","b>",$row_items['item_description'])))))), '<b><u><strong><h1><i>');
if($row_items['item_price'] == 0) {
$item2 = " ";
} else {
$item2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($row_items['item_price'],2,',','.') . "</b>";
}
$item0 = array(array('row1'=>$item1,'row2'=>$item2));
$pdf->ezText(" ");
$pdf->ezTable($item0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$pdf->ezText(" ");
$pdf->saveState();
$pdf->setStrokeColor(0.7,0.7,0.7,1);
$pdf->setLineStyle(0.1);
$pdf->line(70,$pdf->y,535,$pdf->y);
$pdf->restoreState();
} while ($row_items = mysql_fetch_assoc($items));
$pdf->ezText(" ");
$subtotal1 = "<b>Subtotaal:</b>\n";
$subtotal2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($subtotal,2,',','.') . "</b>";
$subtotal0 = array(array('row1'=>$subtotal1,'row2'=>$subtotal2));
$pdf->ezTable($subtotal0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$vat1 = "<b>BTW " . number_format($row_settings['VAT'],2,',','.'). "%:" . "</b>\n";
$VAT = (($subtotal/100)*$row_settings['VAT']);
$vat2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($VAT,2,',','.') . "</b>";
$vat0 = array(array('row1'=>$vat1,'row2'=>$vat2));
$pdf->ezTable($vat0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$total1 = "<b>Totaal:</b>\n";
$total2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($subtotal+$VAT,2,',','.') . "</b>";
$total0 = array(array('row1'=>$total1,'row2'=>$total2));
$pdf->ezTable($total0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$pdf->ezText("\n\nGaarne betaling binnen 8 dagen na factuurdatum op rekeningnummer 1882.12.515. Alle transacties vinden plaats conform onze leveringsvoorwaarden.");
mysql_free_result($bills);
mysql_free_result($items);
mysql_free_result($contacts);
mysql_free_result($types);
mysql_free_result($settings);
// stopcontent
$pdf->ezStopPageNumbers(1,1);
if ($_GET['file'] == 'yes'){
$filename = $row_bills['order_number'] . ".pdf";
$pdfcode = $pdf->ezOutput();
//$fp = fopen($filename,'wb') or die('no write');
//fwrite($fp,$pdfcode) or die('no write');
//fclose($fp) or die('no write');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . basename($filename));
echo $pdfcode;
} else {
$pdf->ezStream();
}
?>