Loading code/QueryCompare.php +12 −4 Original line number Diff line number Diff line Loading @@ -5,11 +5,18 @@ * @var $container \Psr\Container\ContainerInterface */ $sql1 = "SELECT * FROM tbl_piece_jointe"; $sql1 = "SELECT tbj.* FROM tbl_piece_jointe tbj --where intervenant_id = 633563 --JOIN intervenant i ON i.id = tbj.intervenant_id --JOIN piece_jointe pj ON pj.id = tbj.piece_jointe_id"; $sql2 = "SELECT * FROM v_tbl_piece_jointe"; $sql2 = "SELECT tbjo.* FROM tbl_piece_jointe_old2 tbjo --where intervenant_id = 633563 -- JOIN intervenant i ON i.id = tbjo.intervenant_id --JOIN piece_jointe pj ON pj.id = tbjo.piece_jointe_id"; $keyCols = ['TYPE_PIECE_JOINTE_ID', 'INTERVENANT_ID']; $keyCols = ['TYPE_PIECE_JOINTE_ID', 'INTERVENANT_ID', 'ANNEE_ID']; //pays_nationalite => paysNationalite //date_creation => dateCreation Loading @@ -22,6 +29,7 @@ $ignoreCols = [ 'SEUIL_HETD', 'HEURES_POUR_SEUIL', 'ID', 'PIECE_JOINTE_ID' // colonne supprimée ]; Loading @@ -42,7 +50,7 @@ $comparator->setKeyColumns($keyCols); $comparator->setIgnoreColumns($ignoreCols); $comparator->setOnlyColumns($onlyCols); $comparator->setLimit(5000); $comparator->setLimit(100); $result = $comparator->run(); Loading code/test7.php +5 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,10 @@ $stbl = $container->get(\UnicaenTbl\Service\TableauBordService::class); $data = ['INTERVENANT_ID' => 1000171]; $data = [//'INTERVENANT_ID' => '9290', 'INTERVENANT_ID' => 9290, //'ANNEE_ID' => 2015, ]; //$data = []; $stbl->calculer('piece_jointe', $data); module/PieceJointe/src/Tbl/Process/Model/PieceJointe.php 0 → 100644 +22 −0 Original line number Diff line number Diff line <?php namespace PieceJointe\Tbl\Process\Model; class PieceJointe { public ?string $uuid = null; public ?int $annee = null; public ?int $typePieceJointeId = null; public ?int $pieceJointeId = null; public ?int $intervenantId = null; public bool $demandee = false; public bool $fournie = false; public bool $validee = false; public bool $obligatoire = false; public ?int $dateOrigine = null; public ?int $dateValiditee = null; public float $seuilHetd = 0; public bool $demandeApresRecrutement = false; } module/PieceJointe/src/Tbl/Process/PieceJointeProcess.php +83 −102 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace PieceJointe\Tbl\Process; use Application\Service\Traits\AnneeServiceAwareTrait; use Intervenant\Service\IntervenantServiceAwareTrait; use PieceJointe\Tbl\Process\Model\PieceJointe; use Unicaen\BddAdmin\BddAwareTrait; use UnicaenTbl\Event; use UnicaenTbl\Process\ProcessInterface; Loading @@ -25,6 +26,8 @@ class PieceJointeProcess implements ProcessInterface protected array $piecesJointesDemandees = []; protected array $piecesJointesFournies = []; /** @var array|PieceJointe[][] */ private array $piecesJointes = []; protected array $tblData = []; Loading @@ -40,8 +43,8 @@ class PieceJointeProcess implements ProcessInterface { $this->getPiecesJointesDemandees($params); $this->getPiecesJointesFournies($params); //dd($this->piecesJointesDemandees, $this->piecesJointesFournies); $this->traitementPiecesJointes($params); $this->exporterPiecesJointes($params); $this->enregistrement($tableauBord, $params); } Loading Loading @@ -95,7 +98,6 @@ class PieceJointeProcess implements ProcessInterface return $this->piecesJointesFournies; } Loading @@ -112,6 +114,8 @@ class PieceJointeProcess implements ProcessInterface return $piecesJointesFournies; } protected function replaceIntervenantIdbyCodeIntervenantParam(array $params): array { if (isset($params['INTERVENANT_ID'])) { Loading @@ -132,82 +136,63 @@ class PieceJointeProcess implements ProcessInterface protected function traitementPiecesJointes(array $params): void { //On commence par traiter toutes les pièces jointes demandées foreach ($this->piecesJointesDemandees as $pieceJointeDemandee) { $uuid = $pieceJointeDemandee['ANNEE_ID'] . '_' . $pieceJointeDemandee['INTERVENANT_ID'] . '_' . $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $this->tblData[$uuid]['ANNEE_ID'] = $pieceJointeDemandee['ANNEE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_ID'] = $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_CODE'] = $pieceJointeDemandee['TYPE_PJ_CODE']; $this->tblData[$uuid]['PIECE_JOINTE_ID'] = null; $this->tblData[$uuid]['INTERVENANT_ID'] = $pieceJointeDemandee['INTERVENANT_ID']; $this->tblData[$uuid]['FOURNIE'] = 0; $this->tblData[$uuid]['DEMANDEE'] = 1; $this->tblData[$uuid]['VALIDEE'] = 0; $this->tblData[$uuid]['DATE_ORIGINE'] = null; $this->tblData[$uuid]['DATE_VALIDITEE'] = null; $this->tblData[$uuid]['SEUIL_HETD'] = $pieceJointeDemandee['SEUIL_HETD']; $this->tblData[$uuid]['OBLIGATOIRE'] = $pieceJointeDemandee['OBLIGATOIRE']; $this->tblData[$uuid]['DEMANDEE_APRES_RECRUTEMENT'] = $pieceJointeDemandee['DEMANDEE_APRES_RECRUTEMENT']; $this->sortDatas($this->tblData[$uuid]); $pieceJointe = new PieceJointe(); $pieceJointe->uuid = $uuid; $pieceJointe->annee = $pieceJointeDemandee['ANNEE_ID']; $pieceJointe->typePieceJointeId = $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $pieceJointe->intervenantId = $pieceJointeDemandee['INTERVENANT_ID']; $pieceJointe->demandee = true; $pieceJointeFournie = false; $pieceJointe->seuilHetd = $pieceJointeDemandee['SEUIL_HETD']; $pieceJointe->obligatoire = $pieceJointeDemandee['OBLIGATOIRE']; $pieceJointe->demandeApresRecrutement = $pieceJointeDemandee['DEMANDEE_APRES_RECRUTEMENT']; $this->piecesJointes[$uuid] = $pieceJointe; } //On parcourt maintenant les pièces jointes fournies qui sont forcément fournies l'année de leurs dépot //On parcourt maintenant les pièces jointes fournies pour voir si elles ont été fourni sur l'année demandée foreach ($this->piecesJointesFournies as $codeIntervenant => $datas) { foreach ($datas as $typePieceJointeId => $piecesJointesFournies) { foreach ($piecesJointesFournies as $pieceJointeFournie) { $uuid = $pieceJointeFournie['ANNEE_ID'] . '_' . $pieceJointeFournie['INTERVENANT_ID'] . '_' . $pieceJointeFournie['TYPE_PIECE_JOINTE_ID']; if (!array_key_exists($uuid, $this->tblData)) { $this->tblData[$uuid]['DEMANDEE'] = 0; $this->tblData[$uuid]['OBLIGATOIRE'] = 0; if (array_key_exists($uuid, $this->piecesJointes)) { $this->piecesJointes[$uuid]->pieceJointeId = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->piecesJointes[$uuid]->fournie = 1; $this->piecesJointes[$uuid]->dateOrigine = $pieceJointeFournie['ANNEE_ID']; $this->piecesJointes[$uuid]->validee = !empty($pieceJointeFournie['VALIDATION_ID']); $this->piecesJointes[$uuid]->dateValiditee = $pieceJointeFournie['DATE_VALIDITEE']; } $this->tblData[$uuid]['ANNEE_ID'] = $pieceJointeFournie['ANNEE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_ID'] = $pieceJointeFournie['TYPE_PIECE_JOINTE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_CODE'] = $pieceJointeFournie['TYPE_PJ_CODE']; $this->tblData[$uuid]['PIECE_JOINTE_ID'] = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->tblData[$uuid]['INTERVENANT_ID'] = $pieceJointeFournie['INTERVENANT_ID']; $this->tblData[$uuid]['FOURNIE'] = 1; $this->tblData[$uuid]['DATE_ORIGINE'] = $pieceJointeFournie['ANNEE_ID']; $this->tblData[$uuid]['VALIDEE'] = (!empty($pieceJointeFournie['VALIDATION_ID']))?1:0; $this->tblData[$uuid]['DATE_VALIDITEE'] = $pieceJointeFournie['DATE_VALIDITEE']; $this->tblData[$uuid]['SEUIL_HETD'] = $pieceJointeFournie['SEUIL_HETD']; $this->tblData[$uuid]['DEMANDEE_APRES_RECRUTEMENT'] = $pieceJointeFournie['DEMANDEE_APRES_RECRUTEMENT']; $this->sortDatas($this->tblData[$uuid]); } } } //Ensuite on cherche les pièces jointes fournies sur une potentielle année postérieure (durée de vie) foreach ($this->piecesJointesDemandees as $pieceJointeDemandee) { $piecesJointesFournies = $this->extractPiecesJointesFournies($pieceJointeDemandee['CODE_INTERVENANT'], $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']); $codeIntervenant = $pieceJointeDemandee['CODE_INTERVENANT']; $typePieceJointeId = $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $uuid = $pieceJointeDemandee['ANNEE_ID'] . '_' . $pieceJointeDemandee['INTERVENANT_ID'] . "_" . $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; //Piece jointe demandée déjà fournie donc on passe if ($this->tblData[$uuid]['DATE_ORIGINE'] == $this->tblData[$uuid]['ANNEE_ID']) { if ($this->piecesJointes[$uuid]->fournie == 1) { continue; } $piecesJointesFournies = $this->extractPiecesJointesFournies($codeIntervenant, $typePieceJointeId); //J'ai des pieces fournies antérieurement if (!empty($piecesJointesFournies)) { foreach ($piecesJointesFournies as $pieceJointeFournie) { //L'année de la pièce jointe fournie est postérieur à l'année de la pièce jointe demandée if ((int)$pieceJointeDemandee['ANNEE_ID'] > (int)$pieceJointeFournie['ANNEE_ID']) { if (//0 - c'est le même type de piece jointe $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID'] == $pieceJointeFournie['TYPE_PIECE_JOINTE_ID'] && //1 - Si la pièce jointe est validée !empty($pieceJointeFournie['VALIDATION_ID']) && //2 -Si la date de validité de la pièce jointe est strictement supérieure à l'année où elle est demandée if (//1 -Si la date de validité de la pièce jointe est strictement supérieure à l'année où elle est demandée (int)$pieceJointeFournie['DATE_VALIDITEE'] > (int)$pieceJointeDemandee['ANNEE_ID'] && //3 - Si l'année de la pièce fournie est strictement supérieure au maximum de l'ancienneté //de la pièce possible par rapport à la durée de vie paramétrée sur l'année où elle est demandée //2 - L'année de la pièce jointe fournie correspond au critère de durée de vie de la pièce jointe demandée (int)$pieceJointeFournie['ANNEE_ID'] > round((int)$pieceJointeDemandee['ANNEE_ID'] - (int)$pieceJointeDemandee['DUREE_VIE']) && //4 - Si la date d'archive de la pièce fournie est strictement supérieure à l'année où elle est demandée //3 - Si la date d'archive de la pièce fournie est strictement supérieure à l'année où elle est demandée ((int)$pieceJointeFournie['DATE_ARCHIVE'] > (int)$pieceJointeDemandee['ANNEE_ID'] || empty($pieceJointeFournie['DATE_ARCHIVE']))) { $this->tblData[$uuid]['PIECE_JOINTE_ID'] = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->tblData[$uuid]['DATE_ORIGINE'] = $pieceJointeFournie['ANNEE_ID']; $this->tblData[$uuid]['DATE_VALIDITEE'] = $pieceJointeFournie['DATE_VALIDITEE']; $this->tblData[$uuid]['FOURNIE'] = 1; $this->tblData[$uuid]['VALIDEE'] = 1; $this->piecesJointes[$uuid]->pieceJointeId = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->piecesJointes[$uuid]->dateOrigine = $pieceJointeFournie['ANNEE_ID']; $this->piecesJointes[$uuid]->dateValiditee = $pieceJointeFournie['DATE_VALIDITEE']; $this->piecesJointes[$uuid]->fournie = 1; $this->piecesJointes[$uuid]->validee = !empty($pieceJointeFournie['VALIDATION_ID']); } } Loading @@ -215,9 +200,30 @@ class PieceJointeProcess implements ProcessInterface } } $this->sortDatas($this->tblData[$uuid]); ksort($this->piecesJointes); } ksort($this->tblData); public function exporterPiecesJointes(array $params): void { foreach ($this->piecesJointes as $uuid => $piecesJointe) { $this->tblData[] = [ 'ANNEE_ID' => $piecesJointe->annee, 'TYPE_PIECE_JOINTE_ID' => $piecesJointe->typePieceJointeId, 'PIECE_JOINTE_ID' => $piecesJointe->pieceJointeId, 'INTERVENANT_ID' => $piecesJointe->intervenantId, 'DEMANDEE' => $piecesJointe->demandee, 'FOURNIE' => $piecesJointe->fournie, 'VALIDEE' => $piecesJointe->validee, 'OBLIGATOIRE' => $piecesJointe->obligatoire, 'DATE_ORIGINE' => $piecesJointe->dateOrigine, 'DATE_VALIDITEE' => $piecesJointe->dateValiditee, 'SEUIL_HETD' => $piecesJointe->seuilHetd, 'DEMANDEE_APRES_RECRUTEMENT' => $piecesJointe->demandeApresRecrutement, ]; } } Loading @@ -231,9 +237,6 @@ class PieceJointeProcess implements ProcessInterface $table = $this->getBdd()->getTable('TBL_PIECE_JOINTE'); //dd($this->tblData); $options = [ 'where' => $params, 'return-insert-data' => false, Loading @@ -242,34 +245,12 @@ class PieceJointeProcess implements ProcessInterface $tableauBord->onAction(Event::PROGRESS, $progress, $total); }, ]; try { $table->merge($this->tblData, $key, $options); } catch (\Exception $e) { dump($e->getMessage()); } $this->tblData = []; } private function sortDatas(array &$datas): void { uksort($datas, function ($a, $b) { $ordre = [ 'ANNEE_ID', 'TYPE_PIECE_JOINTE_ID', 'TYPE_PIECE_JOINTE_CODE', 'PIECE_JOINTE_ID', 'INTERVENANT_ID', 'DEMANDEE', 'FOURNIE', 'VALIDEE', 'OBLIGATOIRE', 'DATE_ORIGINE', 'DATE_VALIDITEE', 'SEUIL_HETD', 'DEMANDEE_APRES_RECRUTEMENT' ]; $posA = array_search($a, $ordre); $posB = array_search($b, $ordre); return $posA - $posB; }); } } Loading
code/QueryCompare.php +12 −4 Original line number Diff line number Diff line Loading @@ -5,11 +5,18 @@ * @var $container \Psr\Container\ContainerInterface */ $sql1 = "SELECT * FROM tbl_piece_jointe"; $sql1 = "SELECT tbj.* FROM tbl_piece_jointe tbj --where intervenant_id = 633563 --JOIN intervenant i ON i.id = tbj.intervenant_id --JOIN piece_jointe pj ON pj.id = tbj.piece_jointe_id"; $sql2 = "SELECT * FROM v_tbl_piece_jointe"; $sql2 = "SELECT tbjo.* FROM tbl_piece_jointe_old2 tbjo --where intervenant_id = 633563 -- JOIN intervenant i ON i.id = tbjo.intervenant_id --JOIN piece_jointe pj ON pj.id = tbjo.piece_jointe_id"; $keyCols = ['TYPE_PIECE_JOINTE_ID', 'INTERVENANT_ID']; $keyCols = ['TYPE_PIECE_JOINTE_ID', 'INTERVENANT_ID', 'ANNEE_ID']; //pays_nationalite => paysNationalite //date_creation => dateCreation Loading @@ -22,6 +29,7 @@ $ignoreCols = [ 'SEUIL_HETD', 'HEURES_POUR_SEUIL', 'ID', 'PIECE_JOINTE_ID' // colonne supprimée ]; Loading @@ -42,7 +50,7 @@ $comparator->setKeyColumns($keyCols); $comparator->setIgnoreColumns($ignoreCols); $comparator->setOnlyColumns($onlyCols); $comparator->setLimit(5000); $comparator->setLimit(100); $result = $comparator->run(); Loading
code/test7.php +5 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,10 @@ $stbl = $container->get(\UnicaenTbl\Service\TableauBordService::class); $data = ['INTERVENANT_ID' => 1000171]; $data = [//'INTERVENANT_ID' => '9290', 'INTERVENANT_ID' => 9290, //'ANNEE_ID' => 2015, ]; //$data = []; $stbl->calculer('piece_jointe', $data);
module/PieceJointe/src/Tbl/Process/Model/PieceJointe.php 0 → 100644 +22 −0 Original line number Diff line number Diff line <?php namespace PieceJointe\Tbl\Process\Model; class PieceJointe { public ?string $uuid = null; public ?int $annee = null; public ?int $typePieceJointeId = null; public ?int $pieceJointeId = null; public ?int $intervenantId = null; public bool $demandee = false; public bool $fournie = false; public bool $validee = false; public bool $obligatoire = false; public ?int $dateOrigine = null; public ?int $dateValiditee = null; public float $seuilHetd = 0; public bool $demandeApresRecrutement = false; }
module/PieceJointe/src/Tbl/Process/PieceJointeProcess.php +83 −102 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace PieceJointe\Tbl\Process; use Application\Service\Traits\AnneeServiceAwareTrait; use Intervenant\Service\IntervenantServiceAwareTrait; use PieceJointe\Tbl\Process\Model\PieceJointe; use Unicaen\BddAdmin\BddAwareTrait; use UnicaenTbl\Event; use UnicaenTbl\Process\ProcessInterface; Loading @@ -25,6 +26,8 @@ class PieceJointeProcess implements ProcessInterface protected array $piecesJointesDemandees = []; protected array $piecesJointesFournies = []; /** @var array|PieceJointe[][] */ private array $piecesJointes = []; protected array $tblData = []; Loading @@ -40,8 +43,8 @@ class PieceJointeProcess implements ProcessInterface { $this->getPiecesJointesDemandees($params); $this->getPiecesJointesFournies($params); //dd($this->piecesJointesDemandees, $this->piecesJointesFournies); $this->traitementPiecesJointes($params); $this->exporterPiecesJointes($params); $this->enregistrement($tableauBord, $params); } Loading Loading @@ -95,7 +98,6 @@ class PieceJointeProcess implements ProcessInterface return $this->piecesJointesFournies; } Loading @@ -112,6 +114,8 @@ class PieceJointeProcess implements ProcessInterface return $piecesJointesFournies; } protected function replaceIntervenantIdbyCodeIntervenantParam(array $params): array { if (isset($params['INTERVENANT_ID'])) { Loading @@ -132,82 +136,63 @@ class PieceJointeProcess implements ProcessInterface protected function traitementPiecesJointes(array $params): void { //On commence par traiter toutes les pièces jointes demandées foreach ($this->piecesJointesDemandees as $pieceJointeDemandee) { $uuid = $pieceJointeDemandee['ANNEE_ID'] . '_' . $pieceJointeDemandee['INTERVENANT_ID'] . '_' . $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $this->tblData[$uuid]['ANNEE_ID'] = $pieceJointeDemandee['ANNEE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_ID'] = $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_CODE'] = $pieceJointeDemandee['TYPE_PJ_CODE']; $this->tblData[$uuid]['PIECE_JOINTE_ID'] = null; $this->tblData[$uuid]['INTERVENANT_ID'] = $pieceJointeDemandee['INTERVENANT_ID']; $this->tblData[$uuid]['FOURNIE'] = 0; $this->tblData[$uuid]['DEMANDEE'] = 1; $this->tblData[$uuid]['VALIDEE'] = 0; $this->tblData[$uuid]['DATE_ORIGINE'] = null; $this->tblData[$uuid]['DATE_VALIDITEE'] = null; $this->tblData[$uuid]['SEUIL_HETD'] = $pieceJointeDemandee['SEUIL_HETD']; $this->tblData[$uuid]['OBLIGATOIRE'] = $pieceJointeDemandee['OBLIGATOIRE']; $this->tblData[$uuid]['DEMANDEE_APRES_RECRUTEMENT'] = $pieceJointeDemandee['DEMANDEE_APRES_RECRUTEMENT']; $this->sortDatas($this->tblData[$uuid]); $pieceJointe = new PieceJointe(); $pieceJointe->uuid = $uuid; $pieceJointe->annee = $pieceJointeDemandee['ANNEE_ID']; $pieceJointe->typePieceJointeId = $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $pieceJointe->intervenantId = $pieceJointeDemandee['INTERVENANT_ID']; $pieceJointe->demandee = true; $pieceJointeFournie = false; $pieceJointe->seuilHetd = $pieceJointeDemandee['SEUIL_HETD']; $pieceJointe->obligatoire = $pieceJointeDemandee['OBLIGATOIRE']; $pieceJointe->demandeApresRecrutement = $pieceJointeDemandee['DEMANDEE_APRES_RECRUTEMENT']; $this->piecesJointes[$uuid] = $pieceJointe; } //On parcourt maintenant les pièces jointes fournies qui sont forcément fournies l'année de leurs dépot //On parcourt maintenant les pièces jointes fournies pour voir si elles ont été fourni sur l'année demandée foreach ($this->piecesJointesFournies as $codeIntervenant => $datas) { foreach ($datas as $typePieceJointeId => $piecesJointesFournies) { foreach ($piecesJointesFournies as $pieceJointeFournie) { $uuid = $pieceJointeFournie['ANNEE_ID'] . '_' . $pieceJointeFournie['INTERVENANT_ID'] . '_' . $pieceJointeFournie['TYPE_PIECE_JOINTE_ID']; if (!array_key_exists($uuid, $this->tblData)) { $this->tblData[$uuid]['DEMANDEE'] = 0; $this->tblData[$uuid]['OBLIGATOIRE'] = 0; if (array_key_exists($uuid, $this->piecesJointes)) { $this->piecesJointes[$uuid]->pieceJointeId = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->piecesJointes[$uuid]->fournie = 1; $this->piecesJointes[$uuid]->dateOrigine = $pieceJointeFournie['ANNEE_ID']; $this->piecesJointes[$uuid]->validee = !empty($pieceJointeFournie['VALIDATION_ID']); $this->piecesJointes[$uuid]->dateValiditee = $pieceJointeFournie['DATE_VALIDITEE']; } $this->tblData[$uuid]['ANNEE_ID'] = $pieceJointeFournie['ANNEE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_ID'] = $pieceJointeFournie['TYPE_PIECE_JOINTE_ID']; $this->tblData[$uuid]['TYPE_PIECE_JOINTE_CODE'] = $pieceJointeFournie['TYPE_PJ_CODE']; $this->tblData[$uuid]['PIECE_JOINTE_ID'] = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->tblData[$uuid]['INTERVENANT_ID'] = $pieceJointeFournie['INTERVENANT_ID']; $this->tblData[$uuid]['FOURNIE'] = 1; $this->tblData[$uuid]['DATE_ORIGINE'] = $pieceJointeFournie['ANNEE_ID']; $this->tblData[$uuid]['VALIDEE'] = (!empty($pieceJointeFournie['VALIDATION_ID']))?1:0; $this->tblData[$uuid]['DATE_VALIDITEE'] = $pieceJointeFournie['DATE_VALIDITEE']; $this->tblData[$uuid]['SEUIL_HETD'] = $pieceJointeFournie['SEUIL_HETD']; $this->tblData[$uuid]['DEMANDEE_APRES_RECRUTEMENT'] = $pieceJointeFournie['DEMANDEE_APRES_RECRUTEMENT']; $this->sortDatas($this->tblData[$uuid]); } } } //Ensuite on cherche les pièces jointes fournies sur une potentielle année postérieure (durée de vie) foreach ($this->piecesJointesDemandees as $pieceJointeDemandee) { $piecesJointesFournies = $this->extractPiecesJointesFournies($pieceJointeDemandee['CODE_INTERVENANT'], $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']); $codeIntervenant = $pieceJointeDemandee['CODE_INTERVENANT']; $typePieceJointeId = $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; $uuid = $pieceJointeDemandee['ANNEE_ID'] . '_' . $pieceJointeDemandee['INTERVENANT_ID'] . "_" . $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID']; //Piece jointe demandée déjà fournie donc on passe if ($this->tblData[$uuid]['DATE_ORIGINE'] == $this->tblData[$uuid]['ANNEE_ID']) { if ($this->piecesJointes[$uuid]->fournie == 1) { continue; } $piecesJointesFournies = $this->extractPiecesJointesFournies($codeIntervenant, $typePieceJointeId); //J'ai des pieces fournies antérieurement if (!empty($piecesJointesFournies)) { foreach ($piecesJointesFournies as $pieceJointeFournie) { //L'année de la pièce jointe fournie est postérieur à l'année de la pièce jointe demandée if ((int)$pieceJointeDemandee['ANNEE_ID'] > (int)$pieceJointeFournie['ANNEE_ID']) { if (//0 - c'est le même type de piece jointe $pieceJointeDemandee['TYPE_PIECE_JOINTE_ID'] == $pieceJointeFournie['TYPE_PIECE_JOINTE_ID'] && //1 - Si la pièce jointe est validée !empty($pieceJointeFournie['VALIDATION_ID']) && //2 -Si la date de validité de la pièce jointe est strictement supérieure à l'année où elle est demandée if (//1 -Si la date de validité de la pièce jointe est strictement supérieure à l'année où elle est demandée (int)$pieceJointeFournie['DATE_VALIDITEE'] > (int)$pieceJointeDemandee['ANNEE_ID'] && //3 - Si l'année de la pièce fournie est strictement supérieure au maximum de l'ancienneté //de la pièce possible par rapport à la durée de vie paramétrée sur l'année où elle est demandée //2 - L'année de la pièce jointe fournie correspond au critère de durée de vie de la pièce jointe demandée (int)$pieceJointeFournie['ANNEE_ID'] > round((int)$pieceJointeDemandee['ANNEE_ID'] - (int)$pieceJointeDemandee['DUREE_VIE']) && //4 - Si la date d'archive de la pièce fournie est strictement supérieure à l'année où elle est demandée //3 - Si la date d'archive de la pièce fournie est strictement supérieure à l'année où elle est demandée ((int)$pieceJointeFournie['DATE_ARCHIVE'] > (int)$pieceJointeDemandee['ANNEE_ID'] || empty($pieceJointeFournie['DATE_ARCHIVE']))) { $this->tblData[$uuid]['PIECE_JOINTE_ID'] = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->tblData[$uuid]['DATE_ORIGINE'] = $pieceJointeFournie['ANNEE_ID']; $this->tblData[$uuid]['DATE_VALIDITEE'] = $pieceJointeFournie['DATE_VALIDITEE']; $this->tblData[$uuid]['FOURNIE'] = 1; $this->tblData[$uuid]['VALIDEE'] = 1; $this->piecesJointes[$uuid]->pieceJointeId = $pieceJointeFournie['PIECE_JOINTE_ID']; $this->piecesJointes[$uuid]->dateOrigine = $pieceJointeFournie['ANNEE_ID']; $this->piecesJointes[$uuid]->dateValiditee = $pieceJointeFournie['DATE_VALIDITEE']; $this->piecesJointes[$uuid]->fournie = 1; $this->piecesJointes[$uuid]->validee = !empty($pieceJointeFournie['VALIDATION_ID']); } } Loading @@ -215,9 +200,30 @@ class PieceJointeProcess implements ProcessInterface } } $this->sortDatas($this->tblData[$uuid]); ksort($this->piecesJointes); } ksort($this->tblData); public function exporterPiecesJointes(array $params): void { foreach ($this->piecesJointes as $uuid => $piecesJointe) { $this->tblData[] = [ 'ANNEE_ID' => $piecesJointe->annee, 'TYPE_PIECE_JOINTE_ID' => $piecesJointe->typePieceJointeId, 'PIECE_JOINTE_ID' => $piecesJointe->pieceJointeId, 'INTERVENANT_ID' => $piecesJointe->intervenantId, 'DEMANDEE' => $piecesJointe->demandee, 'FOURNIE' => $piecesJointe->fournie, 'VALIDEE' => $piecesJointe->validee, 'OBLIGATOIRE' => $piecesJointe->obligatoire, 'DATE_ORIGINE' => $piecesJointe->dateOrigine, 'DATE_VALIDITEE' => $piecesJointe->dateValiditee, 'SEUIL_HETD' => $piecesJointe->seuilHetd, 'DEMANDEE_APRES_RECRUTEMENT' => $piecesJointe->demandeApresRecrutement, ]; } } Loading @@ -231,9 +237,6 @@ class PieceJointeProcess implements ProcessInterface $table = $this->getBdd()->getTable('TBL_PIECE_JOINTE'); //dd($this->tblData); $options = [ 'where' => $params, 'return-insert-data' => false, Loading @@ -242,34 +245,12 @@ class PieceJointeProcess implements ProcessInterface $tableauBord->onAction(Event::PROGRESS, $progress, $total); }, ]; try { $table->merge($this->tblData, $key, $options); } catch (\Exception $e) { dump($e->getMessage()); } $this->tblData = []; } private function sortDatas(array &$datas): void { uksort($datas, function ($a, $b) { $ordre = [ 'ANNEE_ID', 'TYPE_PIECE_JOINTE_ID', 'TYPE_PIECE_JOINTE_CODE', 'PIECE_JOINTE_ID', 'INTERVENANT_ID', 'DEMANDEE', 'FOURNIE', 'VALIDEE', 'OBLIGATOIRE', 'DATE_ORIGINE', 'DATE_VALIDITEE', 'SEUIL_HETD', 'DEMANDEE_APRES_RECRUTEMENT' ]; $posA = array_search($a, $ordre); $posB = array_search($b, $ordre); return $posA - $posB; }); } }