/** * Creates a new Inventario model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Inventario(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function updateInventario() { $sum = 0; $entradas = Entrada::findAll(['producto_IdProducto' => $this->producto_idProducto]); foreach ($entradas as $e) { $sum += $e->cantidad; } $inv = Inventario::findOne(['producto_IdProducto' => $this->producto_idProducto]); if ($inv == null) { $inv = new Inventario(); $inv->producto_idProducto = $this->producto_idProducto; } $inv->stock = $sum; $inv->save(); }