Having trouble calculating total hours based on "employeeId"? Need help with the logic to solve this problem efficiently.
Expected Result,
[
{
"employeeId": "105",
"totalHours": "2:45"
},
{
"employeeId": "777",
"totalHours": "2:15"
}
]
Response From Ajax Call
[
{
"employeeId": "105",
"totalHours": "1:30"
},
{
"employeeId": "777",
"totalHours": "1:15"
},
{
"employeeId": "105",
"totalHours": "1:15"
},
{
"employeeId": "777",
"totalHours": "1:00"
}
]
My Code
var array = new Array();
Ext.Ajax.request({
url: '/common/services/general/basicOperations/getDataByModelUsingGetMethod',
method: 'GET',
params : {
actionId : 'payroll',
dataJson : '{"aspectType":"Payroll Profile"}'
},
success: function(response){
try{
var res = response.responseText;
var resObj = Ext.decode(res);
for(var j = 0; j < resObj.data.length; j++)
{
for(var k = 0; k < resObj.data[j].payrolltransactionDetail.length; k++)
{
array.push(resObj.data[j].payrolltransactionDetail[k]);
}
}
console.log(JSON.stringify(array, null, 4));
}
catch(e){
console.log(e);
}
},
failure: function(response){
deferred.reject("Error Fetching.");
}
});