Example #1
0
        <div class="clearfix"></div>
        <?php 
}
?>
    
    
   <?php 
$fiador_rut = "";
$fiador_nombre = "";
$fiador_apellido = "";
$fiador_email = "";
$fiador_telefono = "";
$fiador_direccion = "";
$cliente_fiador = ClienteFiador::model()->findByAttributes(array('cliente_id' => $model->id));
if ($cliente_fiador != null) {
    $fiador = Fiador::model()->findByAttributes(array('id' => $cliente_fiador->fiador_id));
    if ($fiador != null) {
        $fiador_rut = $fiador->rut;
        $fiador_nombre = $fiador->nombre;
        $fiador_apellido = $fiador->apellido;
        $fiador_email = $fiador->email;
        $fiador_telefono = $fiador->telefono;
        $fiador_direccion = $fiador->direccion;
    }
}
?>
        <br/>
    <fieldset>
        <legend>Opcionalmente puede agregar un Fiador a este cliente</legend>
        <div class="span2">
            <?php 
Example #2
0
 /**
  * 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 Fiador the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Fiador::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Cliente'])) {
         $model->attributes = $_POST['Cliente'];
         $model->direccion_alternativa = $_POST['Cliente']['direccion_alternativa'];
         $usuario = Usuario::model()->findByPk($model->usuario_id);
         $cliente_fiador = null;
         $fiador = null;
         if ($usuario != null) {
             $usuario->nombre = $_POST['Cliente']['nombre'];
             $usuario->apellido = $_POST['Cliente']['apellido'];
             $usuario->email = $_POST['Cliente']['email'];
             $ok = false;
             if (isset($_POST['Cliente']['fiador_rut'])) {
                 $cliente_fiador = $model->clienteFiadors;
                 if ($cliente_fiador != null) {
                     $fiador = $cliente_fiador->fiador;
                 }
                 if (isset($_POST['Cliente']['fiador_rut'])) {
                     if ($fiador == null) {
                         $fiador = new Fiador();
                     }
                     $fiador->rut = $_POST['Cliente']['fiador_rut'];
                     $fiador->rut = Tools::removeDots($fiador->rut);
                     $fiador->nombre = $_POST['Cliente']['fiador_nombre'];
                     $fiador->apellido = $_POST['Cliente']['fiador_apellido'];
                     $fiador->email = $_POST['Cliente']['fiador_email'];
                     $fiador->telefono = $_POST['Cliente']['fiador_telefono'];
                     $fiador->direccion = $_POST['Cliente']['fiador_direccion'];
                     if ($fiador->validate()) {
                         if ($fiador->save()) {
                             $ok = true;
                         }
                     } else {
                         echo "<br>";
                         echo CHtml::errorSummary($fiador);
                     }
                 }
             }
             if ($model->validate()) {
                 if ($usuario->validate()) {
                     if ($usuario->save()) {
                         if ($model->save()) {
                             if ($ok) {
                                 if ($cliente_fiador == null) {
                                     $cliente_fiador = new ClienteFiador();
                                 }
                                 $cliente_fiador->cliente_id = $model->id;
                                 $cliente_fiador->fiador_id = $fiador->id;
                                 $cliente_fiador->save();
                             }
                             $this->redirect(array('view', 'id' => $model->id));
                         }
                     }
                 } else {
                     echo "<br>";
                     echo CHtml::errorSummary($usuario);
                 }
             } else {
                 echo "<br>";
                 echo CHtml::errorSummary($model);
             }
         }
     }
     $this->render('update', array('model' => $model));
 }