procedure TEnrolmentListReportForm.Process_PDF_Report;
var
rpt: TRptEnrolmentList; // report object
lReport: T_Report;
itm: TRptEnrolmentItem; // report repeatable data items
FtTitle: Integer;
FtText: Integer;
FtTextB: Integer;
lLineStyle: Integer;
LsTitle: Integer;
LsText: Integer;
Col: array[1..5] of Integer; // this report is column based
lDataCount,lCol: Integer;
v: single;
s: string;
lCount: integer;
lAlignment: shortint;
const
cCentreAddressX = 120;
procedure WritePageHeader;
begin
with lReport do
begin
// write title on each page
WriteHeader(cnLeft,lnEnd,'Enrolment List',ColDefaut,FtTitle,LsTitle);
// write page number and total of pages on each page
NumPageSectionFooter(cnRight,lnEnd,'Page','of',True,False, ColDefaut,FtText,LsText);
end;
end;
procedure WriteAddress(const ACentre: TCentre);
begin
with lReport do
begin
// Centre address lines
WritePage(cnLeft,lnEnd,ACentre.Caption,Col[5],FtTextB,LsText);
// leave some whitespace
WritePage(cnLeft,lnEnd,' ',Col[1],FtText,LsText);
WritePage(cnLeft,lnEnd,' ',Col[1],FtText,LsText);
end;
end;
procedure WriteColumnHeaders;
begin
with lReport do
begin
// Report filter details
WritePage(cnLeft,lnCurrent,Format('For Period: %s to %s', [FormatDateTime('yyyy-mm-dd', calStartDate.DateValue), FormatDateTime('yyyy-mm-dd', calEndDate.DateValue)]),ColDefaut,FtText,LsText);
WritePage(cnRight,lnEnd,'Date: ' + FormatDateTime('yyyy-mm-dd', Now),ColDefaut,FtText,LsText);
// Column headers
HorizLinePage(0,0,0,lLineStyle);
WritePage(cnLeft,lnCurrent,'Acc No.',Col[1],FtTextB,LsText);
WritePage(cnLeft,lnCurrent,'Billing Name',Col[2],FtTextB,LsText);
WritePage(cnLeft,lnCurrent,'Learner Name',Col[3],FtTextB,LsText);
WritePage(cnRight,lnEnd,'Effective Date',Col[4],FtTextB,LsText);
HorizLinePage(1,1,0,lLineStyle);
end;
end;
begin
tiProcessing(uiProcessing);
gM2Admin.TransTypeList.Read;
rpt := TRptEnrolmentList.Create;
try
// Set parameters and read report data
rpt.StartDate := calStartDate.DateValue;
rpt.EndDate := calEndDate.DateValue;
rpt.Centre := gM2Application.CurrentCentre;
rpt.Read;
if rpt.Count = 0 then
begin
tiEndProcessing;
tiAppMessage(uiErrNoDataExistsForReport);
Exit; //==>
end;
lReport:= T_Report.Create;
try
with lReport do
begin
DefaultFile:= 'Enrolment_List.pdf';
// define orientation, page format, measurement unit, language, preview (true) or print (false)
BeginWrite(oPortrait,A4,msMM,'E',True);
// create the fonts to be used (use one of the 14 Adobe PDF standard fonts)
FtTitle := Font('helvetica-15:bold',clBlack);
FtText := Font('helvetica-7',clBlack);
FtTextB := Font('helvetica-7:bold',clBlack);
// create columns to be used
Col[1]:= Column(10,23,0); // Acc No
Col[2]:= Column(35,38,0); // Billing Name
Col[3]:= Column(75,76,0); // Learner
Col[4]:= Column(155,30,0); // Effective Date
Col[5]:= Column(cCentreAddressX,70,0); // Centre Address
// create a new section and define the margins with an additional one due to frames drawing
Section(10,10,10,10);
// create the style of lines to be used
lLineStyle:= LineStyle(0.5,clBlack,lsSolid);
// create line spacings to be used
LsTitle := LineSpace(3,0,3);
LsText := LineSpace(1,0,0);
WritePageHeader;
WriteAddress(rpt.Centre);
WriteColumnHeaders;
lCount := 0;
// now the actual report data (repeated rows)
for lDataCount:= 0 to rpt.Count-1 do
begin
itm := TRptEnrolmentItem(rpt.Items[lDataCount]);
lCount := lCount + 1;
for lCol := 1 to 4 do
begin
if lCol = 4 then
v := lnEnd
else
v := lnCurrent;
s := '';
lAlignment := cnLeft;
case lCol of
1: s := itm.AccountNo;
2: s := itm.BillingName;
3: s := itm.FirstName + ' ' + itm.LastName;
4:
begin
s := FormatDateTime('yyyy-mm-dd', itm.EffectiveDate);
lAlignment := cnRight;
end;
end;
WritePage(lAlignment,v,s,Col[lCol],FtText,LsText);
end;
end;
// Leave some whitespace, then write the totals
WritePage(cnLeft,lnEnd,'',Col[1],FtText,LsText);
if lCount = 1 then
WritePage(cnRight,lnEnd,IntToStr(lCount) + ' item found',ColDefaut,FtTextB,LsText)
else
WritePage(cnRight,lnEnd,IntToStr(lCount) + ' items found',ColDefaut,FtTextB,LsText);
// preparation is finished, so create PDF objects
tiEndProcessing;
EndWrite;
end;
finally
lReport.Free;
end;
finally
rpt.Free;
end;
end;