Group Data - Collection Laravel

0

I need to group the data of a SQL function in Indicators and Data, but in my attempt to group, I'm only getting by date (Column), so the data repeats.

Model:

public static function makeCluster($date, $flag_negocio)
{
    /** @var static $instance */
    $instance = new static;

    $table = sprintf('QLIKVIEW.dbo.FN_QLIKVIEW_PAGAMENTOS_DASHBOARD_CLUSTER_CNC(\'%s\',\'%s\')',
        $date,
        $flag_negocio
    );

    return $instance->setTable($table);
}

Controller:

$clusters = Pagamentos::makeCluster($data, $flag_negocio)
    ->selectRaw('DATA_PAGAMENTO, RAZAO_CLI, SUM(VALOR_PAGAMENTO) AS VALOR_PAGAMENTO')
    ->groupBy('RAZAO_CLI', 'DATA_PAGAMENTO')
    ->orderBy('RAZAO_CLI')
    ->get();

View:

<div class="panel panel-default">
<div class="panel-heading">
    <h4 class="panel-title text-center">Pagamento Cluster - Ronaldo</h4>
</div>

@if($clusters->isNotEmpty())
    <div class="table-responsive">
        <table class="table table-bordered table-striped table-condensed table-hover report report-sm">
            <thead>
            <tr>
                <th class="bg-info text-center">Indicador</th>
                @foreach($clusters as $key => $cluster)
                    <th class="bg-info text-center">{{ $cluster->first()->DATA_PAGAMENTO}}</th>
                @endforeach
            </tr>
            </thead>
            <tbody>
            @foreach($clusters as $cluster)
                <tr>
                    <th class="bg-info">{{ $cluster->RAZAO_CLI  }}</th>
                    @foreach($clusters as $cluster)
                        <td>{{ $cluster->first()->VALOR_PAGAMENTO ?? '&mdash;' }}</td>
                    @endforeach
                </tr>
            @endforeach
            </tbody>
        </table>

    </div>
@else
    <div class="panel-body">
        <p class="text-center text-danger">Não há dados para essa seleção.</p>
    </div>
@endif

Print from the visual:

    
asked by anonymous 04.11.2018 / 05:25

0 answers