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