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

CRUD administration employeur et adaptation update-employeur avec ajout d'une...

CRUD administration employeur et adaptation update-employeur avec ajout d'une nouvelle source INSEE.
parent 288e3af9
Loading
Loading
Loading
Loading
+19 −5
Changes for admin/actions/update-employeur.php: 19 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -37,6 +37,19 @@ $phar->extractTo($importDirectory);
exec('cd ' . $importDirectory . ' && tar -xvf ' . $importFilePath);
//Verification si des SIRET sont déjà chargé en base
$bdd = $oa->getBdd();

//On vérifie si la source INSEE existe dans OSE

$haveAlreadyInseeSource = $bdd->select("SELECT * FROM source WHERE code='INSEE'", [], ['fetch' => $bdd::FETCH_ONE]);
if (!($haveAlreadyInseeSource)) {
    $idSource = $bdd->sequenceNextVal('SOURCE_ID_SEQ');
    $bdd->exec("INSERT INTO source (id, code, libelle, importable) VALUES ($idSource, 'INSEE', 'INSEE', 1)");
    //Le source INSEE n'existe pas encore, donc on migre tout ce qui est source OSE vers source INSEE
    $bdd->exec("UPDATE employeur SET source_id = $idSource");
} else {
    $idSource = $haveAlreadyInseeSource['ID'];
}

//$haveAlreadySiret     = $bdd->select("SELECT siret FROM employeur e WHERE siret IS NOT null FETCH FIRST 5 ROWS ONLY", [], ['fetch' => $bdd::FETCH_ONE]);
$haveAlreadySiret = $bdd->select("SELECT siret FROM (SELECT siret, rownum AS rn FROM employeur e WHERE siret IS NOT NULL) e WHERE e.rn < 10", [], ['fetch' => $bdd::FETCH_ONE]);
$haveAlreadyEmployeur = $bdd->select("SELECT * FROM employeur e");
@@ -124,7 +137,7 @@ foreach ($listFiles as $file) {
        $data['RAISON_SOCIALE'] = $raisonSociale;
        $data['NOM_COMMERCIAL'] = $nomCommercial;
        $data['SOURCE_CODE'] = $siret;
        $data['SOURCE_ID'] = $oseSource;
        $data['SOURCE_ID'] = $idSource;
        $data['IDENTIFIANT_ASSOCIATION'] = $identifiantAssociation;
        $data['HISTO_DESTRUCTEUR_ID'] = null;
        $data['HISTO_DESTRUCTION'] = null;
@@ -132,8 +145,8 @@ foreach ($listFiles as $file) {
        $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\') AND SIREN NOT IN (\'999999999\', \'000000000000\')';
        $options['soft-delete'] = true;
        $options['where'] = 'SIREN LIKE \'' . $num . '%\' AND SOURCE_ID = (SELECT id FROM source WHERE code = \'INSEE\') AND SIREN NOT IN (\'999999999\', \'000000000000\')';
        $options['delete'] = false;
    }

    $i++;
@@ -144,13 +157,14 @@ foreach ($listFiles as $file) {
        $tableEmployeur->merge($datas, 'SIRET', $options);
    }
}

