public function cherchercomptebien($code)
 {
     $res = 00;
     $model = new BienSearch();
     $searchModel = new BienSearch();
     //searchConsultationBienSelonCode
     $dataProvider = $searchModel->searchConsultationBienSelonCode(Yii::$app->request->queryParams, $code);
     $modelss = $dataProvider->getModels();
     foreach ($modelss as $rowsF) {
         $searchModelsf = new SousFamilleSearch();
         $dataProvidersf = $searchModelsf->searchSF(Yii::$app->request->queryParams, $rowsF->codesousfamille);
         $modelss = $dataProvidersf->getModels();
         foreach ($modelss as $rowsF) {
             $searchModelsf = new SousFamilleSearch();
             $dataProvidersf = $searchModelsf->searchSF(Yii::$app->request->queryParams, $rowsF->codesousfamille);
             $modelss = $dataProvidersf->getModels();
             foreach ($modelss as $rowsF) {
                 $searchModelF = new FamilleSearch();
                 $dataProviderF = $searchModelF->searchFC(Yii::$app->request->queryParams, $rowsF->codefamille);
                 $modelF = $dataProviderF->getModels();
                 foreach ($modelF as $rowF) {
                     $res = $rowF->codecomptecomptable;
                     return $res;
                 }
             }
         }
     }
 }
