Exemplo n.º 1
0
 /**
  * Modificar
  * 
  * @param AgenciaCargaData $AgenciaCargaData
  * @return array
  */
 function modificar(AgenciaCargaData $AgenciaCargaData)
 {
     $this->getEntityManager()->getConnection()->beginTransaction();
     try {
         $AgenciaCargaDAO = new AgenciaCargaDAO();
         $AgenciaCargaDAO->setEntityManager($this->getEntityManager());
         //$AgenciaCargaData2 = $AgenciaCargaDAO->consultar($AgenciaCargaData->getId());
         $result = $AgenciaCargaDAO->consultarDuplicado('M', $AgenciaCargaData->getId(), $AgenciaCargaData->getNombre());
         $id = $AgenciaCargaData->getId();
         $nombre = $AgenciaCargaData->getNombre();
         if (!empty($result)) {
             $result['validacion_code'] = 'NO-EXISTS';
             $result['respuesta_mensaje'] = 'El registro  existe, no puede ser moficado!!';
         } else {
             $id = $AgenciaCargaDAO->modificar($AgenciaCargaData);
             $result['validacion_code'] = 'OK';
             $result['respuesta_mensaje'] = '';
         }
         //end if
         $this->getEntityManager()->getConnection()->commit();
         return $result;
     } catch (Exception $e) {
         $this->getEntityManager()->getConnection()->rollback();
         $this->getEntityManager()->close();
         throw $e;
     }
 }
 /**
  * Consultar
  * 
  * @param string $id
  * @param int $resultType
  * @return \Dispo\Data\AgenciaCargaData|NULL|array
  */
 public function consultar($id, $resultType = \Application\Constants\ResultType::OBJETO)
 {
     switch ($resultType) {
         case \Application\Constants\ResultType::OBJETO:
             $AgenciaCargaData = new AgenciaCargaData();
             $sql = ' SELECT agencia_carga.* ' . ' FROM agencia_carga ' . ' WHERE agencia_carga.id = :id ';
             $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
             $stmt->bindValue(':id', $id);
             $stmt->execute();
             $row = $stmt->fetch();
             //Se utiliza el fecth por que es un registro
             if ($row) {
                 $AgenciaCargaData->setId($row['id']);
                 $AgenciaCargaData->setNombre($row['nombre']);
                 $AgenciaCargaData->setDireccion($row['direccion']);
                 $AgenciaCargaData->setTelefono($row['telefono']);
                 $AgenciaCargaData->setTipo($row['tipo']);
                 $AgenciaCargaData->setEstado($row['estado']);
                 $AgenciaCargaData->setFecIngreso($row['fec_ingreso']);
                 $AgenciaCargaData->setFecModifica($row['fec_modifica']);
                 $AgenciaCargaData->setUsuarioIngId($row['usuario_ing_id']);
                 $AgenciaCargaData->setUsuarioModId($row['usuario_mod_id']);
                 $AgenciaCargaData->setSinronizado($row['sincronizado']);
                 $AgenciaCargaData->setFecSincronizado($row['fec_sincronizado']);
                 return $AgenciaCargaData;
             } else {
                 return null;
             }
             //end if
             break;
         case \Application\Constants\ResultType::MATRIZ:
             $sql = ' SELECT agencia_carga.*, usuario_ing.username as usuario_ing_user_name, usuario_mod.username as usuario_mod_user_name  ' . ' FROM agencia_carga LEFT JOIN usuario as usuario_ing ' . '                           ON usuario_ing.id = agencia_carga.usuario_ing_id ' . '					 LEFT JOIN usuario as usuario_mod ' . '                           ON usuario_mod.id = agencia_carga.usuario_mod_id ' . ' WHERE agencia_carga.id = :id ';
             $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
             $stmt->bindValue(':id', $id);
             $stmt->execute();
             $row = $stmt->fetch();
             //Se utiliza el fecth por que es un registro
             return $row;
             break;
     }
     //end switch
 }
 public function grabardataAction()
 {
     try {
         $SesionUsuarioPlugin = $this->SesionUsuarioPlugin();
         $usuario_id = $SesionUsuarioPlugin->getUsuarioId();
         $EntityManagerPlugin = $this->EntityManagerPlugin();
         $AgenciaCargaData = new AgenciaCargaData();
         $AgenciaCargaBO = new AgenciaCargaBO();
         $AgenciaCargaBO->setEntityManager($EntityManagerPlugin->getEntityManager());
         $respuesta = $SesionUsuarioPlugin->isLoginAdmin();
         if ($respuesta == false) {
             return false;
         }
         $body = $this->getRequest()->getContent();
         $json = json_decode($body, true);
         $accion = $json['accion'];
         //I, M
         $AgenciaCargaData->setId($json['id']);
         $AgenciaCargaData->setNombre($json['nombre']);
         $AgenciaCargaData->setDireccion($json['direccion']);
         $AgenciaCargaData->setTelefono($json['telefono']);
         $AgenciaCargaData->setTipo($json['tipo']);
         $AgenciaCargaData->setEstado($json['estado']);
         $response = new \stdClass();
         switch ($accion) {
             case 'I':
                 $AgenciaCargaData->setUsuarioIngId($usuario_id);
                 $result = $AgenciaCargaBO->ingresar($AgenciaCargaData);
                 break;
             case 'M':
                 $AgenciaCargaData->setUsuarioModId($usuario_id);
                 $result = $AgenciaCargaBO->modificar($AgenciaCargaData);
                 break;
             default:
                 $result['validacion_code'] = 'ERROR';
                 $result['respuesta_mensaje'] = 'ACCESO NO VALIDO';
                 break;
         }
         //end switch
         //Se consulta el registro siempre y cuando el validacion_code sea OK
         if ($result['validacion_code'] == 'OK') {
             $row = $AgenciaCargaBO->consultar($json['id'], \Application\Constants\ResultType::MATRIZ);
         } else {
             $row = null;
         }
         //end if
         //Retorna la informacion resultante por JSON
         $response = new \stdClass();
         $response->respuesta_code = 'OK';
         $response->validacion_code = $result['validacion_code'];
         $response->respuesta_mensaje = $result['respuesta_mensaje'];
         if ($row) {
             $response->row = $row;
             $response->cbo_tipo = $AgenciaCargaBO->getComboTipo($row['tipo'], " ");
             $response->cbo_estado = \Application\Classes\ComboGeneral::getComboEstado($row['estado'], "");
         } else {
             $response->row = null;
             $response->cbo_tipo = '';
             $response->cbo_estado = '';
         }
         //end if
         $json = new JsonModel(get_object_vars($response));
         return $json;
         //false
     } catch (\Exception $e) {
         $excepcion_msg = utf8_encode($this->ExcepcionPlugin()->getMessageFormat($e));
         $response = $this->getResponse();
         $response->setStatusCode(500);
         $response->setContent($excepcion_msg);
         return $response;
     }
 }