Remove item code prefix form invoice

I have an item code prefix for non-inventory items (Services) for example (08/, 10/, 16/, 21/…etc) and then the item code for example (402010000, 40200000, 40203000…etc), because non-inventory items are repeated with the same codes, but for different categories.
So, the items codes in my invoice view would be like that (08/402010000, 08/402020000… etc).
Can someone help me to hide the prefix from the invoice view?
I need the items code just (40201000, 40202000… etc), as I use the category of these items in a custom field, it would be (08/, 10/, 16/, 21/…etc) in one field on the top of my invoice.
All adjustments on the plain theme would be acceptable.
Here is the plain theme code.

<table style="padding: 30px; width: 100%">
    <thead>
        <tr>
            <td colspan="99">
                <table style="margin-bottom: 20px; width: 100%"><tr>
                    <td style="font-weight: bold; font-size: 32px; vertical-align: top">{{ title }}</td>
                    {% if business.logo != null %}<td style="text-align: end"><img src="{{ business.logo }}" style="max-height: 150px; max-width: 300px" /></td>{% endif %}
                </tr></table>
                
                <table style="margin-bottom: 20px; width: 100%"><tr>
                    <td style="vertical-align: top">
                        <div style="font-weight: bold">{{ recipient.name }}</div>
                        <div>{{ recipient.address | newline_to_br }}</div>
                        <div>{{ recipient.identifier }}</div>
                    </td>
                    <td style="text-align: end; vertical-align: top">
                        {% for field in fields %}
                        <div style="font-weight: bold">{{ field.label }}</div>
                        <div style="margin-bottom: 10px">{{ field.text }}</div>
                        {% endfor %}
                    </td>
                    {% if business.address != null %}
                    <td style="width: 20px"></td>
                    <td style="width: 1px; border-left-width: 1px; border-left-color: #000; border-left-style: solid"></td>
                    <td style="width: 20px"></td>
                    <td style="width: 1px; white-space: nowrap; vertical-align: top">
                        <div style="font-weight: bold">{{ business.name }}</div>
                        <div>{{ business.address | newline_to_br }}</div>
                        {% for field in business.custom_fields %}
                        <div>{{ field.label }} {{ field.text }}</div>
                        {% endfor %}
                    </td>
                    {% endif %}
                </tr></table>

                <div style="font-size: 14px; font-weight: bold; margin-bottom: 20px">{{ description }}</div>
            </td>
        </tr>
        <tr>
            {% for column in table.columns %}
            <td style="writing-mode: horizontal-tb; border-inline-start-width: 1px; border-inline-start-style: solid; border-inline-start-color: #000; {% if forloop.last == true %} border-inline-end-width: 1px; border-inline-end-style: solid; border-inline-end-color: #000{% endif %}; text-align: {{ column.align }}; font-weight: bold; padding: 5px 10px; border-bottom-width: 1px; border-bottom-color: #000; border-top-width: 1px; border-top-color: #000; border-top-style: solid; border-bottom-style: solid{% if column.nowrap %}; width: 80px{% endif %}">{{ column.label }}</td>
            {% endfor %}
        </tr>
    </thead>
    <tbody>
        {% for row in table.rows %}
        <tr>
            {% for cell in row.cells %}
            <td style="writing-mode: horizontal-tb; border-inline-start-width: 1px; border-inline-start-style: solid; border-inline-start-color: #000; {% if forloop.last == true %} border-inline-end-width: 1px; border-inline-end-style: solid; border-inline-end-color: #000{% endif %}; padding: 5px 10px; text-align: {{ table.columns[forloop.index0].align }}; {% if table.columns[forloop.index0].nowrap %}; white-space: nowrap; width: 80px{% endif %}">{{ cell.text | newline_to_br }}</td>
            {% endfor %}
        </tr>
        {% endfor %}
        <tr>
        {% for column in table.columns %}
            <td style="writing-mode: horizontal-tb; border-inline-start-width: 1px; border-inline-start-style: solid; border-inline-start-color: #000; {% if forloop.last == true %} border-inline-end-width: 1px; border-inline-end-style: solid; border-inline-end-color: #000{% endif %}; border-bottom-width: 1px; border-bottom-color: #000000; border-bottom-style: solid">&nbsp;</td>
        {% endfor %}
        </tr>
        {% for total in table.totals %}
        <tr>
            <td colspan="{{ table.columns | size | minus:1 }}" style="text-align: end; padding: 5px 10px{% if total.emphasis == true %}; font-weight: bold{% endif %}">{{ total.label }}</td>
            <td style="border-left-width: 1px; border-left-style: solid; border-left-color: #000; border-right-width: 1px; border-right-style: solid; border-right-color: #000; text-align: right; white-space: nowrap; border-bottom-width: 1px; border-bottom-color: #000000; border-bottom-style: solid; padding: 5px 10px{% if total.emphasis == true %}; font-weight: bold{% endif %}">{{ total.text }}</td>
        </tr>
        {% endfor %}

        {% for field in custom_fields %}
        <tr>
            <td colspan="99">
                <div style="font-weight: bold; padding-top: 20px">{{ field.label }}</div>
                <div>{{ field.text | newline_to_br }}</div>
            </td>
        </tr>
        {% endfor %}

        <tr>
            <td colspan="99">
                {% if emphasis.text != null and emphasis.positive %}
                <div style="text-align: center; margin-top: 40px"><span style="color: #006400; border-width: 5px; border-color: #006400; border-style: solid; padding: 10px; font-size: 20px">{{ emphasis.text | upcase }}</span></div>
                {% endif %}

                {% if emphasis.text != null and emphasis.negative %}
                <div style="text-align: center; margin-top: 40px"><span style="color: #FF0000; border-width: 5px; border-color: #FF0000; border-style: solid; padding: 10px; font-size: 20px">{{ emphasis.text | upcase }}</span></div>
                {% endif %}
            </td>
        </tr>
    </tbody>
