Example #1
0
 public function actionListeaffecter()
 {
     $affect = new Affecter();
     $instance = new Instance();
     $bureau = new Bureau();
     $dat = new Dat();
     $b = 1;
     $y = 0;
     $searchInstance = new InstanceSearch();
     $dataProvider = $searchInstance->search(Yii::$app->request->queryParams);
     $biens = $dataProvider->getModels();
     $selection = (array) Yii::$app->request->post('selection');
     foreach ($selection as $i) {
         $affect = new Affecter();
         $instance = new Instance();
         $bureau = new Bureau();
         $dat = new Dat();
         $bien = new Bien();
         if ($affect->load(Yii::$app->request->post()) && $dat->load(Yii::$app->request->post()) && $bureau->load(Yii::$app->request->post())) {
             $affect->codebien = $i;
             $dte = $dat->dt;
             $affect->dt = $dte;
             //controle de date
             $dateSysteme = date('d/m/Y');
             //récupérer date systeme
             $tabSys = explode('/', $dateSysteme);
             //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('/', $dte);
             $secPicker = mktime(0, 0, 0, $tabPicker[1], $tabPicker[0], $tabPicker[2]);
             if ($secSys >= $secPicker) {
                 $bien = Bien::find()->where(['codebien' => $i])->one();
                 $bien->statutbien = 'affecte';
                 $instance = Instance::find()->where(['codebien' => $i])->one();
                 $instance->status = 'affecte';
                 $instance->save();
                 $bien->save();
                 $dat->save();
                 $codBureau = $bureau->codebureau;
                 $affect->codebureau = $codBureau;
                 $affect->save();
             } else {
                 Yii::$app->getSession()->setFlash('danger', 'La date que vous avez entrée est superieure à celle du système. Veuillez entrer une date valide s il vous plait');
                 return $this->redirect(['listeaffecter']);
             }
         }
         $b = 0;
     }
     if ($b == 0) {
         Yii::$app->getSession()->setFlash('info', 'L affectation a été bien faite.');
         return $this->redirect(['biensaffectes']);
     }
     $instance = new Instance();
     $dat = new Dat();
     $b = 1;
     $y = 0;
     $searchInstance = new InstanceSearch();
     $dataProvider = $searchInstance->search(Yii::$app->request->queryParams);
     $biens = $dataProvider->getModels();
     foreach ($biens as $bien) {
         $bi = Bien::find()->where(['codebien' => $bien->codebien])->one();
         $data[$y] = ['codebien' => $bien->codebien, 'designationbien' => $bi->designationbien, 'codesousfamille' => $bi->codesousfamille, 'numfacture' => $bi->numfacture, 'dt' => $bien->dt];
         $y++;
         $dataProviderRes = new ArrayDataProvider(['key' => 'codebien', 'allModels' => $data, 'sort' => ['attributes' => ['codebien', 'designationbien', 'codesousfamille', 'numfacture', 'dt']]]);
         $dataProvider = $dataProviderRes;
     }
     return $this->render('vueListeAaffecter', ['searchInstance' => $searchInstance, 'dataProvider' => $dataProvider, 'affect' => $affect, 'dat' => $dat, 'bureau' => $bureau]);
     /*$affect = new Affecter;
         	 			$data=null;
         	 			$instance = new Instance;
         	 			$bureau = new Bureau;
         	 			$dat = new Dat;
         	 			$b=1; $y=0;
         	 			$searchInstance = new InstanceSearch();
         	 			$dataProvider = $searchInstance->search(Yii::$app->request->queryParams);
     
         	 			$biens=$dataProvider->getModels();
         	 		$selection=(array)Yii::$app->request->post('selection');
         	 	    	 		
         	 	    
         	 	    	 		
         	 		foreach ($selection as $i){
         	 			
         	 			$affect = new Affecter;
         	 			$instance = new Instance;
         	 			$bureau = new Bureau;
         	 			$dat = new Dat;
         	 			$bien = new Bien;
         	 			
         	 			
         	 			if (   ($affect->load(Yii::$app->request->post()))   &&   ($dat->load(Yii::$app->request->post()))   &&    ($bureau->load(Yii::$app->request->post()))    ){
         	 				
         	 		           $affect->codebien = $i;
         	 				   
         	 					$dte=$dat->dt;
         	 					$affect->dt= $dte;
         	 					
         	 					
         	 					//controle de date
         	 					$dateSysteme = date('d/m/Y'); //récupérer date systeme
         	 					$tabSys = explode('/', $dateSysteme); //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('/', $dte);
         	 					$secPicker= mktime(0, 0, 0, $tabPicker[1], $tabPicker[0], $tabPicker[2]);
         	 					
         	 					if ($secSys >= $secPicker) {
         	 						$bien = Bien::find()->where(['codebien' => $i])->one();
         	 						$bien->statutbien = 'affecte';
         	 						$instance = Instance::find()->where(['codebien' => $i])->one();
         	 						$instance->status = 'affecte';
         	 						$instance->save();
         	 						$bien->save();
         	 						 
         	 						$dat->save();
         	 						 
         	 						$codBureau=$bureau->codebureau;
         	 						$affect->codebureau= $codBureau;
         	 						
         	 						$affect->save();
         	 								
         	 					}else {
         	 						Yii::$app->getSession()->setFlash('danger', 'La date que vous avez entrée est superieure à celle du système. Veuillez entrer une date valide s il vous plait');
         	 						return $this->redirect(['listeaffecter']);
         	 						
         	 					}
         	 					
         	 				}
         	 				
         	 					$b=0;
         	 			}
         	 			if ($b==0) {
         	 				Yii::$app->getSession()->setFlash('info', 'L affectation a été bien faite.');
         	 				return $this->redirect(['biensaffectes']);
         	 				
         	 			}
         	 			
         	 			$instance = new Instance;
         	 			
         	 			$dat = new Dat;
         	 			$b=1; $y=0;
         	 			$searchInstance = new InstanceSearch();
         	 			$dataProvider = $searchInstance->search(Yii::$app->request->queryParams);
         	 			
         	 			$biens=$dataProvider->getModels();
         	 			
         	 				foreach ($biens as $bien){
         	 					
         	 					$searchb = new BienSearch();
         	 					$dataProviderb = $searchb->search(Yii::$app->request->queryParams);
         	 					 
         	 					$biensb=$dataProviderb->getModels();
         	 					
         	 					foreach ($biensb as $bi){
         	 						echo "code = ".$bien->codebien;
         	 						if($bi->codebien==$bien->codebien)
         	 						{
         	 					
         	 						
         	 				
         	 					
         	 					//$bi = Bien::find()->where(['codebien' => $bien->codebien])->one();
         	 			$data[$y] = ['codebien'=>$bien->codebien,'designationbien'=> $bi->designationbien, 'codesousfamille'=> $bi->codesousfamille, 'numfacture'=>$bi->numfacture, 'dt'=>$bien->dt];
         	 			$y++;
         	 						}
         	 					}
         	 			$dataProviderRes = new ArrayDataProvider([
         	 					'key' =>'codebien',
         	 					'allModels' => $data,
         	 					'sort' => [
         	 					'attributes' => ['codebien', 'designationbien', 'codesousfamille','numfacture','dt'],
         	 					],
         	 					]);
         	 			
         	 			
         	 			$dataProvider=$dataProviderRes;
         	 			}
         	 			
         	 			return $this->render('vueListeAaffecter', [
         	 					'searchInstance' => $searchInstance,
         	 					'dataProvider' => $dataProvider,
         	 					'affect' => $affect,
         	 					'dat' => $dat,
         	 					'bureau' => $bureau,
         	 					]);*/
 }