GroupBy and Sum in GridView

Hello,

I have this view where I have 2 GridViews, one (bottom) used for displaying detailed data related to the current model.

In the other GridView (middle) I want to show what’s on the 5th column but grouped by product, the amount used and the total cost of that particular product for that amount.

I’ve attached an image that I hope make the idea more clear.

Hope you can point me in the right direction, as I’m very lost on how handle this.

Thank you.

P.S.: This is the code I used to display every "dosis" related to the "receta" in the second GridView, in case I can use that for the grouping:




[

    'label' => 'Dosis',

    'value' => function($model){

        return join(' _ ', yii\helpers\ArrayHelper::map($model->receta->dosisxrecetas, 'id_dosisxreceta', 'dosis.fulldosis'));

                },

],