Template for invoices, credits etc.

Can an expression be formulated so that the same template can be used for invoice, credit, counter sale and receipt? So that an invoice or counter sale prints the heading Tax Invoice, a credit prints Tax Credit and a receipt prints Receipt. If so, how would the expression be placed on the report eg. as a variable, and what would the expression look like?

 

Regards, Simon

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Template for invoices, credits etc.

Simon - I went through this line of thought when I did the templates for Hong Kong [I had to do templates for 3 businesses]. The best I came up with was a) you can use the same items template for both invoices and credit notes; b) do the invoice template first and then clone the others from this.

That said, within a given template, the expression openvpms:get(.,"shortName") will return the short name of the archetype, and thus for an invoice will return act.customerChargesChargesInvoice - see http://www.openvpms.org/documentation/csh/1.7/reference/reportFields

Hence you can define a field set to [openvpms:get(.,"shortName")] and then define a text field with the expression something like

($F{[openvpms:get(.,"shortName")]}.contains("Invoice"))?"Tax Invoice":($F{[openvpms:get(.,"shortName")]}.contains("Credit"))?"Tax Credit":($F{[openvpms:get(.,"shortName")]}.contains("Payment"))?"Payment":"????"

However, my feeling in that the 'build invoice, then clone others' is in fact a simpler approach.

Regards, Tim G

Re: Template for invoices, credits etc.

The thought that struck me was if iReports would take a

case a then 'b'

case x then 'y'

else 'z'

type statement, it would be easier than many rounds of field property changes then inserting and checking in OP for each use case of the document.  But as you say, Tim, cloning would minimise that, once one is right.  I've done what we need to get this month's statements out, but I might have a play with the expression before next month's round.

Regards, Simon

Simon Slater

Registered Linux User #463789 @ http://linuxcounter.net

Re: Template for invoices, credits etc.

Simon - no you cannot write this sort of code - ie you cannot write stuff like:

if (condition) then {
   a = ......;
   b = ......;
   c = ......;
} else {
   a = ......;
   b = ......;
   c = ......;
}

ie you cannot 'centralise' the settings of a number of variables in one place.

You can do the equivalent of:

if (condition) {a = "xxxx";} else {a = "yyyy";)

using (as I did) the expression:

(condition)? "xxxx" : "yyyy"

My advice remains 'get the invoice going to your satisfaction, then clone the others from it'.

Regards, Tim G

Re: Template for invoices, credits etc.

A Switch-Case statement would be ideal here.

I dont think jasperreports has brought the changes to Switch statements through from Java se7 yet.  

prior to java7 - java could not use switch statements based on strings natively (you could right a enum converter interface to do it)

it can as of java7

But as I said I doubt jasperreports is allowing switch statements yet (certainly version 3.7.5 wasnt (it was compiled against java5 I think)

Switch case just uses String.equals anyway so TimG solution using contains is more intensive but if you know the values will be a limited set then equals would be more efficient.

( $F{FIELDV}.equals("ab") ? "aaaa" :( $F{FIELDV}.equals("bc") ? "bbbb" :( $F{FIELDV}.equals("de") ? "cccc" : "" )))

ben

Regards
 
Ben 
OpenVPMS Installer and Helper 
Ph: +61423044823 
Email: info[at]charltonit.com[dot]au

Re: Template for invoices, credits etc.

So the '?' is part of the syntax for the expression.  Is this java? Simon

Simon Slater

Registered Linux User #463789 @ http://linuxcounter.net

Re: Template for invoices, credits etc.

In java you can express an if-else clause either as

if(boolean){do one thing}else{do another}; 

or as the shorthand 

Object x = (boolean)? resultobject1:resultobject2; 

 

they are basically equivalent however traditionally the first method is used when you run a series of statements within the if statement rather than just return  a value.  The later is used to chose between 2 return values or set a value as in my example.

Regards
 
Ben 
OpenVPMS Installer and Helper 
Ph: +61423044823 
Email: info[at]charltonit.com[dot]au
Syndicate content