Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if (CustomerType::model()->count('active=1') == 0) {
         throw new CHttpException(412, 'No hay tipos de clientes activos. Para crear un cliente, primero debe ' . CHtml::link('crear un tipo de cliente', array('customerType/create')) . '.');
     }
     $model = new Customer();
     $model->contact = new Contact();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         $model->dependence_id = $model->dependence_id == '' ? NULL : $model->dependence_id;
         $model->contact->active = $model->active;
         if (isset($_POST['Contact'])) {
             $model->contact->attributes = $_POST['Contact'];
             $successful = $model->contact->validate();
         }
         $successful = $model->validate() && $successful;
         if ($successful) {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 if ($model->save(false)) {
                     $model->contact->customer_id = $model->id;
                     if ($model->contact->save(false)) {
                         $transaction->commit();
                         if (!empty($_POST['yt1'])) {
                             Yii::app()->user->setFlash('customer-created', "¡El cliente <b><i>&quot;{$model->name}&quot;</i></b> fue creado exitosamente!");
                             $this->redirect(array('create'));
                         } else {
                             $this->redirect(array('view', 'id' => $model->id));
                         }
                     }
                 }
                 $transaction->rollBack();
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Remove the specified product from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     CustomerType::destroy($id);
     return Response::json(array('success' => true, 'message' => array('type' => 'success', 'msg' => 'Xóa loại khách hàng thành công!')));
 }
Exemplo n.º 3
0
echo $form->labelEx($model, 'name');
?>
            <?php 
echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 100));
?>
            <?php 
echo $form->error($model, 'name');
?>
        </div>
        <div class="row">

            <?php 
echo $form->labelEx($model, 'customer_type_id');
?>
            <?php 
echo $form->DropDownList($model, 'customer_type_id', CHtml::listData(CustomerType::model()->findAll(array('condition' => 'active = 1', 'order' => 'type')), 'id', 'type'), array('empty' => 'Seleccionar'));
?>
            <?php 
echo $form->error($model, 'customer_type_id');
?>
            
        </div>
        <div class="row">
            <?php 
echo $form->labelEx($model, 'dependence_id');
?>
            <?php 
echo $form->DropDownList($model, 'dependence_id', CHtml::listData(Dependence::model()->findAll(array('condition' => 'active = 1', 'order' => 'name')), 'id', 'name'), array('empty' => 'Seleccionar'));
?>
            <?php 
echo $form->error($model, 'dependence_id');
Exemplo n.º 4
0
 public static function getActiveCustomerTypes()
 {
     $customer_types = array('' => "Seleccionar");
     $customer_types += CHtml::ListData(CustomerType::model()->findAll('t.active = 1'), 'id', 'type');
     return $customer_types;
 }
 public function run()
 {
     CustomerType::create(['customer_type' => 'Chủ cửa hàng']);
     CustomerType::create(['customer_type' => 'Nhà cung cấp']);
     CustomerType::create(['customer_type' => 'Khách bán lẻ']);
 }
Exemplo n.º 6
0
<?php

$this->breadcrumbs = array('Tipos de cliente' => array('index'), $model->type);
$this->menu = array(array('label' => 'Listar tipos de cliente', 'url' => array('index')), array('label' => 'Crear tipo de cliente', 'url' => array('create')), array('label' => 'Actualizar tipo de cliente', 'url' => array('update', 'id' => $model->id)), array('label' => 'Desactivar tipo de cliente', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => '¿Esta seguro que desea desactivar este Tipo de cliente?'), 'visible' => $model->active == 1), array('label' => 'Activar tipo de cliente', 'url' => '#', 'linkOptions' => array('submit' => array('activate', 'id' => $model->id), 'confirm' => '¿Esta seguro que desea activar este Tipo de cliente?'), 'visible' => $model->active == 0), array('label' => 'Administrar tipos de cliente', 'url' => array('admin')));
?>

<h1>Tipo de cliente: <?php 
echo $model->type;
?>
</h1>

<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'type', array('label' => 'Activo', 'type' => 'raw', 'value' => CustomerType::getActive($model->active)))));
Exemplo n.º 7
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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = CustomerType::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }