Selecting records for reporting according to month and year

Asked

Viewed 19 times

0

I wish to select the records according to the month and year for the report. Where it will dynamically collect the records of the last months and will be shown in the sum.

 $ cobrancas = DB :: table ('cobrancas')
 -> join ('usuários', 'users.id', '=', 'cobrancas.id_loja')
 -> join ('clientes', 'clientes.id', '=', 'cobrancas.id_cliente')
 -> groupby (DB :: raw ('YEAR (cobrancas.data_vencimento)'), DB :: raw ('MONTH (cobrancas.data_vencimento)'))
 -> get ();
 $ total_cobrancas = $ cobrancas-> soma ('valor');

 foreach ($ cobrancas como $ cobranca) {
     if ($ cobrancas-> data_vencimento)
         dd ($ cobranca);
 }

This code is returning the sum value, but only 1 per month, I need to bring all of each month. Where then I will separate the last 5 months and pass the view.

  • In case, you don’t have to ignore the group by line in the YEAR part?

  • It would be interesting to present the result that comes in the $cobrancas attribute using something like dd($cobrancas), and that the excerpt "$cobrancas->soma('valor');" calls a method of the object? or a function?

No answers

Browser other questions tagged

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