Template modification to allow empty lines

I’m doing customization on the invoice template but in the second I duplicate and start working I got result like in the image. As you can see empty lines produces zeros.

I need to add 14 lines to match the sizes of my paper invoice so please dont tell me to remove unused lines. :frowning: In the original version of the invoice I’m able to add as many lines as I want and it still looks the same(empty)

Looking forward to your answer

@fohteh I needed the same for my invoice template and did the following.
I added empty lines based on my max lines, in your case 14, and substracted real invoice lines.

Like this:

<!-- First loop which is already in template, look for it -->
{% for line in lines %}
<tr>
   <td> ... </td>
</tr>
{% endfor %}
     
<!-- Second loop to add missing empty lines -->
{% assign blank_lines = 14 | minus:lines.size %}
{% for i in (1..blank_lines) %}
<tr>
   <td>&nbsp;</td>
</tr>
{% endfor %}

For de table data <td> part of the second loop, you best copy that from the first loop because it may have columns that do not always appear on the invoice and place &nbsp; in the value part as shown in the example.

Good luck.

Hello @Hans @Hans

Thank you for the help but I’m not a coder; I customize it as doing trial and error :slight_smile: I’m afraid to break all actually.

Here’s codes can you show me how to fix this part? I needed 11 lines, sorry for the mistake

. Also; Okay I dont want it to produce "Zero"s in the invoice but after your correction can I still add 2nd 3rd items as normal as the 1st item right?

**<tr>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-bottom: none; border-top: none; vertical-align: top">{{ line.item.name }}</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-bottom: none; border-top: none">{{ line.description | newline_to_br }}</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-bottom: none; border-top: none; text-align: center; vertical-align: top">{{ line.qty }}</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-bottom: none; border-top: none; text-align: right; vertical-align: top">{{ line.unit_price | money_without_currency }}</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-bottom: none; border-top: none; text-align: center; vertical-align: top">{{ line.discount }}</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; text-align: right; border-bottom: none; border-top: none; vertical-align: top; white-space: nowrap">{{ line.total | money_without_currency }}</td>**
                    **</tr>**
                    **{% endfor %}**
                    **<tr>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">&nbsp;</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">&nbsp;</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">&nbsp;</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">&nbsp;</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">&nbsp;</td>**
                        **<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">&nbsp;</td>**
                    **</tr>**

@fohteh, if you are happy with the look of default template, I guess I can make some modifications to it so if no description is entered and unit price is 0.00, then you will get empty line.

That way you wouldn’t need to do anything with HTML, just make sure all your invoices have 20 lines or so. Would that work for you?

Hi @lubos

I actually modified the default template to match my original paper invoice. So making changes in the original invoice would only correct the empty lines.

I exactly need 11 lines for the invoice. But also I need to be able to add items in those lines whenever 2 or more products to be listed.

If you can work on my code then the problem might be solved. But I can’t add it here its too long. Any idea how can I send it to you?

I actually checked the latest version and Manager doesn’t show quantity and amounts on invoices in default template if line item is empty.

So if you really insist on custom HTML, you probably need to use some “if / else” expression.

For example:

{% if qty != 0 %} {{ qty }} {% endif %}

This way qty variable prints only if it’s not zero.

I can’t help with debugging custom HTML issues. I’m more than happy to keep improving default invoice template so no HTML is needed in the first place. As it stands now, default invoice template doesn’t show anything in quantity or amount columns if the line item is empty.

Hi @fohteh,

I have send you a message.
Log in and look under your profile for messages.

Hi @Lubos and @Hans

I’m happy with the default template I Just applied some modifications.

I’m using the latest web desktop version; whenever I edit template it breaks as the image I showed in the first mail. I dont know why

I’ve uploaded a 1 min video via we transfer, showing how the invoice template breaks down from the moment I create one.

its only 20 MB

Here’s the link: http://we.tl/GcKo5AAaXQ

If you use custom HTML template, it shows those columns and zeroes because that’s what is in that template to do. So everything works as expected.

You will need to understand HTML (or have someone to help you) otherwise don’t use any HTML template and stick to default look & feel which is a bit more sophisticated (automatically hiding columns which are not relevant or hiding zeroes).

Understood :slight_smile: !

But why I can’t edit Turkish version of the template; every content changes to english suddenly

The HTML example provided is in English. You can edit HTML to replace English text with Turkish text too.

Yes; that’s what I do and I get zeros in the empty lines. Anyways @lubos; I managed somehow to suit the template to my needs.

You guys made superb tool, thank you for all the help! I’ll for sure invest in Manager after getting results with the free desktop mac version!

keep up the good work!

Hi @fohteh,

I have taken a default template (which @lubos has recently given an extra last line) and adjusted it to your needs. You will have to do some translation into turkish yourself. :smile:

Now you will have 11 lines on your invoice with no zero in the empty lines. Even so for normal line items with a quantity of 0. (See addition @lubos from Sept. 2). Also any additional lines from 11 upward will be added if need be.

You can find it here: Edit fiddle - JSFiddle - Code Playground

Good luck.

Hey @Hans thanks a lot!!!

Will try it today!!!

@Hans… it just worked so perfect!

I appreciate your efforts doing it. Really, really thanks…

One more thing; (I’m asking too much lol)

On the last line; I need to type the amount of the invoice in letters; like “Only one thousand five hundred thirty Turkish Liras.”

Is there a way to add a text on the last line? Because when I add empty lines using your template; it produces zeros again?

If not, I already give you thumbs up!

Thank you brother

When you add a new line don’t forget to edit quantity to zero (default = 1).

For your question about amount in letters, this is my solution:

  1. Go to settings and open ‘Custom fields’
  2. Create custom field under ‘Sales invoice’
  3. Label it AmountAsText, type Single line, Size Average

Get latest template from Edit fiddle - JSFiddle - Code Playground

Now when you create a new invoice you’ll find at the bottom a input field called AmountAsText. Enter your text and create invoice. That’s it.

To change AmountAsText label, you have to change custom field name and template where it says
{{ custom_fields['AmountAsText'] }}

Have fun.

Hi @Hans

“Adding quatitiy to zero” well noted! Thanks.
But custom field is not working.

I can see the custom field while preparing the sales invoice; but it doesnt show up in the invoice

@fohteh, the option will work only if you are not using custom HTML. Once you use custom HTML, you will need to use HTML markup to make custom field visible on printed invoice just like @Hans has suggested.

@fohteh, did you get latest template? Check if you can find a line which looks like this.

<td style="border: 1px solid #000; padding: 5px 10px; border-top: none">{{ custom_fields['AmountAsText'] }}</td>

@Hans yes I did get it; translated it already and I can see the line you mentioned.