controllers/DistribucionController.php
/**
     * Creates a new Distribucion model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Distribucion model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Distribucion model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Distribucion();
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
                Yii::$app->response->format = Response::FORMAT_JSON;
                return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post())) {
            $date = date('Y-m-d');
            $model->FE_REGISTRO = $date;
            $model->ESTATUS_DIS = 1;
            $model->FE_VENCE_PI = Yii::$app->formatter->asDate($model->FE_VENCE_PI, 'Y-MM-dd');
            $cantidadAsignada = $model->CANTIDAD;
            $modelCentrales = Centrales::findOne(['ID'=>$model->CENTRALES_ID]);
            $modelCarga = Carga::findOne(['ID'=>$model->CARGA_ID]);
            $model->DESCRIPCION = $modelCarga->DESCRIPCION.' / '.$modelCentrales->NOMBRE;           
            $sumaCarga = $modelCarga->PESO_DISTRIBUIDO+$cantidadAsignada;
            $modelCarga->PESO_DISTRIBUIDO = $sumaCarga;
            if($sumaCarga == $modelCarga->PESO_ASIGNADO){
                $modelCarga->ESTATUS_CARGA = 0;
            }
            if($modelCarga->save(false)){
                $model->save(false);
            }
            return $this->redirect(['view', 'id' => $model->ID]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
public function actionCreate ( ) { $ model = new Distribucion ( ) ; if ( Yii :: $ app -> request -> isAjax && $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return ActiveForm :: validate ( $ model ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ date = date ( 'Y-m-d' ) ; $ model -> FE_REGISTRO = $ date ; $ model -> ESTATUS_DIS = 1 ; $ model -> FE_VENCE_PI = Yii :: $ app -> formatter -> asDate ( $ model -> FE_VENCE_PI , 'Y-MM-dd' ) ; $ cantidadAsignada = $ model -> CANTIDAD ; $ modelCentrales = Centrales :: findOne ( [ 'ID' => $ model -> CENTRALES_ID ] ) ; $ modelCarga = Carga :: findOne ( [ 'ID' => $ model -> CARGA_ID ] ) ; $ model -> DESCRIPCION = $ modelCarga -> DESCRIPCION . ' / ' . $ modelCentrales -> NOMBRE ; $ sumaCarga = $ modelCarga -> PESO_DISTRIBUIDO + $ cantidadAsignada ; $ modelCarga -> PESO_DISTRIBUIDO = $ sumaCarga ; if ( $ sumaCarga == $ modelCarga -> PESO_ASIGNADO ) { $ modelCarga -> ESTATUS_CARGA = 0 ; } if ( $ modelCarga -> save ( false ) ) { $ model -> save ( false ) ; } return $ this -> redirect ( [ 'view' , 'id' => $ model -> ID ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; } }
Creates a new Distribucion model.
Creates a new Distribucion model .
//var_dump($model->FE_VENCE_PI);die;