/** * Lists all Reparer models. * @return mixed */ public function actionIndex() { $searchModel = new ReparerSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function actionHistorique() { $code = Yii::$app->request->post('code'); $searchModel = new BienSearchHistorique(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $code); $des = ''; $data = null; $i = 0; if ($code) { // rechercher lacquisition $searchModel = new BienSearchHistorique(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $code); $biens = $dataProvider->getModels(); foreach ($biens as $bien) { if ($bien) { $des = $bien->designationbien; $datAcqui = $bien->dateacquisition; $data[$i] = ['date mouvement' => $datAcqui, 'mouvement' => 'acquis']; $i++; } } $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'sort' => ['attributes' => ['date mouvement', 'mouvement']]]); $dataProvider = $dataProviderRes; // rechercher laffectation $searchModel = new AffecterSearch(); $dataProvider = $searchModel->searchHistorique(Yii::$app->request->queryParams, $code); $biens = $dataProvider->getModels(); foreach ($biens as $bien) { if ($bien) { $datAffect = $bien->dt; $codebureau = $bien->codebureau; $data[$i] = ['date mouvement' => $datAffect, 'mouvement' => 'affecté', 'affecté vers' => $codebureau]; $i++; } } $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'sort' => ['attributes' => ['date mouvement', 'mouvement']]]); $dataProvider = $dataProviderRes; // rechercher la mise en instance $searchModel = new InstanceSearch(); $dataProvider = $searchModel->searchHistorique(Yii::$app->request->queryParams, $code); $biens = $dataProvider->getModels(); foreach ($biens as $bien) { if ($bien) { $datInst = $bien->dt; $data[$i] = ['date mouvement' => $datInst, 'mouvement' => 'mis en instance']; $i++; } } $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'sort' => ['attributes' => ['date mouvement', 'mouvement']]]); $dataProvider = $dataProviderRes; // rechercher le transfert $biens = Transferer::find()->where(['codebien' => $code])->orderBy(['dt' => SORT_ASC])->all(); $cont = Transferer::find()->where(['codebien' => $code])->orderBy('dt')->count(); $y = 0; if ($cont > 1) { foreach ($biens as $bien) { if ($bien) { //construire tableau des dates et des bureaux ordonné $datTrans = $bien->dt; $dat[$y] = $bien->dt; $bureau[$y] = $bien->codebureau; $y++; } } //manipuler le tableau des bureaux for ($y = 0; $y < $cont - 1; $y++) { $datDe = $dat[$y]; $datVer = $dat[$y + 1]; $burDe = $bureau[$y]; $burVer = $bureau[$y + 1]; $data[$i] = ['date mouvement' => $datVer, 'mouvement' => 'transféré', 'transféré de' => $burDe, 'transféré vers' => $burVer]; $i++; } } else { //si on a un seul transfert if ($cont == 1) { // on fait la recherche ds la table affecter $bienAffect = Affecter::find()->where(['codebien' => $code])->one(); foreach ($biens as $bien) { $datVer = $bien->dt; $burDe = $bienAffect->codebureau; $burVer = $bien->codebureau; } $data[$i] = ['date mouvement' => $datVer, 'mouvement' => 'transféré', 'transféré de' => $burDe, 'transféré vers' => $burVer]; $i++; } } $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'sort' => ['attributes' => ['date mouvement', 'mouvement', 'transféré de', 'transféré vers']]]); $dataProvider = $dataProviderRes; // rechercher la réparation $searchModel = new ReparerSearch(); $dataProvider = $searchModel->searchHistorique(Yii::$app->request->queryParams, $code); $biens = $dataProvider->getModels(); foreach ($biens as $bien) { if ($bien) { $datSorti = $bien->dt; $datEntre = $bien->datefin; $data[$i] = ['date mouvement' => $datSorti, 'mouvement' => 'en réparation', 'date fin reparation' => $datEntre]; $i++; } } $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'sort' => ['attributes' => ['date mouvement', 'mouvement', 'date fin reparation']]]); $dataProvider = $dataProviderRes; // rechercher la réforme $searchModel = new ReformerSearch(); $dataProvider = $searchModel->searchHistorique(Yii::$app->request->queryParams, $code); $biens = $dataProvider->getModels(); foreach ($biens as $bien) { if ($bien) { $datref = $bien->datereforme; $typeref = $bien->typereforme; $data[$i] = ['date mouvement' => $datref, 'mouvement' => 'réformé', 'type reforme' => $typeref]; $i++; } } $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'sort' => ['attributes' => ['date mouvement', 'mouvement']]]); $dataProvider = $dataProviderRes; } return $this->render('historique', ['designationBien' => $des, 'dataProvider' => $dataProvider]); }