Commit 013de263 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Correction : lors de la génération des information sur les coresponsables et les soustraitances

parent 52b43e82
...@@ -401,7 +401,7 @@ class RegistresController extends AppController { ...@@ -401,7 +401,7 @@ class RegistresController extends AppController {
'restrict' => true, 'restrict' => true,
'fields' => [ 'fields' => [
'Soustraitant.id', 'Soustraitant.id',
'Soustraitant.raisonsociale', 'Soustraitant.raisonsocialestructure',
] ]
]), ]),
'all_responsables' => $this->Responsable->find('list', [ 'all_responsables' => $this->Responsable->find('list', [
......
...@@ -583,8 +583,8 @@ class Fiche extends AppModel implements LinkedOrganisationInterface { ...@@ -583,8 +583,8 @@ class Fiche extends AppModel implements LinkedOrganisationInterface {
} }
// debug(array_keys(Hash::flatten($donnees))); // debug(array_keys(Hash::flatten($donnees)));
// var_dump($donnees); var_dump($donnees['traitement'][0]);
// die; die;
// On effectue la génération // On effectue la génération
$pdf = $this->genereFusion($file, $cheminFile, $donnees, $outputFormat); $pdf = $this->genereFusion($file, $cheminFile, $donnees, $outputFormat);
...@@ -980,26 +980,33 @@ class Fiche extends AppModel implements LinkedOrganisationInterface { ...@@ -980,26 +980,33 @@ class Fiche extends AppModel implements LinkedOrganisationInterface {
private function _addCoresponsable($data, $fiche_id) private function _addCoresponsable($data, $fiche_id)
{ {
$coresponsables = ClassRegistry::init('Coresponsable')->find('all', [ $schemaResponsableFields = array_filter(array_keys($this->Responsable->schema()), function($name) {
'conditions' => [ return in_array($name, ['id', 'createdbyorganisation', 'created', 'modified']) === false && preg_match('/_id$/', $name) !== 1;
'fiche_id' => $fiche_id });
$condition = [];
$query = [
'conditions' => $condition,
'order' => [
'Responsable.raisonsocialestructure ASC'
], ],
'fields' => $schemaResponsableFields
];
$subQuery = [
'alias' => 'coresponsables',
'fields' => [ 'fields' => [
'responsable_id', 'coresponsables.responsable_id'
'nomcoresponsable', ],
'prenomcoresponsable', 'conditions' => [
'fonctioncoresponsable', 'coresponsables.fiche_id' => $fiche_id
'emailcoresponsable',
'telephonecoresponsable',
'raisonsocialestructure',
'siretstructure',
'apestructure',
'telephonestructure',
'faxstructure',
'adressestructure',
'emailstructure',
] ]
]); ];
$sql = $this->Coresponsable->sql($subQuery);
$query['conditions'][] = "Responsable.id IN ( {$sql} )";
$coresponsables = $this->Responsable->find('all', $query);
$coresponsabilitefields = $this->Valeur->find('first', [ $coresponsabilitefields = $this->Valeur->find('first', [
'conditions' => [ 'conditions' => [
...@@ -1026,8 +1033,7 @@ class Fiche extends AppModel implements LinkedOrganisationInterface { ...@@ -1026,8 +1033,7 @@ class Fiche extends AppModel implements LinkedOrganisationInterface {
} }
} }
} else { } else {
$merge = Hash::extract($coresponsables, '{n}.Coresponsable'); $merge = Hash::extract($coresponsables, '{n}.Responsable');
$merge = Hash::remove($merge, '{n}.responsable_id');
} }
$data = $this->_addValueData($data, json_encode($merge, true), 'coresponsables'); $data = $this->_addValueData($data, json_encode($merge, true), 'coresponsables');
...@@ -1037,21 +1043,33 @@ class Fiche extends AppModel implements LinkedOrganisationInterface { ...@@ -1037,21 +1043,33 @@ class Fiche extends AppModel implements LinkedOrganisationInterface {
private function _addSoustraitance($data, $fiche_id) private function _addSoustraitance($data, $fiche_id)
{ {
$soustraitances = ClassRegistry::init('Soustraitance')->find('all', [ $schemaSoustraitantFields = array_filter(array_keys($this->Soustraitant->schema()), function($name) {
'conditions' => [ return in_array($name, ['id', 'createdbyorganisation', 'created', 'modified']) === false && preg_match('/_id$/', $name) !== 1;
'fiche_id' => $fiche_id });
$condition = [];
$query = [
'conditions' => $condition,
'order' => [
'Soustraitant.raisonsocialestructure ASC'
], ],
'fields' => $schemaSoustraitantFields
];
$subQuery = [
'alias' => 'soustraitances',
'fields' => [ 'fields' => [
'soustraitant_id', 'soustraitances.soustraitant_id'
'raisonsociale', ],
'siret', 'conditions' => [
'ape', 'soustraitances.fiche_id' => $fiche_id
'telephone',
'fax',
'adresse',
'email',
] ]
]); ];
$sql = $this->Soustraitance->sql($subQuery);
$query['conditions'][] = "Soustraitant.id IN ( {$sql} )";
$soustraitances = $this->Soustraitant->find('all', $query);
$soustraitancefields = $this->Valeur->find('first', [ $soustraitancefields = $this->Valeur->find('first', [
'conditions' => [ 'conditions' => [
...@@ -1077,8 +1095,7 @@ class Fiche extends AppModel implements LinkedOrganisationInterface { ...@@ -1077,8 +1095,7 @@ class Fiche extends AppModel implements LinkedOrganisationInterface {
} }
} }
} else { } else {
$merge = Hash::extract($soustraitances, '{n}.Soustraitance'); $merge = Hash::extract($soustraitances, '{n}.Soustraitant');
$merge = Hash::remove($merge, '{n}.soustraitant_id');
} }
$data = $this->_addValueData($data, json_encode($merge, true), 'soustraitances'); $data = $this->_addValueData($data, json_encode($merge, true), 'soustraitances');
......
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