What would be the right way of getting the sum of the value in details.sections.details filtered by another attribute which would be the the value in name, i.e.: Earnings / Deduction?
Given the data:
{
"details":{
"totalPay":482.66,
"currency":"OMR",
"contributions":48.24,
"sections":[
{
"name":"Earnings",
"value":519.41,
"details":[
{
"name":"Overtime",
"value":60,
"notes":"Border OT",
"currency":"OMR"
},
{
"name":"H R A",
"value":96,
"notes":"",
"currency":"OMR"
},
{
"name":"LIVING ALLOWANCE",
"value":32,
"notes":"",
"currency":"OMR"
},
{
"name":"T A",
"value":32,
"notes":"",
"currency":"OMR"
},
{
"name":"Basic salary",
"value":299.408,
"notes":"",
"currency":"OMR"
}
]
},
{
"name":"Deductions",
"value":36.75,
"details":[
{
"name":"PASI - Employee (7%) - Employee",
"value":32.1586,
"notes":null,
"currency":"OMR"
},
{
"name":"Social Security Recovery (1%) - Employee",
"value":4.5941,
"notes":null,
"currency":"OMR"
}
]
}
]
}
}
I would expect to get, for Earnings:
60 + 96 + 32 + 32 + 299.408 = 519.408
and, for the Deductions:
32.1586 + 4.5941 = 36.7527
I will then dispalay the summed up values in a table.
I tried
{% set sum = details.sections.details|sum(attribute='value') -%}
But, the script does not load and I think there is an error in it.
I am able to get the individual values by looping.
I have declared a variable:
{% set sumAdditions = 0 %}
{% sumAdditions = sumAdditions + details.value %}
but this seems to fails as the script errors out.