Add values from a table when the client is the same

Asked

Viewed 97 times

1

Look at the table below, the final result should be this:
inserir a descrição da imagem aqui

I wonder how do I make so that only the last record of the client in the table displays the total amount of checks.

I am 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
This is the array I receive to perform the handling of that image shape above. In this case, only the CLIENT 6 has more than 1 release, I need to print all in the table but only in the last row should I show the total of all records of the 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 above array I have to generate this final result: inserir a descrição da imagem aqui

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 }
  • For me this code does not work. Note that the table does not have only one client, I need to do this in the same table, not separately.

  • 1

    I will edit the reply @Davidsantos

  • @Davidsantos See you now! :)

  • No, I don’t think we understand each other. I edited the question by putting more specifically what I need to look for.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.