//On remet l'insertion de l'employeur étrangé
$data = [];
$data['SIREN'] = '999999999';
$data['RAISON_SOCIALE'] = 'EMPLOYEUR ETRANGÉ';
$data['NOM_COMMERCIAL'] = 'EMPLOYEUR ETRANGÉ';
$data['SOURCE_CODE'] = '999999999';
$data['SOURCE_ID'] = $oseSource;
$data['SOURCE_ID'] = $idSource;
$data['IDENTIFIANT_ASSOCIATION'] = null;
$data['HISTO_DESTRUCTEUR_ID'] = null;
$data['HISTO_DESTRUCTION'] = null;
@@ -168,7 +182,7 @@ $data['SIREN'] = '000000000000';
$data['RAISON_SOCIALE'] = 'Employeur non présent dans la liste';
$data['NOM_COMMERCIAL'] = 'Employeur non présent dans la liste';
$data['SOURCE_CODE'] = '000000000000';
$data['SOURCE_ID'] = $oseSource;
$data['SOURCE_ID'] = $idSource;
$data['IDENTIFIANT_ASSOCIATION'] = null;
$data['HISTO_DESTRUCTEUR_ID'] = null;
$data['HISTO_DESTRUCTION'] = null;
+29 −1
Changes for module/Application/config/employeur.config.php: 29 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -20,6 +20,34 @@ return [
                    ],
                ],
                'may_terminate' => true,
                'child_routes'  => [
                    'saisie'    => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/saisie[/:employeur]',
                            'constraints' => [
                                'employeur' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'saisie',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'supprimer' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/supprimer/:employeur',
                            'constraints' => [
                                'employeur' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'supprimer',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                ],
            ],
            'employeur-search' => [
                'type'          => 'Literal',
@@ -103,7 +131,7 @@ return [
            PrivilegeController::class      => [
                [
                    'controller' => 'Application\Controller\Employeur',
                    'action'     => ['index', 'recherche-json'],
                    'action'     => ['index', 'recherche-json', 'saisie'],
                    'privileges' => Privileges::REFERENTIEL_COMMUN_EMPLOYEUR_VISUALISATION,
                ],
            ],
+36 −1
Changes for module/Application/src/Controller/EmployeurController.php: 36 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Application\Controller;


use Application\Entity\Db\Employeur;
use Application\Form\Employeur\Traits\EmployeurSaisieFormAwareTrait;
use Application\Service\Traits\EmployeurServiceAwareTrait;
use Laminas\View\Model\JsonModel;

@@ -15,6 +17,7 @@ class EmployeurController extends AbstractController
{

    use EmployeurServiceAwareTrait;
    use EmployeurSaisieFormAwareTrait;

    public function indexAction()
    {
@@ -25,6 +28,39 @@ class EmployeurController extends AbstractController
        return compact('employeurs');
    }

    public function saisieAction()
    {
        $employeur = $this->getEvent()->getParam('employeur');

        if (empty($employeur)) {
            $title = "Ajout d'un nouvel employeur";
            $employeur = $this->getServiceEmployeur()->newEntity();
        } else {
            $title = "Édition d'un employeur";
        }

        $form = $this->getFormEmployeurSaisie();


        $form->bindRequestSave($employeur, $this->getRequest(), function () use ($employeur, $form) {
            /**
             * @var Employeur $employeur
             */
            $employeur->setCritereRecherche($employeur->getRaisonSociale() . ' ' . $employeur->getNomCommercial() . ' ' . $employeur->getSiret());
            $employeur->setSourceCode($employeur->getSiret());
            $this->getServiceEmployeur()->save($employeur);
            $this->flashMessenger()->addSuccessMessage(
                "Ajout réussi"
            );
        });

        return compact('form', 'title');
    }

    public function supprimerAction()
    {
        return true;
    }


    public function rechercheAction()
@@ -42,7 +78,6 @@ class EmployeurController extends AbstractController
    }



    public function rechercheJsonAction()
    {
        $critere = $this->params()->fromPost('critere');
+1 −0
Changes for module/Application/src/Controller/Factory/EmployeurControllerFactory.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ class EmployeurControllerFactory
     */
    public function __invoke(ContainerInterface $container, $requestedName, $options = null)
    {

        $controller = new EmployeurController();

        return $controller;
+35 −34
Changes for module/Application/src/Entity/Db/Employeur.php: 35 added lines, 34 removed lines.
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use UnicaenImport\Entity\Db\Interfaces\ImportAwareInterface;
use UnicaenImport\Entity\Db\Traits\ImportAwareTrait;

/**
 * Discipline
 * Employeur
 */
class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
{
@@ -23,28 +23,32 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
    /**
     * @var string
     */
    protected $raisonSociale;
    protected ?string $raisonSociale = null;

    /**
     * @var string
     */
    protected $nomCommercial;
    protected ?string $nomCommercial = null;

    /**
     * @var string
     */
    protected $identifiantAssociation;
    protected ?string $identifiantAssociation = null;

    /**
     * @var string
     */
    protected $siren;
    protected ?string $siren = null;

    /**
     * @var string
     */
    protected $siret;
    protected ?string $siret = null;

    /**
     * @var string
     */
    protected ?string $critereRecherche = null;


    /**
@@ -58,116 +62,113 @@ class Employeur implements HistoriqueAwareInterface, ImportAwareInterface
    }



    /**
     * @return string
     */
    public function getRaisonSociale()
    public function getRaisonSociale(): ?string
    {
        return $this->raisonSociale;
    }



    /**
     * @param string $raisonSociale
     */
    public function setRaisonSociale($raisonSociale)
    public function setRaisonSociale($raisonSociale): void
    {
        $this->raisonSociale = $raisonSociale;

        return $this;
    }



    /**
     * @return string
     */
    public function getSiren()
    public function getSiren(): ?string
    {
        return $this->siren;
    }



    /**
     * @param string $siren
     */
    public function setSiren($siren)
    public function setSiren($siren): void
    {
        $this->siren = $siren;

        return $this;
    }



    /**
     * @return string
     */
    public function getSiret()
    public function getSiret(): ?string
    {
        return $this->siret;
    }



    /**
     * @param string $siret
     */
    public function setSiret($siret)
    public function setSiret($siret): void
    {
        $this->siret = $siret;

        return $this;
    }



    /**
     * @return string
     */
    public function getNomCommercial()
    public function getNomCommercial(): ?string
    {
        return $this->nomCommercial;
    }



    /**
     * @param string $nomCommercial
     */
    public function setNomCommercial($nomCommercial)
    public function setNomCommercial($nomCommercial): void
    {
        $this->nomCommercial = $nomCommercial;

        return $this;
    }



    /**
     * @return string
     */
    public function getIdentifiantAssociation()
    public function getIdentifiantAssociation(): ?string
    {
        return $this->identifiantAssociation;
    }



    /**
     * @param string $identifiantAssociation
     */
    public function setIdentifiantAssociation($identifiantAssociation)
    public function setIdentifiantAssociation($identifiantAssociation): void
    {
        $this->identifiantAssociation = $identifiantAssociation;
    }

        return $this;
    /**
     * @return string
     */
    public function getCritereRecherche(): ?string
    {
        return $this->critereRecherche;
    }


    /**
     * @param string $critereRecherche
     */
    public function setCritereRecherche($critereRecherche): void
    {
        $this->critereRecherche = $critereRecherche;
    }


    public function __toString()
    {
Loading