0
Hello!
I have the following function of the controller.
public function lancamento_listar()
{
$lista = $this->lancamento->obter_dados();
$data = array();
$no = $_POST['start'];
foreach ($lista as $lancamento) {
$no++;
$row = array();
$row[] = $lancamento->id;
$row[] = $lancamento->tipo == 1 ? '<span class="label label-success">'.'Receita'.'</span>' : '<span class="label label-danger">'.'Despesa'.'</span>';
$row[] = date('d/m/Y H:i',strtotime($lancamento->dt_lancamento));
$row[] = $lancamento->descricao;
$row[] = date('d/m/Y',strtotime($lancamento->dt_vencimento));
$row[] = 'R$ ' .number_format($lancamento->valor, 2, ',', '0');
$row[] = $lancamento->recebido == 1 ? '<span class="label label-success">'.'Pago'.'</span>' : '<span class="label label-warnning">'.'Pendente'.'</span>';
//add html para a ação
$row[] = '<a class="btn btn-flat btn-primary" href="javascript:void(0)" title="Editar" onclick="editar_lancamento('."'".$lancamento->id."'".')"><i class="fa fa-pencil"></i></a>
<a class="btn btn-flat btn-danger" href="javascript:void(0)" title="Excluir" onclick="excluir_lancamento('."'".$lancamento->id."'".')"><i class="fa fa-trash"></i></a>';
$data[] = $row;
}
$saida = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->lancamento->lancamento_tudo(),
"recordsFiltered" => $this->lancamento->lancamento_filtrado(),
"data" => $data,
);
//Saída para o formato json
echo json_encode($saida);
}
And through the Datetable plugin, I am returning the data from the database.
My point is, I want to add the releases and display them in a <tfoot>
.
For example:
$totalReceita = 0;
<tfoot>
<tr>
<td colspan="5" style="text-align: right; color: green"> <strong>Total Receitas:</strong></td>
<td colspan="2" style="text-align: left; color: green"><strong>R$ <?php echo number_format($totalReceita,2,',','.') ?></strong></td>
</tr>
</tfoot>
This $totalReceita
must be the sum of the values in(controller)
$row[] = 'R$ ' .number_format($lancamento->valor, 2, ',', '0');
How to do this calculation since the data is coming by ajax ?
I can do this sum when the foreach is in the view itself, but I don’t know how to do this using the plugin DataTable
and Ajax
.
I would do a sum storage: $total_revenue += $lancamento->value; inside the loop, then display at the end $total_revenue. I would do so.
– Sr. André Baill
And what would you call it in the view ?
– Wagner Fillio