Commit f8bbe0e2 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Ajout du SIRET dans la notion d'employeur (tâche #40810)

parent a3f1efc0
......@@ -8,7 +8,7 @@ $oseSource = $oa->getSourceOseId();
$oseId = $oa->getOseAppliId();
$c->println("Mise à jour de la table employeur");
ini_set('memory_limit', '1024M');
ini_set('memory_limit', '6144M');
$importDirectory = $osedir . 'cache/employeurs/';
$importArchive = 'employeurs.tar.gz';
$importFilePath = $importDirectory . $importArchive;
......@@ -28,8 +28,15 @@ if (count($listFiles) > 0) {
$c->printDie("Merci de supprimer les fichiers CSV présents dans le dossier $importDirectory");
}
//Extraction du PharData
$phar = new PharData($importFilePath);
$phar->extractTo($importDirectory);
//$phar = new PharData($importFilePath);
//$phar->extractTo($importDirectory);
exec('cd ' . $importDirectory . ' && tar -xvf ' . $importFilePath);
//Verification si des SIRET sont déjà chargé en base
$bdd = $oa->getBdd();
$haveAlreadySiret = $bdd->select("SELECT siret FROM employeur e WHERE siret IS NOT null FETCH FIRST 5 ROWS ONLY", [], ['fetch' => $bdd::FETCH_ONE]);
$haveAlreadyEmployeur = $bdd->select("SELECT * FROM employeur e");
//récupération de la liste des fichiers CSV
$listFiles = preg_grep('~\.(csv)$~', scandir($importDirectory));
$nbFiles = count($listFiles);
......@@ -48,7 +55,7 @@ foreach ($listFiles as $file) {
while (($data = fgetcsv($csvFile, 1000, ",")) !== false) {
/*
* $data[0] = Siret
* $data[0] = Siren
* $data[1] = Etat Administratif
* $data[2] = Nom unité légale (cas entreprise en nom propre)
* $data[3] = Nom usage unité légale
......@@ -59,13 +66,15 @@ foreach ($listFiles as $file) {
* $data[8] = Date de dernier traitement de l'unité légale
* $data[9] = Unité pouvant employer des personnes
* $data[10] = Identifiant association
* $data[12] = Siret
*
*/
if ($row == 0) {
$row++;
continue;
}
/* if ($row == 0) {
$row++;
continue;
}*/
//DENOMINATION_USUELLE
$nomCommercial = (!empty($data[5])) ? $data[5] : '';
$nomCommercial .= (!empty($data[6])) ? ' ' . $data[6] : '';
......@@ -75,6 +84,9 @@ foreach ($listFiles as $file) {
$nomJuridique = $data[4];
//SIREN
$siren = $data[0];
//SIRET
$siret = $data[0] . $data[12];
//IDENTIFIANT ASSOCIATION
$identifiantAssociation = $data[10];
//Nom propre entité
......@@ -98,22 +110,29 @@ foreach ($listFiles as $file) {
$data = [];
$options = [];
$data['SIREN'] = $siren;
$data['SIRET'] = $siret;
$data['RAISON_SOCIALE'] = $raisonSociale;
$data['NOM_COMMERCIAL'] = $nomCommercial;
$data['SOURCE_CODE'] = $siren;
$data['SOURCE_CODE'] = $siret;
$data['SOURCE_ID'] = $oseSource;
$data['IDENTIFIANT_ASSOCIATION'] = $identifiantAssociation;
$data['HISTO_DESTRUCTEUR_ID'] = null;
$data['HISTO_DESTRUCTION'] = null;
$data['IDENTIFIANT_ASSOCIATION'] = $identifiantAssociation;
$data['CRITERE_RECHERCHE'] = reduce($raisonSociale . ' ' . $nomCommercial . ' ' . $siren);
$data['CRITERE_RECHERCHE'] = reduce($raisonSociale . ' ' . $nomCommercial . ' ' . $siren . ' ' . $siret);
$datas[] = $data;
$options['histo-user-id'] = $oseId;
$options['where'] = 'SIREN LIKE \'' . $num . '%\' AND SOURCE_ID = (SELECT id FROM source WHERE code = \'OSE\')';
$options['soft-delete'] = true;
$options['where'] = 'SIREN LIKE \'' . $num . '%\' AND SOURCE_ID = (SELECT id FROM source WHERE code = \'OSE\') AND SIREN NOT IN (\'999999999\', \'000000000000\')';
$options['soft-delete'] = false;
}
$i++;
$tableEmployeur->merge($datas, 'SIREN', $options);
if (!$haveAlreadySiret) {
$c->println('Migration avec ajouts des SIRET des entreprises');
$tableEmployeur->merge($datas, 'SIRET', $options);
}
}
//On remet l'insertion de l'employeur étrangé
$data = [];
......@@ -127,7 +146,7 @@ $data['HISTO_DESTRUCTEUR_ID'] = null;
$data['HISTO_DESTRUCTION'] = null;
$data['IDENTIFIANT_ASSOCIATION'] = null;
$data['CRITERE_RECHERCHE'] = reduce('Employeur étrangé 999999999');
$options['histo-user-id'] = $oseId;
$options['histo - user - id'] = $oseId;
$options['where'] = 'SIREN = \'999999999\'';
$options['soft-delete'] = true;
$datas = [];
......@@ -156,6 +175,8 @@ $tableEmployeur->merge($datas, 'SIREN', $options);
exec('cd ' . $importDirectory . ' && rm -rf *.csv');
$c->println("Fin de mise à jour des données employeurs", $c::COLOR_LIGHT_GREEN);
unlink($importFilePath);
exec('rm -r ' . $importDirectory);
function reduce($str, $encoding = 'UTF-8')
{
......
......@@ -4,7 +4,7 @@
return [
'name' => 'EMPLOYEUR_SIREN_IDX',
'unique' => TRUE,
'unique' => FALSE,
'table' => 'EMPLOYEUR',
'columns' => [
'SIREN',
......
<?php
//@formatter:off
return [
'name' => 'EMPLOYEUR_SIRET_IDX',
'unique' => TRUE,
'table' => 'EMPLOYEUR',
'columns' => [
'SIRET',
],
];
//@formatter:on
......@@ -153,6 +153,18 @@ return [
'position' => 2,
'commentaire' => NULL,
],
'SIRET' => [
'name' => 'SIRET',
'type' => 'string',
'bdd-type' => 'VARCHAR2',
'length' => 100,
'scale' => NULL,
'precision' => NULL,
'nullable' => TRUE,
'default' => NULL,
'position' => 2,
'commentaire' => NULL,
],
'SOURCE_CODE' => [
'name' => 'SOURCE_CODE',
'type' => 'string',
......
......@@ -40,6 +40,12 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
*/
protected $siren;
/**
* @var string
*/
protected $siret;
/**
* Get id
......@@ -51,6 +57,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this->id;
}
/**
* @return string
*/
......@@ -59,6 +67,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this->raisonSociale;
}
/**
* @param string $raisonSociale
*/
......@@ -69,6 +79,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this;
}
/**
* @return string
*/
......@@ -77,6 +89,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this->siren;
}
/**
* @param string $siren
*/
......@@ -87,6 +101,30 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this;
}
/**
* @return string
*/
public function getSiret()
{
return $this->siret;
}
/**
* @param string $siret
*/
public function setSiret($siret)
{
$this->siret = $siret;
return $this;
}
/**
* @return string
*/
......@@ -95,6 +133,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this->nomCommercial;
}
/**
* @param string $nomCommercial
*/
......@@ -105,6 +145,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this;
}
/**
* @return string
*/
......@@ -113,6 +155,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this->identifiantAssociation;
}
/**
* @param string $identifiantAssociation
*/
......@@ -123,6 +167,8 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
return $this;
}
public function __toString()
{
return $this->getLibelle();
......
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\Db\Employeur" table="EMPLOYEUR">
<id name="id" type="integer" column="ID">
<generator strategy="SEQUENCE"/>
</id>
<field name="raisonSociale" type="string" column="RAISON_SOCIALE" length="250" nullable="false"/>
<field name="nomCommercial" type="string" column="NOM_COMMERCIAL" length="250" nullable="false"/>
<field name="siren" type="string" column="SIREN" length="250" nullable="false"/>
<field name="identifiantAssociation" type="string" column="IDENTIFIANT_ASSOCIATION" length="250" nullable="false"/>
<many-to-one field="source" target-entity="UnicaenImport\Entity\Db\Source">
<join-columns>
<join-column name="SOURCE_ID" referenced-column-name="ID"/>
</join-columns>
</many-to-one>
<field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="false"/>
<field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
<many-to-one field="histoCreateur" target-entity="Application\Entity\Db\Utilisateur">
<join-column name="HISTO_CREATEUR_ID" referenced-column-name="ID"/>
</many-to-one>
<field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/>
<many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur">
<join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/>
</many-to-one>
<field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
<many-to-one field="histoDestructeur" target-entity="Application\Entity\Db\Utilisateur">
<join-column name="HISTO_DESTRUCTEUR_ID" referenced-column-name="ID"/>
</many-to-one>
</entity>
<entity name="Application\Entity\Db\Employeur" table="EMPLOYEUR">
<id name="id" type="integer" column="ID">
<generator strategy="SEQUENCE"/>
</id>
<field name="raisonSociale" type="string" column="RAISON_SOCIALE" length="250" nullable="false"/>
<field name="nomCommercial" type="string" column="NOM_COMMERCIAL" length="250" nullable="false"/>
<field name="siren" type="string" column="SIREN" length="250" nullable="false"/>
<field name="siret" type="string" column="SIRET" length="250" nullable="true"/>
<field name="identifiantAssociation" type="string" column="IDENTIFIANT_ASSOCIATION" length="250" nullable="false"/>
<many-to-one field="source" target-entity="UnicaenImport\Entity\Db\Source">
<join-columns>
<join-column name="SOURCE_ID" referenced-column-name="ID"/>
</join-columns>
</many-to-one>
<field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="false"/>
<field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
<many-to-one field="histoCreateur" target-entity="Application\Entity\Db\Utilisateur">
<join-column name="HISTO_CREATEUR_ID" referenced-column-name="ID"/>
</many-to-one>
<field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/>
<many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur">
<join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/>
</many-to-one>
<field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
<many-to-one field="histoDestructeur" target-entity="Application\Entity\Db\Utilisateur">
<join-column name="HISTO_DESTRUCTEUR_ID" referenced-column-name="ID"/>
</many-to-one>
</entity>
</doctrine-mapping>
......@@ -88,11 +88,12 @@ class EmployeurService extends AbstractEntityService
$stmt = $this->getEntityManager()->getConnection()->executeQuery($sql);
while ($r = $stmt->fetch()) {
$siren = $r['SIREN'];
$siret = $r['SIRET'];
$employeurs[$r['ID']] = [
'id' => $r['ID'],
'label' => $r['RAISON_SOCIALE'],
'siren' => $siren,
'extra' => "<small>($siren)</small>",
'siret' => $siret,
'extra' => "<small>($siret)</small>",
];
}
......
......@@ -39,7 +39,7 @@ $dossierInsee = $form->get('DossierEmployeur');
<?php endif; ?>
</div>
<div class="panel-body">
<div class="well" role="alert">Saissisez les premières lettres de votre employeur ou directement le N° de SIREN.
<div class="well" role="alert">Saissisez les premières lettres de votre employeur ou directement le N° de SIRET.
</div>
<?= $this->formControlGroup($dossierInsee->get('employeur')); ?>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment