private function findModel($id)
 {
     $listaComercioProductos = ComercioProductosRelacionados::find()->where(['id_comercio' => $id])->all();
     $listaProductos = [];
     foreach ($listaComercioProductos as $comercioProductos) {
         $producto = Producto::find()->where(['id' => $comercioProductos->id_producto])->one();
         $listaProductos[] = $producto;
     }
     return $listaProductos;
 }
 /**
  * Creates a new Producto model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Producto();
     $categoria = new Categoria();
     $categoriasActivas = $categoria->getCategoriasActivas();
     if ($model->load(Yii::$app->request->post())) {
         $nombreImagen = $model->nombre;
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->imagen = 'img/' . $nombreImagen . '.' . $model->file->extension;
         if ($model->validate()) {
             $model->save();
             $model->file->saveAs('img/' . $model->nombre . '.' . $model->file->extension);
             Yii::$app->getSession()->setFlash('success', Yii::t('core', 'Product has been succesfully created'));
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'categorias' => $categoriasActivas]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'categorias' => $categoriasActivas]);
     }
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Producto::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'categoria_producto_id' => $this->categoria_producto_id]);
     $query->andFilterWhere(['like', 'codigo_producto', $this->codigo_producto])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'estado', $this->estado]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Producto::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'id_categoria' => $this->id_categoria, 'precio' => $this->precio]);
     if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'Yes'))) {
         $query->andFilterWhere(['esActivo' => $this->esActivo == 0]);
     } else {
         if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'No'))) {
             $query->andFilterWhere(['esActivo' => $this->esActivo == 1]);
         }
     }
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'imagen', $this->imagen]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductos()
 {
     return $this->hasMany(Producto::className(), ['id_categoria' => 'id']);
 }
Пример #6
0
 /**
  * Finds the Producto model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Producto the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Producto::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdProducto()
 {
     return $this->hasOne(Producto::className(), ['id' => 'id_producto']);
 }
echo $form->field($model, 'fecha')->textInput(['label' => Yii::t('core', 'Date')]);
?>

    <?php 
echo $form->field($model, 'vendidos')->textInput(['label' => Yii::t('core', 'Sold')]);
?>

    <?php 
$comercio = array(Comercio::find()->all());
$listData = ArrayHelper::map(Comercio::find()->all(), 'id', 'nombre');
echo $form->field($model, 'id_comercio')->dropDownList($listData, ['prompt' => Yii::t('core', 'Select...')]);
?>

    <?php 
//$comercio=array(Comercio::find()->all());
$listData = ArrayHelper::map(Producto::find()->all(), 'id', 'nombre');
echo $form->field($model, 'id_producto')->dropDownList($listData, ['prompt' => Yii::t('core', 'Select...')]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
 private function cargarArrayPedidos($idComercio, $fechaDesde, $fechaHasta)
 {
     $respuesta = [];
     $queryRutaDiaria = RutaDiaria::find()->select('id')->where(['between', 'fecha', $fechaDesde, $fechaHasta]);
     $queryRutaDiariaCom = RutaDiariaComercio::find()->where(['ruta_diaria_comercio.id_comercio' => $idComercio])->andWhere(['in', 'id_ruta_diaria', $queryRutaDiaria]);
     if ($queryRutaDiariaCom->count() > 0) {
         $rutaDiariaComercios = $queryRutaDiariaCom->all();
         $pedidos = [];
         $i = 0;
         foreach ($rutaDiariaComercios as $rutaDiariaComercio) {
             if (Pedido::find()->where(['id_ruta_diaria_com' => $rutaDiariaComercio->id])->count() > 0) {
                 $pedidosRutaDiariaComercio = Pedido::find()->where(['id_ruta_diaria_com' => $rutaDiariaComercio->id])->all();
                 foreach ($pedidosRutaDiariaComercio as $pedido) {
                     $pedidos[$i] = $pedido;
                     $i++;
                 }
             }
         }
         if (count($pedidos) > 0) {
             foreach ($pedidos as $pedido) {
                 if (isset($respuesta[$pedido->id_producto])) {
                     $respuesta[$pedido->id_producto]['cantidad'] = $respuesta[$pedido->id_producto]['cantidad'] + $pedido->cantidad;
                 } else {
                     $nombreProducto = Producto::Find()->select('nombre')->where(['id' => $pedido->id_producto])->one()->nombre;
                     $respuesta[$pedido->id_producto] = ['nombre' => $nombreProducto, 'cantidad' => $pedido->cantidad];
                 }
             }
         }
     }
     return $respuesta;
 }
Пример #10
0
 public function actionRemove_product()
 {
     $ProductoTiendaModel = new ProductoTienda();
     if ($ProductoTiendaModel->load(Yii::$app->request->post())) {
         $producto = Producto::find()->where(['id' => $ProductoTiendaModel->idproducto])->one();
         $categoria = Categorias::findOne($producto->idcategoria);
         $ProductoTienda = ProductoTienda::find()->where(['idproducto' => $ProductoTiendaModel->idproducto, 'idcomercio' => $ProductoTiendaModel->idcomercio])->one();
         $ProductoTienda->delete();
         $tooltip = Yii::t('app', 'Click to add');
         $message = ['id' => $producto->id, 'nombre' => $producto->Nombre, 'categoria' => $categoria->nombre, 'tooltip' => $tooltip];
         Yii::$app->response->format = 'json';
         return $message;
     }
 }