Multiple invoice templates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple invoice templates

iwolf
Hi All,

I am looking for a way to add additional invoice templates without changing to much of the original ofbiz code if possible.

The case:
- multiple unrelated companies
- multi tenant environment
- multiple invoice layouts

Any hint/idea would be appreciated.

Kind regards,
Ingo
Reply | Threaded
Open this post in threaded view
|

Re: Multiple invoice templates

Malin Nicolas
Hi Ingo,

When I have this case on a projet, I use the content system to load the
template.

Example :
  Store a default template for each organization or a template specific
by some customer.
  * Create PartyContentType : INVOICE_TEMPLATE
  * Load your templates en Content
  * Associate your content to each organization in ofbiz
  * if a customer have a specific template associate it

On your InvoicePDF screen resolve the template by a groovy script :
[code]
    //resolve if customer template is present
    partyContents = delegator.findByAndCache("PartyContent", [partyId :
invoice.partyId])
    if (partyContents) partyContents =
EntityUtil.filterByDate(partyContents, invoice.invoiceDate)
    if (partyContents) partyContent = partyContents[0]

    if (!partyContent) { //resolve if organization hasa template
        partyContents = delegator.findByAndCache("PartyContent",
[partyId : invoice.partyIdFrom])
        if (partyContents) partyContents =
EntityUtil.filterByDate(partyContents, invoice.invoiceDate)
        if (partyContents) partyContent = partyContents[0]
    }
[/code]
Warn, I wrote the code on the fly, maybe it doesn't contains the
absolute true ;)

Now you have a content, you can resolve your flow has you want (ftl
injection, content service to renderer string), etc ....


Le 05/09/2014 23:25, iwolf a écrit :

> Hi All,
>
> I am looking for a way to add additional invoice templates without changing
> to much of the original ofbiz code if possible.
>
> The case:
> - multiple unrelated companies
> - multi tenant environment
> - multiple invoice layouts
>
> Any hint/idea would be appreciated.
>
> Kind regards,
> Ingo
>
>
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Multiple-invoice-templates-tp4654897.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Multiple invoice templates

iwolf
Hi Nicolas,

sounds like a good solution for me. Thanks for the fast reply and help.

Kind regards,
Ingo
Reply | Threaded
Open this post in threaded view
|

Re: Multiple invoice templates

Pierre Smits
In reply to this post by Malin Nicolas
Nicolas,

It seems to me that this is essential to running OFBiz in a multi
organisation setup. Would you care to raise a JIRA issue of the type
'improvement' and include your code snippet there as a starting point?

Best regards,

Pierre Smits

*ORRTIZ.COM <http://www.orrtiz.com>*
Services & Solutions for Cloud-
Based Manufacturing, Professional
Services and Retail & Trade
http://www.orrtiz.com


On Sat, Sep 6, 2014 at 8:44 AM, Nicolas Malin <[hidden email]
> wrote:

> Hi Ingo,
>
> When I have this case on a projet, I use the content system to load the
> template.
>
> Example :
>  Store a default template for each organization or a template specific by
> some customer.
>  * Create PartyContentType : INVOICE_TEMPLATE
>  * Load your templates en Content
>  * Associate your content to each organization in ofbiz
>  * if a customer have a specific template associate it
>
> On your InvoicePDF screen resolve the template by a groovy script :
> [code]
>    //resolve if customer template is present
>    partyContents = delegator.findByAndCache("PartyContent", [partyId :
> invoice.partyId])
>    if (partyContents) partyContents = EntityUtil.filterByDate(partyContents,
> invoice.invoiceDate)
>    if (partyContents) partyContent = partyContents[0]
>
>    if (!partyContent) { //resolve if organization hasa template
>        partyContents = delegator.findByAndCache("PartyContent", [partyId
> : invoice.partyIdFrom])
>        if (partyContents) partyContents = EntityUtil.filterByDate(partyContents,
> invoice.invoiceDate)
>        if (partyContents) partyContent = partyContents[0]
>    }
> [/code]
> Warn, I wrote the code on the fly, maybe it doesn't contains the absolute
> true ;)
>
> Now you have a content, you can resolve your flow has you want (ftl
> injection, content service to renderer string), etc ....
>
>
> Le 05/09/2014 23:25, iwolf a écrit :
>
>  Hi All,
>>
>> I am looking for a way to add additional invoice templates without
>> changing
>> to much of the original ofbiz code if possible.
>>
>> The case:
>> - multiple unrelated companies
>> - multi tenant environment
>> - multiple invoice layouts
>>
>> Any hint/idea would be appreciated.
>>
>> Kind regards,
>> Ingo
>>
>>
>>
>> --
>> View this message in context: http://ofbiz.135035.n4.nabble.
>> com/Multiple-invoice-templates-tp4654897.html
>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Multiple invoice templates

Malin Nicolas
Yes sure Pierre, but isn't in my priority to contribute to it, currently
I works to convert simple CRUD service ;)

Nicolas

