diff --git a/src/Dto/SignalementExport.php b/src/Dto/SignalementExport.php index 3a86cd57d..daec5af49 100644 --- a/src/Dto/SignalementExport.php +++ b/src/Dto/SignalementExport.php @@ -51,6 +51,8 @@ public function __construct( public ?string $modifiedAt = null, public ?string $closedAt = null, public ?string $motifCloture = null, + public ?string $geoloc = null, + public ?string $interventionStatus = null, ) { } } diff --git a/src/Factory/SignalementExportFactory.php b/src/Factory/SignalementExportFactory.php index cad150092..d9d1d15c8 100644 --- a/src/Factory/SignalementExportFactory.php +++ b/src/Factory/SignalementExportFactory.php @@ -2,8 +2,11 @@ namespace App\Factory; +use App\Dto\SignalementAffectationListView; use App\Dto\SignalementExport; use App\Entity\Enum\MotifCloture; +use App\Entity\Enum\VisiteStatus; +use App\Entity\Intervention; use App\Entity\User; use App\Service\Signalement\SignalementAffectationHelper; @@ -35,6 +38,10 @@ public function createInstanceFrom(User $user, array $data): SignalementExport $motifCloture = $data['motifCloture'] instanceof MotifCloture ? $data['motifCloture']->label() : null; $status = SignalementAffectationHelper::getStatusLabelFrom($user, $data); + $geoloc = json_encode($data['geoloc']); + + $statusVisite = $this->getVisiteStatut($data['interventionsStatus']); + return new SignalementExport( reference: $data['reference'], createdAt: $createdAt, @@ -57,8 +64,8 @@ public function createInstanceFrom(User $user, array $data): SignalementExport situations: $data['familleSituation'] ?? null, desordres: $data['desordres'] ?? null, etiquettes: $data['etiquettes'] ?? null, - photos: empty($data['photos']) ? self::NON : self::OUI, - documents: empty($data['documents']) ? self::NON : self::OUI, + photos: $data['photosName'] ?? self::NON, + documents: $data['documentsName'] ?? self::NON, isProprioAverti: $this->mapData($data, 'isProprioAverti'), nbAdultes: $data['nbAdultes'], nbEnfantsM6: $data['nbEnfantsM6'] ?? self::NON_RENSEIGNE, @@ -74,12 +81,14 @@ public function createInstanceFrom(User $user, array $data): SignalementExport isNotOccupant: 1 == $data['isNotOccupant'] ? self::OUI : self::NON, nomDeclarant: $data['nomDeclarant'] ?? '-', structureDeclarant: $data['structureDeclarant'] ?? '-', - lienDeclarantOccupant: $data['lienDeclarantOccupant'], + lienDeclarantOccupant: $data['lienDeclarantOccupant'] ?? '-', dateVisite: $dateVisite, isOccupantPresentVisite: $isOccupantPresentVisite, modifiedAt: $modifiedAt, closedAt: $closedAt, - motifCloture: $motifCloture + motifCloture: $motifCloture, + geoloc: $geoloc, + interventionStatus: $statusVisite, ); } @@ -106,4 +115,32 @@ private function mapData(array $data, string $keyColumn): ?string return $value; } + + private function getVisiteStatut(?string $interventionStatus): string + { + if (null === $interventionStatus) { + $statusVisite = VisiteStatus::NON_PLANIFIEE->value; + } else { + $interventions = explode(SignalementAffectationListView::SEPARATOR_CONCAT, $interventionStatus); + foreach ($interventions as $intervention) { + $interventionExploded = explode(SignalementExport::SEPARATOR_GROUP_CONCAT, $intervention); + if (Intervention::STATUS_PLANNED === $interventionExploded[0]) { + $todayDatetime = new \DateTime(); + if ($interventionExploded[1] > $todayDatetime->format('Y-m-d')) { + $statusVisite = VisiteStatus::PLANIFIEE->value; + } else { + $statusVisite = VisiteStatus::CONCLUSION_A_RENSEIGNER->value; + } + } elseif (Intervention::STATUS_CANCELED === $interventionExploded[0]) { + $statusVisite = 'Annulée'; + } elseif (Intervention::STATUS_NOT_DONE === $interventionExploded[0]) { + $statusVisite = 'Non effectuée'; + } else { + $statusVisite = VisiteStatus::TERMINEE->value; + } + } + } + + return $statusVisite; + } } diff --git a/src/Repository/SignalementRepository.php b/src/Repository/SignalementRepository.php index 09788f400..9d5c6a418 100755 --- a/src/Repository/SignalementRepository.php +++ b/src/Repository/SignalementRepository.php @@ -450,13 +450,21 @@ public function findSignalementAffectationIterable(User|null $user, array $optio s.modifiedAt, s.closedAt, s.motifCloture, + s.geoloc, GROUP_CONCAT(DISTINCT situations.label SEPARATOR :group_concat_separator_1) as familleSituation, GROUP_CONCAT(DISTINCT criteres.label SEPARATOR :group_concat_separator_1) as desordres, - GROUP_CONCAT(DISTINCT tags.label SEPARATOR :group_concat_separator_1) as etiquettes + GROUP_CONCAT(DISTINCT tags.label SEPARATOR :group_concat_separator_1) as etiquettes, + GROUP_CONCAT(DISTINCT CONCAT(i.status, :group_concat_separator_1, i.scheduledAt) SEPARATOR :concat_separator) as interventionsStatus, + GROUP_CONCAT(DISTINCT photos.filename SEPARATOR :group_concat_separator_1) as photosName, + GROUP_CONCAT(DISTINCT documents.filename SEPARATOR :group_concat_separator_1) as documentsName ' )->leftJoin('s.situations', 'situations') ->leftJoin('s.criteres', 'criteres') ->leftJoin('s.tags', 'tags') + ->leftJoin('s.interventions', 'i', 'WITH', 'i.type LIKE \'VISITE\'') + ->leftJoin('s.files', 'photos', 'WITH', 'photos.fileType LIKE \'photo\'') + ->leftJoin('s.files', 'documents', 'WITH', 'documents.fileType LIKE \'document\'') + ->setParameter('concat_separator', SignalementAffectationListView::SEPARATOR_CONCAT) ->setParameter('group_concat_separator_1', SignalementExport::SEPARATOR_GROUP_CONCAT); // TODO : dateVisite, isOccupantPresentVisite ? return $qb->getQuery()->toIterable(); @@ -721,7 +729,8 @@ public function countByVisiteFiltered(StatisticsFilters $statisticsFilters): arr { $qb = $this->createQueryBuilder('s'); $qb->select('COUNT(s.id) as count') - ->addSelect('case + ->addSelect( + 'case when i.id IS NULL then \'Non\' else \'Oui\' end as visite' diff --git a/src/Service/Signalement/Export/SignalementExportHeader.php b/src/Service/Signalement/Export/SignalementExportHeader.php index 1d9aa5465..3ac90a121 100644 --- a/src/Service/Signalement/Export/SignalementExportHeader.php +++ b/src/Service/Signalement/Export/SignalementExportHeader.php @@ -12,15 +12,16 @@ public static function getHeaders(): array 'Référence', 'Déposé le', 'Statut', + 'Criticité au dépôt', 'Description', 'Nom', 'Prénom', 'Téléphone', - 'Téléphone', + 'Téléphone sec.', 'Email', 'Adresse', 'Code postal', - 'Commmune', + 'Commune', 'Code INSEE', 'Étage', 'Escalier', @@ -29,8 +30,8 @@ public static function getHeaders(): array 'Situations', 'Désordres', 'Étiquettes', -// 'Photos', -// 'Documents', + 'Photos', + 'Documents', 'Propriétaire averti', 'Nb adultes', 'Nb enfants -6 ans', @@ -47,13 +48,13 @@ public static function getHeaders(): array 'Nom tiers', 'Structure tiers', 'Lien tiers occupant', - 'Criticité au dépôt', 'Visité le', 'Occupant présent visite', 'Dernière MAJ le', 'Clôturé le', 'Motif de clôture', - 'Criticité à la clôture', + 'Géolocalisation', + 'Statut de la visite', ]; } } diff --git a/tests/Unit/Factory/SignalementExportFactoryTest.php b/tests/Unit/Factory/SignalementExportFactoryTest.php index 37af71299..40cd9734f 100644 --- a/tests/Unit/Factory/SignalementExportFactoryTest.php +++ b/tests/Unit/Factory/SignalementExportFactoryTest.php @@ -4,6 +4,7 @@ use App\Dto\SignalementExport; use App\Entity\Enum\MotifCloture; +use App\Entity\Enum\VisiteStatus; use App\Entity\User; use App\Factory\SignalementExportFactory; use App\Tests\UserHelper; @@ -68,6 +69,8 @@ public function testCreateSignalementExportFactory(): void 'desordres' => "Les sols sont humides.|Les installations électriques ne sont pas en bon état.| Les murs ont des fissures.|De l'eau s’infiltre dans mon logement.|Il y a des trace ", 'etiquettes' => null, + 'geoloc' => '{"lat": "43.3426152", "lng": "5.3711848"}', + 'interventionsStatus' => 'PLANNED|2023-07-13 13:41:15', ]; $user = $this->getUserFromRole(User::ROLE_ADMIN); @@ -104,5 +107,6 @@ public function testCreateSignalementExportFactory(): void $this->assertEquals(SignalementExportFactory::NON_RENSEIGNE, $signalementExportFactory->isRelogement); $this->assertEquals(SignalementExportFactory::NON, $signalementExportFactory->isNotOccupant); $this->assertEquals('-', $signalementExportFactory->isOccupantPresentVisite); + $this->assertEquals(VisiteStatus::CONCLUSION_A_RENSEIGNER->value, $signalementExportFactory->interventionStatus); } } diff --git a/tests/Unit/Service/Signalement/Export/SignalementExportLoaderTest.php b/tests/Unit/Service/Signalement/Export/SignalementExportLoaderTest.php index aa8ece121..7b13fc9ae 100644 --- a/tests/Unit/Service/Signalement/Export/SignalementExportLoaderTest.php +++ b/tests/Unit/Service/Signalement/Export/SignalementExportLoaderTest.php @@ -30,7 +30,7 @@ public function testLoad() ->with($user, $filters) ->willReturn($this->getSignalementExportGenerator($signalementExports)); - $expectedOutput = $this->getHeaderAsString()."2023-01;31-03-2023;nouveau;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n2023-02;31-03-2023;nouveau;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n"; + $expectedOutput = $this->getHeaderAsString()."2023-01;31-03-2023;nouveau;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n2023-02;31-03-2023;nouveau;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n"; $loader = new SignalementExportLoader($signalementManager); ob_start();