Multiple Templates

Subscribe to Multiple Templates 10 post(s), 3 voice(s)

 
Avatar AdamJ 51 post(s)

This is a pretty small request I think, and I’m pretty sure this has been brought up before, but I couldn’t find it in a quick search just now.

What I would love to see is being able to have multiple active templates, which you choose from when you are producing an invoice or estimate. My reason? For some projects I charge a flat rate, for others I work by the hour (not generally a mix of the two). I would love to be able to have one template which displays the hours worked and hourly rate but not the flat rate column, and another template that doesnt, just shows the total (as its a flat rate for each item). It makes it a bit cleaner, and less confusing for my clients. I understand I could switch out the default template each time, but it is quite time consuming to do so.

If it was possible to assign a template, that would be awesome!

 
Avatar drak0 23 post(s)

This is kind of a hack, but since liquid templates supports logic and cashboard supports custom invoice numbers (i think), you could prefix fixed fee invoices with ‘FF’.

- pseudo code
if invoice_id.startswith('FF'): use fixed width template
else: use other template

Seth, is something like this possible? Although, this is kinda kludgy… shrug

 
Avatar Seth - Subimage LLC Administrator 445 post(s)

Interesting! I’m not sure if that’s valid Liquid syntax, but a similar approach could be used I suppose.

You could make use of the liquid include function with the if / elseif statement.

 
Avatar AdamJ 51 post(s)

I’ll have to give this a go and I’ll post back with the results, thanks for the advice guys!

Seth, any interest in adding assignable templates to the core?

 
Avatar Seth - Subimage LLC Administrator 445 post(s)

Yes, I’m interested in doing that, along with a million other things… Problem is there’s a ton of stuff that will give us more bang for the buck before I’d get a chance to get to this.

It’s on my radar.

 
Avatar AdamJ 51 post(s)

No worries, good to know its on the list at least. I’ll try what you and drak0 suggested for now.

 
Avatar AdamJ 51 post(s)

I’m back! So I quickly realised that adding a character to the id would then be entered into the invoice the client sees too, which I didnt really want. That character could have been removed from the invoice with some code when it is displayed too, but I thought of another way to do it without having to change anything in the invoice.

What I did was create two variables ‘flatfee’ and ‘hourly’ and made them false. Then loop through all the line items in the invoice, and if either didnt equal 0, assigned the appropriate variable as true. Then have an if/else if statement to include the appropriate templates for each situation.


 {% assign flatfee = false %}
{% assign hourly = false %}
{% for item in invoice.line_items %}
  {% if item.flat_fee != '0.00' %}
    {% assign flatfee = true %}
  {% endif %}
  {% if item.quantity != '0.0' %}
    {% assign hourly = true %}
  {% endif %}
{% endfor %}

{% if flatfee == false && hourly == true %}
 {{ # THIS IS HOURLY }}
 {% include 'html_invoice_hourly' %}
{% else if flatfee == true && hourly == false %}
 {{ # THIS IS FLAT FEE }}
 {% include 'html_invoice_flatfee' %}
{% else %}
 {{ # THIS IS MIXED }}
 {% include 'html_invoice_mixed' %}
{% endif %}

Thanks for all the help guys, its greatly appreciated!


[edit] Had '%%' instead of '&&' in the 'else if' line

 
Avatar drak0 23 post(s)

Adam.. nice! I like you being able to determine what invoice to use on the fly vs my orig. idea!

A slightly more robust solution (that didn’t depend on the way seth format’s his numbers) would be to sum the hourly vs flatfee hours. And then use logic like ‘if flatfee_hours > 0”, etc…

Anyway, nice work! This should be the default template :)

I’m digging cashboard’s ability to give powerusers… well, power!

 
Avatar Seth - Subimage LLC Administrator 445 post(s)

Awesome use of the features guys ;)

Moved this to the Templates section so others might find it and use the technique.

 
Avatar AdamJ 51 post(s)

Just in case someone finds this, drak0’s comment came to pass as it looks like the formatting for the flat fee changed from 0.00 to 0.0. I’ve implemented his idea with maths instead of comparing strings, so use this one instead of my previous.


{% assign flatfee = 0 %}
{% assign hourly = 0 %}
{% for item in invoice.line_items %}
  {% assign flatfee = flatfee + item.flat_fee %}
  {% assign hourly = hourly + item.quantity %}
{% endfor %}

{% if flatfee == 0 && hourly > 0 %}
 {{ # THIS IS HOURLY }}
 {% include 'html_invoice_hourly' %}
{% else if flatfee > 0 %% hourly == 0 %}
 {{ # THIS IS FLAT FEE }}
 {% include 'html_invoice_flatfee' %}
{% else %}
 {{ # THIS IS MIXED }}
 {% include 'html_invoice_mixed' %}
{% endif %}