Example #1
0
 public function indexAction()
 {
     $session = new \Shared\Session\ClientSession();
     //if(!$session->isActive())
     //return $this->redirect()->toUrl('http://itrade/login');
     $request = $this->getRequest();
     //echo $request;
     $message = "success";
     //$id = $session->getData()['idcliente'];
     $id = 1;
     $entity = \ClienteQuery::create()->findPk($id);
     if ($request->isPost()) {
         $success = false;
         $post_data = $request->getPost();
         $post_files = $request->getFiles();
         //Campos de datos generales
         $entity->setClienteRazonsocial($post_data['cliente_razon_social']);
         $entity->setClienteRfc($post_data['cliente_rfc']);
         $entity->setClienteCalle($post_data['cliente_calle']);
         $entity->setClienteNumero($post_data['cliente_numero_exterior']);
         $entity->setClienteInterior($post_data['cliente_numero_interior']);
         $entity->setClienteColonia($post_data['cliente_colonia']);
         $entity->setClienteCiudad($post_data['cliente_ciudad']);
         $entity->setClienteCodigopostal($post_data['cliente_cp']);
         if ($post_data['cliente_estado'] != 'Seleccione un estado') {
         }
         $entity->setClienteEstado($post_data['cliente_estado']);
         if ($post_data['cliente_pais'] != 'Seleccione un país') {
         }
         $entity->setClientePais($post_data['cliente_pais']);
         $entity->setClienteEmail($post_data['cliente_email']);
         $entity->setClienteTelefono($post_data['cliente_telefono']);
         $entity->setClienteRfc($post_data['cliente_rfc']);
         $entity->setClienteNombrecontacto($post_data['cliente_nombre']);
         //Terminan campos generales
         //Campos Fiscales
         //$entity->setClienteRazonsocial($post_data['cliente_f_razon_social']);
         //$entity->setClienteRfc($post_data['cliente_f_rfc']);
         $entity->setClienteCallefiscal($post_data['cliente_f_calle']);
         $entity->setClienteNumerofiscal($post_data['cliente_f_numero_exterior']);
         $entity->setClienteInteriorfiscal($post_data['cliente_f_numero_interior']);
         $entity->setClienteColoniafiscal($post_data['cliente_f_colonia']);
         $entity->setClienteCiudadfiscal($post_data['cliente_f_ciudad']);
         $entity->setClienteCodigopostalfiscal($post_data['cliente_f_cp']);
         if ($post_data['cliente_f_estado'] != 'Seleccione un estado') {
         }
         $entity->setClienteEstadofiscal($post_data['cliente_f_estado']);
         if ($post_data['cliente_f_pais'] != 'Seleccione un país') {
         }
         $entity->setClientePaisfiscal($post_data['cliente_f_pais']);
         //Terminan campos fiscales
         //Ruta donde se guardaran los archivos
         $upload_folder = $_SERVER['DOCUMENT_ROOT'] . "/files/clientes/" . $id . "/";
         //Clase auxiliar para validar y guardar archivos
         $fileClass = new \Client\Files\SaveFiles();
         //Creamos el directorio del cliente si no existe
         if (!file_exists($upload_folder)) {
             mkdir($upload_folder);
         }
         $names = array('cliente_padron', 'cliente_encargoconferido');
         /*
         foreach ($post_files as $file ) 
         {
             $i = 0;
             //Verificamos si el no archivo es valido, si lo es proseguimos con el else
             if( !$fileClass->validateFile($file) == "") 
                 $message = $message.$fileClass->validateFile($file);
             else
             {
                 $newName = $names[$i];
                 $fileClass->saveFile($upload_folder,$file,$newName);
                 $debug = $names[$i];
             }
             $i++;
         }
         */
         //Verificamos que el usuario haya subido algún archivo
         $file = $post_files['cliente_padron'];
         if ($file['name'] != "") {
             $debug = $file;
             if (!$fileClass->validateFile($file) == "") {
                 //Si el archivo que se quiso subir tiene error
                 $message = $message . $fileClass->validateFile($file);
             } else {
                 //Si se valido que el archivo sea correcto
                 $fileClass->saveFile($upload_folder, $file, 'cliente_padron');
                 //Insertamos a la base de datos
                 $entity->setClientePadronimportador("/files/clientes/" . $id . "/cliente_padron." . $fileClass->getType($file));
             }
         }
         //copy($post_files['cliente_padron']['tmp_name'], $upload_folder);
         if ($message == "success") {
             $entity->save();
         }
         /*
                     $entity->setClienteNombrecontacto('Victor');
                     $entity->save();
         			
             		/*
             		$cliente = \ClienteQuery::create()
         			->filterByEmpleadoEmail($user)
         			->find();	  		
         */
     } else {
         $message = "";
     }
     $mexico_states = \Shared\GeneralFunction\Geolocation::getMexicoStates();
     $form = new \Client\Form\ClienteForm($mexico_states, $entity);
     //$form = new \Catalogo\Form\ClienteForm();
     $layout = $this->layout();
     $layout->setTemplate('client/layout/layout');
     //RETORNAMOS A NUESTRA VISTA
     return new ViewModel(array('form' => $form, 'message' => $message, 'session' => $session, 'debug' => $debug));
 }
