[wiaflos-devel] COMMIT - r209 - in trunk: . contrib/templates/invoices contrib/templates/receipts contrib/templates/statements contrib/templates/supplier_receipts soap wiaflos wiaflos/server

svn at linuxrulz.org svn at linuxrulz.org
Mon Aug 4 13:25:35 GMT 2008


Author: nkukard
Date: 2008-08-04 13:25:34 +0000 (Mon, 04 Aug 2008)
New Revision: 209

Added:
   trunk/contrib/templates/invoices/readme.txt
   trunk/contrib/templates/receipts/readme.txt
   trunk/contrib/templates/statements/readme.txt
   trunk/contrib/templates/supplier_receipts/readme.txt
   trunk/wiaflos/server/templating.pm
Modified:
   trunk/REQUIREMENTS
   trunk/contrib/templates/invoices/invoice1.tt2
   trunk/contrib/templates/receipts/receipt1.tt2
   trunk/contrib/templates/statements/statement1.tt2
   trunk/contrib/templates/supplier_receipts/supplier_receipt1.tt2
   trunk/soap/wiaflos-server
   trunk/soap/wiaflos.conf
   trunk/wiaflos/constants.pm
   trunk/wiaflos/server/Invoicing.pm
   trunk/wiaflos/server/Receipting.pm
   trunk/wiaflos/server/Statements.pm
   trunk/wiaflos/server/SupplierReceipting.pm
   trunk/wiaflos/version.pm
Log:
* Implemented new templating engine using Template-Toolkit


Modified: trunk/REQUIREMENTS
===================================================================
--- trunk/REQUIREMENTS	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/REQUIREMENTS	2008-08-04 13:25:34 UTC (rev 209)
@@ -4,5 +4,8 @@
 perl-TimeDate
 perl-DateTime
 perl-Crypt-GPG
+
+perl-Template-Toolkit
+
 # Optional
 perl-Term-ReadLine-Gnu

Modified: trunk/contrib/templates/invoices/invoice1.tt2
===================================================================
--- trunk/contrib/templates/invoices/invoice1.tt2	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/contrib/templates/invoices/invoice1.tt2	2008-08-04 13:25:34 UTC (rev 209)
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
 <head>
