function contablidadempresa(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idempresa = $request->getAttribute("idempresa"); $fechainicial = $request->getAttribute("fechainicial"); $fechafinal = $request->getAttribute("fechafinal"); $sucu = Sucursal::select('id', 'nombre')->where('idEmpresa', '=', $idempresa)->get(); for ($i = 0; $i < count($sucu); $i++) { $turno = Turno::select('turno.idEmpleado', 'turno.idServicio', 'turno.fechaSolicitud', 'empleado.nombres', 'empleado.apellidos', 'servicio.nombre as servicio')->join('empleado', 'empleado.id', '=', 'turno.idEmpleado')->join('servicio', 'servicio.id', '=', 'turno.idServicio')->where('turno.idSucursal', '=', $sucu[$i]->id)->where('turno.estadoTurno', '=', 'TERMINADO')->whereBetween('turno.fechaSolicitud', array($fechainicial, $fechafinal))->groupBy('turno.idServicio')->groupBy('turno.idEmpleado')->get(); $sucu[$i]['sucursal'] = $turno; for ($j = 0; $j < count($turno); $j++) { $ingreso = Ingreso::select('valor', 'idServicio', 'idEmpleado')->where('idServicio', '=', $turno[$j]->idServicio)->where('idEmpleado', '=', $turno[$j]->idEmpleado)->sum('valor'); $turno[$j]['suma'] = $ingreso; } } $response->getBody()->write($sucu); return $response; }
public function update($id) { //RECIBE EL CONTENIDO DEL TEX $input = Input::all(); $turno = Turno::find($id); $turno->nombre = $input['nombre']; $nombre = $input['nombre']; $a = '[{"nombre":"' . $nombre . '"}]'; $b = Turno::select('nombre')->where('nombre', $nombre)->get(); if ($a == $b) { Session::flash('message', "El turno ({$nombre}) ya existe en la base de datos!"); Session::flash('class', 'danger'); return Redirect::to('turno/' . $id . '/edit'); } else { $turno->save(); Session::flash('message', 'Modificado correctamente!'); Session::flash('class', 'success'); return Redirect::to('turno/' . $id); } }
function getServiciosBySucursal(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idSucursal = $request->getAttribute("idSucursal"); $data = Servicio::select('servicio.*')->join("serviciossucursal", "serviciossucursal.idServicio", "=", "servicio.id")->where('serviciossucursal.idSucursal', '=', $idSucursal)->where('servicio.estado', '=', 'ACTIVO')->get(); if (count($data) == 0) { $response = $response->withStatus(404); } else { for ($i = 0; $i < count($data); $i++) { $tur = Turno::select('turno.turno')->join("empleado", "empleado.id", "=", "turno.idEmplado")->where('turno.idSucursal', '=', $idSucursal)->where('turno.idServicio', '=', $data[$i]->idServicio)->where('turno.estadoTurno', '=', 'CONFIRMADO')->orwhere('turno.estadoTurno', '=', 'ATENDIENDO')->orderBy("turno.fechaSolicitud", "Desc")->first(); $turno = 1; if ($tur != null) { $turno = $tur->turno; } } } $response->getBody()->write($data); return $response; }
function reporteempleado(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idsucursal = $request->getAttribute("idsucursal"); $fechainicial = $request->getAttribute("fechainicial"); $fechafinal = $request->getAttribute("fechafinal"); $empl = Empleado::select('id', 'nombres', 'apellidos')->where('idSucursal', '=', $idsucursal)->get(); for ($i = 0; $i < count($empl); $i++) { /*$suma = Ingreso::select('id') ->where('idEmpleado','=',$empl[$i]->id) ->sum('valor');*/ $tur = Turno::select('turno.id')->where('turno.estadoTurno', '=', 'TERMINADO')->where('turno.idEmpleado', '=', $empl[$i]->id)->whereBetween('turno.fechaSolicitud', array($fechainicial, $fechafinal))->count(); $empl[$i]['contador'] = $tur; } $response->getBody()->write($empl); return $response; }
public function postTurnoAnonimo(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); //VALIDAR SI EL CLIENTE EXISTE $cli = Cliente::select("id")->where("email", "=", $data["email"])->first(); $idCliente = ""; if ($cli == null) { try { $cliente = new Cliente(); $cliente->email = $data['email']; $cliente->nombres = $data['nombres']; $cliente->apellidos = $data['apellidos']; $cliente->telefono = ""; $cliente->pass = sha1($data['email']); $cliente->estado = "ACTIVO"; $cliente->save(); $idCliente = $cliente->id; } catch (Exception $err) { } } else { $idCliente = $cli->id; } //VALIDAR SI TIENE UN TURNO EN EL SERVICIO DE LA SUCURSAL SOLICITADA $turnoCliente = Turno::select("idCliente")->where("idCliente", "=", $idCliente)->where("idServicio", "=", $data["idServicio"])->where("idEmpleado", "=", $data["idEmpleado"])->where("idSucursal", "=", $data["idSucursal"])->where("estadoTurno", "<>", "TERMINADO")->where("estadoTurno", "<>", "CANCELADO")->first(); if ($turnoCliente == null) { //CALCULAR EL SIGUIENTE TURNO $turnoSiguiente = 0; $turnoReal = 0; $lista = Turno::select("*")->where("idServicio", "=", $data["idServicio"])->where("idEmpleado", "=", $data["idEmpleado"])->where("idSucursal", "=", $data["idSucursal"])->where("estadoTurno", "<>", "TERMINADO")->where("estadoTurno", "<>", "CANCELADO")->orderBy('turno', 'desc')->get(); //echo json_encode($lista); if (count($lista) > 0) { $turnoSiguiente = $lista[0]->turno; } $turnoSiguiente++; $turnoReal = $turnoSiguiente; //VERIFICO QUE TIPO DE TURNO ES if ($data['tipoTurno'] == 2) { //SI ES VIP $ban = true; $cont = 0; $ind = 0; $lista = Turno::select("*")->where("idServicio", "=", $data["idServicio"])->where("idEmpleado", "=", $data["idEmpleado"])->where("idSucursal", "=", $data["idSucursal"])->where("estadoTurno", "<>", "TERMINADO")->where("estadoTurno", "<>", "CANCELADO")->orderBy('turnoReal', 'asc')->get(); for ($i = 0; $i < count($lista); $i++) { if ($lista[$i]->estadoTurno != "ATENDIENDO") { if ($lista[$i]->tipoTurno == 1) { $turUp = Turno::select("*")->where("id", "=", $lista[$i]->id)->first(); if ($ban) { $turnoReal = $turUp->turnoReal; $ban = false; } $turUp->turnoReal = $lista[$i]->turnoReal + 1; $turUp->save(); } } } } //INSERTAR TURNO try { $turno = new Turno(); $turno->idCliente = $idCliente; $turno->idEmpleado = $data['idEmpleado']; $turno->idSucursal = $data['idSucursal']; $turno->idServicio = $data['idServicio']; $turno->tiempo = 0; //$data['tiempo']; $turno->turno = $turnoSiguiente; $turno->turnoReal = $turnoReal; $turno->tipoTurno = $data['tipoTurno']; $turno->avisado = 1; $turno->estadoTurno = "CONFIRMADO"; $turno->estado = "ACTIVO"; $turno->save(); $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "numeroTurno" => $turnoSiguiente)); $response = $response->withStatus(200); //ENVIAR NOTIFICACION AL EMPLEADO Y AL ADMINISTRADOR DE LA SUCURSAL } catch (Exception $err) { $respuesta = json_encode(array('msg' => "error al pedir el turno", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } } else { $respuesta = json_encode(array('msg' => "Ya tienes un turno activo en este servicio", "std" => 0)); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }