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(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Inventario::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(['idInventario' => $this->idInventario, 'producto_idProducto' => $this->producto_idProducto, 'stock' => $this->stock]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Inventario::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, 'cantidad' => $this->cantidad, 'articulos_aid' => $this->articulos_aid, 'estatus_did' => $this->estatus_did, 'fechacreacion_ft' => $this->fechacreacion_ft]); return $dataProvider; }
public function actionItems($idPedido) { $contenido_pedido = Carropedido::findAll(['pedido_idPedido' => $idPedido]); $id_productos = array_map(function ($o) { return $o->producto_idProducto; }, $contenido_pedido); $productos = Producto::find()->where(['NOT IN', 'idProducto', $id_productos])->all(); $items = array_map(function ($u) { $temp = Inventario::findOne(['producto_IdProducto' => $u->idProducto]); if (empty($temp)) { $existencias = 0; } else { $existencias = $temp->stock; } $row['idProducto'] = $u->idProducto; $row['codigo'] = $u->codigo; $row['nombre'] = $u->producto; $row['precio'] = $u->precio; $row['embalaje'] = $u->embalajeIdEmbalaje->nombre; $row['existencias'] = $existencias; return $row; }, $productos); return Json::encode($items); }
/** * Finds the Inventario model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Inventario the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Inventario::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getInventarios() { return $this->hasMany(Inventario::className(), ['estatus_did' => 'id']); }
/** * Finds the Inventario model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $idInventario * @param integer $producto_idProducto * @return Inventario the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($idInventario, $producto_idProducto) { if (($model = Inventario::findOne(['idInventario' => $idInventario, 'producto_idProducto' => $producto_idProducto])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getInventarios() { return $this->hasMany(Inventario::className(), ['articulos_aid' => 'id']); }