-	<title>Invoice: %{invoice number}</title>
+	<title>Invoice: [% InvoiceNumber %]</title>
 	<style type="text/css">
 		body		{
 		    	font-family: sans-serif;
@@ -115,7 +115,7 @@
 									Invoice client:
 									<table class="border centeralign" width="100%">
 										<tr><td class="bold">
-											%{client name}
+											[% ClientName %]
 										</td></tr>
 									</table>
 								</td>
@@ -125,7 +125,7 @@
 									Bill to:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{client billing address}
+											[% ClientBillingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -134,7 +134,7 @@
 									Ship to:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{invoice shipping address}
+											[% ClientShippingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -145,27 +145,27 @@
 						<table class="rightalign">
 							<tr>
 								<td>Account</td>
-								<td class="border bold">%{client code}</td>
+								<td class="border bold">[% ClientCode %]</td>
 							</tr>
 							<tr>
 								<td>Client Tax #</td>
-								<td class="border bold">%{client tax reference}</td>
+								<td class="border bold">[% ClientTaxReference %]</td>
 							</tr>
 							<tr>
 								<td>Invoice #</td>
-								<td class="border bold">%{invoice number}</td>
+								<td class="border bold">[% InvoiceNumber %]</td>
 							</tr>
 							<tr>
 								<td>Order #</td>
-								<td class="border bold">%{invoice order number}</td>
+								<td class="border bold">[% InvoiceOrderNumber %]</td>
 							</tr>
 							<tr>
 								<td>Issue Date</td>
-								<td class="border bold">%{invoice issue date}</td>
+								<td class="border bold">[% InvoiceIssueDate %]</td>
 							</tr>
 							<tr>
 								<td>Due Date</td>
-								<td class="border bold">%{invoice due date}</td>
+								<td class="border bold">[% InvoiceDueDate %]}</td>
 							</tr>
 						</table>
 					</td>
@@ -187,25 +187,25 @@
 					<td class="border centeralign">VAT</td>
 					<td class="border centeralign">Total Incl.</td>
 				</tr>
-				<!-- begin items -->
+				[% FOREACH item = LineItems %]
 				<tr>
-					<td class="centeralign bold">%{item code}</td>
-					<td class="bold">%{item description}</td>
-					<td class="centeralign bold">%{item qty}</td>
-					<td class="centeralign bold">%{item unit}</td>
-					<td class="rightalign bold">%{item unit price}</td>
-					<td class="rightalign bold">%{item discount amount}</td>
-					<td class="rightalign bold">%{item total excl}</td>
-					<td class="rightalign bold">%{item tax amount}</td>
-					<td class="rightalign bold">%{item total incl}</td>
+					<td class="centeralign bold">[% item.InventoryCode %]</td>
+					<td class="bold">[% item.Description %]</td>
+					<td class="centeralign bold">[% item.Quantity %]</td>
+					<td class="centeralign bold">[% item.Unit %]</td>
+					<td class="rightalign bold">[% item.UnitPrice %]</td>
+					<td class="rightalign bold">[% item.DiscountAmount %]</td>
+					<td class="rightalign bold">[% item.PriceExcl %]</td>
+					<td class="rightalign bold">[% item.TaxAmount %]</td>
+					<td class="rightalign bold">[% item.PriceIncl %]</td>
 				</tr>
-				<!-- end items -->
+				[% END %]
 				<tr>
 					<td colspan="5" class="rightalign">Totals</td>
-					<td class="border rightalign bold">%{invoice total discount}</td>
-					<td class="border rightalign bold">%{invoice total excl}</td>
-					<td class="border rightalign bold">%{invoice total tax}</td>
-					<td class="border rightalign bold">%{invoice total incl}</td>
+					<td class="border rightalign bold">[% InvoiceDiscountTotal %]</td>
+					<td class="border rightalign bold">[% InvoiceTotalExcl %]</td>
+					<td class="border rightalign bold">[% InvoiceTotalTaxAmount %]</td>
+					<td class="border rightalign bold">[% InvoiceTotalIncl %]</td>
 				</tr>
 				<tr>
 					<td colspan="5"></td>
@@ -219,7 +219,7 @@
 			<div class="bold">Notes:</div>
 			<table class="border" width="100%">
 				<tr><td class="top smalltext">
-				%{invoice note}
+				[% InvoiceNote %]<br />
 				</td></tr>
 			</table>
 		</td>
@@ -230,7 +230,7 @@
 	</tr>
 
 </table>
-<div class="smalltext centeralign">%{document footer}</div>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
 
 
 </body>

Added: trunk/contrib/templates/invoices/readme.txt
===================================================================
--- trunk/contrib/templates/invoices/readme.txt	                        (rev 0)
+++ trunk/contrib/templates/invoices/readme.txt	2008-08-04 13:25:34 UTC (rev 209)
@@ -0,0 +1,87 @@
+Here are the variables defined:
+
+*
+* VARIABLES FOR THE MESSAGE BODY
+*
+
+InvoiceFilename - Filename of invoice we attaching
+InvoiceSignatureFilename - Filename of invoice digital signature
+
+
+
+*
+* VARIABLES FOR INVOICE ITSELF
+*
+
+Misc:
+-----
+WiaflosString: text
+	- "Generated by $APPNAME ($APPURL)"
+
+
+
+Client Details:
+----------------
+
+ClientName: text
+	- Clients name
+
+ClientCode: text
+	- Clients code on our system
+
+
+
+Invoice Details:
+----------------
+
+ClientTaxReference: text
+	- Clients tax reference
+
+ClientBillingAddress: text
+	- Client billing address
+
+ClientShippingAddress: text
+	- Client shipping address
+
+InvoiceNumber: text
+	- Invoice number
+
+InvoiceOrderNumber: text
+	- Invoice order number
+
+InvoiceIssueDate: text
+	- Invoice issue date
+
+InvoiceDueDate: text
+	- Invoice due date
+
+InvoiceTotalExcl: text
+	- Invoice total excluding tax
+
+InvoiceDiscountTotal: text
+	- Invoice discount total for entire invoice
+
+InvoiceTotalTaxAmount: text
+	- Invoice total tax amount
+
+InvoiceTotalIncl: text
+	- Invoice total including tax
+
+
+
+Invoice Line Items:
+-------------------
+
+LineItems: array of hashes
+	InventoryCode
+	Description
+	Quantity
+	Unit
+	Discount - In %
+	DiscountAmount
+	UnitPrice
+	PriceExcl - Excl tax
+	PriceIncl - Incl tax
+	TaxRate - Rate of tax in %
+	TaxAmount
+

Added: trunk/contrib/templates/receipts/readme.txt
===================================================================
--- trunk/contrib/templates/receipts/readme.txt	                        (rev 0)
+++ trunk/contrib/templates/receipts/readme.txt	2008-08-04 13:25:34 UTC (rev 209)
@@ -0,0 +1,83 @@
+Here are the variables defined:
+
+*
+* VARIABLES FOR THE MESSAGE BODY
+*
+
+ReeiptFilename - Filename of receipt we attaching
+ReceiptSignatureFilename - Filename of receipt digital signature
+
+
+
+*
+* VARIABLES FOR INVOICE ITSELF
+*
+
+Misc:
+-----
+WiaflosString: text
+	- "Generated by $APPNAME ($APPURL)"
+
+
+
+Client Details:
+----------------
+
+ClientName: text
+	- Clients name
+
+ClientCode: text
+	- Clients code on our system
+
+
+
+Receipt Details:
+----------------
+
+ClientTaxReference: text
+	- Clients tax reference
+
+ClientBillingAddress: text
+	- Client billing address
+
+ClientShippingAddress: text
+	- Client shipping address
+
+ReceiptNumber: text
+	- Receipt number
+
+ReceiptDate: text
+	- Receipt date
+
+ReceiptNote: text (not yet used)
+	- Receipt note
+
+
+
+Receipt Line Items:
+-------------------
+
+LineItems: array of hashes
+	InvoiceNumber: text
+		- Invoice number
+
+	InvoiceIssueDate: text
+		- Invoice issue date
+
+	InvoiceDueDate: text
+		- Invoice due date
+
+	InvoicePaid: text
+		- 'yes' or 'no' depending if invoice is paid or not
+
+	InvoiceTotalIncl: text
+		- Invoice total including tax
+
+	ReceiptAllocatedAmount: text
+		- Amount allocated towards invoice
+
+	ReceiptBalance: text
+		- Receipt balance after all receipts applied to invoices
+
+
+

Modified: trunk/contrib/templates/receipts/receipt1.tt2
===================================================================
--- trunk/contrib/templates/receipts/receipt1.tt2	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/contrib/templates/receipts/receipt1.tt2	2008-08-04 13:25:34 UTC (rev 209)
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
 <head>
-	<title>Receipt: %{receipt number}</title>
+	<title>Receipt: [% ReceiptNumber %]</title>
 	<style type="text/css">
 		body		{
 			font-family: sans-serif;
@@ -120,7 +120,7 @@
 									Payment from client:
 									<table class="border centeralign" width="100%">
 										<tr><td class="bold">
-											%{client name}
+											[% ClientName %]
 										</td></tr>
 									</table>
 								</td>
@@ -130,7 +130,7 @@
 									Billing address:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{client billing address}
+											[% ClientBillingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -139,7 +139,7 @@
 									Shipping address:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{client shipping address}
+											[% ClientShippingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -150,19 +150,19 @@
 						<table class="rightalign">
 							<tr>
 								<td>Account</td>
-								<td class="border bold">%{client code}</td>
+								<td class="border bold">[% ClientCode %]</td>
 							</tr>
 							<tr>
 								<td>Receipt #</td>
-								<td class="border bold">%{receipt number}</td>
+								<td class="border bold">[% ReceiptNumber %]</td>
 							</tr>
 							<tr>
 								<td>Receipt Date</td>
-								<td class="border bold">%{receipt date}</td>
+								<td class="border bold">[% ReceiptDate %]</td>
 							</tr>
 							<tr>
 								<td>Amount</td>
-								<td class="border bold">%{receipt amount}</td>
+								<td class="border bold">[% ReceiptAmount %]</td>
 							</tr>
 						</table>
 					</td>
@@ -181,16 +181,16 @@
 					<td class="border centeralign">Allocated</td>
 					<td class="border centeralign">Paid</td>
 				</tr>
-				<!-- begin items -->
+				[% FOREACH item = LineItems %]
 				<tr>
-					<td class="centeralign bold">%{invoice number}</td>
-					<td class="centeralign bold">%{invoice issue date}</td>
-					<td class="centeralign bold">%{invoice due date}</td>
-					<td class="rightalign bold">%{invoice amount}</td>
-					<td class="rightalign bold">%{amount allocated}</td>
-					<td class="centeralign bold">%{invoice paid}</td>
+					<td class="centeralign bold">[% item.InvoiceNumber %]</td>
+					<td class="centeralign bold">[% item.InvoiceIssueDate %]</td>
+					<td class="centeralign bold">[% item.InvoiceDueDate %]</td>
+					<td class="rightalign bold">[% item.InvoiceTotalIncl %]</td>
+					<td class="rightalign bold">[% item.ReceiptAllocatedAmount %]</td>
+					<td class="centeralign bold">[% item.InvoicePaid %]</td>
 				</tr>
-				<!-- end items -->
+				[% END %]
 				<tr>
 					<td class="centeralign" colspan="6">All values in <span class="bold">USD</span> funds.</td>
 				</tr>
@@ -202,7 +202,7 @@
 			<div class="bold">Notes:</div>
 			<table class="border" width="100%">
 				<tr><td class="top smalltext">
-				%{receipt note}<br />
+				[% ReceiptNote %]<br />
 				</td></tr>
 			</table>
 		</td>
@@ -212,7 +212,7 @@
 		</td>
 	</tr>
 </table>
-<div class="smalltext centeralign">%{document footer}</div>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
 
 
 

Added: trunk/contrib/templates/statements/readme.txt
===================================================================
--- trunk/contrib/templates/statements/readme.txt	                        (rev 0)
+++ trunk/contrib/templates/statements/readme.txt	2008-08-04 13:25:34 UTC (rev 209)
@@ -0,0 +1,72 @@
+Here are the variables defined:
+
+*
+* VARIABLES FOR THE MESSAGE BODY
+*
+
+ReeiptFilename - Filename of statement we attaching
+StatementSignatureFilename - Filename of statement digital signature
+
+
+
+*
+* VARIABLES FOR INVOICE ITSELF
+*
+
+Misc:
+-----
+WiaflosString: text
+	- "Generated by $APPNAME ($APPURL)"
+
+
+
+Client Details:
+----------------
+
+ClientName: text
+	- Clients name
+
+ClientCode: text
+	- Clients code on our system
+
+
+
+Statement Details:
+----------------
+
+ClientBillingAddress: text
+	- Client billing address
+
+ClientShippingAddress: text
+	- Client shipping address
+
+StatementDate: text
+	- Statement date
+
+StatementBalance: text
+	- Statements final balance
+
+StatementNote: text (not yet used)
+	- Statement note
+
+
+
+Statement Line Items:
+-------------------
+
+LineItems: array of hashes
+	TransactionDescription: text
+		- Description of transaction
+
+	TransactionDate: text
+		- Transaction date
+
+	TransactionAmount: text
+		- Transaction amount
+
+	StatementBalance: text
+		- Statement running balance
+
+
+
+

Modified: trunk/contrib/templates/statements/statement1.tt2
===================================================================
--- trunk/contrib/templates/statements/statement1.tt2	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/contrib/templates/statements/statement1.tt2	2008-08-04 13:25:34 UTC (rev 209)
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
 <head>
-	<title>Statement: %{statement date}</title>
+	<title>Statement: [% StatementDate %]<title>
 	<style type="text/css">
 		body		{
 			font-family: sans-serif;
@@ -120,7 +120,7 @@
 									Statement for client:
 									<table class="border centeralign" width="100%">
 										<tr><td class="bold">
-											%{client name}
+											[% ClientName %]
 										</td></tr>
 									</table>
 								</td>
@@ -130,7 +130,7 @@
 									Billing address:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{client billing address}
+											[% ClientBillingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -139,7 +139,7 @@
 									Shipping address:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{client shipping address}
+											[% ClientShippingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -150,15 +150,15 @@
 						<table class="rightalign">
 							<tr>
 								<td>Account</td>
-								<td class="border bold">%{client code}</td>
+								<td class="border bold">[% ClientCode %]</td>
 							</tr>
 							<tr>
 								<td>Date</td>
-								<td class="border bold">%{statement date}</td>
+								<td class="border bold">[% StatementDate %]</td>
 							</tr>
 							<tr>
 								<td>Amount Due</td>
-								<td class="border bold">%{statement balance}</td>
+								<td class="border bold">[% StatementBalance %]</td>
 							</tr>
 						</table>
 					</td>
@@ -175,14 +175,14 @@
 					<td class="border centeralign">Amount</td>
 					<td class="border centeralign">Balance</td>
 				</tr>
-				<!-- begin items -->
+				[% FOREACH item = LineItems %]
 				<tr>
-					<td class="centeralign bold">%{transaction date}</td>
-					<td class="bold">%{transaction description}</td>
-					<td class="rightalign bold">%{transaction amount}</td>
-					<td class="rightalign bold">%{statement balance}</td>
+					<td class="centeralign bold">[% item.TransactionDate %]</td>
+					<td class="bold">[% item.TransactionDescription %]</td>
+					<td class="rightalign bold">[% item.TransactionAmount %]</td>
+					<td class="rightalign bold">[% item.StatementBalance %]</td>
 				</tr>
-				<!-- end items -->
+				[% END %]
 				<tr>
 					<td class="centeralign" colspan="4">All values in <span class="bold">USD</span> funds.</td>
 				</tr>
@@ -194,7 +194,7 @@
 			<div class="bold">Notes:</div>
 			<table class="border" width="100%">
 				<tr><td class="top smalltext">
-				%{statement note}<br />
+				[% StatementNote %]<br />
 				</td></tr>
 			</table>
 		</td>
@@ -204,7 +204,7 @@
 		</td>
 	</tr>
 </table>
-<div class="smalltext centeralign">%{document footer}</div>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
 
 
 

Added: trunk/contrib/templates/supplier_receipts/readme.txt
===================================================================
--- trunk/contrib/templates/supplier_receipts/readme.txt	                        (rev 0)
+++ trunk/contrib/templates/supplier_receipts/readme.txt	2008-08-04 13:25:34 UTC (rev 209)
@@ -0,0 +1,85 @@
+Here are the variables defined:
+
+*
+* VARIABLES FOR THE MESSAGE BODY
+*
+
+ReceiptFilename - Filename of invoice we attaching
+ReceiptSignatureFilename - Filename of invoice digital signature
+
+
+
+*
+* VARIABLES FOR INVOICE ITSELF
+*
+
+Misc:
+-----
+WiaflosString: text
+	- "Generated by $APPNAME ($APPURL)"
+
+
+
+Supplier Details:
+----------------
+
+SupplierCode: text
+	- Suppliers code on our system
+
+SupplierName: text
+	- Suppliers name
+
+SupplierBillingAddress: text
+	- Suppliers billing address
+
+SupplierShippingAddress: text
+	- Suppliers shipping address
+
+SupplierShippingAddress: text
+	- Suppliers shipping address
+
+
+
+Receipt Details:
+----------------
+
+ReceiptNumber: text
+	- Receipt number
+
+ReceiptBalance: text
+	- Final receipt balance
+
+ReceiptDate: text
+	- Receipt date
+
+ReceiptAmount: text
+	- Receipt amount
+
+ReceiptNote: text (not currently implemented)
+	- Receipt note
+
+
+
+Receipt Line Items:
+-------------------
+
+LineItems: array of hashes
+	CreditNoteNumber: text
+		- Credit note number
+	
+	CreditNoteIssueDate: text
+		- Credit note issue date
+	
+	CreditNoteAmount: text
+		- Credit note amount
+	
+	CreditNoteAmountAllocated: text
+		- Credit note amount allocated
+	
+	CreditNoteClosed: text
+		- 'yes' or 'no' whether credit note is closed or not
+	
+	ReceiptBalance: text
+		- Final receipt balance
+
+

Modified: trunk/contrib/templates/supplier_receipts/supplier_receipt1.tt2
===================================================================
--- trunk/contrib/templates/supplier_receipts/supplier_receipt1.tt2	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/contrib/templates/supplier_receipts/supplier_receipt1.tt2	2008-08-04 13:25:34 UTC (rev 209)
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
 <head>
-	<title>Receipt: %{receipt number}</title>
+	<title>Receipt: [% ReceiptNumber %]</title>
 	<style type="text/css">
 		body		{
 			font-family: sans-serif;
@@ -120,7 +120,7 @@
 									Payment from supplier:
 									<table class="border centeralign" width="100%">
 										<tr><td class="bold">
-											%{supplier name}
+											[% SupplierName %]
 										</td></tr>
 									</table>
 								</td>
@@ -130,7 +130,7 @@
 									Billing address:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{supplier billing address}
+											[% SupplierBillingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -139,7 +139,7 @@
 									Shipping address:
 									<table class="border" width="100%">
 										<tr><td class="bold">
-											%{supplier shipping address}
+											[% SupplierShippingAddress %]
 										</td></tr>
 									</table>
 								</td>
@@ -150,19 +150,19 @@
 						<table class="rightalign">
 							<tr>
 								<td>Account</td>
-								<td class="border bold">%{supplier code}</td>
+								<td class="border bold">[% SupplierCode %]</td>
 							</tr>
 							<tr>
 								<td>Receipt #</td>
-								<td class="border bold">%{receipt number}</td>
+								<td class="border bold">[% ReceiptNumber %]</td>
 							</tr>
 							<tr>
 								<td>Receipt Date</td>
-								<td class="border bold">%{receipt date}</td>
+								<td class="border bold">[% ReceiptDate %]</td>
 							</tr>
 							<tr>
 								<td>Amount</td>
-								<td class="border bold">%{receipt amount}</td>
+								<td class="border bold">[% ReceiptAmount %]</td>
 							</tr>
 						</table>
 					</td>
@@ -180,15 +180,15 @@
 					<td class="border centeralign">Allocated</td>
 					<td class="border centeralign">Closed</td>
 				</tr>
-				<!-- begin items -->
+				[% FOREACH item = LineItems %]
 				<tr>
-					<td class="centeralign bold">%{credit note number}</td>
-					<td class="centeralign bold">%{credit note issue date}</td>
-					<td class="rightalign bold">%{credit note amount}</td>
-					<td class="rightalign bold">%{amount allocated}</td>
-					<td class="centeralign bold">%{credit note closed}</td>
+					<td class="centeralign bold">[% item.CreditNoteNumber %]</td>
+					<td class="centeralign bold">[% item.CreditNoteIssueDate %]</td>
+					<td class="rightalign bold">[% item.CreditNoteAmount %]</td>
+					<td class="rightalign bold">[% item.CreditNoteAmountAllocated %]</td>
+					<td class="centeralign bold">[% item.CreditNoteClosed %]</td>
 				</tr>
-				<!-- end items -->
+				[% END %]
 				<tr>
 					<td class="centeralign" colspan="6">All values in <span class="bold">USD</span> funds.</td>
 				</tr>
@@ -200,7 +200,7 @@
 			<div class="bold">Notes:</div>
 			<table class="border" width="100%">
 				<tr><td class="top smalltext">
-				%{receipt note}<br />
+				[% ReceiptNote %]<br />
 				</td></tr>
 			</table>
 		</td>
@@ -208,7 +208,7 @@
 		</td>
 	</tr>
 </table>
-<div class="smalltext centeralign">%{document footer}</div>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
 
 
 

Modified: trunk/soap/wiaflos-server
===================================================================
--- trunk/soap/wiaflos-server	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/soap/wiaflos-server	2008-08-04 13:25:34 UTC (rev 209)
@@ -35,8 +35,10 @@
 use wiaflos::version;
 use wiaflos::server::dblayer;
 use wiaflos::server::dbilayer;
+use wiaflos::server::cache;
 use wiaflos::server::logging;
 use wiaflos::server::users;
+use wiaflos::server::templating;
 use Auth qw();
 
 
@@ -44,16 +46,12 @@
 use Config::IniFiles;
 use Getopt::Long;
 
-use Data::Dumper;
 
-
-
 # Override configuration
 sub configure {
 	my $self = shift;
 	my $server = $self->{'server'};
 	my $cfg;
-	my $soap;
 	my $cmdline;
 
 
@@ -101,7 +99,7 @@
 	my %config = %inifile;
 	untie(%inifile);
 
-	# Pull in config for the server
+	# Server config
 	my @server_params = (
 			'log_level','log_file',
 			'syslog_logsock', 'syslog_ident', 'syslog_logopt', 'syslog_facility',
@@ -120,11 +118,11 @@
 		$server->{'setsid'} = 1;
 	}
 
-
 	# SOAP config
 	my @soap_params = (
 			'plugins',
 	);
+	my $soap;
 	foreach my $param (@soap_params) {
 		$soap->{$param} = $config{'soap'}{$param} if (defined($config{'soap'}{$param}));
 	}
@@ -140,7 +138,23 @@
 	# Set other stuff
 	$soap->{'on_action'} = \&Auth::checkAccess;
 
-	# Pull in config params
+	# Template engine config
+	my @template_params = (
+			'path',
+			'global_header',
+			'global_footer',
+	);
+	my $templates;
+	foreach my $param (@template_params) {
+		$templates->{$param} = $config{'templates'}{$param} if (defined($config{'templates'}{$param}));
+	}
+
+	if (!defined($templates->{'path'})) {
+		$self->log(LOG_ERR,"SOAP configuration error: Under 'templates' section, required parameter 'path' not found");
+		exit 1;
+	}
+
+	# MISC config
 	$cfg->{'hostname'} = gethostbyname($server->{'hostname'});
 	$cfg->{'url'} = sprintf('%s://%s%s/',"http",$server->{'hostname'},($server->{'port'} eq "80") ? "" : ":".$server->{'port'});
 
@@ -150,6 +164,7 @@
 	# Save our config and stuff
 	$self->{'config'} = $cfg;
 	$self->{'soap_config'} = $soap;
+	$self->{'template_config'} = $templates;
 	$self->{'cmdline'} = $cmdline;
 	$self->{'inifile'} = \%config;
 }
@@ -185,6 +200,8 @@
 	
 	$self->log(LOG_INFO,"Initializing system modules...");
 	wiaflos::server::config::Init($self);
+	# Init templating engine
+	wiaflos::server::templating::Init($self);
 	# Init caching engine
 	wiaflos::server::cache::Init($self);
 	$self->log(LOG_INFO,"System modules initialized.");

Modified: trunk/soap/wiaflos.conf
===================================================================
--- trunk/soap/wiaflos.conf	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/soap/wiaflos.conf	2008-08-04 13:25:34 UTC (rev 209)
@@ -49,7 +49,15 @@
 EOT
 
 
+# Templating engine config
+[templates]
+path = ../contrib/templates
 
+# Global header & footer
+global_header = header.tt2
+global_footer = footer.tt2
+
+
 # Email configuration
 [mail]
 server = localhost
@@ -63,7 +71,7 @@
 [invoicing]
 
 # Email attachment template
-#email_template=../contrib/invoices/invoice1.tmpl
+#email_template= invoices/invoice1.tt2
 
 # Email body template
 #email_message_template=
@@ -77,10 +85,7 @@
 # Sign invoice with this gpg key
 #use_gpg_key=
 
-# Document footer
-#footer=
 
-
 #
 # Receipting configuration
 #
@@ -88,7 +93,7 @@
 [receipting]
 
 # Email attachment template
-#email_template=../contrib/receipts/receipt1.tmpl
+#email_template= receipts/receipt1.tt2
 
 # Email body template
 #email_message_template=
@@ -102,11 +107,7 @@
 # Sign receipt with this gpg key
 #use_gpg_key=
 
-# Document footer
-#footer=
 
-
-
 #
 # Statement configuration
 #
@@ -114,7 +115,7 @@
 [statements]
 
 # Email attachment template
-#email_template=../contrib/statements/statement1.tmpl
+#email_template= statements/statement1.tt2
 
 # Email body template
 #email_message_template=
@@ -128,11 +129,8 @@
 # Sign statement with this gpg key
 #use_gpg_key=
 
-# Document footer
-#footer=
 
 
-
 #
 # Supplier receipting configuration
 #
@@ -140,7 +138,7 @@
 [supplierreceipting]
 
 # Email attachment template
-#email_template=../contrib/supplier_receipts/receipt1.tmpl
+#email_template= supplier_receipts/supplier_receipt1.tt2
 
 # Email body template
 #email_message_template=
@@ -154,6 +152,4 @@
 # Sign receipt with this gpg key
 #use_gpg_key=
 
-# Document footer
-#footer=
 

Modified: trunk/wiaflos/constants.pm
===================================================================
--- trunk/wiaflos/constants.pm	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/wiaflos/constants.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -35,6 +35,7 @@
 	ERR_SRVFILE
 	ERR_SRVEXEC
 	ERR_SRVCACHE
+	ERR_SRVTEMPLATE
 
 
 	ERR_DB
@@ -79,6 +80,7 @@
 	ERR_SRVFILE		=>	-511,
 	ERR_SRVEXEC		=>	-512,
 	ERR_SRVCACHE	=>	-590,
+	ERR_SRVTEMPLATE	=>	-600,
 
 
 	ERR_DB		=>	-2001, # -2

Modified: trunk/wiaflos/server/Invoicing.pm
===================================================================
--- trunk/wiaflos/server/Invoicing.pm	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/wiaflos/server/Invoicing.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -29,10 +29,12 @@
 use wiaflos::constants;
 use wiaflos::server::config;
 use wiaflos::server::dblayer;
+use wiaflos::server::templating;
 use wiaflos::server::GL;
 use wiaflos::server::Inventory;
 use wiaflos::server::Clients;
 use wiaflos::server::Tax;
+use wiaflos::server::Tax;
 
 # Whole money transactions, precision is two
 use Math::BigFloat;
@@ -1160,139 +1162,62 @@
 	# If no accounts address, use general address
 	$billEmailAddr = @billEmailAddrs > 0 ? join(',', at billEmailAddrs) : join(',', at genEmailAddrs);
 
-	# Some stuff that may be null
-	my $orderNumber = defined($invoice->{'OrderNumber'}) ? $invoice->{'OrderNumber'} : "";
+	# Build array of stuff we can use
+	my $vars = {
+		'WiaflosString' => $GENSTRING,
 
-	# Get invoice template file
-	my $template = defined($config->{'invoicing'}{'email_template'}) ? $config->{'invoicing'}{'email_template'} : "../contrib/invoices/invoice1.tmpl";
+		# Client
+		'ClientName' => $client->{'Name'},
+		'ClientCode' => $client->{'Code'},
+		'ClientBillingAddress' => $billAddr,
+		'ClientShippingAddress' => $shipAddr,
 
-	# Open template
-	if (!open(INVT, "< $template")) {
-		setError("Failed to open invoice template '$template' when sending invoice '".$invoice->{'Number'}."': $!");
-		return ERR_SRVFILE;
-	}
+		# Invoice
+		'ClientTaxReference' => defined($invoice->{'TaxReference'}) ? $invoice->{'TaxReference'} : "",
 
-	# Get receipt template file
-	my $footer = defined($config->{'invoicing'}{'footer'}) ? $config->{'invoicing'}{'footer'} : "Generatd by Wiaflos Accounting (http://www.wiaflos.org)";
+		'InvoiceNumber' => $invoice->{'Number'},
+		'InvoiceOrderNumber' => defined($invoice->{'OrderNumber'}) ? $invoice->{'OrderNumber'} : "",
+		'InvoiceIssueDate' => $invoice->{'IssueDate'},
+		'InvoiceDueDate' => $invoice->{'DueDate'},
+		'InvoiceNote' => defined($invoice->{'Note'}) ? $invoice->{'Note'} : "",
 
-	# Output array
-	my @invoiceData;
+		'InvoiceTotalExcl' => sprintf('%.2f',$invoice->{'SubTotal'}),
+		'InvoiceDiscountTotal' => (defined($invoice->{'DiscountTotal'}) && $invoice->{'DiscountTotal'} ne "0.00") 
+				? sprintf('%.2f',$invoice->{'DiscountTotal'}) : "",
+		'InvoiceTotalTaxAmount' => sprintf('%.2f',$invoice->{'TaxTotal'}),
+		'InvoiceTotalIncl' => sprintf('%.2f',$invoice->{'Total'}),
+	};
 
-	# Loop with template lines
-	my $itemList = 0;
-	my @itemLines;
-	while ((my $line = <INVT>)) {
-		# If we beginning
-		if ($line =~ /^\s*<!-- begin items -->\s*$/) {
-			$itemList = 1;
-			next;
-		}
-
-		# When we hit the end, write out
-		if ($itemList && $line =~ /^\s*<!-- end items -->\s*$/) {
-
-			# Loop with items
-			foreach my $item (@{$invoiceItems}) {
-
-				# And then with lines for items
-				foreach my $itemLine (@itemLines) {
-					my $tmp = $itemLine;
-
-					# Various fixups & amount sanitizations
-					(my $qty = $item->{'Quantity'}) =~ s/\.0+$//;  # Remove .0's from quantity
-					my $unit = defined($item->{'Unit'}) ? $item->{'Unit'} : "";
-					my $discount = defined($item->{'Discount'}) ? $item->{'Discount'} : "";
-					my $discountAmount = defined($item->{'DiscountAmount'}) ? sprintf('%.2f',$item->{'DiscountAmount'}) : "";
-
-					my $unitPrice = sprintf('%.2f',$item->{'UnitPrice'});
-					my $price = sprintf('%.2f',$item->{'Price'});
-					my $totalPrice = sprintf('%.2f',$item->{'TotalPrice'});
-					my $taxRate = sprintf('%.2f',$item->{'TaxRate'});
-					my $taxAmount = sprintf('%.2f',$item->{'TaxAmount'});
-
-					# Substitute
-					$tmp =~ s/%{item code}/$item->{'InventoryCode'}/g;
-					$tmp =~ s/%{item description}/$item->{'Description'}/g;
-					$tmp =~ s/%{item qty}/$qty/g;
-					$tmp =~ s/%{item unit}/$unit/g;
-					$tmp =~ s/%{item unit price}/$unitPrice/g;
-					$tmp =~ s/%{item total excl}/$price/g;
-					$tmp =~ s/%{item total incl}/$totalPrice/g;
-					$tmp =~ s/%{item discount}/$discount/g;
-					$tmp =~ s/%{item discount amount}/$discountAmount/g;
-					$tmp =~ s/%{item tax rate}/$taxRate/g;
-					$tmp =~ s/%{item tax amount}/$taxAmount/g;
-
-					push(@invoiceData,$tmp);
-				}
-			}
-
-			$itemList = 0;
-			next;
-		}
-
-		# Normal line
-		if ($itemList == 0) {
-			# tax reference may be null in the DB
-			my $taxRef = defined($invoice->{'TaxReference'}) ? $invoice->{'TaxReference'} : "";
-
-			my $discountTotal = "";
-			if (defined($invoice->{'DiscountTotal'}) && $invoice->{'DiscountTotal'} ne "0.00") {
-				$discountTotal = $invoice->{'DiscountTotal'};
-			}
-
-			my $subTotal = sprintf('%.2f',$invoice->{'SubTotal'});
-			my $taxTotal = sprintf('%.2f',$invoice->{'TaxTotal'});
-			my $total = sprintf('%.2f',$invoice->{'Total'});
-
-
-			$line =~ s/%{client name}/$client->{'Name'}/g;
-			$line =~ s/%{client code}/$client->{'Code'}/g;
-			$line =~ s/%{client tax reference}/$taxRef/g;
-			$line =~ s/%{client billing address}/$billAddr/g;
-		
-			$line =~ s/%{invoice number}/$invoice->{'Number'}/g;
-			$line =~ s/%{invoice order number}/$orderNumber/g;
-			$line =~ s/%{invoice issue date}/$invoice->{'IssueDate'}/g;
-			$line =~ s/%{invoice due date}/$invoice->{'DueDate'}/g;
-			$line =~ s/%{invoice shipping address}/$shipAddr/g;
-
-			my $invNote = defined($invoice->{'Note'}) ? $invoice->{'Note'} : "";
-			$line =~ s/%{invoice note}/$invNote/g;
-
-#			$line =~ s/%{invoice page number}/1/g;
-#			$line =~ s/%{invoice page total}/1/g;
-			$line =~ s/%{invoice total discount}/$discountTotal/g;
-			$line =~ s/%{invoice total excl}/$subTotal/g;
-			$line =~ s/%{invoice total tax}/$taxTotal/g;
-			$line =~ s/%{invoice total incl}/$total/g;
-		
-			$line =~ s/%{document footer}/$footer/g;
-		
-			push(@invoiceData,$line);
-		} else {
-			push(@itemLines,$line);	
-		}
+	# Load invoice line items
+	foreach my $item (@{$invoiceItems}) {
+		my $titem;
+		# Various fixups & amount sanitizations
+		$titem->{'Quantity'} =~ s/\.0+$//;  # Remove .0's from quantity
+		$titem->{'Unit'} = "" if (!defined($item->{'Unit'}));
+		$titem->{'Discount'} = "" if (!defined($item->{'Discount'})); # %
+		$titem->{'DiscountAmount'} = defined($item->{'DiscountAmount'}) ? sprintf('%.2f',$item->{'DiscountAmount'}) : ""; # amount
+		$titem->{'UnitPrice'} = sprintf('%.2f',$item->{'UnitPrice'});
+		$titem->{'PriceExcl'} = sprintf('%.2f',$item->{'Price'}); # excl tax
+		$titem->{'PriceIncl'} = sprintf('%.2f',$item->{'TotalPrice'}); # incl tax
+		$titem->{'TaxRate'} = sprintf('%.2f',$item->{'TaxRate'});
+		$titem->{'TaxAmount'} = sprintf('%.2f',$item->{'TaxAmount'});
+		push(@{$vars->{'LineItems'}},$titem);
 	}
 
-	close(INVT);
+	# Get invoice template file
+	my $template = defined($config->{'invoicing'}{'email_template'}) ? $config->{'invoicing'}{'email_template'} : "invoices/invoice1.tt2";
 
 	# Check where invoice must go
 	if ($detail->{'SendTo'} =~ /^file:(\S+)/i) {
 		my $filename = $1;
 
-		# Open file
-		if (!open(FN,"> $filename")) {
-			setError("Failed to open invoice file '$filename': $!");
-			return ERR_SRVFILE;
+		# Load template
+		my $res = loadTemplate($template,$vars,$filename);
+		if (!$res) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
 		}
 
-		# Write out invoice
-		print(FN @invoiceData);
-
-		# And close
-		close(FN);
-
 	# Write out using email
 	} elsif ($detail->{'SendTo'} =~ /^email(?:\:(\S+))?/i) {
 		# Pull email addr
@@ -1314,41 +1239,35 @@
 
 		# Invoice filename
 		(my $invoiceFilename = $invoice->{'Number'} . ".html") =~ s,/,-,g;
-
 		# Invoice signature filename
 		my $invSignFilename = $invoiceFilename . ".asc";
 
-
 		# If we must, pull in email body
 		my $message_template = $config->{'invoicing'}{'email_message_template'};
 		my $emailBody = "";
 		if (defined($message_template) && $message_template ne "") {
-			# Open & check
-			if (!open(MB,"< $message_template")) {
-				setError("Failed to open invoice email message '$message_template': $!");
-				return ERR_SRVFILE;
+			# Variables for our template
+			my $vars2 = {
+				'InvoiceFilename' => $invoiceFilename,
+				'InvoiceSignatureFilename' => $invSignFilename,
+			};
+			# Load template
+			$emailBody = loadTemplate($vars2,$message_template,$emailBody);
+			if (!$emailBody) {
+				setError("Failed to load template '$message_template': ".wiaflos::server::templating::Error());
+				return ERR_SRVTEMPLATE;	
 			}
-			# Read in each line
-			my @emailBody;
-			while (my $line = <MB>) {
-				push(@emailBody,$line);
-			}
 
-			close(MB);
-
-			# Join up
-			$emailBody = join('', at emailBody);
-
-			# Substitute
-			$emailBody =~ s/%{invoice filename}/$invoiceFilename/g;
-			$emailBody =~ s/%{invoice signature filename}/$invSignFilename/g;
+			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol for crypt-gpg
+		}
 		
-			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol
+		# Load template
+		my $invoiceData = "";
+		$invoiceData = loadTemplate($template,$vars,$invoiceData);
+		if (!$invoiceData) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
 		}
-
-
-		# This is our entire invoice
-		my $invoiceData = join('', at invoiceData);
 		$invoiceData =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol, needed to fix bug in crypt-gpg where it mangles \n
 
 		# See if we must use GPG
@@ -1360,7 +1279,7 @@
 			$gpg->gpgbin("/usr/bin/gpg");
 			$gpg->secretkey($use_gpg_key);
 			$gpg->armor(1);
-			$gpg->comment("Wiaflos Accounting v$VERSION (www.wiaflos.org)");
+			$gpg->comment("$APPNAME v$VERSION ($APPURL)");
 			# Sign invoice
 			$sign = $gpg->sign($invoiceData);
 			if (!defined($sign)) {
@@ -1418,7 +1337,6 @@
 		return ERR_PARAM;
 	}
 
-
 	return 0;
 }
 

Modified: trunk/wiaflos/server/Receipting.pm
===================================================================
--- trunk/wiaflos/server/Receipting.pm	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/wiaflos/server/Receipting.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -30,6 +30,7 @@
 use wiaflos::server::config;
 use wiaflos::server::dblayer;
 use wiaflos::server::cache;
+use wiaflos::server::templating;
 use wiaflos::server::Clients;
 use wiaflos::server::GL;
 
@@ -1012,129 +1013,74 @@
 	# If no accounts address, use general address
 	$billEmailAddr = @billEmailAddrs > 0 ? join(',', at billEmailAddrs) : join(',', at genEmailAddrs);
 
-	# Get receipt template file
-	my $template = defined($config->{'receipting'}{'email_template'}) ? $config->{'receipting'}{'email_template'} : "../contrib/receipts/receipt1.tmpl";
-
-	# Open template
-	if (!open(INVT, "< $template")) {
-		setError("Failed to open receipt template '$template' for receipt '".$receipt->{'Number'}."': $!");
-		return ERR_SRVFILE;
-	}
-
-	# Get receipt template file
-	my $footer = defined($config->{'receipting'}{'footer'}) ? $config->{'receipting'}{'footer'} : "Generated by Wiaflos Accounting (http://www.wiaflos.org)";
-
-	# Output array
-	my @receiptData;
-
-	# Loop with template lines
-	my $itemList = 0;
-	my @itemLines;
+	# We change this as we go along...
 	my $receiptBalance = Math::BigFloat->new($receipt->{'Amount'});
-	while ((my $line = <INVT>)) {
-		# If we beginning
-		if ($line =~ /^\s*<!-- begin items -->\s*$/) {
-			$itemList = 1;
-			next;
-		}
 
-		# When we hit the end, write out
-		if ($itemList && $line =~ /^\s*<!-- end items -->\s*$/) {
+	# Build array of stuff we can use
+	my $vars = {
+		'WiaflosString' => $GENSTRING,
 
-			# Loop with items
-			foreach my $item (@{$allocations}) {
+		# Client
+		'ClientName' => $client->{'Name'},
+		'ClientCode' => $client->{'Code'},
+		'ClientBillingAddress' => $billAddr,
+		'ClientShippingAddress' => $shipAddr,
+		
+		# Receipt
+		'ClientTaxReference' => defined($receipt->{'TaxReference'}) ? $receipt->{'TaxReference'} : "",
 
-				# Pull invoice
-				$data = undef;
-				$data->{'ID'} = $item->{'InvoiceID'};
-				my $invoice = wiaflos::server::Invoicing::getInvoice($data);
-				if (ref $invoice ne "HASH") {
-					setError(wiaflos::server::Invoicing::Error());
-					return $invoice;
-				}
+		'ReceiptAmount' => sprintf('%.2f',$receipt->{'Amount'}),
+		'ReceiptNumber' => $receipt->{'Number'},
+		'ReceiptDate' => $receipt->{'TransactionDate'},
+		# TODO: receipt note not implemented yet
+		'ReceiptNote' => "",
+	};
 
-				# Keep balance
-				$receiptBalance->bsub($item->{'Amount'});
-				my $balance = sprintf('%.2f',$receiptBalance->bstr());
-					
-				# And then with lines for items
-				foreach my $itemLine (@itemLines) {
-					my $tmp = $itemLine;
+	# Load receipt line items
+	foreach my $item (@{$allocations}) {
 
-					# Fix some stuff up & sanitize
-					my $paid = $invoice->{'Paid'} ? 'yes' : 'no';
-					
-					my $total = sprintf('%.2f',$invoice->{'Total'});
-					my $amount = sprintf('%.2f',$item->{'Amount'});
-
-					# Substitute
-					$tmp =~ s/%{invoice number}/$invoice->{'Number'}/g;
-					$tmp =~ s/%{invoice issue date}/$invoice->{'IssueDate'}/g;
-					$tmp =~ s/%{invoice due date}/$invoice->{'DueDate'}/g;
-					$tmp =~ s/%{invoice amount}/$total/g;
-					$tmp =~ s/%{amount allocated}/$amount/g;
-					$tmp =~ s/%{invoice paid}/$paid/g;
-					$tmp =~ s/%{receipt balance}/$balance/g;
-
-					push(@receiptData,$tmp);
-				}
-			}
-
-			$itemList = 0;
-			next;
+		# Pull invoice
+		$data = undef;
+		$data->{'ID'} = $item->{'InvoiceID'};
+		my $invoice = wiaflos::server::Invoicing::getInvoice($data);
+		if (ref $invoice ne "HASH") {
+			setError(wiaflos::server::Invoicing::Error());
+			return $invoice;
 		}
 
-		# Normal line
-		if ($itemList == 0) {
-#			my $discountTotal = "";
-#			if (defined($invoice->{'DiscTotal'}) && $invoice->{'DiscTotal'} ne "0.00") {
-#				$discountTotal = $invoice->{'DiscTotal'};
-#			}
-			# Sanitize
-			my $amount = sprintf('%.2f',$receipt->{'Amount'});
+		my $titem;
 
-			$line =~ s/%{client name}/$client->{'Name'}/g;
-			$line =~ s/%{client code}/$client->{'Code'}/g;
-			$line =~ s/%{client billing address}/$billAddr/g;
-			$line =~ s/%{client shipping address}/$shipAddr/g;
-		
-			$line =~ s/%{receipt number}/$receipt->{'Number'}/g;
-			$line =~ s/%{receipt date}/$receipt->{'TransactionDate'}/g;
-			$line =~ s/%{receipt amount}/$amount/g;
+		# Fix some stuff up & sanitize
+		$titem->{'ReceiptAllocatedAmount'} = sprintf('%.2f',$item->{'Amount'});
+		# Keep balance
+		$receiptBalance->bsub($item->{'Amount'});
+		$titem->{'ReceiptBalance'} = sprintf('%.2f',$receiptBalance->bstr());
+			
+		$titem->{'InvoiceNumber'} = $invoice->{'Number'};
+		$titem->{'InvoiceIssueDate'} = $invoice->{'IssueDate'};
+		$titem->{'InvoiceDueDate'} = $invoice->{'DueDate'};
+		$titem->{'InvoicePaid'} = $invoice->{'Paid'} ? 'yes' : 'no';
+		$titem->{'InvoiceTotalIncl'} = sprintf('%.2f',$invoice->{'Total'});
 
-			# This MUST be at the END of your template, AFTER the items above to be of any use
-			my $balance = sprintf('%.2f',$receiptBalance->bstr());
-			$line =~ s/%{receipt balance}/$balance/g;
-	
-			# TODO: receipt note not implemented yet
-			$line =~ s/%{receipt note}//g;
-
-			$line =~ s/%{document footer}/$footer/g;
-
-			push(@receiptData,$line);
-		} else {
-			push(@itemLines,$line);	
-		}
+		push(@{$vars->{'LineItems'}},$titem);
 	}
+	# This MUST be at the END of your template, AFTER the items above to be of any use
+	$vars->{'ReceiptBalance'} = sprintf('%.2f',$receiptBalance->bstr());
 
-	close(INVT);
+	# Get receipt template file
+	my $template = defined($config->{'receipting'}{'email_template'}) ? $config->{'receipting'}{'email_template'} : "receipts/receipt1.tt2";
 
 	# Check where receipt must go
 	if ($detail->{'SendTo'} =~ /^file:(\S+)/i) {
 		my $filename = $1;
 
-		# Open file
-		if (!open(FN,"> $filename")) {
-			setError("Failed to open destination receipt file '$filename': $!");
-			return ERR_SRVFILE;
+		# Load template
+		my $res = loadTemplate($template,$vars,$filename);
+		if (!$res) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
 		}
 
-		# Write out receipt
-		print(FN @receiptData);
-
-		# And close
-		close(FN);
-
 	# Write out using email
 	} elsif ($detail->{'SendTo'} =~ /^email(?:\:(\S+))?/i) {
 		# Pull email addr
@@ -1155,41 +1101,35 @@
 
 		# Receipt filename
 		(my $receiptFilename = $receipt->{'Number'} . ".html") =~ s,/,-,g;
-
 		# Invoice signature filename
 		my $rctSignFilename = $receiptFilename . ".asc";
 
-
 		# If we must, pull in email body
 		my $message_template = $config->{'receipting'}{'email_message_template'};
 		my $emailBody = "";
 		if (defined($message_template) && $message_template ne "") {
-			# Open & check
-			if (!open(MB,"< $message_template")) {
-				setError("Failed to open receipt email message template '$message_template': $!");
-				return ERR_SRVFILE;
+			# Variables for our template
+			my $vars2 = {
+				'ReceiptFilename' => $receiptFilename,
+				'ReceiptSignatureFilename' => $rctSignFilename,
+			};
+			# Load template
+			$emailBody = loadTemplate($vars2,$message_template,$emailBody);
+			if (!$emailBody) {
+				setError("Failed to load template '$message_template': ".wiaflos::server::templating::Error());
+				return ERR_SRVTEMPLATE;	
 			}
-			# Read in each line
-			my @emailBody;
-			while (my $line = <MB>) {
-				push(@emailBody,$line);
-			}
 
-			close(MB);
-
-			# Join up
-			$emailBody = join('', at emailBody);
-
-			# Substitute
-			$emailBody =~ s/%{receipt filename}/$receiptFilename/g;
-			$emailBody =~ s/%{receipt signature filename}/$rctSignFilename/g;
-		
-			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol
+			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol for crypt-gpg
 		}
 
-
-		# This is our entire receipt
-		my $receiptData = join('', at receiptData);
+		# Load template
+		my $receiptData = "";
+		$receiptData = loadTemplate($template,$vars,$receiptData);
+		if (!$receiptData) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
+		}
 		$receiptData =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol, needed to fix bug in crypt-gpg where it mangles \n
 
 		# See if we must use GPG
@@ -1201,7 +1141,7 @@
 			$gpg->gpgbin('/usr/bin/gpg');
 			$gpg->secretkey($use_gpg_key);
 			$gpg->armor(1);
-			$gpg->comment("Wiaflos Accounting v$VERSION (www.wiaflos.org)");
+			$gpg->comment("$APPNAME v$VERSION ($APPURL)");
 			# Sign receipt
 			$sign = $gpg->sign($receiptData);
 			if (!defined($sign)) {

Modified: trunk/wiaflos/server/Statements.pm
===================================================================
--- trunk/wiaflos/server/Statements.pm	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/wiaflos/server/Statements.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -29,6 +29,7 @@
 use wiaflos::constants;
 use wiaflos::server::config;
 use wiaflos::server::dblayer;
+use wiaflos::server::templating;
 use wiaflos::server::Clients;
 use wiaflos::server::GL;
 
@@ -224,125 +225,65 @@
 	# If no accounts address, use general address
 	$billEmailAddr = @billEmailAddrs > 0 ? join(',', at billEmailAddrs) : join(',', at genEmailAddrs);
 
-	# Get statement template file
-	my $template = defined($config->{'statements'}{'email_template'}) ? $config->{'statements'}{'email_template'} : "../contrib/statements/statement1.tmpl";
+	# Build array of stuff we can use
+	my $vars = {
+		'WiaflosString' => $GENSTRING,
 
-	# Open template
-	if (!open(INVT, "< $template")) {
-		setError("Failed to open statement template '$template': $!");
-		return ERR_SRVFILE;
-	}
+		# Client
+		'ClientName' => $client->{'Name'},
+		'ClientCode' => $client->{'Code'},
+		'ClientBillingAddress' => $billAddr,
+		'ClientShippingAddress' => $shipAddr,
 
-	# Pull in date
-	my $date = DateTime->from_epoch( epoch => time() )->ymd();
+		# Statement
+		'StatementDate' => DateTime->from_epoch( epoch => time() )->ymd(),
+		# FIXME - not implemented yet
+		'StatementNote' => "",
+	};
 
+	# Tally up a running balance
+	my $runningBalance = Math::BigFloat->new();
+	$runningBalance->precision(-2);
+
+	# Load invoice line items
+	foreach my $item (@{$entries}) {
+		my $titem;
+
+		# Keep balance
+		$runningBalance->badd($item->{'Amount'});
+			
+		# Fix some stuff up
+		$titem->{'TransactionDescription'} = defined($item->{'Reference'}) ? $item->{'Reference'} : $item->{'TransactionReference'}; 
+		$titem->{'TransactionDate'} = $item->{'TransactionDate'};
+		$titem->{'TransactionAmount'} = sprintf('%.2f',$item->{'Amount'});
+		$titem->{'StatementBalance'} = sprintf('%.2f',$runningBalance->bstr());
+
+		# Various fixups & amount sanitizations
+		push(@{$vars->{'LineItems'}},$titem);
+	}
+	
 	# Get statement balance
 	my $statementBalance = Math::BigFloat->new();
 	$statementBalance->precision(-2);
 	foreach my $item (@{$entries}) {
 		$statementBalance->badd($item->{'Amount'});
 	}
+	$vars->{'StatementBalance'} = $statementBalance->bstr();
 
-	# Get receipt template file
-	my $footer = defined($config->{'statements'}{'footer'}) ? $config->{'statements'}{'footer'} : "Generated by Wiaflos Accounting (http://www.wiaflos.org)";
+	# Get statement template file
+	my $template = defined($config->{'statements'}{'email_template'}) ? $config->{'statements'}{'email_template'} : "statements/statement1.tt2";
 
-	# Output array
-	my @statementData;
-
-	# Loop with template lines
-	my $itemList = 0;
-	my @itemLines;
-	my $runningBalance = Math::BigFloat->new();
-	$runningBalance->precision(-2);
-	while ((my $line = <INVT>)) {
-		# If we beginning
-		if ($line =~ /^\s*<!-- begin items -->\s*$/) {
-			$itemList = 1;
-			next;
-		}
-
-		# When we hit the end, write out
-		if ($itemList && $line =~ /^\s*<!-- end items -->\s*$/) {
-
-			# Loop with items
-			foreach my $item (@{$entries}) {
-
-				# Keep balance
-				$runningBalance->badd($item->{'Amount'});
-				my $balance = $runningBalance->bstr();
-					
-				# And then with lines for items
-				foreach my $itemLine (@itemLines) {
-					my $tmp = $itemLine;
-
-					# Fix some stuff up
-#					my $paid = $invoice->{'Paid'} ? 'yes' : 'no';
-					my $ref = defined($item->{'Reference'}) ? $item->{'Reference'} : $item->{'TransactionReference'}; 
-					my $amount = sprintf('%.2f',$item->{'Amount'});
-
-					# Substitute
-					$tmp =~ s/%{transaction date}/$item->{'TransactionDate'}/g;
-					$tmp =~ s/%{transaction description}/$ref/g;
-					$tmp =~ s/%{transaction amount}/$amount/g;
-#					$tmp =~ s/%{invoice issue date}/$invoice->{'IssueDate'}/g;
-#					$tmp =~ s/%{invoice amount}/$invoice->{'otal'}/g;
-#					$tmp =~ s/%{amount allocated}/$item->{'Amount'}/g;
-#					$tmp =~ s/%{invoice paid}/$paid/g;
-					$tmp =~ s/%{statement balance}/$balance/g;
-
-					push(@statementData,$tmp);
-				}
-			}
-
-			$itemList = 0;
-			next;
-		}
-
-		# Normal line
-		if ($itemList == 0) {
-			$line =~ s/%{client name}/$client->{'Name'}/g;
-			$line =~ s/%{client code}/$client->{'Code'}/g;
-			$line =~ s/%{client billing address}/$billAddr/g;
-			$line =~ s/%{client shipping address}/$shipAddr/g;
-		
-#			$line =~ s/%{receipt reference}/$receipt->{'ReceiptRef'}/g;
-#			$line =~ s/%{receipt date}/$receipt->{'TransactionDate'}/g;
-#			$line =~ s/%{receipt amount}/$receipt->{'Amount'}/g;
-
-			$line =~ s/%{statement date}/$date/g;
-
-			my $balance = $statementBalance->bstr();
-			$line =~ s/%{statement balance}/$balance/g;
-
-			# TODO: statement note not implemented yet
-			$line =~ s/%{statement note}//g;
-
-			$line =~ s/%{document footer}/$footer/g;
-
-			push(@statementData,$line);
-		} else {
-			push(@itemLines,$line);	
-		}
-	}
-
-	close(INVT);
-
 	# Check where statement must go
 	if ($detail->{'SendTo'} =~ /^file:(\S+)/i) {
 		my $filename = $1;
 
-		# Open file
-		if (!open(FN,"> $filename")) {
-			setError("Failed to open statement file '$filename': $!");
-			return ERR_SRVFILE;
+		# Load template
+		my $res = loadTemplate($template,$vars,$filename);
+		if (!$res) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
 		}
 
-		# Write out statement
-		print(FN @statementData);
-
-		# And close
-		close(FN);
-
 	# Write out using email
 	} elsif ($detail->{'SendTo'} =~ /^email(?:\:(\S+))?/i) {
 		# Pull email address user specified if its defined and not blank, or use billing email address
@@ -363,7 +304,6 @@
 
 		# Receipt filename
 		(my $statementFilename = "statement.html") =~ s,/,-,g;
-
 		# Invoice signature filename
 		my $stmtSignFilename = $statementFilename . ".asc";
 
@@ -372,32 +312,28 @@
 		my $message_template = $config->{'statements'}{'email_message_template'};
 		my $emailBody = "";
 		if (defined($message_template) && $message_template ne "") {
-			# Open & check
-			if (!open(MB,"< $message_template")) {
-				setError("Failed to open statement email message '$message_template': $!");
-				return ERR_SRVFILE;
+			# Variables for our template
+			my $vars2 = {
+				'StatementFilename' => $statementFilename,
+				'StatementSignatureFilename' => $stmtSignFilename,
+			};
+			# Load template
+			$emailBody = loadTemplate($vars2,$message_template,$emailBody);
+			if (!$emailBody) {
+				setError("Failed to load template '$message_template': ".wiaflos::server::templating::Error());
+				return ERR_SRVTEMPLATE;	
 			}
-			# Read in each line
-			my @emailBody;
-			while (my $line = <MB>) {
-				push(@emailBody,$line);
-			}
 
-			close(MB);
-
-			# Join up
-			$emailBody = join('', at emailBody);
-
-			# Substitute
-			$emailBody =~ s/%{statement filename}/$statementFilename/g;
-			$emailBody =~ s/%{statement signature filename}/$stmtSignFilename/g;
-		
-			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol
+			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol for crypt-gpg
 		}
 
-
 		# This is our entire statement
-		my $statementData = join('', at statementData);
+		my $statementData = "";
+		$statementData = loadTemplate($template,$vars,$statementData);
+		if (!$statementData) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
+		}
 		$statementData =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol, needed to fix bug in crypt-gpg where it mangles \n
 
 		# See if we must use GPG
@@ -409,7 +345,7 @@
 			$gpg->gpgbin('/usr/bin/gpg');
 			$gpg->secretkey($use_gpg_key);
 			$gpg->armor(1);
-			$gpg->comment("Wiaflos Accounting v$VERSION (www.wiaflos.org)");
+			$gpg->comment("$APPNAME v$VERSION ($APPURL)");
 			# Sign statement
 			$sign = $gpg->sign($statementData);
 			if (!defined($sign)) {

Modified: trunk/wiaflos/server/SupplierReceipting.pm
===================================================================
--- trunk/wiaflos/server/SupplierReceipting.pm	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/wiaflos/server/SupplierReceipting.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -29,6 +29,7 @@
 use wiaflos::server::config;
 use wiaflos::server::dblayer;
 use wiaflos::server::cache;
+use wiaflos::server::templating;
 use wiaflos::server::Suppliers;
 use wiaflos::server::GL;
 
@@ -997,120 +998,73 @@
 	# If no accounts address, use general address
 	$billEmailAddr = @billEmailAddrs > 0 ? join(',', at billEmailAddrs) : join(',', at genEmailAddrs);
 
-	# Get receipt template file
-	my $template = defined($config->{'supplierreceipting'}{'email_template'}) ? 
-			$config->{'supplierreceipting'}{'email_template'} : "../contrib/supplier receipts/receipt1.tmpl";
+	# Build array of stuff we can use
+	my $vars = {
+		'WiaflosString' => $GENSTRING,
 
-	# Open template
-	if (!open(INVT, "< $template")) {
-		setError("Failed to open supplier receipt template '$template' for supplier receipt '".$receipt->{'Number'}."': $!");
-		return ERR_SRVFILE;
-	}
+		# Supplier
+		'SupplierCode' => $supplier->{'Code'},
+		'SupplierName' => $supplier->{'Name'},
+		'SupplierBillingAddress' => $billAddr,
+		'SupplierShippingAddress' => $shipAddr,
 
-	# Get receipt template file
-	my $footer = defined($config->{'supplierreceipting'}{'footer'}) ? 
-			$config->{'supplierreceipting'}{'footer'} : "Generated by Wiaflos Accounting (http://www.wiaflos.org)";
+		# Receipt
+		'ReceiptNumber' => $receipt->{'Number'},
+		'ReceiptDate' => $receipt->{'TransactionDate'},
+		'ReceiptAmount' => sprintf('%.2f',$receipt->{'Amount'}),
+		# FIXME - not implemented
+		'ReceiptNote' => "",
+	};
 
-	# Output array
-	my @receiptData;
-
-	# Loop with template lines
-	my $itemList = 0;
-	my @itemLines;
+	# Keep balance
 	my $receiptBalance = Math::BigFloat->new($receipt->{'Amount'});
-	while ((my $line = <INVT>)) {
-		# If we beginning
-		if ($line =~ /^\s*<!-- begin items -->\s*$/) {
-			$itemList = 1;
-			next;
-		}
 
-		# When we hit the end, write out
-		if ($itemList && $line =~ /^\s*<!-- end items -->\s*$/) {
+	# Load receipt line items
+	foreach my $item (@{$allocations}) {
+		my $titem;
 
-			# Loop with items
-			foreach my $item (@{$allocations}) {
-
-				# Pull credit note
-				$data = undef;
-				$data->{'ID'} = $item->{'SupplierCreditNoteID'};
-				my $creditnote = wiaflos::server::SupplierCreditNotes::getSupplierCreditNote($data);
-				if (ref $creditnote ne "HASH") {
-					setError(wiaflos::server::SupplierCreditNotes::Error());
-					return $creditnote;
-				}
-
-				# Keep balance
-				$receiptBalance->bsub($item->{'Amount'});
-				my $balance = $receiptBalance->bstr();
-					
-				# And then with lines for items
-				foreach my $itemLine (@itemLines) {
-					my $tmp = $itemLine;
-
-					# Fix some stuff up
-					my $closed = $creditnote->{'Closed'} ? 'yes' : 'no';
-
-					# Substitute
-					$tmp =~ s/%{credit note number}/$creditnote->{'Number'}/g;
-					$tmp =~ s/%{credit note issue date}/$creditnote->{'IssueDate'}/g;
-					$tmp =~ s/%{credit note amount}/$creditnote->{'Total'}/g;
-					$tmp =~ s/%{amount allocated}/$item->{'Amount'}/g;
-					$tmp =~ s/%{credit note closed}/$closed/g;
-					$tmp =~ s/%{receipt balance}/$balance/g;
-
-					push(@receiptData,$tmp);
-				}
-			}
-
-			$itemList = 0;
-			next;
+		# Pull credit note
+		$data = undef;
+		$data->{'ID'} = $item->{'SupplierCreditNoteID'};
+		my $creditnote = wiaflos::server::SupplierCreditNotes::getSupplierCreditNote($data);
+		if (ref $creditnote ne "HASH") {
+			setError(wiaflos::server::SupplierCreditNotes::Error());
+			return $creditnote;
 		}
 
-		# Normal line
-		if ($itemList == 0) {
-			$line =~ s/%{supplier name}/$supplier->{'Name'}/g;
-			$line =~ s/%{supplier code}/$supplier->{'Code'}/g;
-			$line =~ s/%{supplier billing address}/$billAddr/g;
-			$line =~ s/%{supplier shipping address}/$shipAddr/g;
-		
-			$line =~ s/%{receipt number}/$receipt->{'Number'}/g;
-			$line =~ s/%{receipt date}/$receipt->{'TransactionDate'}/g;
-			$line =~ s/%{receipt amount}/$receipt->{'Amount'}/g;
+		# Keep balance
+		$receiptBalance->bsub($item->{'Amount'});
 
-			# This MUST be at the END of your template, AFTER the items above to be of any use
-			my $balance = $receiptBalance->bstr();
-			$line =~ s/%{receipt balance}/$balance/g;
-	
-			# TODO: receipt note not implemented yet
-			$line =~ s/%{receipt note}//g;
+		# Fix some stuff up
+		$titem->{'CreditNoteNumber'} = $creditnote->{'Number'};
+		$titem->{'CreditNoteIssueDate'} = $creditnote->{'IssueDate'};
+		$titem->{'CreditNoteAmount'} = $creditnote->{'Total'};
+		$titem->{'CreditNoteAmountAllocated'} = $item->{'Amount'};
+		$titem->{'CreditNoteClosed'} = $creditnote->{'Closed'} ? 'yes' : 'no';
 
-			$line =~ s/%{document footer}/$footer/g;
+		$titem->{'ReceiptBalance'} = sprintf('%.2f',$receiptBalance->bstr());
 
-			push(@receiptData,$line);
-		} else {
-			push(@itemLines,$line);	
-		}
+		# Various fixups & amount sanitizations
+		push(@{$vars->{'LineItems'}},$titem);
 	}
+	# Get end receipt balance
+	$vars->{'ReceiptBalance'} = $receiptBalance->bstr();
 
-	close(INVT);
+	# Get receipt template file
+	my $template = defined($config->{'supplierreceipting'}{'email_template'}) ? 
+			$config->{'supplierreceipting'}{'email_template'} : "supplier_receipts/supplier_receipt1.tt2";
 
 	# Check where receipt must go
 	if ($detail->{'SendTo'} =~ /^file:(\S+)/i) {
 		my $filename = $1;
 
-		# Open file
-		if (!open(FN,"> $filename")) {
-			setError("Failed to open destination receipt file '$filename': $!");
-			return ERR_SRVFILE;
+		# Load template
+		my $res = loadTemplate($template,$vars,$filename);
+		if (!$res) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
 		}
 
-		# Write out receipt
-		print(FN @receiptData);
-
-		# And close
-		close(FN);
-
 	# Write out using email
 	} elsif ($detail->{'SendTo'} =~ /^email(?:\:(\S+))?/i) {
 		# Pull email addr
@@ -1131,41 +1085,36 @@
 
 		# Receipt filename
 		(my $receiptFilename = $receipt->{'Number'} . ".html") =~ s,/,-,g;
-
-		#  signature filename
+		# Signature filename
 		my $rctSignFilename = $receiptFilename . ".asc";
 
-
 		# If we must, pull in email body
 		my $message_template = $config->{'supplierreceipting'}{'email_message_template'};
 		my $emailBody = "";
 		if (defined($message_template) && $message_template ne "") {
-			# Open & check
-			if (!open(MB,"< $message_template")) {
-				setError("Failed to open receipt email message template '$message_template': $!");
-				return ERR_SRVFILE;
+			# Variables for our template
+			my $vars2 = {
+				'ReceiptFilename' => $receiptFilename,
+				'ReceiptSignatureFilename' => $rctSignFilename,
+			};
+			# Load template
+			$emailBody = loadTemplate($vars2,$message_template,$emailBody);
+			if (!$emailBody) {
+				setError("Failed to load template '$message_template': ".wiaflos::server::templating::Error());
+				return ERR_SRVTEMPLATE;	
 			}
-			# Read in each line
-			my @emailBody;
-			while (my $line = <MB>) {
-				push(@emailBody,$line);
-			}
 
-			close(MB);
-
-			# Join up
-			$emailBody = join('', at emailBody);
-
-			# Substitute
-			$emailBody =~ s/%{supplier receipt filename}/$receiptFilename/g;
-			$emailBody =~ s/%{supplier receipt signature filename}/$rctSignFilename/g;
-		
 			$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol
 		}
 
 
-		# This is our entire receipt
-		my $receiptData = join('', at receiptData);
+		# Load template
+		my $receiptData = "";
+		$receiptData = loadTemplate($template,$vars,$receiptData);
+		if (!$receiptData) {
+			setError("Failed to load template '$template': ".wiaflos::server::templating::Error());
+			return ERR_SRVTEMPLATE;	
+		}
 		$receiptData =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol, needed to fix bug in crypt-gpg where it mangles \n
 
 		# See if we must use GPG
@@ -1177,7 +1126,7 @@
 			$gpg->gpgbin('/usr/bin/gpg');
 			$gpg->secretkey($use_gpg_key);
 			$gpg->armor(1);
-			$gpg->comment("Wiaflos Accounting v$VERSION (www.wiaflos.org)");
+			$gpg->comment("$APPNAME v$VERSION ($APPURL)");
 			# Sign receipt
 			$sign = $gpg->sign($receiptData);
 			if (!defined($sign)) {

Added: trunk/wiaflos/server/templating.pm
===================================================================
--- trunk/wiaflos/server/templating.pm	                        (rev 0)
+++ trunk/wiaflos/server/templating.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -0,0 +1,122 @@
+# Templating functions
+# Copyright (C) 2005-2007 Nigel Kukard  <nkukard at lbsd.net>
+# Copyright (C) 2008, LinuxRulz
+# 
+# This program 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 program 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 program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+
+
+package wiaflos::server::templating;
+
+use strict;
+use warnings;
+
+
+use Template;
+
+
+# Exporter stuff
+require Exporter;
+our (@ISA, at EXPORT, at EXPORT_OK);
+ at ISA = qw(Exporter);
+ at EXPORT = qw(
+	loadTemplate
+);
+ at EXPORT_OK = qw(
+);
+
+
+# Server instance
+my $config;
+
+
+# Our current error message
+my $error = "";
+
+# Set current error message
+# Args: error_message
+sub setError
+{
+	my $err = shift;
+	my ($package,$filename,$line) = caller;
+	my (undef,undef,undef,$subroutine) = caller(1);
+
+	# Set error
+	$error = "$subroutine($line): $err";
+}
+
+# Return current error message
+# Args: none
+sub Error
+{
+	my $err = $error;
+
+	# Reset error
+	$error = "";
+
+	# Return error
+	return $err;
+}
+
+
+# Initialize templating engine
+sub Init
+{
+	my $server = shift;
+
+	$config = $server->{'template_config'};
+};
+
+
+# Create a template object
+# Args: template_name params
+sub loadTemplate
+{
+	my ($templateName,$params,$output) = @_;
+
+
+	# Build config
+	my $cfg = {
+		# Include paths, separated by :
+		INCLUDE_PATH => $config->{'path'},
+		# Header
+		PRE_PROCESS => $config->{'global_header'},
+		# Footer
+		POST_PROCESS => $config->{'global_footer'},
+	};
+
+	# Create template object
+	my $template = Template->new($cfg);
+	if (!$template) {
+		setError($Template::ERROR);
+		return undef;
+	}
+
+	# Process
+	my $res = $template->process($templateName,$params,$output);
+	if (!$res) {
+		setError($template->error());
+		return undef;
+	}
+
+	return $output;
+}
+
+
+
+
+1;
+# vim: ts=4

Modified: trunk/wiaflos/version.pm
===================================================================
--- trunk/wiaflos/version.pm	2008-08-04 07:35:26 UTC (rev 208)
+++ trunk/wiaflos/version.pm	2008-08-04 13:25:34 UTC (rev 209)
@@ -30,9 +30,10 @@
 @EXPORT = qw(
 	$APPNAME
 	$APPURL
-	$APPSTRING
 	$COPYRIGHT
 	$VERSION
+	$APPSTRING
+	$GENSTRING
 );
 
 # Our vars
@@ -42,6 +43,7 @@
 	$APPSTRING,
 	$COPYRIGHT,
 	$VERSION,
+	$GENSTRING,
 );
 
 $APPNAME = "Wiaflos Accounting";
@@ -49,6 +51,7 @@
 $COPYRIGHT = "Copyright (c) 2005-2008, LinuxRulz";
 $VERSION = "0.0.11";
 $APPSTRING = "$APPNAME - %s v$VERSION, $COPYRIGHT";
+$GENSTRING = "Generatd by $APPNAME ($APPURL)";
 
 1;
 # vim: ts=4



More information about the wiaflos-devel mailing list