I've created a table report and using 'formatValue' the only parameter that's working fine is $value. From my Laravel application, I used 'dd' to show the content form $row and $cKey, and both of them are with the value null. Could you help me, please? Bellow part of my code ...
Table::create( [
"dataSource"=>$this->dataStore('vendas_por_vendedor_data'),
'showfooter' => true,
"columns"=>[
'Nome' => [
'label' => 'Vendedor',
'footerText' => "<b>Totais Gerais:</b>"
],
'DataPedido' => [
'label' => 'Data do Pedido',
'formatValue' => function ($value,$row) {
return $value->format('d/m/Y');
},
'cssStyle' => "text-align:center",
],
'QtdVendas' => [
'label' => 'Qtd Vendas',
'formatValue' => function ($value,$row) {
dd($row);
return formataValor($value,true,0);
},
'cssStyle' => 'text-align:center',
'footer' => function ($value) {
return formataValor($value->sum('QtdVendas'),true,0);
},
'footerText' =>"<b>@value</b>",
],
'ValorTelhas' => [
'label' => 'Valor da Venda',
'formatValue' => function ($value,$row) {
return formataValoresEmReais($value);
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return formataValoresEmReais($value->sum('ValorTelhas'));
},
'footerText' =>"<b>@value</b>",
],
'PesoTelhas' => [
'label' => 'Peso KG',
'formatValue' => function ($value, $row) {
return formataValor($value,true,2);
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return formataValor($value->sum('PesoTelhas'),true,2);
},
'footerText' => "<b>@value</b>"
],
'TicketMedio' => [
'label' => 'Ticket Médio',
'formatValue' => function ($value, $row, $cKey) {
return ($row['QtdVendas'] > 0) ? formataValoresEmReais($value / $row['QtdVendas']) : 0.00 ;
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return ($value->sum('QtdVendas') > 0 ) ?
formataValoresEmReais($value->sum('TicketMedio') / $value->sum('QtdVendas')) :
0.00;
},
'footerText' => "<b>@value</b>"
],
'PesoMedio' => [
'label' => 'Valor/KG',
'formatValue' => function ($value, $row) {
return ($row['QtdVendas'] > 0) ? formataValoresEmReais($value / $row['QtdVendas']) : 0.00 ;
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return ($value->sum('PesoMedio') > 0) ? formataValoresEmReais($value->sum('PesoMedio')) : 0.00;
},
'footerText' => "<b>@value</b>"
],
'QtdVendasPago' => [
'label' => 'Qtd Vendas (Pg)',
'formatValue' => function ($value) {
return formataValor($value,true,0);
},
'cssStyle' => 'text-align:center',
'footer' => function ($value) {
return formataValor($value->sum('QtdVendasPago'),true,0);
},
'footerText' =>"<b>@value</b>",
],
'ValorTelhasPago' => [
'label' => 'Valor da Venda (Pg)',
'formatValue' => function ($value,$row) {
return formataValoresEmReais($value);
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return formataValoresEmReais($value->sum('ValorTelhasPago'));
},
'footerText' =>"<b>@value</b>",
],
'PesoTelhasPago' => [
'label' => 'Peso KG (Pg)',
'formatValue' => function ($value, $row) {
return formataValor($value,true,2);
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return formataValor($value->sum('PesoTelhasPago'),true,2);
},
'footerText' => "<b>@value</b>"
],
'TicketMedioPago' => [
'label' => 'Ticket Médio (Pg)',
'formatValue' => function ($value, $row) {
return formataValoresEmReais($value / $row['QtdVendasPago']) ;
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return ($value->sum('QtdVendasPago') > 0.00)
? formataValoresEmReais($value->sum('ValorTelhaPago') / $value->sum('QtdVendasPago'))
: 0.00;
},
'footerText' => "<b>@value</b>"
],
'PesoMedioPago' => [
'label' => 'Valor/KG (Pg)',
'formatValue' => function ($value, $row) {
return ($row['QtdVendasPago'] > 0)
? formataValoresEmReais($value / $row['QtdVendasPago'])
: 0.00;
},
'cssStyle' => 'text-align:right',
'footer' => function ($value) {
return ($value->sum('QtdVendasPago') > 0.00)
? formataValoresEmReais($value->sum('PesoMedioPago') / $value->sum('QtdVendasPago'))
: 0.00;
},
'footerText' => "<b>@value</b>"
],
],
'grouping' => [
'Nome' => [
'calculate' => [
"{sumQtdVendas}" => ['sum','QtdVendas'],
"{sumValorTelhas}" => ['sum','ValorTelhas'],
"{sumPesoTelhas}" => ['sum','PesoTelhas'],
"{avgTicketMedio}" => ['avg','TicketMedio'],
// "{avgTicketMedio}" => function ($store) {
//
// },
"{avgPesoMedio}" => ['avg','PesoMedio'],
"{sumValorTelhasPago}" => ['sum','ValorTelhasPago'],
"{sumPesoTelhasPago}" => ['sum','PesoTelhasPago'],
"{avgTicketMedioPago}" => ['avg','TicketMedioPago'],
"{avgPesoMedioPago}" => ['avg','PesoMedioPago'],
],
'bottom' => "<td class='table-dark' colspan=2><b> Total do Vendedor: {Nome}</b></td>
<td style='text-align: center;'><b>{sumQtdVendas}</b></td>
<td style='text-align: right;'><b>{sumValorTelhas}</b></td>
<td style='text-align: right;'><b>{sumPesoTelhas}</b></td>
<td style='text-align: right;'><b>{avgTicketMedio}</b></td>
<td style='text-align: right;'><b>{avgPesoMedio}</b></td>
<td style='text-align: right;'><b>{sumValorTelhasPago}</b></td>
<td style='text-align: right;'><b>{sumPesoTelhasPago}</b></td>
<td style='text-align: right;'><b>{avgTicketMedioPago}</b></td>
<td style='text-align: right;'><b>{avgPesoMedioPago}</b></td>",
],
],
'sorting' => [
'Nome' => 'asc',
'DataPedido' => 'asc',
],
"cssClass" => [
'table' => 'table-primary table-striped table-hover table-bordered',
],
'groupCellsInColumns' => ['Nome'],
]);