Skip to content

Commit

Permalink
Merge pull request #1849 from MTES-MCT/bugfix/1782-export-add-infos
Browse files Browse the repository at this point in the history
[BO Signalement] Export, corrections et nouvelles données
  • Loading branch information
sfinx13 authored Oct 26, 2023
2 parents 50d5931 + a012409 commit af4d770
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Dto/SignalementExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
}
45 changes: 41 additions & 4 deletions src/Factory/SignalementExportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
);
}

Expand All @@ -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;
}
}
13 changes: 11 additions & 2 deletions src/Repository/SignalementRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'
Expand Down
13 changes: 7 additions & 6 deletions src/Service/Signalement/Export/SignalementExportHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
];
}
}
4 changes: 4 additions & 0 deletions tests/Unit/Factory/SignalementExportFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit af4d770

Please sign in to comment.