controllers/ListaController.php
/**
     * Creates a new Lista model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Lista model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Lista model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Lista();
        $modelFlete = new Flete();
        $modelDistribucion = new Distribucion();
        $items = Lista::getChoferesDisponibles();
        if ($model->load(Yii::$app->request->post()) && $modelFlete->load(Yii::$app->request->post())) {
            $fecha = Yii::$app->formatter->asDate($model->FECHA_CREACION, 'Y-MM-dd');
            $model->ESTATUS_LISTA = 1;
            $model->FECHA_CREACION = $fecha;
            if($model->save()){
                $choferes = Json::decode($modelFlete->EMPRESACHOFER_ID);
                foreach($choferes as $chofer)
                {
                    $modelFlete = new Flete();
                    $modelEmpresachofer = Empresachofer::findOne(['CHOFER_ID'=>$chofer]);
                    $modelFlete->ESTATUS_FLETE_ID = 1;
                    $modelFlete->EMPRESACHOFER_ID = $modelEmpresachofer->ID;
                    $modelFlete->VEHICULO_ID = $modelEmpresachofer->VEHICULO_ID;
                    $modelFlete->LISTA_ID = $model->ID;
                    if($modelFlete->save()){
                        $modelEmpresachofer->BLOQUEADO = "1";
                        $modelEmpresachofer->save();
                    }
                }
            }
            Yii::$app->getSession()->setFlash('success', [
                'type' => Growl::TYPE_SUCCESS,
                'icon' => 'fa fa-users',
                'message' => Html::encode('La Lista ha sido creada exitósamente'),
                'title' => Html::encode('Resultado'),
                'showSeparator' => true,
            ]);
            return $this->redirect(['view', 'id' => $model->ID]);
        } else {
            return $this->render('create', [
                'model' => $model,
                'modelFlete' => $modelFlete,
                'modelDistribucion' => $modelDistribucion,
                'items'=>$items
            ]);
        }
    }
public function actionCreate ( ) { $ model = new Lista ( ) ; $ modelFlete = new Flete ( ) ; $ modelDistribucion = new Distribucion ( ) ; $ items = Lista :: getChoferesDisponibles ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ modelFlete -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ fecha = Yii :: $ app -> formatter -> asDate ( $ model -> FECHA_CREACION , 'Y-MM-dd' ) ; $ model -> ESTATUS_LISTA = 1 ; $ model -> FECHA_CREACION = $ fecha ; if ( $ model -> save ( ) ) { $ choferes = Json :: decode ( $ modelFlete -> EMPRESACHOFER_ID ) ; foreach ( $ choferes as $ chofer ) { $ modelFlete = new Flete ( ) ; $ modelEmpresachofer = Empresachofer :: findOne ( [ 'CHOFER_ID' => $ chofer ] ) ; $ modelFlete -> ESTATUS_FLETE_ID = 1 ; $ modelFlete -> EMPRESACHOFER_ID = $ modelEmpresachofer -> ID ; $ modelFlete -> VEHICULO_ID = $ modelEmpresachofer -> VEHICULO_ID ; $ modelFlete -> LISTA_ID = $ model -> ID ; if ( $ modelFlete -> save ( ) ) { $ modelEmpresachofer -> BLOQUEADO = " 1 " ; $ modelEmpresachofer -> save ( ) ; } } } Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , [ 'type' => Growl :: TYPE_SUCCESS , 'icon' => 'fa fa-users' , 'message' => Html :: encode ( 'La Lista ha sido creada exitósamente') , 'title' => Html :: encode ( 'Resultado' ) , 'showSeparator' => true , ] ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> ID ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , 'modelFlete' => $ modelFlete , 'modelDistribucion' => $ modelDistribucion , 'items' => $ items ] ) ; } }
Creates a new Lista model.
Creates a new Lista model .
//$modelFlete = new Chofer(); /*if ($model->load(Yii::$app->request->post())){
            var_dump(Yii::$app->request->post());
            die;
            
        }*/ //if ($model->load(Yii::$app->request->post()) && $model->save()) { //var_dump($model->attributes);die; //var_dump($modelFlete->attributes);die; //var_dump($modelFlete->EMPRESA_CHOFER_ID);die; //echo $model->FECHA_CREACION."<br>"; //var_dump(Json::decode($modelFlete->EMPRESA_CHOFER_ID));die; #$model->FECHA_CREACION = new Expression('now()'); //echo $model->FECHA_CREACION; die; //var_dump($prueba);die; //var_dump($flete)."<hr>"; //echo $chofer."<hr>"; //die; /*$model->ESTATUS_LISTA = 1;
            if($model->save()){

            }*/