Add Cr or Dr to PDF

Hello guys,
I’m going to describe my problem and if someone can help me ill be more than thankful :slight_smile:
When I click on menu, then print, a PDF will open, so here in this page I want to add in balance column beside the amount “DR” if its a Debit or “CR” if its a Credit. Check 1st part of the picture. in this picture, I showed an example, even if the display is false but I want to display it like this. Red section.
so in atom, I should update my .html file in order to add it, I tried many times but I didn’t get the result I want. Check 2nd part of the picture to see the code.


Thanks in advance.

Try a ternary statement in that same line you’re doing the formatting in:

{%= data[i].credit ? (format_currency(data[i].credit, filters.presentation_currency)) + "CR" : (format_currency(data[i].debit, filters.presentation_currency)) + "DR" %}

first of all thanks for your help, but i tried this nothing happens this means that there is an error because the page didn’t even open. and yesterday, i tried something similar, i don’t know if its right, but also it didn’t work.

{%= data[i].balance < 0 ? format_currency(data[i].balance[(“CR”)], filters.presentation_currency) : format_currency(data[i].balance[(“DR”)], filters.presentation_currency) %}

any other suggestions?

Sorry, I was thinking you just wanted the credit or debit formatted. I also gave you the JavaScript ternary syntax and I think you want the server side one (python)

flt(data[i].balance) because currency is stored as a string. So it won’t compare it to 0 (the number).

The other syntax error you’ve got is this: data[i].balance[(“CR”)] which it probably can’t parse because data[i].balance doesn’t have a key or attribute named “CR”.

{%= format_currency(data[i].balance) + " CR" if flt(data[i].balance) else " DR" %}

I don’t have access to your report to test this so I can’t guarantee it’ll work. That’s the way print formats go.

I tried the first option u gave me, and it worked but i had to change a little bit in it in order to display the total balance in the field, but i have a problem now that CR and DR are displayed in a wrong way. in the picture, you can find an example.


the red section should display beside the balance “CR”.

I also tried to create a variable and put inside the balance so i can check if its <0 or >0 in order to display CR/DR, if its a negative number it should display CR and the opposite for DR.

{% var bal = format_currency(data[i].balance); %}
{%= bal < 0 ? (format_currency(data[i].balance, filters.presentation_currency)) + " CR" : (format_currency(data[i].balance, filters.presentation_currency)) + " DR" %}

Thank you very much for your replies! :slight_smile:

Why the topic was closed! i didnt get the result i want!!