Add values from a table when the client is the same

1

Please note the table below, the end result should be this:

I would like to know how to make only the last record of the customer in the table display the total value of checks.

I'm using PHP (Laravel 5.4) and I need to generate a report in this format, but I have no idea how to do this.

EDITED Home This is the array I get to handle that form of the image above. In this case, only the CLIENT 6 has more than 1 release, I need to print all in the table but only the last line should show the total of all CLIENT 6 .

array:8 [▼
  0 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-06"
    "VALORCHEQUE" => "307.8900"
    "NOME" => "CLIENTE 1"
    "CPFCNPJ" => "00000000001"
  ]
  1 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-06"
    "VALORCHEQUE" => "272.8100"
    "NOME" => "CLIENTE 2"
    "CPFCNPJ" => "00000000002"
  ]
  2 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-07"
    "VALORCHEQUE" => "696.0000"
    "NOME" => "CLIENTE 3"
    "CPFCNPJ" => "00000000003"
  ]
  3 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-06"
    "VALORCHEQUE" => "312.0000"
    "NOME" => "CLIENTE 4"
    "CPFCNPJ" => "00000000004"
  ]
  4 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-10"
    "VALORCHEQUE" => "320.0000"
    "NOME" => "CLIENTE 5"
    "CPFCNPJ" => "00000000005"
  ]
  5 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-18"
    "VALORCHEQUE" => "383.8200"
    "NOME" => "CLIENTE 6"
    "CPFCNPJ" => "00000000006"
  ]
  6 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-13"
    "VALORCHEQUE" => "323.4000"
    "NOME" => "CLIENTE 6"
    "CPFCNPJ" => "00000000006"
  ]
  7 => array:4 [▼
    "VENCIMENTOCH" => "2017-11-04"
    "VALORCHEQUE" => "320.8600"
    "NOME" => "CLIENTE 6"
    "CPFCNPJ" => "00000000006"
  ]
]

With the array above I have to generate this final result:

    
asked by anonymous 03.11.2017 / 17:45

1 answer

0

This is pseudo code:

     $array = [];

        $account =  Client::with('users')->orderBy('id', 'desc')->get();

       $length = count($posts);

            $user = new Controller();

       for($i = 0; $i < = $length ; $i++){ 
             $array[$i]['total'] =$account[$i]->$user->getMaxSimpleUser($account[$i]->user->User_id);


function getMaxSimpleUser(){

$max = 0;
       $account =  Client::where('user_id', '=', $id)->get();
       foreach($accounts as $account){  $max += $max + $account->total;} return $max }
    
03.11.2017 / 18:05