public function store()
 {
     //se valida y se ingresa datos en la vista crear
     $result = new Rol($request::all());
     //obtenos los datos y luego es llamado abajo
     $rules = array('nombre' => 'required', 'descripcion' => 'required', 'rut' => 'required');
     //Segundo metodo: es mas corto, prefiero el primer metodo
     //Primer metodo
     $v = Validator::make($data, $rules);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     }
     //$result = Rol::create($data);
     //  $result->push();
     //$result->save();
     //$result=Rol::find(0);
     //$result->roles_usuarios()->create($data);
     //$result->save();
     $result = new Rol();
     $result->nombre = $data['nombre'];
     $result->descripcion = $data['descripcion'];
     $result->save();
     $idRol = $result->id;
     $resultt = new RolUsuario();
     $resultt->rut = $data['rut'];
     $resultt->rol_id = $idRol;
     $resultt->save();
     return redirect()->route('usuarios.store');
     //otra forma de hacerlo */
     //dd($request->all());
     //$result= new Rol(Request::all());  //obtener los datos
     //graba al usuario
     //Session::flash('message', $result->nombre.' fue creado');
 }
Example #2
0
 public function down()
 {
     $rol = new Rol();
     $rol->id = 'calendario';
     $rol->nombre = 'Calendario';
     $rol->descripcion = '';
     $rol->save();
     Doctrine::getTable('Rol')->findByNombre('Calendario-Aprobador')->delete();
 }
Example #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Rol();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Rol'])) {
         $model->attributes = $_POST['Rol'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id_rol));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #4
0
 public function postUp()
 {
     $rol = new Rol();
     $rol->id = 'cal-editor';
     $rol->nombre = 'Calendario-Editor';
     $rol->descripcion = 'Usuario que puede agregar eventos en las fichas';
     $rol->save();
     $rol = new Rol();
     $rol->id = 'cal-publicador';
     $rol->nombre = 'Calendario-Publicador';
     $rol->descripcion = 'Usuario que puede publicar eventos en el calendario';
     $rol->save();
 }
 public function store()
 {
     $validator = Validator::make(Input::all(), Rol::$rules);
     if ($validator->passes()) {
         $rol = new Rol();
         $rol->name = Input::get('name');
         $rol->description = Input::get('description');
         $rol->save();
         $organization = app('organization');
         return Redirect::to('organization/name/' . $organization->auxName . '/rol')->with('message', 'Rol creado con exito');
     } else {
         return Redirect::to('rol/create')->with('eror', 'Ocurrieron los siguientes errores')->withErrors($validator)->withInput();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('nombre' => array('required'), 'descripcion' => array('required'), 'permisos' => array('required'));
     $messages = array('nombre.required' => 'Campo requerido', 'descripcion.required' => 'Campo requerido', 'permisos.required' => 'Se necesita un permiso como mínimo');
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         $permisos = Input::get('permisos');
         if (Auth::user()->tipousuarios_id == 2) {
             $empresausuario = UsuarioEmpresaRenta::with('usuario', 'empresa')->where('usuarios_id', Auth::user()->id)->first();
             $empresaid = $empresausuario->empresas_renta_id;
         } else {
             if (Auth::user()->tipousuarios_id == 3) {
                 $empresausuario = UsuarioEmpleado::with('usuario', 'empresa')->where('usuarioid', Auth::user()->id)->first();
                 $empresaid = $empresausuario->empresarentaid;
             }
         }
         $comprueba = Rol::where('nombre', Input::get('nombre'))->where('empresas_renta_id', $empresaid)->first();
         if ($comprueba) {
             Session::flash('mensaje', 'Ya existe el nombre del puesto!');
             return Redirect::back()->withInput();
         }
         //return Input::get('permisos');
         $rol = new Rol();
         $rol->nombre = Input::get('nombre');
         $rol->descripcion = Input::get('descripcion');
         $rol->activo = 1;
         $rol->empresas_renta_id = $empresaid;
         $rol->save();
         foreach ($permisos as $permiso) {
             $rolaccion = new RolAccion();
             $rolaccion->roles_id = $rol->id;
             $rolaccion->acciones_id = $permiso;
             $rolaccion->empresarentaid = $empresaid;
             $rolaccion->save();
         }
         if (Auth::user()->tipousuarios_id == 2) {
             Session::flash('mensaje', 'Se ha creado correctamente!');
             return Redirect::to('administradorempresa/roles');
         } else {
             if (Auth::user()->tipousuarios_id == 3) {
                 Session::flash('mensaje', 'Se ha creado correctamente!');
                 return Redirect::to('administradorempleado/roles');
             }
         }
     }
 }
Example #7
0
 public function nuevoAction()
 {
     $form = new \Empleados\Form\RolForm();
     //Modulos disponibles
     $modulosCollection = \ModuloQuery::create()->find();
     $modulos = array();
     foreach ($modulosCollection as $modulo) {
         $modulos[$modulo->getIdmodulo()] = $modulo->getModuloNombre();
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         //Si hicieron POST
         $post_data = $request->getPost();
         //filtro
         $filer = new \Empleados\Filter\RolFilter();
         $form->setInputFilter($filer->getInputFilter());
         //Le ponemos los datos a nuestro formulario
         $form->setData($request->getPost());
         //Validamos nuestro formulario de articulo
         if ($form->isValid()) {
             $rol = new \Rol();
             //Recorremos nuestro formulario y seteamos los valores a nuestro objeto Articulo
             foreach ($form->getData() as $key => $value) {
                 $rol->setByName($key, $value, \BasePeer::TYPE_FIELDNAME);
             }
             $rol->save();
             if (!$rol->isPrimaryKeyNull()) {
                 //Ya se guardo y por lo tanto tiene un pk
                 //Si asignaron modulos
                 if (isset($post_data["modulos"])) {
                     foreach ($post_data["modulos"] as $idmodulo) {
                         $rolmodulo = new \Rolmodulo();
                         $rolmodulo->setIdrol($rol->getIdrol());
                         $rolmodulo->setIdmodulo($idmodulo);
                         $rolmodulo->save();
                     }
                 }
                 //Agregamos un mensaje
                 $this->flashMessenger()->addMessage('Rol guardado exitosamente!');
                 //Redireccionamos a nuestro list
                 $this->redirect()->toRoute('empleados-roles');
             }
         }
     }
     return new ViewModel(array('form' => $form, 'modulos' => $modulos));
 }
