public function eliminar_empresa(Request $request)
 {
     header("Access-Control-Allow-Origin: *");
     header("Allow: GET, POST, OPTIONS");
     $empresa = null;
     $msg = "";
     $error = false;
     try {
         $id = $request->input('id');
         $enuso = Lista::whereRaw("empresa_id=?", [$id])->count();
         if ($enuso > 0) {
             $error = true;
             $msg = "La empresa se encuentra en uso";
         }
         if ($error == false) {
             $empresa = Empresa::find($id);
             $empresa->delete();
         }
     } catch (\Exception $e) {
         $error = true;
         $msg = $e->getMessage();
     }
     return ["empresa" => $empresa, "msg" => $msg, "error" => $error];
 }
 public function generar_ticket(Request $request)
 {
     header("Access-Control-Allow-Origin: *");
     header("Allow: GET, POST, OPTIONS");
     $user_id = $request->input('user_id');
     $codigo = $request->input('codigo');
     $atencion = Atencion::whereRaw('codigo = ?', [$codigo])->get()->first();
     if ($atencion == null) {
         $atencion = Atencion::whereRaw('numero = ?', [$codigo])->get()->first();
     }
     if ($atencion == null) {
         Session::put('atencion', $atencion);
         return $atencion;
     } else {
         if ($atencion->posicion == null) {
             $atencion->posicion = Atencion::whereRaw('numero is not null and lista_id = ?', [$atencion->lista_id])->count() + 1;
             $atencion->save();
             $lista = Lista::find($atencion->lista_id);
             $atencion->numero = $lista->codigo . $atencion->posicion;
             $atencion->fecha_generado = Carbon::now();
             $atencion->estado_id = 1;
             //estado 1 es en espera
             $atencion->save();
         }
         //estado_id=1 es en espera
         $predecesores = Atencion::whereRaw('estado_id = 1 and posicion < ? and lista_id = ? and colaborador_id is null', [$atencion->posicion, $atencion->lista_id])->count();
         $estimado = DB::table('atencions')->select(DB::raw('avg(TIME_TO_SEC(timediff(fecha_asignado,fecha_generado)))/60 + avg(TIME_TO_SEC(timediff(fecha_atendido,fecha_asignado)))/60 as atendido, lista_id'))->where('fecha_atendido', '<>', 'null')->where('fecha_generado', '<>', 'null')->where('fecha_asignado', '<>', 'null')->where('lista_id', '=', $atencion->lista_id)->where('created_at', '>=', DB::raw('curdate()'))->get()[0]->atendido;
         if ($estimado == null) {
             $estimado = 0;
         }
         $array = $atencion->toArray();
         $array['predecesores'] = $predecesores;
         $array['tiempo'] = round($predecesores * $estimado, 2) . " minutos";
         Session::put('atencion', $array);
         return $array;
     }
 }
 public function obtener_lista(Request $request)
 {
     header("Access-Control-Allow-Origin: *");
     header("Allow: GET, POST, OPTIONS");
     $id = $request->input('id');
     $lista = Lista::find($id);
     return $lista;
 }