Can anyone give code for pos invoice which is in jinja format to show customer balance. i am using following code but it didnt show exact result.
"{% set invoices = frappe.get_list(‘Sales Invoice’, {‘customer’: doc.customer, ‘docstatus’: 1}, [‘outstanding_amount’]) %}
{% set total_unpaid_amount = invoices | map(attribute=‘outstanding_amount’) | sum %}
Your outstanding balance as of {{ doc.posting_date.strftime('%d-%m-%Y') }} is: {{ total_unpaid_amount | default(0.0) }}
Hello I managed to display the unpaid and paid POS Invoices as well as the Outstanding Balances using the code below but am failing to add the 3 totals to that I get the correct Balance including the UnConsolidated POS Invoices. Adding the 3 allows me to see the actual outstanding balance including unposted POS Invoice transactions.
{% set total_unpaid_amount = [0] %}
{% for invoice_unpaid in invoices_unpaid %}
{% set total_unpaid_invoice = invoice_unpaid.grand_total %}
{% if total_unpaid_amount.append(total_unpaid_amount.pop() + total_unpaid_invoice) %}{% endif %}
{% endfor %}
{% set total_paid_amount = [0] %}
{% for invoice_paid in invoices_paid %}
{% set total_paid_invoice = invoice_paid.grand_total %}
{% if total_paid_amount.append(total_paid_amount.pop() + total_paid_invoice) %}{% endif %}
{% endfor %}
Your outstanding balance as of {{ frappe.utils.get_datetime(doc.posting_date).strftime(“%d-%m-%Y”) }} is: {{ total_unpaid_amount.pop() | default(0.0) }} Your paid amount as of {{ frappe.utils.get_datetime(doc.posting_date).strftime(“%d-%m-%Y”) }} is: {{ total_paid_amount.pop() | default(0.0) }}
{% if doc.customer %}
{% set ledger_entries = frappe.get_all(“GL Entry”, filters={“party_type”: “Customer”, “party”: doc.customer}, fields=[“SUM(debit) - SUM(credit) as balance”]) %}
{% if ledger_entries %}
{% set balance = ledger_entries[0].balance %} Customer Balance: {{ frappe.format_value(balance, { “fieldtype”: “Currency” }) }}
{% endif %}
{% endif %}