/** * Listar registro de actividades con estado 1 * POST reporte/tecnicoofficetrack * * @return Response */ public function postTecnicoofficetrack() { //recibir los parametros y enviarlos al modelo, ahi ejecutar el query //1 dia, 2 rango de fechas $tipoRepor = Input::get('tipo_repo'); $tecnicos = Input::get('tecnicos'); $fecha = Input::get('fecha'); $table = ''; if ($tipoRepor == "1") { $reporte = Tecnico::asisTecnicos($fecha, $tecnicos); if (count($reporte) > 0) { if (Input::has('excel')) { $filename = 'asistencia_tecnicos_por_dia'; } else { $h = array(); foreach ($reporte as $row) { foreach ($row as $key => $val) { if (!in_array($key, $h)) { $h[] = $key; } } } $table = "<thead></thead>"; $cabecera = "<tr>"; foreach ($h as $key) { $key = ucwords($key); $cabecera .= '<th>' . $key . '</th>'; } $cabecera .= '</tr>'; $table = "<thead>" . $cabecera . "</thead>"; $table . "<tbody id='tb_reporte'>"; $imgHabilitado = 'img/admin/datatable/estado_habilitado.png'; $imgInhabilitado = 'img/admin/datatable/estado_deshabilitado.png'; foreach ($reporte as $row) { $table .= "<tr>"; foreach ($row as $field) { if ($field == "Activo") { $field = "<img src={$imgHabilitado}>"; } elseif ($field == "Inactivo") { $field = "<img src={$imgInhabilitado}>"; } $table .= "<td class='td_res_grupal2'>" . $field . "</td>"; } $table .= "</tr>"; } $table .= "</tbody><tfoot>" . $cabecera . "</tfoot>"; } } } elseif ($tipoRepor == "2") { list($fechaIni, $fechaFin) = explode(" - ", $fecha); $reporte = Tecnico::asisTecnicosRango($fechaIni, $fechaFin, $tecnicos); if (count($reporte) > 0) { if (Input::has('excel')) { $filename = 'asistencia_tecnicos_por_rango_fecha'; } else { $h = array(); foreach ($reporte as $row) { foreach ($row as $key => $val) { if (!in_array($key, $h)) { $h[] = $key; } } } $table = "<thead></thead>"; $cabecera = "<tr>"; foreach ($h as $key) { $key = ucwords($key); $cabecera .= '<th>' . $key . '</th>'; } $cabecera .= '</tr>'; $table = "<thead>" . $cabecera . "</thead>"; $table . "<tbody id='tb_reporte'>"; foreach ($reporte as $row) { $table .= "<tr>"; foreach ($row as $field) { $table .= "<td class='td_res_grupal2'>" . $field . "</td>"; } $table .= "</tr>"; } $table .= "</tbody><tfoot>" . $cabecera . "</tfoot>"; } } } if (Input::has('excel')) { if (count($reporte) > 0) { $filename = Helpers::convert_to_file_excel($filename); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-Transfer-Encoding: binary"); header('Pragma: public'); $n = 1; foreach ($reporte as $data) { //Encabezado if ($n == 1) { foreach ($data as $key => $val) { echo $key . "\t"; } echo $val . "\r\n"; } //Datos foreach ($data as $val) { $val = str_replace(array("\r\n", "\n", "\n\n", "\t", "\r"), array("", "", "", "", ""), $val); echo $val . "\t"; } echo "\r\n"; $n++; } } else { return Response::json(array('rst' => 1, 'datos' => $table)); } } else { return Response::json(array('rst' => 1, 'datos' => $table)); } }