Exemplo n.º 1
0
 public function store()
 {
     //RECUPERAR LOS DATOS  DE CREATE Y GUARDAR LOS DATOS EN LA BASE DE DATOS
     $nombre = Input::get('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');
     } else {
         $turno = new Turno();
         $turno->nombre = Input::get('nombre');
         $turno->save();
         Session::flash('message', 'Guardado correctamente!');
         Session::flash('class', 'success');
     }
     return Redirect::to('turno/create');
 }
Exemplo n.º 2
0
 protected function saveCiclolectivo($ciclolectivo)
 {
     //si se guarda el ciclo y se marca como actual
     //los demas ciclo del establecimiento tiene que quedar como ACUAL = false
     $con = Propel::getConnection();
     try {
         $con->beginTransaction();
         if ($ciclolectivo->getActual()) {
             $c1 = new Criteria();
             $c1->add(CiclolectivoPeer::FK_ESTABLECIMIENTO_ID, $this->getUser()->getAttribute('fk_establecimiento_id'));
             $c2 = new Criteria();
             $c2->add(CiclolectivoPeer::ACTUAL, false);
             BasePeer::doUpdate($c1, $c2, $con);
         }
         $ciclolectivo->setFkEstablecimientoId($this->getUser()->getAttribute('fk_establecimiento_id'));
         $isNew = $ciclolectivo->isNew();
         $ciclolectivo->save();
         if ($isNew) {
             # Codigo para copiar las divisiones del ciclo lectivo actual al nuevo
             # La consulta debe contemplar que lo haga desde el ciclo lectivo actual
             if ($this->getRequestParameter('importar')) {
                 $ciclo_actual = CiclolectivoPeer::retrieveByPk($this->getUser()->getAttribute('fk_ciclolectivo_id'));
                 if ($ciclo_actual) {
                     $this->logMessage('ciclo_actual: ' . $ciclo_actual, 'debug');
                     //clonar turnos
                     foreach ($ciclo_actual->getTurnos() as $turno) {
                         $nt = new Turno();
                         $nt->setFkCiclolectivoId($ciclolectivo->getId());
                         $nt->setHoraInicio($turno->getHoraInicio());
                         $nt->setHoraFin($turno->getHoraFin());
                         $nt->setDescripcion($turno->getDescripcion());
                         $nt->save();
                         //clonar las divisiones
                         foreach ($turno->getDivisions() as $division) {
                             $this->logMessage('division: ' . $division, 'debug');
                             $nd = new Division();
                             $nd->setFkAnioId($division->getFkAnioId());
                             $nd->setDescripcion($division->getDescripcion());
                             $nd->setFkTurnoId($nt->getId());
                             $nd->setFkOrientacionId($division->getFkOrientacionId());
                             $nd->setOrden($division->getOrden());
                             $nd->save();
                         }
                     }
                 } else {
                     //no existe el ciclo actual
                     $this->getUser()->setFlash('error', 'No hay un ciclo actual seleccionado');
                 }
             }
         }
         $con->commit();
         if ($ciclolectivo->getActual()) {
             //cambio el attributo porque se cambio el ciclo actual
             $this->getUser()->setAttribute('fk_ciclolectivo_id', $ciclolectivo->getId());
             $this->getUser()->setAttribute('ciclolectivo_descripcion', $ciclolectivo->getDescripcion());
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemplo n.º 3
0
 public function postTurnoRecurrente(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $data = json_decode($request->getBody(), true);
     $fechaReserva = $data['fechaReserva'];
     $rango = $data["rango"];
     $meses = $data["meses"];
     $fechaFinal = strtotime("+{$meses} month", strtotime($fechaReserva));
     $fechaFinal = date('Y/m/d', $fechaFinal);
     $datetime1 = new DateTime($fechaReserva);
     $datetime2 = new DateTime($fechaFinal);
     $interval = $datetime1->diff($datetime2);
     $minutosServicio = ServiciosSucursal::select("minutos")->where("idServicio", "=", $data["idServicio"])->where("idSucursal", "=", $data["idSucursal"])->first();
     /*
       Valores de Rangos 
       
       diario = 1
       semanal = 2
       mensual = 3
     */
     switch ($rango) {
         case '1':
             $tiempo = floor($interval->format('%a'));
             break;
         case '2':
             $tiempo = floor($interval->format('%a') / 7);
             break;
         default:
             $tiempo = $meses;
             break;
     }
     //echo $tiempo;
     $fecha = $fechaReserva;
     for ($i = 0; $i <= $tiempo; $i++) {
         switch ($rango) {
             case '1':
                 $fechaReservaFinal = strtotime("+1 day", strtotime($fecha));
                 $fechaReservaFinal = date('Y/m/d', $fechaReservaFinal);
                 break;
             case '2':
                 $fechaReservaFinal = strtotime("+7 day", strtotime($fecha));
                 $fechaReservaFinal = date('Y/m/d', $fechaReservaFinal);
                 break;
             default:
                 $fechaReservaFinal = strtotime("+1 month", strtotime($fecha));
                 $fechaReservaFinal = date('Y/m/d', $fechaReservaFinal);
                 break;
         }
         $respuesta = null;
         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 = $fecha;
             $turno->horaReserva = $data['horaReserva'];
             $horaInicial = $data['horaReserva'];
             for ($j = 0; $j < $data["cupos"]; $j++) {
                 $segundos_horaInicial = strtotime($horaInicial);
                 $segundos_minutoAnadir = $minutosServicio->minutos * 60;
                 $nuevaHora = date("H:i", $segundos_horaInicial + $segundos_minutoAnadir);
                 $horaInicial = $nuevaHora;
             }
             $turno->horaFinalReserva = $nuevaHora;
             $turno->save();
             $fecha = $fechaReservaFinal;
             $respuesta = json_encode(array('msg' => "Su turno ha sido asignado satisfactoriamente.", "std" => 1, 'idTurno' => $turno->id));
             $response = $response->withStatus(200);
         } 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;
 }
 public function asignacionturnos()
 {
     $trn = Turno::all();
     if (count($trn) == 0) {
         $turnoss = Turno::all();
         if (count($turnoss) != 0) {
             $error = "los turnos ya estan asignados";
             return View::make('administrador.turnos.errores')->with('error', $error);
         } else {
             $año = date("Y");
             $añosig = $año + 1;
             $fecha = $año . "-01-1";
             $dias = "";
             $controlaño = "";
             while ($año != $añosig) {
                 $controlaño = $fecha[0] . $fecha[1] . $fecha[2] . $fecha[3];
                 if ($controlaño == $añosig) {
                     break;
                 } else {
                     $turno = new Turno();
                     $turno->fechaturno = $fecha;
                     $turno->save();
                 }
                 $fecha = strtotime('+1 day', strtotime($fecha));
                 $fecha = date('Y-m-j', $fecha);
             }
             //echo "termino asignacion de turnos";
             return Redirect::route('turno.index');
         }
     } else {
         $error = "no puede introducir turnos po que ya fueron asignados";
         return View::make('administrador.turnos.errores')->with('error', $error);
     }
 }