/**
  * 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 $id the ID of the model to be loaded
  * @return SolicitudCitaEntregaMercancia the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SolicitudCitaEntregaMercancia::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function getSolicitudCita($miIdNumeroSolicitud)
 {
     // @todo Please modify the following code to remove attributes that should not be searched.
     $criteria = new CDbCriteria();
     $criteria->select = 'SC.*, FA.Nombre AS NombreFabricante, CE.NombreCEDI, TR.Nombre AS NombreTransportador, ' . ' CONCAT(CO.PrimerNombre, " ", CO.SegundoNombre, " ", CO.PrimerApellido, " ", CO.SegundoApellido) AS NombreConductor ';
     $criteria->alias = 'SC';
     $criteria->join = 'LEFT JOIN m_Fabricante FA ON SC.IdFabricante = FA.IdFabricante ' . 'LEFT JOIN m_Cedi CE ON SC.IdCedi = CE.IdCedi ' . 'LEFT JOIN m_Transportador TR ON TR.IdTransportador = SC.IdTransportador ' . 'LEFT JOIN m_Conductor CO ON SC.IdConductor = CO.IdConductor ';
     $criteria->condition = 'SC.IdNumeroSolicitud =' . $miIdNumeroSolicitud;
     $solicitudCitaEntregaMercancia = SolicitudCitaEntregaMercancia::model()->find($criteria);
     return $solicitudCitaEntregaMercancia;
 }
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     $dataProviderSolicitudes = new CActiveDataProvider(SolicitudCitaEntregaMercancia::model(), array('keyAttribute' => 'IdNumeroSolicitud', 'criteria' => array('condition' => 'IdOrdenCompra=-1'), 'sort' => array('defaultOrder' => 'FechaSolicitudCita DESC')));
     if (Yii::app()->request->isAjaxRequest) {
         // el update del CGridView Solicitudes hecho en Ajax produce un ajaxRequest sobre el mismo
         // action que lo invoco por primera vez y el argumento fue pasado mediante {data: xxx} al // momento de hacer el update al CGridView con id 'productos'
         if (isset($_GET[0])) {
             $numeroOrdenCompra = $_GET[0];
         } else {
             $numeroOrdenCompra = -1;
         }
         //Yii::log("\nAJAX_REQUEST\nPROVOCADO_POR_EL_UPDATE_AL_CGRIDVIEW_PRODUCTOS"
         //		."\nNumero Orden Compra seleccionada es=".$numeroOrdenCompra
         //,"info");
         // actualizas el criteria del data provider para ajustarlo a lo que se pide:
         $dataProviderSolicitudes->criteria = array('condition' => 'IdOrdenCompra=' . $numeroOrdenCompra);
         // para responderle al request ajax debes hacer un ECHO con el JSON del dataprovider
         echo CJSON::encode($dataProviderSolicitudes);
     }
     $model = new OrdenesCompraCitasCedi('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['OrdenesCompraCitasCedi'])) {
         $model->attributes = $_GET['OrdenesCompraCitasCedi'];
     }
     $this->render('index', array('model' => $model, 'modelsolicitudcita' => $dataProviderSolicitudes));
 }