Example #2
0
 public function editarAction()
 {
     //ID ENTIDAD
     $id = $this->params()->fromRoute('id');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $post_files = $request->getFiles();
         //INSTANCIAMOS NUESTRA ENTIDAD
         $entity = \EmpleadoQuery::create()->findPk($id);
         //SETIAMOS NUESTROS DATOS CON EXCEPCIONES
         foreach ($post_data as $key => $value) {
             if (\EmpleadoPeer::getTableMap()->hasColumn($key) && $key != 'empleado_iniciocontrato' && $key != 'empleado_password' && $key != 'empleado_foto') {
                 $entity->setByName($key, $value, \BasePeer::TYPE_FIELDNAME);
             }
         }
         //SETIAMOS LA FECHA DE CONTRATO
         if (!empty($post_data['empleado_iniciocontrato'])) {
             $empleado_iniciocontrato = date_create_from_format('d/m/Y', $post_data['empleado_iniciocontrato']);
             $entity->setEmpleadoIniciocontrato($empleado_iniciocontrato);
         }
         //SETIAMOS LA CONTRASEÑA EN MD5
         if (!empty($post_data['empleado_password'])) {
             $entity->setEmpleadoPassword(md5($post_data['empleado_password']));
         }
         //ELIMINAMOS LA FOTOGRAFIA DEL EMPLEADO
         $entity->setEmpleadoFoto(NULL);
         unlink($_SERVER['DOCUMENT_ROOT'] . "/img/admin/profiles/empleado_avatar_" . $entity->getIdempleado() . ".jpg");
         $entity->save();
         //LA FOTO DEL EMPLEADO
         if (!empty($post_files['empleado_foto']['name'])) {
             $upload_folder = '/img/admin/profiles/';
             $img_type = $post_files['empleado_foto']['type'];
             $img_type = explode('/', $img_type);
             $img_type = $img_type[1];
             $img_info = getimagesize($post_files['empleado_foto']['tmp_name']);
             $img_original = imagecreatefromjpeg($post_files['empleado_foto']['tmp_name']);
             $max_ancho = 250;
             $max_alto = 250;
             list($ancho, $alto) = getimagesize($post_files['empleado_foto']['tmp_name']);
             //Se calcula ancho y alto de la imagen final
             $x_ratio = $max_ancho / $ancho;
             $y_ratio = $max_alto / $alto;
             //Si el ancho y el alto de la imagen no superan los maximos,
             //ancho final y alto final son los que tiene actualmente
             if ($ancho <= $max_ancho && $alto <= $max_alto) {
                 //Si ancho
                 $ancho_final = $ancho;
                 $alto_final = $alto;
             } elseif ($x_ratio * $alto < $max_alto) {
                 $alto_final = ceil($x_ratio * $alto);
                 $ancho_final = $max_ancho;
             } else {
                 $ancho_final = ceil($y_ratio * $ancho);
                 $alto_final = $max_alto;
             }
             //Creamos una imagen en blanco de tamaño $ancho_final  por $alto_final .
             $tmp = imagecreatetruecolor($ancho_final, $alto_final);
             //Copiamos $img_original sobre la imagen que acabamos de crear en blanco ($tmp)
             imagecopyresampled($tmp, $img_original, 0, 0, 0, 0, $ancho_final, $alto_final, $ancho, $alto);
             //Se destruye variable $img_original para liberar memoria
             imagedestroy($img_original);
             //Definimos la calidad de la imagen final
             $calidad = 95;
             //Se crea la imagen final en el directorio indicado
             imagejpeg($tmp, $_SERVER['DOCUMENT_ROOT'] . "/img/admin/profiles/empleado_avatar_" . $entity->getIdempleado() . ".jpg", $calidad);
             //SETIAMOS LA FOTO
             $entity->setEmpleadoFoto("/img/admin/profiles/empleado_avatar_" . $entity->getIdempleado() . ".jpg");
             $entity->save();
         }
         //Agregamos un mensaje
         $this->flashMessenger()->addSuccessMessage('Registro guardado exitosamente!');
         //REDIRECCIONAMOS A LA ENTIDAD QUE ACABAMOS DE CREAR
         return $this->redirect()->toRoute('admin/catalogo/empleados', array('action' => 'editar', 'id' => $entity->getIdempleado()));
     }
     $exist = \EmpleadoQuery::create()->filterByIdempleado($id)->exists();
     if ($exist) {
         $entity = \EmpleadoQuery::create()->findPk($id);
         //INSTANCIAMOS NUESTRO FORMULARIO
         $mexico_states = \Shared\GeneralFunction\Geolocation::getMexicoStates();
         $form = new \Catalogo\Form\EmpleadoForm($mexico_states);
         $form->setData($entity->toArray(\BasePeer::TYPE_FIELDNAME));
         //REMOVEMOS EL CAMPO DE LA FECHA
         $form->get('empleado_iniciocontrato')->setValue('');
         //RETORNAMOS A NUESTRA VISTA
         $view_model = new ViewModel();
         $view_model->setTemplate('admin/catalogo/empleado/editar');
         $view_model->setVariables(array('entity' => json_encode($entity->toArray(\BasePeer::TYPE_FIELDNAME)), 'successMessages' => json_encode($this->flashMessenger()->getSuccessMessages()), 'form' => $form));
         return $view_model;
     } else {
         return $this->redirect()->toRoute('admin/catalogo/empleados', array('action' => 'index'));
     }
 }