groupBy('client_account_id')->map(function($act) use ($acts) {
return $act->reduce(
function ($total, $item) {
return [
margin_change => total[margin_change]+$item['margin_change'],
fin_result => ...,
full_commision_fee => ..,
swap_rate => ...,
];
}, [
margin_change => 0,
fin_result => 0,
full_commision_fee => 0,
swap_rate => 0,
])
) + [
'start_balance' => $act[0]['start_balance'],
'end_balance' => $act[count($acts) -1]['end_balance'],
'client_account_id' = ClientAccount::whereId($key)->value('account_n'),
'client_name' = $act[0]['client_name'],
];
});