<?php
/*
*******************************************************************************
FiChecks -- PHP Class to generate printable checks via PDF
Copyright (C) 2004 Daniel McFeeters
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The original author of this library can be contacted at the following
address:
Daniel McFeeters
182 Baker Rd.
Faubush, KY 42544-6526
email:databases at alltel dot net
Project Started May 14, 2004
*******************************************************************************
checkReport Class Library
Main library for check printing
*******************************************************************************
*/
// requires PHP-Pdf libraries
// http://www.ros.co.nz/pdf
// http://sourceforge.net/projects/pdf-php
// Tested with version 0.09
// You also need an MICR font. I use GnuMICR
// http://lager.dyndns.org/GnuMICR/
require_once ('pdf/class.ezpdf.php');
include ('FiChecks_check.inc.php');
include ('FiChecks_numberWords.inc.php');
class checkReport
{
// paper variables
var $width;
var $height;
var $marginLeft;
var $marginBottom;
var $marginRight;
var $marginTop;
var $checks; // array of check objects
var $convert; // number to words converter
var $fontPath;
var $normalFont;
var $boldFont;
var $micrFont;
var $signatureFile;
var $pdf;
var $payorTitle; // Title of Payor
var $payorAddress; // Address of Payor
var $bankAddress; // Address of Bank
var $routingNo;
var $acctNo;
var $transitCode;
function checkReport()
{
$this->marginLeft = 0.25;
$this->marginBottom = 0.25;
$this->marginRight = 0.5;
$this->marginTop = 0.25;
$this->width=8.5;
$this->height=11;
$this->convert = new numberWords();
$this->normalFont = "Helvetica";
$this->boldFont = "Helvetica-Bold";
$this->micrFont = "GnuMICR";
}
function setFont($fontName)
{
$this->pdf->selectFont($this->fontPath.$fontName.".afm");
}
function printText($left, $bottom, $size, $text)
{
$textArray = explode("\n",$text);
$offset = 0;
foreach($textArray as $oneLine)
{
$this->pdf->addText(($this->marginLeft+$left)*72,
($this->marginBottom+$bottom)*72-$offset,
$size,
$oneLine);
$offset += $size;
} // foreach
} // printText
function innerHeight()
{
return($this->height - $this->marginTop - $this->marginBottom);
}
function innerWidth()
{
return($this->width - $this->marginLeft - $this->marginRight);
}
function drawLine($x1,$y1,$x2,$y2)
// accepts parameters in inches, and offsets for margins
{
$this->pdf->setLineStyle(1);
$this->pdf->line(($this->marginLeft + $x1)*72,
($this->marginBottom + $y1)*72,
($this->marginLeft + $x2)*72,
($this->marginBottom + $y2)*72);
}
function generateReport()
{
$this->pdf =& new Cezpdf(array(0,0,$this->width*72,$this->height*72));
$beginning = TRUE;
foreach($this->checks as $thischeck)
{
if(!$beginning)
$this->pdf->ezNewPage();
$beginning = FALSE;
$wd = $this->innerWidth();
$ht = $this->innerHeight();
// Generate Check Stub
$this->setFont($this->normalFont);
$this->printText(0,$ht,9,"\nCheck Number: ".
$thischeck->checkNo.
" Check Date:".
$thischeck->date.
"\nPayee: ".
$thischeck->payeeID.", ".
$thischeck->payeeName);
// Generate Check
// Payor Info
$this->setFont($this->boldFont);
$this->printText(0,2.875,11,"PAYOR:");
$this->printText(0.65,2.875,11,$this->payorTitle);
$this->setFont($this->normalFont);
$this->printText(0.65,2.7,9,$this->payorAddress);
// Bank Info
$this->printText(4,2.875,9,$this->bankAddress);
// Check No & etc.
$this->printText($wd-1.2,2.875,7,"Check No.");
$this->printText($wd-0.63,2.63,8,$this->transitCode);
$this->setFont($this->boldFont);
$this->printText($wd-0.625,2.875,12,$thischeck->checkNo);
// Payee Address
$this->setFont($this->boldFont);
$this->printText(0,0.975,9,"PAY\nTO THE\nORDER\nOF");
$this->setFont($this->normalFont);
$this->printText(0.875,0.875,9,$thischeck->payeeName."\n".
$thischeck->payeeAddress);
// Dollar Amount (Words)
$this->printText(0,1.77,10,
"***".trim($this->convert->toWords(floor($thischeck->amount))).
" Dollars and ".(($thischeck->amount*100) % 100)." Cents***");
// Dollar Amount (Numbers)
$this->printText($wd-1.2,1.55,9,"Pay This Amount:");
$this->printText($wd-0.8,1.37,9,"$".$thischeck->amount."***");
// Date
$this->printText($wd-1.3,2.25,9,"Date");
$this->printText($wd-1.41,2.02,9,$thischeck->date);
// Payee ID
$this->printText($wd-0.7,2.25,9,"Payee ID");
$this->printText($wd-0.7,2.02,9,$thischeck->payeeID);
// Borders
$this->drawLine($wd, 27/16, 0, 27/16);
$this->drawLine($wd, 31/16, 0, 31/16);
$this->drawLine($wd, 21/16, $wd-1.5, 21/16);
$this->drawLine($wd, 35/16, $wd-1.5, 35/16);
$this->drawLine($wd, 39/16, $wd-1.5, 39/16);
$this->drawLine($wd-1.5, 39/16, $wd-1.5, 31/16);
$this->drawLine($wd-0.85, 39/16, $wd-0.85, 31/16);
$this->drawLine($wd, 39/16, $wd, 21/16);
$this->drawLine($wd-1.5, 21/16, $wd-1.5, 27/16);
// MICR Routing Number
$this->setFont($this->micrFont);
$this->printText( 23/16, 0, 12,
"C".sprintf($thischeck->checkNo).
"C A".trim($this->routingNo)."A ".
trim($this->acctNo)."C"
);
// signature
if($this->signatureFile)
$this->pdf->addPngFromFile($this->signatureFile,
($this->innerWidth()+$this->marginLeft-2.75)*72,
(0.14+$this->marginBottom)*72,2.6*72);
$this->drawline($this->innerWidth(),0.25,$this->innerWidth()-2.875,0.25);
}
$this->pdf->ezStream();
}
} // class checkReport
?>