Le 07/09/2014 11:04, Pierre Smits a écrit :

> Nicolas,
>
> It seems to me that this is essential to running OFBiz in a multi
> organisation setup. Would you care to raise a JIRA issue of the type
> 'improvement' and include your code snippet there as a starting point?
>
> Best regards,
>
> Pierre Smits
>
> *ORRTIZ.COM <http://www.orrtiz.com>*
> Services & Solutions for Cloud-
> Based Manufacturing, Professional
> Services and Retail & Trade
> http://www.orrtiz.com
>
>
> On Sat, Sep 6, 2014 at 8:44 AM, Nicolas Malin <[hidden email]
>> wrote:
>> Hi Ingo,
>>
>> When I have this case on a projet, I use the content system to load the
>> template.
>>
>> Example :
>>   Store a default template for each organization or a template specific by
>> some customer.
>>   * Create PartyContentType : INVOICE_TEMPLATE
>>   * Load your templates en Content
>>   * Associate your content to each organization in ofbiz
>>   * if a customer have a specific template associate it
>>
>> On your InvoicePDF screen resolve the template by a groovy script :
>> [code]
>>     //resolve if customer template is present
>>     partyContents = delegator.findByAndCache("PartyContent", [partyId :
>> invoice.partyId])
>>     if (partyContents) partyContents = EntityUtil.filterByDate(partyContents,
>> invoice.invoiceDate)
>>     if (partyContents) partyContent = partyContents[0]
>>
>>     if (!partyContent) { //resolve if organization hasa template
>>         partyContents = delegator.findByAndCache("PartyContent", [partyId
>> : invoice.partyIdFrom])
>>         if (partyContents) partyContents = EntityUtil.filterByDate(partyContents,
>> invoice.invoiceDate)
>>         if (partyContents) partyContent = partyContents[0]
>>     }
>> [/code]
>> Warn, I wrote the code on the fly, maybe it doesn't contains the absolute
>> true ;)
>>
>> Now you have a content, you can resolve your flow has you want (ftl
>> injection, content service to renderer string), etc ....
>>
>>
>> Le 05/09/2014 23:25, iwolf a écrit :
>>
>>   Hi All,
>>> I am looking for a way to add additional invoice templates without
>>> changing
>>> to much of the original ofbiz code if possible.
>>>
>>> The case:
>>> - multiple unrelated companies
>>> - multi tenant environment
>>> - multiple invoice layouts
>>>
>>> Any hint/idea would be appreciated.
>>>
>>> Kind regards,
>>> Ingo
>>>
>>>
>>>
>>> --
>>> View this message in context: http://ofbiz.135035.n4.nabble.
>>> com/Multiple-invoice-templates-tp4654897.html
>>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: Multiple invoice templates

iwolf
For anyone who is interested, here is my solutions:

/applications/accounting/widget/AccountingPrintScreens.xml add:

<screen name="InvoicePDF">
   <section>
   <actions>       
     <script location="component://accounting/webapp/accounting/WEB-INF/actions/invoice/InvoiceTemplate.groovy"/>
   </actions>               
   <widgets>                               
       <include-screen name="${template}" location="${templatepath}"/>
   </widgets>
   </section>               
</screen>

Then rename the existing <screen name="InvoicePDF"> to <screen name="InvoicePDF_default">

Add the following script accounting/webapp/accounting/WEB-INF/actions/invoice/InvoiceTemplate.groovy

##START
import org.ofbiz.accounting.invoice.*;

invoiceId = parameters.get("invoiceId");
templatepath = "component://accounting/widget/AccountingPrintScreens.xml"
template = "InvoicePDF_default";

if (invoiceId) {
    invoice = delegator.findOne("Invoice", [invoiceId : invoiceId], false);

        billingParty = InvoiceWorker.getBillToParty(invoice);
    sendingParty = InvoiceWorker.getSendFromParty(invoice);
       
        if (billingParty) {
                partyId = billingParty.partyId;
               
                                // get the template
                partyContents = delegator.findByAndCache("PartyContent", [partyId : partyId])
                templateattr = delegator.findByAnd("PartyAttribute", [partyId : partyId, attrName :"invoiceTemplate"], null, false);
        }
        if (templateattr.size()==0){
                partyId = sendingParty.partyId;
                partyContents = delegator.findByAndCache("PartyContent", [partyId : partyId])
                templateattr = delegator.findByAnd("PartyAttribute", [partyId : partyId, attrName :"invoiceTemplate"], null, false);
        }
       
        if(templateattr.size()>0){
                tmp_template = templateattr[0].get("attrValue").split("#");
                templatepath = tmp_template[0]
                template = tmp_template[1]
        }
        context.templatepath = templatepath
        context.template = template
}
###END

I use the partyAttributes pointing to the screen definition. For example:

attribute Name = invoiceTemplate
attribute Value = component://accounting/widget/AccountingPrintScreens.xml#InvoicePDF_default

If no template is defined it falls back to the default default screen definition.

Again thanks to Nicolas for pointing me here!