/**
  * @return html nombre de partida compuesto con el nombre
  */
 public function etiquetaExtranjero()
 {
     //echo count($this->id);
     //die;
     $extranjero = ProveedoresExtranjeros::model()->findByAttributes(array('proveedor_id' => $this->id));
     return CHtml::encode($this->rif . ' - ' . $this->razon_social . ' - ' . $extranjero->num_identificacion . ' - ' . $extranjero->pais->nombre);
 }
 public function actionAjaxObtenerProveedores()
 {
     if (isset($_GET['q'])) {
         $partes = explode("99999999999910", $_GET['q']);
         $_GET['q'] = $partes[0];
         if (@$partes[1]) {
             $nacional = (string) $partes[1];
             $nacional = str_replace(' ', '', $nacional);
         }
         if (count($partes) >= 2) {
             if (@$partes[1] == 'no') {
                 $nacional = false;
             } else {
                 $nacional = true;
             }
         } else {
             $nacional = false;
         }
         if (@$nacional) {
             $proveedores = Proveedores::model()->findAll(array('order' => 'rif', 'condition' => '(rif LIKE :rif) and nacional=:nacional', 'params' => array(':nacional' => $nacional, ':rif' => strtoupper('%' . $_GET['q'] . '%'))));
             //echo 'Hola'; die;
         } else {
             $proveedores = Proveedores::model()->findAll(array('order' => 'razon_social', 'condition' => '(rif LIKE :q or razon_social LIKE :q) and nacional=:nacional', 'params' => array(':nacional' => $nacional, ':q' => strtoupper('%' . $_GET['q'] . '%'))));
             if (count($proveedores) == 0) {
                 $proveedoresExtranjeros = ProveedoresExtranjeros::model()->findAll(array('order' => 'num_identificacion', 'condition' => 'num_identificacion LIKE :num_identificacion ', 'params' => array(':num_identificacion' => strtoupper('%' . $_GET['q'] . '%'))));
                 foreach ($proveedoresExtranjeros as $key => $value) {
                     $proveedores[$key] = $value->proveedor;
                 }
             }
         }
         $data = array();
         foreach ($proveedores as $value) {
             $data[] = array('id' => $value->id, 'text' => $nacional ? $value->etiquetaProveedor() : $value->etiquetaExtranjero());
         }
         echo CJSON::encode($data);
     }
     Yii::app()->end();
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ProveedoresExtranjeros::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }