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