/** * Creates a new Transferer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Transferer(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'codebien' => $model->codebien, 'dt' => $model->dt, 'codebureau' => $model->codebureau]); } else { return $this->render('create', ['model' => $model]); } }
public function actionTransfert() { $trans = new Transferer(); $dat = new Dat(); $bureau = new Bureau(); $nomStruct = ''; $bur = ''; $des = ''; $y = 0; $str = ''; $datt = ''; $code = Yii::$app->request->post('code'); if ($code) { //on fait la recherche d'abord ds la table transferer sinon on la fait ds la table affecter $Codebiens = Transferer::find()->where(['codebien' => $code])->orderBy(['dt' => SORT_ASC])->all(); foreach ($Codebiens as $Codebien) { if ($Codebien) { $datTab[0] = $Codebien->dt; $bureauTab[0] = $Codebien->codebureau; $datt = $datTab[0]; $bur = $bureauTab[0]; $Designationbien = Bien::find()->where(['codebien' => $code])->one(); $des = $Designationbien->designationbien; $struct = Bureau::find()->where(['codebureau' => $bur])->one(); if ($struct) { $str1 = Structure::find()->where(['codestructure' => $struct->codestructure])->one(); $str = $str1->designation; } } } $Codebien = Transferer::find()->where(['codebien' => $code])->orderBy(['dt' => SORT_ASC])->all(); if ($Codebien == null) { // on fait la recherche ds la table affecter $Codebien = Affecter::find()->where(['codebien' => $code])->one(); if ($Codebien) { $datt = 'null'; $bur = $Codebien->codebureau; $Designationbien = Bien::find()->where(['codebien' => $code])->one(); $des = $Designationbien->designationbien; $struct = Bureau::find()->where(['codebureau' => $bur])->one(); if ($struct) { $str1 = Structure::find()->where(['codestructure' => $struct->codestructure])->one(); $str = $str1->designation; } } else { Yii::$app->getSession()->setFlash('info', 'Le bien n est même pas affecté, vous ne pouvez pas le transférer'); return $this->redirect(['transfert']); } } //itwas here lacolade de for } $dte = date('d/m/Y'); //récupérer date systeme $trans->dt = $dte; if ($trans->load(Yii::$app->request->post()) && $bureau->load(Yii::$app->request->post())) { $bien = Bien::find()->where(['codebien' => $code])->one(); if ($bien) { //controle de date $tabSys = explode('/', $dte); //convertir en tableau dont le séparateur est / $secSys = mktime(0, 0, 0, $tabSys[1], $tabSys[0], $tabSys[2]); //convertir la date en seconde $tabPicker = explode('/', $trans->dt); $secPicker = mktime(0, 0, 0, $tabPicker[1], $tabPicker[0], $tabPicker[2]); if ($secSys >= $secPicker) { $trans->codebien = $code; $codBureau = $bureau->codebureau; $trans->codebureau = $codBureau; $dateTrans = $trans->dt; $bien->statutbien = 'transfere'; $trans->save(); $bien->save(); if ($trans->save()) { Yii::$app->getSession()->setFlash('success', 'Le transfert est éffectué avec succès'); return $this->redirect(['transferer/view', 'codebien' => $trans->codebien, 'dt' => $dateTrans, 'codebureau' => $trans->codebureau]); } } else { Yii::$app->getSession()->setFlash('danger', 'La date du transfert est superieure à la date d aujourdhui'); return $this->redirect(['transfert']); } } else { Yii::$app->getSession()->setFlash('danger', 'Veuillez entrer un code valide s il vous plait'); return $this->redirect(['transfert']); } } return $this->render('_formTransfert', ['designationBien' => $des, 'structu' => $str, 'bureau1' => $bur, 'datTrans' => $datt, 'nomStruct' => $nomStruct, 'trans' => $trans, 'dat' => $dat, 'bureau' => $bureau]); }