Print Format JS ERROR

Hi everyone,

i am trying to customize print format for offline pos,

i am trying to implement if statement condition but i think if statement is not working, however i tried with 2,3 syntax, can anybody guide for the right syntax for JS print format?

{% for d in taxes %}
    {% if(d.account_head == "CGST 6% - E"){ %}
        {% cgst += d.tax_amount %}
    {% } %}
    {% if d.account_head == "CGST 6% - E" %}
        {% cgst += d.tax_amount %}
    {% endif %}
{% endfor %}

the aim is to use In/includes instead of == but its also not working.

Try

{% for d in taxes %}
    {% if "CGST 6% - E" in d.account_head %}
        {% cgst += d.tax_amount %}
    {% endif %}
{% endfor %}

hi @dj12djdjs,

now its not even opening the print.

{% var cgst = 0 %}
{% var sgst = 0 %}
{% for d in taxes %}
    {% if "CGST 6% - E" in d.account_head %}
        {% cgst += d.tax_amount %}
    {% endif %}
{% endfor %}

Use set not var

{% set cgst = 0 %}
{% set sgst = 0 %}
{% for d in taxes %}
    {% if "CGST 6% - E" in d.account_head %}
        {% cgst += d.tax_amount %}
    {% endif %}
{% endfor %}

This isn’t formatted with Java Script. It is compiled with Python+Jinja

i tried it already, now again i tried but same error.

{% set cgst = 0 %}
{% set sgst = 0 %}
{% for d in taxes %}
    {% if "CGST 6% - E" in d.account_head %}
        {% cgst += d.tax_amount %}
    {% endif %}
{% endfor %}

It seems += does not work in Jinja ether. Try this.

{% set cgst = 0 %}
{% set sgst = 0 %}
{% for d in taxes %}
    {% if "CGST 6% - E" in d.account_head %}
        {% set cgst = cgst + d.tax_amount %}
    {% endif %}
{% endfor %}

if i am using set, it gives error, when using var it doesn’t give error but if statement not working.

{% var cgst = 0 %}
{% var sgst = 0 %}
{% for d in taxes %}
       {%  cgst +=  d.tax_amount %}

{% endfor %}

this code is calculating the result, but i need to filter using if statement.

{% var cgst = 0 %}
{% var sgst = 0 %}
{% var test = 0 %}
{% for d in taxes %}
    {%  cgst +=  d.tax_amount %}
    {% if "KFC - E" in d.account_head %}
        {% test = 1 %}
    {% else %}
        {% test = 0 %}
    {% endif %}
{% endfor %}
{{ test }}

I’ll admit I’m confused now. Are you not using Jinja as a template language?

No its JS. for offline pos print.

Any help?

This is for loop correct syntax use the following syntax.

{%- for d in taxes -%}
— Conditions
{%- endfor -%}

thanks for reply @Vaibhav_Parmar but the question is if statement is not working, loop is working fine.

Any help?

You need a second loop I think. You can’t use “in” operator for d.account_head variable.