Example #2
0
 public function actionTransferercompteamort()
 {
     $model = new Bien();
     //$now = time();
     $i = 0;
     $anneeExercice = date('Y');
     /*?????????????????????????????????????????????????????????????*/
     if ($model->load(Yii::$app->request->post())) {
         $anneeExercice = $model->datetrensfert;
         if (date("Y") < $anneeExercice) {
             \Yii::$app->getSession()->setFlash('danger', "SVP insérer une année inférieur ou égale à l'année actuelle");
         } else {
             $dattr = $model->datetrensfert;
             $selection = (array) Yii::$app->request->post('selection');
             foreach ($selection as $id) {
                 $x = 0;
                 $resultat = 0;
                 $model = $this->findModel($id);
                 $searchModelsf = new SousFamilleSearch();
                 $dataProvidersf = $searchModelsf->searchSF(Yii::$app->request->queryParams, $model->codesousfamille);
                 $modelssf = $dataProvidersf->getModels();
                 foreach ($modelssf as $rowsF) {
                     $searchModelF = new FamilleSearch();
                     $dataProviderF = $searchModelF->searchFC(Yii::$app->request->queryParams, $rowsF->codefamille);
                     $modelF = $dataProviderF->getModels();
                     foreach ($modelF as $rowF) {
                         $searchModelCc = new ComptecomptableamortSearch();
                         $dataProviderCc = $searchModelCc->search(Yii::$app->request->queryParams, $rowF->codecomptecomptable);
                         $modelCc = $dataProviderCc->getModels();
                         foreach ($modelCc as $rowCc) {
                             if ($rowCc->codecomptecomptable == $rowF->codecomptecomptable) {
                                 $resultat = 0.0;
                                 $searchModeltrans = new transfererrefinvamortSearch();
                                 $dataProvidertrans = $searchModeltrans->searchRef(Yii::$app->request->queryParams, $rowCc->codecomptecomptable, $rowCc->comptecomptableref, $dattr);
                                 $modeltrans = $dataProvidertrans->getModels();
                                 if ($dataProvidertrans->getTotalCount() != 0) {
                                     foreach ($modeltrans as $rowtrans) {
                                         $modeltresfer = new Transfererrefinvamort();
                                         $modeltresfer->dat = $dattr;
                                         $modeltresfer = Transfererrefinvamort::findOne(['codecomptecomptable' => $rowtrans->codecomptecomptable, 'dat' => $dattr]);
                                         $resultat = intval($rowtrans->mnt);
                                         /**************************************************************************************************************
                                          *
                                          *on calcule l'amortissement des comptes et on fait le transferer vers les coppte d'amortissement de reforme
                                          *
                                          ***************************************************************************************************************/
                                         $ref = new Reformer();
                                         $modelReformerSearch = new ReformerSearch();
                                         $dataProviderRS = $modelReformerSearch->searchRef(Yii::$app->request->queryParams, $model->codebien);
                                         $modelb = $dataProviderRS->getModels();
                                         foreach ($modelb as $rowsbb) {
                                             ///
                                             //$rowamort=$this->calculeAmort($model, $rowsbb->datereforme);
                                             /*                                              On calcule l amortissement                               */
                                             $dateref = $rowsbb->datereforme;
                                             $anneeExercice = explode('/', $dateref);
                                             $anneeExercice = "20" . $anneeExercice[2];
                                             $datref = explode('/', $dateref);
                                             $secdref = mktime(0, 0, 0, $datref[1], $datref[0], $datref[2]);
                                             $datac = explode('/', $model->dateacquisition);
                                             $dateStr = $datac[1] . '/' . $datac[0] . '/' . $datac[2];
                                             $date2 = new \DateTime($dateStr);
                                             $dureevie = $model->dureevie;
                                             date_add($date2, date_interval_create_from_date_string($dureevie . "years"));
                                             $dataamo = date_format($date2, "d/m/y");
                                             $datsep2 = explode('/', $dataamo);
                                             $secdtamo = mktime(0, 0, 0, $datsep2[1], $datsep2[0], $datsep2[2]);
                                             if ($secdtamo <= $secdref) {
                                                 $model->amortpratiquee = $model->prixachat;
                                             } else {
                                                 $resamort = $this->CalculeAmortissementsref($model->dateacquisition, $dateref, $anneeExercice, $model->dureevie, $model->prixachat);
                                                 $model->amortpratiquee = $resamort[count($resamort) - 1][3];
                                             }
                                             /*  $resamort=$this->CalculeAmortissements ($model->dateacquisition, $anneeExercice, $model->dureevie, $model->prixachat);
                                             				 $model->prixachat=$resamort[count($resamort)-1][1];
                                             				$model->amortpratiquee=$resamort[count($resamort)-1][2];
                                             				$model->actifbrut=$model->prixachat;
                                             				$model->valeurnet= ($model->actifbrut - $model->amortpratiquee);
                                             				echo "valeur nette = ".$model->valeurnet;*/
                                             /*
                                              *  *  si le compte deja exite dans cet ann e on rajoute le resultat
                                              **/
                                             /*   A ne pas touché */
                                             $resultat = intval($resultat) + intval($resamort[count($resamort) - 1][3]);
                                             $modeltresfer->mnt = '' . $resultat;
                                             $modeltresfer->save();
                                             if ($dattr != null) {
                                                 if ($model->statutbien == 'reformertransf') {
                                                     $model2 = new Bien();
                                                     $model2 = $this->findModel($model->codebien);
                                                     $model2->statutbien = "reformertransfinvamort";
                                                     $model2->save();
                                                 } else {
                                                     $model2 = new Bien();
                                                     $model2 = $this->findModel($model->codebien);
                                                     $model2->statutbien = "reformertransfamort";
                                                     $model2->save();
                                                 }
                                             } else {
                                                 if ($x == 0) {
                                                     $x = 1;
                                                     \Yii::$app->getSession()->setFlash('danger', "SVP insérer l'année de réforme");
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     $modeltresfer = new Transfererrefinvamort();
                                     $modeltresfer->dat = '' . $dattr;
                                     $modeltresfer->codecomptecomptable = '' . $rowCc->codecomptecomptable;
                                     $modeltresfer->codecomptecomptableref = '' . $rowCc->comptecomptableref;
                                     $ref = new Reformer();
                                     $modelReformerSearch = new ReformerSearch();
                                     $dataProviderRS = $modelReformerSearch->searchRef(Yii::$app->request->queryParams, $model->codebien);
                                     $modelb = $dataProviderRS->getModels();
                                     foreach ($modelb as $rowsbb) {
                                         $dateref = $rowsbb->datereforme;
                                         $anneeExercice = explode('/', $dateref);
                                         $anneeExercice = "20" . $anneeExercice[2];
                                         $datref = explode('/', $dateref);
                                         $secdref = mktime(0, 0, 0, $datref[1], $datref[0], $datref[2]);
                                         //$resamort=$this->CalculeAmortissements ($model->dateacquisition, $anneeExercice, $model->dureevie, $model->prixachat);
                                         $datac = explode('/', $model->dateacquisition);
                                         $dateStr = $datac[1] . '/' . $datac[0] . '/' . $datac[2];
                                         $date2 = new \DateTime($dateStr);
                                         $dureevie = $model->dureevie;
                                         date_add($date2, date_interval_create_from_date_string($dureevie . " years"));
                                         $dataamo = date_format($date2, "d/m/y");
                                         $datsep2 = explode('/', $dataamo);
                                         $secdtamo = mktime(0, 0, 0, $datsep2[1], $datsep2[0], $datsep2[2]);
                                         if ($secdtamo <= $secdref) {
                                             //$resamort=$this->CalculeAmortissements($row->dateacquisition, $anneeExercice, $row->dureevie, $row->prixachat);
                                             $model->amortpratiquee = $model->prixachat;
                                         } else {
                                             $resamort = $this->CalculeAmortissementsref($model->dateacquisition, $dateref, $anneeExercice, $model->dureevie, $model->prixachat);
                                             $model->amortpratiquee = $resamort[count($resamort) - 1][3];
                                         }
                                         //$model->amortpratiquee=$resamort[count($resamort)-1][2];
                                     }
                                     $modeltresfer->mnt = '' . $model->amortpratiquee;
                                     $modeltresfer->save();
                                     if ($dattr != null) {
                                         if ($model->statutbien == 'reformertransf') {
                                             $model2 = new Bien();
                                             $model2 = $this->findModel($model->codebien);
                                             $model2->statutbien = "reformertransfinvamort";
                                             $model2->save();
                                         } else {
                                             $model2 = new Bien();
                                             $model2 = $this->findModel($model->codebien);
                                             $model2->statutbien = "reformertransfamort";
                                             $model2->save();
                                         }
                                     } else {
                                         if ($x == 0) {
                                             $x = 1;
                                             \Yii::$app->getSession()->setFlash('info', "SVP insérer l'année de réforme");
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     /*??????????????????????????Pour initialiser le tableau ??????????????*/
     $searchModel = new BienSearch();
     $dataProvider = $searchModel->searchListeReformerAllAmort(Yii::$app->request->queryParams);
     $models = $dataProvider->getModels();
     $resamortpratiquee = null;
     $resactifbrut = null;
     $resvaleurnet = null;
     $data = null;
     foreach ($models as $row) {
         $ref = new Reformer();
         $modelReformerSearch = new ReformerSearch();
         $dataProviderRS = $modelReformerSearch->searchRef(Yii::$app->request->queryParams, $row->codebien);
         $modelb = $dataProviderRS->getModels();
         foreach ($modelb as $rowsbb) {
             /*
              * 1. calculer date amortissement
              * 2. comparaison (date amortissement , date reforme)
              * if > on utilise date reforme
              * si non date amortissement
              * */
             /*on recupere la date de reforme*/
             $dateref = $rowsbb->datereforme;
             $anneeExercice = explode('/', $dateref);
             $anneeExercice = "20" . $anneeExercice[2];
             $datref = explode('/', $dateref);
             $secdref = mktime(0, 0, 0, $datref[1], $datref[0], $datref[2]);
             /********************      annee amortissement               *********************/
             $datac = explode('/', $row->dateacquisition);
             $dateStr = $datac[1] . '/' . $datac[0] . '/' . $datac[2];
             $date2 = new \DateTime($dateStr);
             $dureevie = $row->dureevie;
             date_add($date2, date_interval_create_from_date_string($dureevie . " years"));
             $dataamo = date_format($date2, "d/m/y");
             $datsep2 = explode('/', $dataamo);
             $secdtamo = mktime(0, 0, 0, $datsep2[1], $datsep2[0], $datsep2[2]);
             if ($secdtamo < $secdref) {
                 //$resamort=$this->CalculeAmortissements($row->dateacquisition, $anneeExercice, $row->dureevie, $row->prixachat);
                 $resamortpratiquee = $row->prixachat;
                 $resactifbrut = $row->prixachat;
                 $resvaleurnet = 0.0;
             } else {
                 $resamort = $this->CalculeAmortissementsref($row->dateacquisition, $dateref, $anneeExercice, $row->dureevie, $row->prixachat);
                 $resactifbrut = $resamort[count($resamort) - 1][1];
                 //	$row->dotation = $resamort[count($resamort)-1][2];
                 $resamortpratiquee = $resamort[count($resamort) - 1][3];
                 $resvaleurnet = $resamort[count($resamort) - 1][4];
             }
             //	date_add($date2,date_interval_create_from_date_string($annee." years"." ".$mois." months"." ".$jours." days"));
         }
         /*                                type et annee de reforme                                */
         $modelReformerSearch = new ReformerSearch();
         $dataProviderRS = $modelReformerSearch->searchRef(Yii::$app->request->queryParams, $row->codebien);
         $modelb = $dataProviderRS->getModels();
         $typ = null;
         $ann = null;
         foreach ($modelb as $rowb) {
             $typ = $rowb->typereforme;
             $ann = $rowb->datereforme;
             $searchModelsf = new SousFamilleSearch();
             $dataProvidersf = $searchModelsf->searchSF(Yii::$app->request->queryParams, $row->codesousfamille);
             $modelssf = $dataProvidersf->getModels();
             foreach ($modelssf as $rowsF) {
                 $searchModelF = new FamilleSearch();
                 $dataProviderF = $searchModelF->searchFC(Yii::$app->request->queryParams, $rowsF->codefamille);
                 $modelF = $dataProviderF->getModels();
                 foreach ($modelF as $rowF) {
                     $searchModelCc = new ComptecomptableSearch();
                     $dataProviderCc = $searchModelCc->search(Yii::$app->request->queryParams, $rowF->codecomptecomptable);
                     $modelCc = $dataProviderCc->getModels();
                     foreach ($modelCc as $rowCc) {
                         $formatter = \Yii::$app->formatter;
                         $resactifbrut = number_format($resactifbrut, 2, ',', ' ');
                         $resamortpratiquee = number_format($resamortpratiquee, 2, ',', ' ');
                         $resvaleurnet = number_format($resvaleurnet, 2, ',', ' ');
                         $data[$i] = ['comptecomptable' => $rowCc->codecomptecomptable, 'codebien' => $row->codebien, 'designationbien' => $row->designationbien, 'typereforme' => $typ, 'actifbrut' => $resactifbrut, 'amortpratiquee' => $resamortpratiquee, 'valeurnet' => $resvaleurnet, 'dateRef' => $ann];
                         $i++;
                     }
                 }
             }
         }
     }
     $dataProviderRes = new ArrayDataProvider(['allModels' => $data, 'key' => 'codebien', 'sort' => ['attributes' => ['comptecomptable', 'codebien', 'designationbien', 'typereforme', 'actifbrut', 'amortpratiquee', 'valeurnet', 'dateRef']]]);
     $dataProvider = $dataProviderRes;
     return $this->render('listecompteAmortAtransferer', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'model' => $model]);
 }