I am currently working with a JSON object that contains information about various clients, including the payments made over different date ranges within each month. My goal is to loop through this list of customers and display a table for each customer, highlighting any variations in payments between periods. However, I am facing difficulty comparing the payment made at the end of one month with the payment made at the beginning of the next month.
The JSON data from the legacy system looks like this:
{
"customers":[
{
"name":"John",
"months":{
"1":{
"details":[
{
"startDate":1483225200000,
"endDate":1483830000000,
"payment":250
},
{
"startDate":1483916400000,
"endDate":1485817200000,
"payment":350
}
]
},
...
}
},
...
]
}
Below is my HTML code where I use ng-repeat to iterate over the data and apply the "highlight" class when payments vary:
<table ng-repeat="customer in customersList">
<tbody ng-repeat="month in customer.months">
<tr ng-repeat="detail in customer.details track by $index">
<td data-ng-class="{'highlight' : month.details[$index-1].payment != month.details[$index].payment && $index > 0}">{{::detail.payment}}</td>
<td data-ng-class="{'highlight' : month.details[$index-1].payment != month.details[$index].payment && $index > 0}">{{::detail.payment | currency}}</td>
</tr>
</tbody>
</table>
Although I attempted to use $parent to access previous month data for comparison, I encountered difficulties in achieving the desired outcome. I would appreciate any insights on what might be causing this issue and whether it is feasible to compare payments across months in this manner.