function contabilidadsector(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute("idSector"); $fechainicial = $request->getAttribute("fechainicial"); $fechafinal = $request->getAttribute("fechafinal"); $data = SectorEmpresa::select('sectorempresa.idEmpresa', 'empresa.razonSocial')->join('empresa', 'empresa.id', '=', 'sectorempresa.idEmpresa')->where('idSector', '=', $id)->get(); for ($i = 0; $i < count($data); $i++) { $sucu = Sucursal::select('sucursal.id', 'sucursal.nombre')->where('sucursal.idEmpresa', '=', $data[$i]->idEmpresa)->get(); $data[$i]['sucu'] = $sucu; for ($j = 0; $j < count($sucu); $j++) { $empl = Empleado::select('empleado.id as idempleado')->where('idSucursal', '=', $sucu[$j]->id)->get(); $sucu[$j]['idEmpleado'] = $empl; for ($k = 0; $k < count($empl); $k++) { $ingreso = Ingreso::select('ingresos.valor')->where('ingresos.idEmpleado', '=', $empl[$k]->idempleado)->whereBetween('ingresos.fecha', array($fechainicial, $fechafinal))->sum('ingresos.valor'); $empl[$k]['valor'] = $ingreso; } } } $response->getBody()->write($data); return $response; }
function empleadosDisponibles(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idServicio = $request->getAttribute("idServicio"); $idSucursal = $request->getAttribute("idSucursal"); $fecha = $request->getAttribute("fecha"); $hora = $request->getAttribute("hora"); $cupos = $request->getAttribute("cupos"); $dataMitiempo = ServiciosSucursal::select("minutos")->where("idServicio", "=", $idServicio)->where("idSucursal", "=", $idSucursal)->first(); $minutos = 60; if ($data != null) { $minutos = $dataMitiempo->minutos; } $empleado = Empleado::select("*")->where("idSucursal", "=", $idSucursal)->where("idPerfil", "=", 2)->get(); //$horaFinal = "(sec_to_time(time_to_sec('$hora') + (time_to_sec('$hora') * $cupos)))"; $tiempo = 0; for ($i = 0; $i < $cupos; $i++) { $tiempo += $minutos; } $horaFinal = "ADDTIME('{$hora}', SEC_TO_TIME({$tiempo}*60))"; $data = array(); for ($i = 0; $i < count($empleado); $i++) { $query = "SELECT " . "tur.id " . "FROM " . "turno tur " . "WHERE " . "tur.idServicio = {$idServicio} AND " . "tur.idSucursal = {$idSucursal} AND " . "tur.idEmpleado = " . $empleado[$i]->id . " AND " . "tur.fechaReserva = '{$fecha}' AND " . "tur.reserva = 'A' AND " . "(tur.estadoTurno <> 'TERMINADO' AND tur.estadoTurno <> 'CANCELADO') AND (" . "(TIMESTAMP('{$fecha}','{$hora}') >= tur.horaReserva AND TIMESTAMP('{$fecha}','{$hora}') < tur.horaFinalReserva) OR " . "(TIMESTAMP('{$fecha}',{$horaFinal}) > tur.horaReserva AND TIMESTAMP('{$fecha}',{$horaFinal}) <= tur.horaFinalReserva))"; //. "(TIMESTAMP('$fecha','$hora') < tur.horaReserva AND TIMESTAMP('$fecha',$horaFinal) > tur.horaReserva))"; $disp = DB::select(DB::raw($query)); if (count($disp) == 0) { $data[] = $empleado[$i]; } } $response->getBody()->write(json_encode($data)); return $response; }
function empleadosporempresa(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute("id"); $sucursal = Sucursal::select('sucursal.id', 'sucursal.nombre as sucursal', 'empresa.razonSocial')->join('empresa', 'empresa.id', '=', 'sucursal.idEmpresa')->where('sucursal.idEmpresa', '=', $id)->get(); for ($i = 0; $i < count($sucursal); $i++) { $empleado = Empleado::select('empleado.nombres', 'empleado.apellidos', 'empleado.identificacion', 'empleado.estado', 'empleado.id', 'empleado.telefono', 'empleado.email')->where('empleado.idSucursal', '=', $sucursal[$i]->id)->where('empleado.idPerfil', '=', 2)->get(); $sucursal[$i]['empleados'] = $empleado; } $response->getBody()->write($sucursal); return $response; }
public function postReserva(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $minutosServicio = ServiciosSucursal::select("minutos")->where("idServicio", "=", $data["idServicio"])->where("idSucursal", "=", $data["idSucursal"])->first(); try { $turno = new Turno(); $turno->idCliente = $data['idCliente']; $turno->idEmpleado = $data['idEmpleado']; $turno->idSucursal = $data['idSucursal']; $turno->idServicio = $data['idServicio']; $turno->tiempo = 0; $turno->turno = 0; $turno->turnoReal = 0; $turno->tipoTurno = 1; $turno->estadoTurno = "SOLICITADO"; $turno->estado = "ACTIVO"; $turno->reserva = "A"; $turno->fechaReserva = $data['fechaReserva']; $turno->horaReserva = $data['horaReserva']; $horaInicial = $data['horaReserva']; for ($i = 0; $i < $data["cupos"]; $i++) { $segundos_horaInicial = strtotime($horaInicial); $segundos_minutoAnadir = $minutosServicio->minutos * 60; $nuevaHora = date("H:i", $segundos_horaInicial + $segundos_minutoAnadir); $horaInicial = $nuevaHora; } $turno->horaFinalReserva = $nuevaHora; $turno->save(); $respuesta = json_encode(array('msg' => "Su turno ha sido asignado satisfactoriamente.", "std" => 1, 'idTurno' => $turno->id)); $response = $response->withStatus(200); //ENVIAR NOTIFICACION AL EMPLEADO Y AL ADMINISTRADOR DE LA SUCURSAL $dataEmple = Empleado::select("idPush")->where("id", "=", $data['idEmpleado'])->first(); if ($dataEmple != null) { $payload = array('title' => "Turno movil", 'msg' => "Te han solicitado un turno", 'std' => 1, 'idServicio' => $data['idServicio']); enviarNotificacion(array($dataEmple->idPush), $payload); } } catch (Exception $err) { $respuesta = json_encode(array('msg' => "error al pedir el turno", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; //echo $minutosServicio; }