/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PartidaProductos(); //$lista_partidas = $usuario = Usuarios::model()->findByPk(Yii::app()->user->getId()); $criteria = new CDbCriteria(); $criteria->condition = 'p3 <> 0'; //$criteria->params = array(':p1'=>$general->p1, ':p2' => $general->p2); $especificas = new Partidas('search'); $especificas = $especificas->findAll($criteria); $especificas_lista = CHtml::listData($especificas, function ($especificas) { return CHtml::encode($especificas->partida_id); }, function ($especificas) { return CHtml::encode($especificas->p1 . ' - ' . $especificas->p2 . '-' . $especificas->p3 . '-' . $especificas->p4 . ' ' . $especificas->nombre); }); $productos = Productos::model()->findAll(); $lista_productos = CHtml::listData($productos, function ($productos) { return CHtml::encode($productos->producto_id); }, function ($productos) { return CHtml::encode($productos->cod_segmento . '-' . $productos->cod_familia . '-' . $productos->cod_clase . '-' . $productos->cod_producto . ' ' . $productos->nombre); }); //print_r($especificas_lista); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $operacion = array('C' => 'Compra', 'V' => 'Venta'); //$operacion = CHtml::listData($pro); if (isset($_POST['PartidaProductos'])) { $model->attributes = $_POST['PartidaProductos']; $variable = $model->producto_id; if ($model->validate()) { if (count($variable) != 1) { foreach ($variable as $key) { $modeltodos = new PartidaProductos(); $modeltodos->partida_id = $model->partida_id; $modeltodos->producto_id = $key; $modeltodos->tipo_operacion = $model->tipo_operacion; $modeltodos->fecha_desde = $model->fecha_desde; $modeltodos->fecha_hasta = $model->fecha_hasta; $modeltodos->save(); } Yii::app()->user->setFlash('success', "Productos agregados con éxito a la partida seleccionada "); } else { $model->producto_id = $variable[0]; $model->save(); Yii::app()->user->setFlash('success', "Producto agregado con éxito a la partida seleccionada"); } $this->refresh(); } /*if($model->save()) $this->redirect(array('view','id'=>$model->partida_producto_id));*/ } $this->render('create', array('model' => $model, 'especificas_lista' => $especificas_lista, 'productos' => $lista_productos, 'operacion' => $operacion)); }
public function actionAutocomplete($term) { $criteria = new CDbCriteria(); $criteria->compare('LOWER(Descripcion)', strtolower($_GET['term']), true); $criteria->order = 'Descripcion'; $criteria->limit = 30; $data = Productos::model()->findAll($criteria); if (!empty($data)) { $arr = array(); foreach ($data as $item) { $arr[] = array('id' => $item->CodProducto, 'value' => $item->Descripcion, 'label' => $item->Descripcion, 'Precio' => $item->PreCompra, 'UniMedida' => $item->UniMedida, 'Saldo' => $item->CanExistencia, 'Iva' => $item->Iva); } } else { $arr = array(); $arr[] = array('id' => '', 'value' => 'No se han encontrado resultados para su búsqueda', 'label' => 'No se han encontrado resultados para su búsqueda'); } echo CJSON::encode($arr); }
public function getMenuProducto() { return CHtml::listData(Productos::model()->findAll(), 'Id', 'Descripcion'); }
</table> <!--<div class="table"> <table> <tr> <th> <div class="row_buttons"> <tr> <?php echo $form->labelEx($model_detalle, 'CodProducto'); ?> <?php echo $form->dropDownList($model_detalle, 'CodProducto', CHtml::listData(Productos::model()->findAll(), 'CodProducto', 'Descripcion'), array('empty' => ' ')); ?> <?php echo $form->error($model_detalle, 'CodProducto'); ?> </tr> <p align="left"><input type="button" class="submit extra_long" id="buscar_prod_serv" value="Añadir Producto" /></p> <br clear="all" /> </div> <table cellpadding="0" cellspacing="0" width="100%"> <thead> <tr> <th style="text-align:left" width="2%"> Item</th> <th width="30%">Descripción</th> <th style="text-align:right" width="10%">Cantidad</th>
/** * 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 = Productos::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }