My current service method retrieves income data from different projects and creates a new array of objects. I am seeking assistance to sort this array by year and trimester in order to simplify looping through it using ng-repeat in the view.
The data structure I have returned by Incomes.buildAndGetIncomes() is as follows:
[
{
"projectName": "Deuxième test",
"clientName": "Deuxième client",
"typeIncome": "Accompte",
"amount": 1000,
"date": "2014-09-10",
"notes": "Cheque / LDD",
"trim": "third",
"year": "2014"
},
// More income objects...
]
I want the desired data structure to be organized by year and trimester like this:
[
{
year: 2014,
trim: [
{
name : 'first',
content : [
// some content
]
},
// More trimesters...
]
},
// More years...
]
Currently, I have a method called `trimestral` that attempts to achieve this sorting functionality. However, I am facing challenges with accurately checking for existing years and trimesters within the data structure.
This implementation checks if it's the first index of the loop and adds the year/trimester/content accordingly. While this works for that scenario, I struggle with handling cases where the year or trimester already exists. Any guidance on improving this logic would be greatly appreciated!