This topic is locked

Reporting / Mailmerge and storing generated output

9/19/2008 3:49:00 AM
PHPRunner General questions
M
mattd1 author

I couldn't find much on using reports/other methods to effect production of letters (effective mailmerges). I saw a couple of useful discussions but they weren't very clear to me, a bit specific. My requirements are as follows - can I achieve this/what's the outline approach you would recommend? (I see this as one of the critical features of the business application I aim to develop, yet it somehow seems poorly supported in PHPR - this is probably due to my lack of understanding!!).
(1) I have some data about people and some detail records, like orders history. I want to produce a letter to a selected [contact], including their address from my [address] table, and including in the body of the letter a list of their [order] records for a period [order.orderdate]<=X or >=Y.
(2) When the letter is generated I want it to be stored as generated (or at least so it can be reproduced exactly) in a [docs] table, either linked as a file to the file system, or as a BLOB (don't mind which). The [doc] record is to be linked to the [contactlog] table - so I can easily see exactly what letters/docs I have sent to who.
(3) Of course, I need to be able to print the document!
I'm guessing that "Add a report" won't do it - it appears unsuitable. Therefore I am considering the "print friendly view". Because I want to include a repeating group of data (orders) I think I'll need to embed some PHP script within the page, or generate the whole page from a scripted event ("Before page is displayed" event?).
I guess if I do this, I could copy the generated HTML to a rich text field that would be my "stored copy"?
Is there any better way to do this? I was thinking of using my own smarty template and driving that from PHP, or maybe even building a template using a Rich Text Editor and positioning "substitution" strings, like [[contactname]] or something, then using this template and replacing the strings with the actual data.
All pointers are welcomed.
Thank you.
Matt

M
mattd1 author 9/19/2008

Found a useful approach here at phpbuilder.com:
http://www.phpbuilder.com/columns/yunus20031124.php3?page=1
It's about using MSWord templates, bookmark replacement, and then launching Word at the client. This is probably going to work for me - it sounds like it won't work in a LAMP arrangement as the server needs to be running MSWord (so demanding a Windows server, I think unless there's a MSWord for Linux etc out there).
I would subsitute a whole paragraph as my "repeating group" building it in a string variable first before replacing (I am guessing here!)
Any other ideas are welcomed.
Matt

T
thesofa 9/20/2008

I have had to do a similar thing witht he behaviour management system at school, as a kid is given a detention for after school, the system generates a letter to go to the parents.

The letter needs a header of the school headed paper and certain set paragraphs with the kids name stuck into the letter, along with the date and reason for the detention

So I looked at going down the word route and decided against it.

I have customised the printer friendly page by removing all the data from the list page from it and I use $data as passed to the BeforeProcessRowPrint event on the Print page- before record processed event.

I get the data from $data["field"] thus

$given=date("l, F j, Y");

$dep=$data["Department"];

$pup="<b>".$data["Pupil"]."</b>";

$d4d=$data["Day for Detention"];



I then use this bit

// this bit of code blagged from http://www.webmasterworld.com/forum88/1132.htm with thanks

$stringArray = explode("-", $d4d);
$date = mktime(0,0,0,$stringArray[1],$stringArray[2],$stringArray[0]);
$converteddate = date("l, F j, Y", $date);

$why="<b>".$data["Reason"].".</b> ".$data["Comments"];

$giver=$data["Teacher"];

$open=$given."<p><p><p><big>Dear Parent/Carer of ".$pup.",<p><big><b>School Detention for ".$dep."</b></big></p>";
$a="In line with school policy, which applies the 1997 Education Act regarding the legalities of detention, I am writing to give you the required 24 hours notice that I shall be detaining ".$pup." from 3.00pm to 4.00pm on <b>".$converteddate."</b>.";

$a1="The reason for detention is: ".$why.".";

$c="Transport home is the responsibility of parents so you may need to arrange suitable alternative transport home if he/she normally travels on a school bus. (There is a late bus in operation which leaves school at 4.30pm prompt to most local areas).";

$d="The decision to place pupils in detention is not taken lightly and the offence is deemed serious. It is hoped that you will work with the school in the attempt to correct breaches of discipline.";

$e="Yours sincerely,";

$f="<b>Teacher: ".$giver."</b>";

echo "<IMG src=images/head.jpg width =667 height = 144 border=0>";

echo $b;

echo $open;

echo $b;

echo $b;

echo $b;

echo $a;

echo $b;

echo $a1;

echo $b;

echo $c;

echo $b;

echo $d;

echo $b;

echo $e;

echo $b;

echo $b;

echo $b;

echo $b;

echo $f;

echo $b;

return true;


This produces the letter as a web page for the teacher to print, I suppose it could be saved too, I have just saved it as an html file and I can reload it in the browser, so it can be recalled, I should need to look at automatic file naming or the staff will overwrite all the letters.