Example #8
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aRol !== null) {
             if ($this->aRol->isModified() || $this->aRol->isNew()) {
                 $affectedRows += $this->aRol->save($con);
             }
             $this->setRol($this->aRol);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->empleadofacturacionsScheduledForDeletion !== null) {
             if (!$this->empleadofacturacionsScheduledForDeletion->isEmpty()) {
                 EmpleadofacturacionQuery::create()->filterByPrimaryKeys($this->empleadofacturacionsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->empleadofacturacionsScheduledForDeletion = null;
             }
         }
         if ($this->collEmpleadofacturacions !== null) {
             foreach ($this->collEmpleadofacturacions as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #9
0
 public function add_rol()
 {
     $inputs = Input::all();
     $rules = array('rol_nombre' => 'required|max:30|unique:rol,rol_nombre');
     $validator = Validator::make($inputs, $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator);
     } else {
         $rol = new Rol();
         $rol->rol_nombre = Input::get('rol_nombre');
         if ($rol->save()) {
             Session::flash('message', 'Guardado Correctamente');
             Session::flash('class', 'success');
         } else {
             Session::flash('message', 'Ha ocurrido un error, intentelo nuevamente');
             Session::flash('class', 'danger');
         }
         return Redirect::to('rol');
     }
 }
Example #10
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aModulo !== null) {
             if ($this->aModulo->isModified() || $this->aModulo->isNew()) {
                 $affectedRows += $this->aModulo->save($con);
             }
             $this->setModulo($this->aModulo);
         }
         if ($this->aRol !== null) {
             if ($this->aRol->isModified() || $this->aRol->isNew()) {
                 $affectedRows += $this->aRol->save($con);
             }
             $this->setRol($this->aRol);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
<?php

include '../../Model/class/clsRol.php';
$type = isset($_POST['type']) ? $_POST['type'] : "";
$name = isset($_POST['name']) ? $_POST['name'] : "";
$description = isset($_POST['description']) ? $_POST['description'] : "";
$id = isset($_POST['id']) ? $_POST['id'] : "";
$conex = new Rol($id, $name, $description);
switch ($type) {
    case "save":
        $conex->save();
        break;
    case "update":
        $conex->update();
        break;
    case "load":
        $conex->load();
        break;
    case "erase":
        $conex->erase();
        break;
    default:
}
?>


 /**
  * Show the form for creating a new resource.
  * GET /admins/create
  * 
  * @return Response
  */
 public function create()
 {
     $resp = [];
     $catalogo = Input::get('catalogo');
     $msgError = $this->_validar();
     if ($msgError) {
         return Response::json($msgError, 500);
     }
     try {
         switch ($catalogo) {
             case 'Almacen':
                 $almacen = new Almacen();
                 $clave = Input::get('clave');
                 $almacen->clave = $clave;
                 $almacen->nombre = Input::get('nombre');
                 $almacen->estatus = Input::get('estatus');
                 $almacen->save();
                 $campo = "clave";
                 $resp = DB::table('almacen')->where("clave", $clave)->first();
                 break;
             case 'Cliente':
                 $usuario = new Usuario();
                 $usuario->rol_id = 1;
                 $usuario->usuario = Input::get('usuario');
                 $password = Input::get('contraseña');
                 $usuario->password = Hash::make($password);
                 $usuario->email = Input::get('email');
                 if ($usuario->save()) {
                     $cliente = new Cliente();
                     $cliente->rfc = Input::get('rfc');
                     $cliente->usuario_id = $usuario->id;
                     $cliente->agente_id = Input::get('agente_id');
                     $cliente->nivel_descuento_id = Input::get('nivel_descuento_id');
                     $cliente->nombre_cliente = Input::get('nombre');
                     $cliente->paterno = Input::get('paterno');
                     $cliente->materno = Input::get('materno');
                     $cliente->nombre_comercial = Input::get('nombre_comercial');
                     $cliente->razon_social = Input::get('razon_social');
                     $cliente->numero_cliente = date('Y') . date('m') . date("d") . date('G') . date('i') . date('s') . $cliente->usuario_id;
                     $cliente->save();
                     $resp = DB::table('cliente')->where('cliente.id', $cliente->id)->leftJoin('usuario', 'usuario.id', '=', 'cliente.usuario_id')->leftJoin('usuario as usuarioAg', 'usuarioAg.id', '=', 'cliente.agente_id')->leftJoin('Nivel_Descuento', 'Nivel_Descuento.id', '=', 'cliente.nivel_descuento_id')->select('cliente.id', 'cliente.rfc', 'cliente.nombre_cliente', 'cliente.paterno', 'cliente.materno', 'cliente.nombre_comercial', 'cliente.razon_social', 'cliente.numero_cliente', 'cliente.agente_id as idAgente', 'cliente.nivel_descuento_id as idDescuento', 'usuario.usuario', 'usuario.email', 'usuario.id as idUsuario', 'usuarioAg.usuario as agente', 'nivel_descuento.descripcion as descripcion')->first();
                     return Response::json($resp);
                 }
                 break;
             case 'TelefonoCliente':
                 $telefono = new telefonoCliente();
                 $telefono->cliente_id = Input::get('cliente_id');
                 $telefono->numero = Input::get('numero');
                 $telefono->tipo_tel = Input::get('tipo');
                 $telefono->estatus = Input::get('estatus');
                 $telefono->save();
                 $resp = DB::table('telefono_cliente')->where('id', '=', $telefono->id)->first();
                 break;
             case 'DireccionCliente':
                 $dirCliente = new DireccionCliente();
                 $dirCliente->pais_id = Input::get('pais');
                 $dirCliente->estado_id = Input::get('estado');
                 $dirCliente->municipio_id = Input::get('municipio');
                 $dirCliente->calle1 = Input::get('calle1');
                 $dirCliente->calle2 = Input::get('calle2');
                 $dirCliente->colonia = Input::get('colonia');
                 $dirCliente->delegacion = Input::get('delegacion');
                 $dirCliente->codigo_postal = Input::get('cp');
                 $dirCliente->cliente_id = Input::get('cliente_id');
                 $dirCliente->tipo = Input::get('tipoDir');
                 $dirCliente->estatus = "1";
                 $dirCliente->telefono_cliente_id = Input::get('telefonoDir');
                 $dirCliente->save();
                 $resp = DB::table('direccion_cliente as direccion')->where('direccion.id', '=', $dirCliente->id)->leftJoin('pais', 'pais.id', '=', 'direccion.pais_id')->leftJoin('estado', 'estado.id', '=', 'direccion.estado_id')->leftJoin('municipio', 'municipio.id', '=', 'direccion.municipio_id')->select('direccion.id as idDir', 'direccion.cliente_id as idCliente', 'direccion.pais_id as idPais', 'direccion.estado_id as idEstado', 'direccion.municipio_id as idMunicipio', 'direccion.calle1', 'direccion.calle2', 'direccion.colonia', 'direccion.delegacion', 'direccion.codigo_postal', 'direccion.tipo', 'direccion.estatus', 'direccion.telefono_cliente_id as idTelDir', 'pais.pais', 'estado.estados', 'municipio.municipio')->first();
                 # code...
                 break;
             case 'Comercializador':
                 $comercializador = new Comercializador();
                 $comercializador->nombre = Input::get('nombre');
                 $comercializador->save();
                 $resp = DB::table('Comercializador')->where("nombre", $comercializador->nombre)->first();
                 break;
             case 'FormaPago':
                 $formaPago = new FormaDePago();
                 $formaPago->descripcion = Input::get('descripcion');
                 $formaPago->save();
                 $resp = DB::table('forma_pago')->where('id', '=', $formaPago->id)->first();
                 break;
             case 'NivelDescuento':
                 $descuento = new nivelDescuento();
                 $descuento->descripcion = Input::get('descripcion');
                 $descuento->descuento = Input::get('descuento');
                 $descuento->estatus = Input::get('estatus');
                 $descuento->save();
                 $resp = DB::table('Nivel_Descuento')->where('id', $descuento->id)->first();
                 break;
             case 'DescuentoCliente':
                 $descuento = new nivelDescuento();
                 $descuento->descripcion = Input::get('descripcion');
                 $descuento->descuento = Input::get('descuento');
                 $descuento->estatus = 1;
                 $descuento->save();
                 $resp = DB::table('Nivel_Descuento')->where('id', $descuento->id)->first();
                 break;
             case 'UnidadMedida':
                 $unidadMedida = new UnidadMedida();
                 $unidadMedida->descripcion = Input::get('descripcion');
                 $unidadMedida->estatus = Input::get('estatus');
                 $unidadMedida->save();
                 $resp = DB::table('unidad_Medida')->where('id', '=', $unidadMedida->id)->first();
                 break;
             case 'Rol':
                 $rol = new Rol();
                 $rol->nombre = Input::get('nombre');
                 $rol->save();
                 $resp = DB::table('rol')->where('id', $rol->id)->first();
                 # code...
                 break;
             case 'Pais':
                 $pais = new Pais();
                 $pais->pais = Input::get('pais');
                 $pais->estatus = Input::get('estatus');
                 $pais->save();
                 $resp = DB::table('Pais')->where('id', $pais->id)->first();
                 break;
             case 'Estados':
                 $estado = new Estado();
                 $estado->estados = Input::get('estado');
                 $estado->pais_id = Input::get('pais');
                 $estado->estatus = Input::get('estatus');
                 $estado->save();
                 $resp['estado'] = DB::table('estado')->where('id', $estado->id)->first();
                 $resp['paises'] = DB::table('pais')->where('estatus', '=', '1')->select('pais.id', 'pais.pais')->get();
                 break;
             case 'Municipios':
                 $municipio = new Municipio();
                 $municipio->municipio = Input::get('municipio');
                 $municipio->estado_id = Input::get('estado');
                 $municipio->estatus = Input::get('estatus');
                 $municipio->save();
                 $resp['municipio'] = DB::table('municipio')->where('id', '=', $municipio->id)->first();
                 $resp['estados'] = DB::table('estado')->where('estatus', '=', '1')->select('estado.id', 'estado.estados')->get();
                 break;
             case 'Proveedor':
                 $proveedor = new Proveedor();
                 $proveedor->nombre = Input::get('nombre');
                 $proveedor->nombre_comercial = Input::get('nombreComercial');
                 $proveedor->razon_social = Input::get('razonSocial');
                 $proveedor->comercializador_id = Input::get('comercializador');
                 $proveedor->estatus = "1";
                 $proveedor->save();
                 $resp = DB::table('proveedor')->where('id', $proveedor->id)->select('proveedor.id as idProveedor', 'proveedor.nombre', 'proveedor.nombre_comercial', 'proveedor.razon_social', 'proveedor.estatus', 'proveedor.comercializador_id as idComercializador')->first();
                 break;
             case 'TelefonoProveedor':
                 $telefono = new TelefonoProveedor();
                 $telefono->proveedor_id = Input::get('idProveedor');
                 $telefono->numero = Input::get('numero');
                 $telefono->tipo_tel = Input::get('tipo');
                 $telefono->estatus = Input::get('estatus');
                 $telefono->save();
                 $resp = DB::table('telefono_proveedor')->where('id', '=', $telefono->id)->first();
                 break;
             case 'DireccionProveedor':
                 $idProveedor = new DireccionProveedor();
                 $idProveedor->pais_id = Input::get('pais');
                 $idProveedor->estado_id = Input::get('estado');
                 $idProveedor->municipio_id = Input::get('municipio');
                 $idProveedor->calle1 = Input::get('calle1');
                 $idProveedor->calle2 = Input::get('calle2');
                 $idProveedor->colonia = Input::get('colonia');
                 $idProveedor->delegacion = Input::get('delegacion');
                 $idProveedor->codigo_postal = Input::get('cp');
                 $idProveedor->proveedor_id = Input::get('idProveedor');
                 $idProveedor->tipo = Input::get('tipoDir');
                 $idProveedor->estatus = "1";
                 //$idProveedor -> telefono_cliente_id = Input::get('telefonoDir');
                 $idProveedor->save();
                 $resp = DB::table('direccion_proveedor as direccion')->where('direccion.id', '=', $idProveedor->id)->leftJoin('pais', 'pais.id', '=', 'direccion.pais_id')->leftJoin('estado', 'estado.id', '=', 'direccion.estado_id')->leftJoin('municipio', 'municipio.id', '=', 'direccion.municipio_id')->select('direccion.id as idDir', 'direccion.proveedor_id as idProveedor', 'direccion.pais_id as idPais', 'direccion.estado_id as idEstado', 'direccion.municipio_id as idMunicipio', 'direccion.calle1', 'direccion.calle2', 'direccion.colonia', 'direccion.delegacion', 'direccion.codigo_postal', 'direccion.tipo', 'direccion.estatus', 'pais.pais', 'estado.estados', 'municipio.municipio')->first();
                 # code...
                 break;
             case 'Contacto':
                 $contacto = new Contacto();
                 $contacto->nombre = Input::get('nombre');
                 $contacto->correo = Input::get('correo');
                 $contacto->proveedor_id = Input::get('idProveedor');
                 $contacto->estatus = "1";
                 $contacto->save();
                 $resp = DB::table('contacto')->where('id', '=', $contacto->id)->select('contacto.id as idContacto', 'contacto.proveedor_id as idProveedor', 'contacto.nombre', 'contacto.correo', 'contacto.estatus')->first();
                 break;
             default:
                 return Response::json(';No guardado;', 500);
                 break;
         }
         return Response::json($resp);
     } catch (Exception $e) {
         return Response::json(array("error" => $e->getCode()), 500);
     }
 }