Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 /**
  * 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.');
     }
 }
Ejemplo n.º 4
0
 /**
  * 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.');
     }
 }