</table>

I would be very grateful for any help from members.

  • Use batch update to move the prefix from the item code to the custom field on all your Non-inventory items.
  • Then use a custom theme to display the prefix before the item number on the documents you want it displayed that way.

Non-Inventory items with the same code and the different prefix are different services provided by different prices, removing the prefix from items codes will confuse these items with each other. also if I will use a custom theme any way, I’m asking for help to hide the prefix from Invoice not remove, just hide

Replace:

{{ cell.text | newline_to_br }}

With:

{% if cell.text contains "/" %}
    {{ cell.text | slice: 3,1000  | newline_to_br }}
{% else %}
    {{ cell.text | newline_to_br }}
{% endif %}

This will work but you have to ensure the following:

  • the delimiter used for perfixes is always “/”
  • the delimiter is not used elsewhere, otherwise you need to use another delimiter
  • the length of text to be removed incl. the delimiter is always equal to 3 characters
  • the total length of description text does not exceed 1003 characters
2 Likes

you are always the savior, many hearts :two_hearts: for you Mr. Ebrahim.

1 Like

need more help if you can:
how to make the filter works for only five conditions instead of “/”, I need it works if the prefix are one of these only (08/, 10/, 16/, 21/ and T/)
:rose:

you can also replace the below code in your plain theme

{% for cell in row.cells %}
<td style="writing-mode: horizontal-tb; border-inline-start-width: 1px; border-inline-start-style: solid; border-inline-start-color: #000; {% if forloop.last == true %} border-inline-end-width: 1px; border-inline-end-style: solid; border-inline-end-color: #000{% endif %}; padding: 5px 10px; text-align: {{ table.columns[forloop.index0].align }}; {% if table.columns[forloop.index0].nowrap %}; white-space: nowrap; width: 80px{% endif %}">{{ cell.text | newline_to_br }}</td>
{% endfor %}

with

{% for cell in row.cells %}
{% assign n = cell.text.size %}
<td style="writing-mode: horizontal-tb; border-inline-start-width: 1px; border-inline-start-style: solid; border-inline-start-color: #000; {% if forloop.last == true %} border-inline-end-width: 1px; border-inline-end-style: solid; border-inline-end-color: #000{% endif %}; padding: 5px 10px; text-align: {{ table.columns[forloop.index0].align }}; {% if table.columns[forloop.index0].nowrap %}; white-space: nowrap; width: 80px{% endif %}">{% if forloop.first %}{{ cell.text | slice: 3, n }}{% else %}{{ cell.text | newline_to_br }}{% endif %}</td>
{% endfor %}

as long as the item code is the first column, the size of the string is captured and the first 3 characters are sliced to display the rest.

if you want to slice more than 3 characters, just replace the number 3 with any other number of your choice in {{ cell.text | slice: 3, n }}

4 Likes

How could it be if it is the 2nd column?

just make sure all the prefix are limited to no less than 3 characters. for example, you can add another suitable character to T/ and still use the code provided above.

there are some limitations in both methods provided by @Ealfardan and me.

1 Like

I can replace “T/” with “T0/” that’s fine, could you please edit to work with the 2nd column? I’ve the line number in the first column.

I have made a modification to the code I provided earlier.

{% for cell in row.cells %}
{% assign n = cell.text.size %}
<td style="writing-mode: horizontal-tb; border-inline-start-width: 1px; border-inline-start-style: solid; border-inline-start-color: #000; {% if forloop.last == true %} border-inline-end-width: 1px; border-inline-end-style: solid; border-inline-end-color: #000{% endif %}; padding: 5px 10px; text-align: {{ table.columns[forloop.index0].align }}; {% if table.columns[forloop.index0].nowrap %}; white-space: nowrap; width: 80px{% endif %}">{% if forloop.index == 1 %}{{ cell.text | slice: 3, n }}{% else %}{{ cell.text | newline_to_br }}{% endif %}</td>
{% endfor %}

the above code will work if the item code is your first column.
{% if forloop.index == 1 %} this is the code which controls which column needs to be sliced. if your item code is on the second column, then change the value from 1 to 2.

3 Likes

Thanks @Ealfardan and @sharpdrivetek for your kind support. Also, thank you @Patch for your reply.

1 Like