controllers/ListaController.php
/**
     * Updates an existing Lista model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $id
     * @return mixed
     */
Updates an existing Lista model.
If update is successful, the browser will be redirected to the 'view' page.
@param string $id
@return mixed
Updates an existing Lista model . If update is successful the browser will be redirected to the ' view ' page . @param string $id @return mixed
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $modelDistribucion = Distribucion::findOne($model->DISTRIBUCION_ID);
        $modelFlete = new Flete();
        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()){
		$fletes_anteriores = Flete::findAll(['LISTA_ID'=>$model->ID]);
		foreach($fletes_anteriores as $flete_anterior){
			$empresa_chofer_anterior = Empresachofer::findOne($flete_anterior->EMPRESACHOFER_ID);
			$empresa_chofer_anterior->BLOQUEADO = '0';
			$empresa_chofer_anterior->save();
			$flete_anterior->delete();
		}
                $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('update', [
                'model' => $model,
                'modelFlete' => $modelFlete,
                'modelDistribucion' => $modelDistribucion,
            ]);
        }
    }
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ modelDistribucion = Distribucion :: findOne ( $ model -> DISTRIBUCION_ID ) ; $ modelFlete = new Flete ( ) ; 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 ( ) ) { $ fletes_anteriores = Flete :: findAll ( [ 'LISTA_ID' => $ model -> ID ] ) ; foreach ( $ fletes_anteriores as $ flete_anterior ) { $ empresa_chofer_anterior = Empresachofer :: findOne ( $ flete_anterior -> EMPRESACHOFER_ID ) ; $ empresa_chofer_anterior -> BLOQUEADO = '0' ; $ empresa_chofer_anterior -> save ( ) ; $ flete_anterior -> delete ( ) ; } $ 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 ( 'update' , [ 'model' => $ model , 'modelFlete' => $ modelFlete , 'modelDistribucion' => $ modelDistribucion , ] ) ; } }
Updates an existing Lista model.
Updates an existing Lista model .
// Flete::find()->where(['LISTA_ID'=>$model->ID]); //var_dump($modelFlete);die; //$modelFlete->EMPRESACHOFER_ID = [11=>11,22=>22,33=>33,44=>44,55=>55]; //var_dump($modelDistribucion->attributes);die;