controllers/PedidoController.php
/**
     * Creates a new Pedido model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Pedido model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Pedido model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Pedido();
        if ($model->load(Yii::$app->request->post()) ) {
            $model->Status = true;
            $receta = Receta::find()->where(['ProductoID' => $model->ProductoID])->all();
            $permiso = 0;
            foreach($receta as $r){
                $insumo = Insumo::findOne($r->InsumoID);
                $insumo->Stock -= (($model->UnidadXLote * $r->Cantidad) / (100)); 
                if ($insumo->Stock < 0.0){
                   $permiso = 1; 
                }
            }
            if ($permiso == 0){
                foreach($receta as $r){
                $insumo = Insumo::findOne($r->InsumoID);
                $insumo->Stock -= (($model->UnidadXLote * $r->Cantidad) / (100)); 
                $insumo->save();
                }
                $model->save();
                return $this->redirect(['view', 'id' => $model->PedidoID]);
                }else{
                 return $this->redirect(['noti']);
            }
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new Pedido ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ model -> Status = true ; $ receta = Receta :: find ( ) -> where ( [ 'ProductoID' => $ model -> ProductoID ] ) -> all ( ) ; $ permiso = 0 ; foreach ( $ receta as $ r ) { $ insumo = Insumo :: findOne ( $ r -> InsumoID ) ; $ insumo -> Stock -= ( ( $ model -> UnidadXLote * $ r -> Cantidad ) / ( 100 ) ) ; if ( $ insumo -> Stock < 0.0 ) { $ permiso = 1 ; } } if ( $ permiso == 0 ) { foreach ( $ receta as $ r ) { $ insumo = Insumo :: findOne ( $ r -> InsumoID ) ; $ insumo -> Stock -= ( ( $ model -> UnidadXLote * $ r -> Cantidad ) / ( 100 ) ) ; $ insumo -> save ( ) ; } $ model -> save ( ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> PedidoID ] ) ; } else { return $ this -> redirect ( [ 'noti' ] ) ; } } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Pedido model.
Creates a new Pedido model .