Commit 149a3abd authored by tguillon's avatar tguillon
Browse files

Correction titre de l'onglet co-responsable.

Correction de la suppression d'un responsable, car cela supprime l'entité
Correction de l'erreur lorsqu'on affecter un responsable ou un sous-traitant sans choisir d'entité
parent d57322b6
......@@ -86,7 +86,7 @@ CREATE TABLE organisations (
numerocil VARCHAR(50) DEFAULT NULL,
verrouiller BOOLEAN NOT NULL DEFAULT TRUE,
force INTEGER NOT NULL DEFAULT 4,
responsable_id INTEGER REFERENCES responsables(id) ON DELETE CASCADE ON UPDATE CASCADE,
responsable_id INTEGER REFERENCES responsables(id) ON DELETE SET NULL,
created timestamp without time zone NOT NULL,
modified timestamp without time zone NOT NULL
);
......
......@@ -66,7 +66,7 @@ ALTER TABLE responsables ADD CONSTRAINT responsables_emailstructure_email_chk CH
ALTER TABLE responsables ADD CONSTRAINT responsables_telephoneresponsable_phone_chk CHECK ( cakephp_validate_phone( telephoneresponsable, NULL, 'fr' ) );
ALTER TABLE responsables ADD CONSTRAINT responsables_emailresponsable_email_chk CHECK ( cakephp_validate_email( emailresponsable ) );
ALTER TABLE organisations ADD COLUMN responsable_id INTEGER REFERENCES responsables(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE organisations ADD COLUMN responsable_id INTEGER REFERENCES responsables(id) ON DELETE SET NULL;
--
-- Création de la table de jointure Responsables Organisations
......
......@@ -51,53 +51,55 @@ class ResponsablesController extends AppController {
if ($this->request->is('post')) {
// Affectation
if (isset($this->request->data['ResponsableOrganisation']) === true) {
$success = true;
$this->Organisation->begin();
$organisations_ids = Hash::extract($this->request->data, 'ResponsableOrganisation.organisation_id');
$responsables_ids = Hash::extract($this->request->data, 'ResponsableOrganisation.responsable_id');
foreach ($organisations_ids as $organisation_id) {
$responsableEntite = [];
$responsableEntite = $this->ResponsableOrganisation->find('list', [
'conditions' => [
'organisation_id' => $organisation_id
],
'fields' => [
'responsable_id'
]
]);
if (!empty($this->request->data['ResponsableOrganisation']['organisation_id'])) {
if (isset($this->request->data['ResponsableOrganisation']) === true) {
$success = true;
$this->Organisation->begin();
$diff = array_diff($responsableEntite, $responsables_ids);
$organisations_ids = Hash::extract($this->request->data, 'ResponsableOrganisation.organisation_id');
$responsables_ids = Hash::extract($this->request->data, 'ResponsableOrganisation.responsable_id');
foreach ($organisations_ids as $organisation_id) {
$responsableEntite = [];
$resultResponsable = [];
if (!empty($diff)) {
$resultResponsable = array_merge($responsables_ids, $responsableEntite);
} else {
$resultResponsable = $responsables_ids;
$responsableEntite = $this->ResponsableOrganisation->find('list', [
'conditions' => [
'organisation_id' => $organisation_id
],
'fields' => [
'responsable_id'
]
]);
$diff = array_diff($responsableEntite, $responsables_ids);
$resultResponsable = [];
if (!empty($diff)) {
$resultResponsable = array_merge($responsables_ids, $responsableEntite);
} else {
$resultResponsable = $responsables_ids;
}
$data = [
'Organisation' => [
'id' => $organisation_id,
],
'Responsable' => [
'Responsable' => $resultResponsable
]
];
$this->Organisation->create($data);
$success = $success && false !== $this->Organisation->save(null, ['atomic' => false]);
}
$data = [
'Organisation' => [
'id' => $organisation_id,
],
'Responsable' => [
'Responsable' => $resultResponsable
]
];
$this->Organisation->create($data);
$success = $success && false !== $this->Organisation->save(null, ['atomic' => false]);
}
if ($success == true) {
$this->Organisation->commit();
$this->Session->setFlash(__d('responsable', 'responsable.flashsuccessSousTraitantAffecterEnregistrer'), 'flashsuccess');
if ($success == true) {
$this->Organisation->commit();
$this->Session->setFlash(__d('responsable', 'responsable.flashsuccessSousTraitantAffecterEnregistrer'), 'flashsuccess');
$this->redirect(['action' => 'index']);
} else {
$this->Organisation->rollback();
$this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurEnregistrementSousTraitantAffecter'), 'flasherror');
$this->redirect(['action' => 'index']);
} else {
$this->Organisation->rollback();
$this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurEnregistrementSousTraitantAffecter'), 'flasherror');
}
}
}
......@@ -147,22 +149,22 @@ class ResponsablesController extends AppController {
$maxLimit = $limit;
}
}
} else {
$query = [
'contain' => [
'Organisation' => [
'raisonsociale',
'order' => ['raisonsociale']
]
],
'conditions' => $condition,
'order' => [
'Responsable.raisonsocialestructure ASC'
],
'limit' => $limit,
'maxLimit' => $maxLimit
];
}
}
$query = [
'contain' => [
'Organisation' => [
'raisonsociale',
'order' => ['raisonsociale']
]
],
'conditions' => $condition,
'order' => [
'Responsable.raisonsocialestructure ASC'
],
'limit' => $limit,
'maxLimit' => $maxLimit
];
$this->paginate = $query;
......@@ -478,9 +480,9 @@ class ResponsablesController extends AppController {
}
/**
* Permet la visualisation des informations d'un sous-traitant
* Permet la visualisation des informations d'un responsable
*
* @param type $id | Id du sous-traitant
* @param type $id | Id du responsable
*
* @author Théo GUILLON <theo.guillon@libriciel.coop>
* @access public
......@@ -523,9 +525,9 @@ class ResponsablesController extends AppController {
}
/**
* Permet de supprimer un sous-traitant
* Permet de supprimer un responsable
*
* @param type $id | Id du sous-traitant
* @param type $id | Id du responsable
*
* @author Théo GUILLON <theo.guillon@libriciel.coop>
* @access public
......
......@@ -51,53 +51,55 @@ class SoustraitantsController extends AppController {
if ($this->request->is('post')) {
// Affectation
if (isset($this->request->data['SoustraitantOrganisation']) === true) {
$success = true;
$this->Organisation->begin();
$organisations_ids = Hash::extract($this->request->data, 'SoustraitantOrganisation.organisation_id');
$soustraitants_ids = Hash::extract($this->request->data, 'SoustraitantOrganisation.soustraitant_id');
foreach ($organisations_ids as $organisation_id) {
$soustraitantEntite = [];
$soustraitantEntite = $this->SoustraitantOrganisation->find('list', [
'conditions' => [
'organisation_id' => $organisation_id
],
'fields' => [
'soustraitant_id'
]
]);
if (!empty($this->request->data['ResponsableOrganisation']['organisation_id'])) {
if (isset($this->request->data['SoustraitantOrganisation']) === true) {
$success = true;
$this->Organisation->begin();
$diff = array_diff($soustraitantEntite, $soustraitants_ids);
$organisations_ids = Hash::extract($this->request->data, 'SoustraitantOrganisation.organisation_id');
$soustraitants_ids = Hash::extract($this->request->data, 'SoustraitantOrganisation.soustraitant_id');
foreach ($organisations_ids as $organisation_id) {
$soustraitantEntite = [];
$resultSoustraitant = [];
if (!empty($diff)) {
$resultSoustraitant = array_merge($soustraitants_ids, $soustraitantEntite);
} else {
$resultSoustraitant = $soustraitants_ids;
}
$soustraitantEntite = $this->SoustraitantOrganisation->find('list', [
'conditions' => [
'organisation_id' => $organisation_id
],
'fields' => [
'soustraitant_id'
]
]);
$data = [
'Organisation' => [
'id' => $organisation_id,
],
'Soustraitant' => [
'Soustraitant' => $resultSoustraitant
]
];
$this->Organisation->create($data);
$success = $success && false !== $this->Organisation->save(null, ['atomic' => false]);
}
$diff = array_diff($soustraitantEntite, $soustraitants_ids);
if ($success == true) {
$this->Organisation->commit();
$this->Session->setFlash(__d('soustraitant', 'soustraitant.flashsuccessSousTraitantAffecterEnregistrer'), 'flashsuccess');
$resultSoustraitant = [];
if (!empty($diff)) {
$resultSoustraitant = array_merge($soustraitants_ids, $soustraitantEntite);
} else {
$resultSoustraitant = $soustraitants_ids;
}
$this->redirect(['action' => 'index']);
} else {
$this->Organisation->rollback();
$this->Session->setFlash(__d('soustraitant', 'soustraitant.flasherrorErreurEnregistrementSousTraitantAffecter'), 'flasherror');
$data = [
'Organisation' => [
'id' => $organisation_id,
],
'Soustraitant' => [
'Soustraitant' => $resultSoustraitant
]
];
$this->Organisation->create($data);
$success = $success && false !== $this->Organisation->save(null, ['atomic' => false]);
}
if ($success == true) {
$this->Organisation->commit();
$this->Session->setFlash(__d('soustraitant', 'soustraitant.flashsuccessSousTraitantAffecterEnregistrer'), 'flashsuccess');
$this->redirect(['action' => 'index']);
} else {
$this->Organisation->rollback();
$this->Session->setFlash(__d('soustraitant', 'soustraitant.flasherrorErreurEnregistrementSousTraitantAffecter'), 'flasherror');
}
}
}
......@@ -147,22 +149,22 @@ class SoustraitantsController extends AppController {
$maxLimit = $limit;
}
}
} else {
$query = [
'contain' => [
'Organisation' => [
'raisonsociale',
'order' => ['raisonsociale']
]
],
'conditions' => $condition,
'order' => [
'Soustraitant.raisonsociale ASC'
],
'limit' => $limit,
'maxLimit' => $maxLimit
];
}
}
$query = [
'contain' => [
'Organisation' => [
'raisonsociale',
'order' => ['raisonsociale']
]
],
'conditions' => $condition,
'order' => [
'Soustraitant.raisonsociale ASC'
],
'limit' => $limit,
'maxLimit' => $maxLimit
];
$this->paginate = $query;
......
......@@ -224,6 +224,9 @@ msgstr "Co-responsable ?"
msgid "fiche.ongletCoresponsable"
msgstr "Co-responsable"
msgid "fiche.textInfoConcernantCoresponsable"
msgstr "Information concernant la co-responsabilité :"
msgid "fiche.champCoresponsableid"
msgstr "Co-responsable"
......
......@@ -72,13 +72,19 @@
</a>
</li>
<li id="liOngletCoresponsable" class="disabled">
<a id="aOngletCoresponsable" href="#ongletCoresponsable" role="" data-toggle="">
<?php
echo __d('fiche', 'fiche.ongletCoresponsable');
<?php
if (!empty($responsables)) {
?>
</a>
</li>
<li id="liOngletCoresponsable" class="disabled">
<a id="aOngletCoresponsable" href="#ongletCoresponsable" role="" data-toggle="">
<?php
echo __d('fiche', 'fiche.ongletCoresponsable');
?>
</a>
</li>
<?php
}
?>
<li>
<a href="#infos" role="tab" data-toggle="tab">
......@@ -279,37 +285,43 @@
</div>
</div>
<!-- Co-responsabilité sur le traitement -->
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('fiche', 'fiche.textInfoCoresponsable');
<?php
if (!empty($responsables)) {
?>
</span>
<div class="row row35"></div>
</div>
<!-- Co-responsabilité sur le traitement -->
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('fiche', 'fiche.textInfoCoresponsable');
?>
</span>
<div class="row row35"></div>
</div>
<div class="row">
<!-- Colonne de gauche -->
<div class="col-md-6">
<div class="row">
<!-- Colonne de gauche -->
<div class="col-md-6">
<?php
echo $this->WebcilForm->inputs([
'coresponsable' => [
'id' => 'coresponsable',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'usersDeroulant transformSelect form-control',
'required' => true,
'empty' => false,
'data-placeholder' => ' ',
'default' => false
]
]);
?>
</div>
</div>
<?php
echo $this->WebcilForm->inputs([
'coresponsable' => [
'id' => 'coresponsable',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'usersDeroulant transformSelect form-control',
'required' => true,
'empty' => false,
'data-placeholder' => ' ',
'default' => false
]
]);
?>
</div>
</div>
}
?>
</div>
<!-- Fin onglet Information concernant le traitement-->
......@@ -642,162 +654,168 @@
</div>
<!-- Fin onglet Annexe(s) -->
<!-- Onglet Co-responsable -->
<div id="ongletCoresponsable" class="tab-pane">
<br/>
<!-- Information sur le rédacteur -->
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('fiche', 'fiche.textInfoSoustraitant');
?>
</span>
<div class="row row35"></div>
</div>
<?php
if (!empty($responsables)) {
?>
<!-- Onglet Co-responsable -->
<div id="ongletCoresponsable" class="tab-pane">
<br/>
<!-- Champs du formulaire -->
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('coresponsableid', [
'id' => 'coresponsableid',
'class' => 'form-control usersDeroulant',
'options' => Hash::combine($responsables, '{n}.Responsable.id', '{n}.Responsable.raisonsocialestructure'),
'empty' => true,
'multiple' => false,
'required' => true,
'data-placeholder' => __d('fiche', 'fiche.placeholderChampCoresponsable')
]);
<!-- Information sur le rédacteur -->
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('fiche', 'fiche.textInfoConcernantCoresponsable');
?>
</span>
<div class="row row35"></div>
</div>
?>
</div>
</div>
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('responsable', 'responsable.titreResponsable');
?>
</span>
<div class="row row35"></div>
</div>
<!-- Champs du formulaire -->
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('coresponsableid', [
'id' => 'coresponsableid',
'class' => 'form-control usersDeroulant',
'options' => Hash::combine($responsables, '{n}.Responsable.id', '{n}.Responsable.raisonsocialestructure'),
'empty' => true,
'multiple' => false,
'required' => true,
'data-placeholder' => __d('fiche', 'fiche.placeholderChampCoresponsable')
]);
<div class="row">
<!-- Colonne de gauche -->
<div class="col-md-6">
<?php
echo $this->WebcilForm->inputs([
'nomcoresponsable' => [
'id' => 'nomcoresponsable',
'required' => true,
'readonly' => true,
'placeholder' => false
],
'prenomcoresponsable' => [
'id' => 'prenomcoresponsable',
'required' => true,
'readonly' => true,
'placeholder' => false
],
'fonctioncoresponsable' => [
'id' => 'fonctioncoresponsable',
'required' => true,
'readonly' => true,
'placeholder' => false
]
]);
?>
</div>
?>
</div>
</div>
<!-- Colonne de droite -->
<div class="col-md-6">
<?php
echo $this->WebcilForm->inputs([
'emailcoresponsable' => [
'id' => 'emailcoresponsable',
'required' => true,
'readonly' => true,
'placeholder' => false
],
'telephonecoresponsable' => [
'id' => 'telephonecoresponsable',
'required' => true,
'readonly' => true,
'placeholder' => false
]
]);
?>
</div>
</div>
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('responsable', 'responsable.titreResponsable');
?>
</span>
<div class="row row35"></div>
</div>
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('responsable', 'responsable.titreStructureResponsable');
?>
</span>
<div class="row row35"></div>
</div>
<div class="row">
<!-- Colonne de gauche -->
<div class="col-md-6">
<?php
echo $this->WebcilForm->inputs([
'raisonsocialestructure' => [
'id' => 'raisonsocialestructure',
'required' => true,
'readonly' => true,
'placeholder' => false
],
'siretstructure' => [
'id' => 'siretstructure',
'required' => true,
'readonly' => true,
'placeholder' => false
],
'apestructure' => [
'id' => 'apestructure',
'required' => true,
'readonly' => true,
'placeholder' => false
]
]);
?>
</div>
<div class="row">
<!-- Colonne de gauche -->
<div class="col-md-6">
<?php
echo $this->WebcilForm->inputs([
'nomcoresponsable' => [
'id' => 'nomcoresponsable',
'required' => true,
'readonly' => true,
'placeholder' => false
],
'prenomcoresponsable' => [
'id' => 'prenomcoresponsable',
'required' => true,