public function getDataGrafica($id) { $query = DB::table('transacciones')->selectRaw('fecha, sum(valor) as sum')->where('user_id', $id)->groupBy('fecha')->orderBy('fecha')->get(); $datos = array(); $prepara = array(); $suma = 0; foreach ($query as $key => $value) { $fechaUTC = Recursos::fechaUTC($value->fecha); $suma = $suma + $value->sum; $datos[] = array($fechaUTC, $suma); $prepara[] = array($suma, $fechaUTC, $value->fecha); } // Logica, para agregar al comienzo del arreglo, un dato 0, el día anterior de un deposito. if ($query) { $fecha_ini = $prepara[0][2]; $ayer = date('Y-m-d', strtotime('-1 day', strtotime($fecha_ini))); $ayer = Recursos::fechaUTC($ayer); $nuevo = array($ayer, 0); array_unshift($datos, $nuevo); } return Response::json(['success' => true, 'datos' => $datos]); }