1 |
vpihour |
688 |
<?php |
2 |
|
|
//$Id$ |
3 |
|
|
//gen openMairie le 14/11/2012 12:54 |
4 |
|
|
|
5 |
|
|
require_once ("../gen/obj/dossier_autorisation.class.php"); |
6 |
|
|
|
7 |
|
|
class dossier_autorisation extends dossier_autorisation_gen { |
8 |
|
|
|
9 |
nhaye |
1097 |
|
10 |
|
|
var $valIdDemandeur = array("petitionnaire_principal" => "", |
11 |
|
|
"delegataire" => "", |
12 |
|
|
"petitionnaire" => array()); |
13 |
|
|
|
14 |
vpihour |
688 |
function dossier_autorisation($id,&$db,$debug) { |
15 |
|
|
$this->constructeur($id,$db,$debug); |
16 |
|
|
}// fin constructeur |
17 |
|
|
|
18 |
mlimic |
789 |
|
19 |
|
|
/** |
20 |
|
|
* Assure que la date passee par reference soit en |
21 |
|
|
* format attendu par la fonction dateDB du fichier |
22 |
|
|
* core/om_dbform.class.php. Change le format de la |
23 |
|
|
* date si necessaire. |
24 |
|
|
* @param $string $field Le date dans format DB, ou |
25 |
|
|
* celui attendu par setvalF |
26 |
|
|
*/ |
27 |
|
|
private function changeDateFormat(&$field) { |
28 |
|
|
if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})/', |
29 |
|
|
$field, $matches)) { |
30 |
|
|
$field = $matches[3].'/'.$matches[2].'/'.$matches[1]; |
31 |
|
|
} |
32 |
|
|
} |
33 |
mlimic |
783 |
|
34 |
|
|
function setvalF($val) { |
35 |
mlimic |
789 |
// verifie que les dates envoyes au parent::setvalF sont ont |
36 |
|
|
// bon format, et change le format si necessaire |
37 |
|
|
$this->changeDateFormat($val['erp_date_ouverture']); |
38 |
|
|
$this->changeDateFormat($val['erp_date_arrete_decision']); |
39 |
|
|
|
40 |
mlimic |
783 |
parent::setvalF($val); |
41 |
mlimic |
789 |
|
42 |
mlimic |
783 |
// si la valeur d'erp_arrete_decision n'etait pas set, laisse elle a null |
43 |
|
|
if ($val['erp_arrete_decision'] == null) { |
44 |
|
|
$this->valF['erp_arrete_decision'] = null; |
45 |
|
|
} |
46 |
|
|
// si la valeur d'erp_ouvert n'etait pas set, laisse elle a null |
47 |
|
|
if ($val['erp_ouvert'] == null) { |
48 |
|
|
$this->valF['erp_ouvert'] = null; |
49 |
|
|
} |
50 |
|
|
} |
51 |
|
|
|
52 |
nhaye |
907 |
function setValFAjout($val) { |
53 |
fmichon |
927 |
|
54 |
|
|
// Récupération du type de dossier ou série |
55 |
|
|
$sql = "SELECT da_t.code |
56 |
|
|
FROM ".DB_PREFIXE."dossier_autorisation_type as da_t |
57 |
|
|
INNER JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille as da_t_d |
58 |
|
|
ON da_t.dossier_autorisation_type=da_t_d.dossier_autorisation_type |
59 |
|
|
WHERE da_t_d.dossier_autorisation_type_detaille=".$val['dossier_autorisation_type_detaille'].";"; |
60 |
|
|
// |
61 |
|
|
$da_type_code = $this->db->getone($sql); |
62 |
|
|
$this->addToLog("setValFAjout(): db->getone(\"".$sql."\")", VERBOSE_MODE); |
63 |
|
|
database::isError($da_type_code); |
64 |
|
|
// Récupération du code département |
65 |
|
|
$departement = $this->f->getParameter("departement"); |
66 |
|
|
// Récupération du code commune |
67 |
|
|
$commune = $this->f->getParameter("commune"); |
68 |
vpihour |
1044 |
|
69 |
fmichon |
927 |
/// IDENTIFIANT DU DOSSIER |
70 |
|
|
// PC 013 055 12 00001 |
71 |
vpihour |
1071 |
$this->valF[$this->clePrimaire] = $da_type_code.$departement.$commune.date("y").$this->createNumeroDossier($da_type_code); |
72 |
fmichon |
927 |
|
73 |
nhaye |
907 |
} |
74 |
nhaye |
1097 |
// {{{ |
75 |
|
|
|
76 |
|
|
// getter |
77 |
|
|
function getValIdDemandeur() { |
78 |
|
|
return $this->valIdDemandeur; |
79 |
|
|
} |
80 |
|
|
// setter |
81 |
|
|
function setValIdDemandeur($valIdDemandeur) { |
82 |
|
|
$this->valIdDemandeur = $valIdDemandeur; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
// }}} |
86 |
vpihour |
1044 |
/* |
87 |
|
|
* Créée une numérotation pour le dossier à partir d'un numéro dans un séquence, |
88 |
vpihour |
1071 |
* définie par le code du dossier_autorisation_type. |
89 |
vpihour |
1044 |
* */ |
90 |
vpihour |
1071 |
function createNumeroDossier($datc){ |
91 |
vpihour |
1044 |
|
92 |
|
|
$numero_dossier = str_pad(rand(1, 9999), 5, "0", STR_PAD_LEFT); |
93 |
|
|
|
94 |
vpihour |
1071 |
/* Créé le code du dossier_autorisation_type associé au |
95 |
|
|
* code du dossier_autorisation_type_detaille passé en paramètre.*/ |
96 |
|
|
if ( isset($datc) && is_string($datc) ){ |
97 |
|
|
|
98 |
|
|
/*Récupère l'identifiant suivant dans la séquence correspondant au |
99 |
|
|
* code passé en paramètre*/ |
100 |
|
|
$nextID = $this->db->nextId(DB_PREFIXE.'dossier_'.strtolower($datc)); |
101 |
vpihour |
1044 |
|
102 |
vpihour |
1071 |
$this->addToLog("createNumeroDossier(): db->nextId(\"".DB_PREFIXE."dossier_".strtolower($datc)."\");", VERBOSE_MODE); |
103 |
|
|
if (database :: isError($nextID)) |
104 |
|
|
die($nextID->getMessage()."erreur ".$sql); |
105 |
vpihour |
1044 |
|
106 |
vpihour |
1071 |
/*Création du numéro de dossier*/ |
107 |
|
|
$numero_dossier = str_pad($nextID, 5, "0", STR_PAD_LEFT); |
108 |
vpihour |
1044 |
} |
109 |
nhaye |
907 |
|
110 |
vpihour |
1044 |
return $numero_dossier; |
111 |
|
|
} |
112 |
nhaye |
1097 |
|
113 |
|
|
/** |
114 |
|
|
* Méthode permettant de récupérer les id des demandeur liés à la demande ou |
115 |
|
|
* liés au dossier d'autorisation |
116 |
|
|
**/ |
117 |
|
|
function listeDemandeur($from, $id) { |
118 |
|
|
// Récupération des demandeurs de la base |
119 |
|
|
$sql = "SELECT demandeur.demandeur, |
120 |
|
|
demandeur.type_demandeur, |
121 |
|
|
lien_".$from."_demandeur.petitionnaire_principal |
122 |
|
|
FROM ".DB_PREFIXE."lien_".$from."_demandeur |
123 |
|
|
INNER JOIN ".DB_PREFIXE."demandeur |
124 |
|
|
ON demandeur.demandeur=lien_".$from."_demandeur.demandeur |
125 |
|
|
WHERE ".$from." = '".$id."'"; |
126 |
|
|
$res = $this->f->db->query($sql); |
127 |
|
|
$this->f->addToLog("listeDemandeur() : ".$sql); |
128 |
|
|
$this->f->isDatabaseError($res); |
129 |
|
|
// Stoquage du résultat dans un tableau |
130 |
|
|
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){ |
131 |
|
|
if ($row['petitionnaire_principal'] == 't' AND |
132 |
|
|
$row['type_demandeur']=="petitionnaire") { |
133 |
|
|
$this->valIdDemandeur['petitionnaire_principal']=$row['demandeur']; |
134 |
|
|
} elseif ($row['petitionnaire_principal'] == 'f' AND |
135 |
|
|
$row['type_demandeur']=="petitionnaire"){ |
136 |
|
|
$this->valIdDemandeur['petitionnaire'][]=$row['demandeur']; |
137 |
|
|
} elseif ($row['type_demandeur']=="delegataire"){ |
138 |
|
|
$this->valIdDemandeur['delegataire']=$row['demandeur']; |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
/** |
144 |
|
|
* Ajout de la liste des demandeurs |
145 |
|
|
*/ |
146 |
|
|
function formSpecificContent($maj) { |
147 |
|
|
if(!$this->correct AND $maj != 0) { |
148 |
|
|
$this->listeDemandeur("dossier_autorisation", $this->val[array_search('dossier_autorisation', $this->champs)]); |
149 |
|
|
} |
150 |
|
|
if($maj < 2 AND !$this->correct) { |
151 |
|
|
$linkable = true; |
152 |
|
|
} else { |
153 |
|
|
$linkable = false; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
// Conteneur de la listes des demandeurs |
157 |
|
|
echo "<div id=\"liste_demandeur\" class=\"demande_hidden_bloc col_12\">"; |
158 |
|
|
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">"; |
159 |
|
|
echo " <legend class=\"ui-corner-all ui-widget-content ui-state-active\">" |
160 |
|
|
._("Petitionnaire")."</legend>"; |
161 |
|
|
// Si des demandeurs sont liés à la demande |
162 |
|
|
require_once "../obj/petitionnaire.class.php"; |
163 |
|
|
require_once "../obj/delegataire.class.php"; |
164 |
|
|
|
165 |
|
|
// Affichage du bloc pétitionnaire principal / délégataire |
166 |
|
|
// L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS |
167 |
|
|
echo "<div id=\"petitionnaire_principal_delegataire\">"; |
168 |
|
|
// Affichage de la synthèse |
169 |
|
|
if (isset ($this->valIdDemandeur["petitionnaire_principal"]) AND |
170 |
|
|
!empty($this->valIdDemandeur["petitionnaire_principal"])) { |
171 |
|
|
$demandeur = new petitionnaire( |
172 |
|
|
$this->valIdDemandeur["petitionnaire_principal"], |
173 |
|
|
$this->f->db,false); |
174 |
|
|
$demandeur -> afficherSynthese("petitionnaire_principal", $linkable); |
175 |
|
|
$demandeur -> __destruct(); |
176 |
|
|
} |
177 |
|
|
// Si en édition de formulaire |
178 |
|
|
if($maj < 2) { |
179 |
|
|
// Bouton d'ajout du pétitionnaire principal |
180 |
|
|
// L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS |
181 |
|
|
echo "<span id=\"add_petitionnaire_principal\" |
182 |
|
|
class=\"om-form-button add-16\">". |
183 |
|
|
_("Saisir le petitionnaire principal"). |
184 |
|
|
"</span>"; |
185 |
|
|
} |
186 |
|
|
// Bouton d'ajout du delegataire |
187 |
|
|
// L'ID DU DIV ET DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS |
188 |
|
|
echo "<div id=\"delegataire\">"; |
189 |
|
|
if ($maj < 2 OR ($maj == 3 AND !empty($this->valIdDemandeur["delegataire"]))) { |
190 |
|
|
echo " <span class=\"om-icon om-icon-16 om-icon-fix arrow-right-16\"> |
191 |
|
|
<!-- --> |
192 |
|
|
</span> "; |
193 |
|
|
} |
194 |
|
|
// Affichage de la synthèse |
195 |
|
|
if (isset ($this->valIdDemandeur["delegataire"]) AND |
196 |
|
|
!empty($this->valIdDemandeur["delegataire"])) { |
197 |
|
|
$demandeur = new delegataire($this->valIdDemandeur["delegataire"], |
198 |
|
|
$this->f->db,false); |
199 |
|
|
$demandeur -> afficherSynthese("delegataire", $linkable); |
200 |
|
|
$demandeur -> __destruct(); |
201 |
|
|
} |
202 |
|
|
if($maj < 2) { |
203 |
|
|
echo "<span id=\"add_delegataire\" |
204 |
|
|
class=\"om-form-button add-16\">". |
205 |
|
|
_("Saisir le delegataire"). |
206 |
|
|
"</span>"; |
207 |
|
|
} |
208 |
|
|
echo "</div>"; |
209 |
|
|
|
210 |
|
|
echo "</div>"; |
211 |
|
|
// Bloc des pétitionnaires secondaires |
212 |
|
|
// L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS |
213 |
|
|
echo "<div id=\"listePetitionnaires\">"; |
214 |
|
|
|
215 |
|
|
// Affichage de la synthèse |
216 |
|
|
if (isset ($this->valIdDemandeur["petitionnaire"]) AND |
217 |
|
|
!empty($this->valIdDemandeur["petitionnaire"])) { |
218 |
|
|
|
219 |
|
|
foreach ($this->valIdDemandeur["petitionnaire"] as $petitionnaire) { |
220 |
|
|
$demandeur = new petitionnaire($petitionnaire, |
221 |
|
|
$this->f->db,false); |
222 |
|
|
$demandeur -> afficherSynthese("petitionnaire", $linkable); |
223 |
|
|
$demandeur -> __destruct(); |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
} |
227 |
|
|
if ($maj < 2) { |
228 |
|
|
// L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS |
229 |
|
|
echo "<span id=\"add_petitionnaire\" |
230 |
|
|
class=\"om-form-button add-16\">". |
231 |
|
|
_("Ajouter un petitionnaire") |
232 |
|
|
."</span>"; |
233 |
|
|
} |
234 |
|
|
echo "</div>"; |
235 |
|
|
echo "</fieldset>"; |
236 |
|
|
echo "</div>"; |
237 |
|
|
} |
238 |
nhaye |
1636 |
|
239 |
|
|
|
240 |
|
|
/** |
241 |
|
|
* Méthode permettant de recalculer à tout moment les données en cours de |
242 |
|
|
* validité d'un dossier d'autorisation |
243 |
|
|
*/ |
244 |
|
|
function majDossierAutorisation() { |
245 |
|
|
|
246 |
|
|
/* |
247 |
nhaye |
1639 |
* Mise à jour des données (terrain, ref. cadastrales, demandeurs, lots) |
248 |
nhaye |
1636 |
*/ |
249 |
|
|
// Initialisation des requêtes |
250 |
|
|
$sql_terrain = "SELECT dossier.terrain_references_cadastrales, |
251 |
|
|
dossier.terrain_adresse_voie_numero, |
252 |
|
|
dossier.complement, |
253 |
|
|
dossier.terrain_adresse_lieu_dit, |
254 |
|
|
dossier.terrain_adresse_localite, |
255 |
|
|
dossier.terrain_adresse_code_postal, |
256 |
|
|
dossier.terrain_adresse_bp, |
257 |
|
|
dossier.terrain_adresse_cedex, |
258 |
|
|
dossier.terrain_superficie |
259 |
|
|
FROM ".DB_PREFIXE."dossier"; |
260 |
|
|
|
261 |
|
|
$sql_lots = "SELECT lien_dossier_lot.lot |
262 |
|
|
FROM ".DB_PREFIXE."lien_dossier_lot |
263 |
|
|
LEFT JOIN ".DB_PREFIXE."dossier ON |
264 |
|
|
dossier.dossier = lien_dossier_lot.dossier"; |
265 |
|
|
$sql_demandeurs = "SELECT lien_dossier_demandeur.demandeur, lien_dossier_demandeur.petitionnaire_principal |
266 |
|
|
FROM ".DB_PREFIXE."dossier |
267 |
|
|
LEFT JOIN ".DB_PREFIXE."lien_dossier_demandeur ON |
268 |
|
|
dossier.dossier = lien_dossier_demandeur.dossier"; |
269 |
|
|
$sql_etat = "SELECT avis_decision.typeavis |
270 |
|
|
FROM ".DB_PREFIXE."dossier"; |
271 |
|
|
// Récupération du nombre de dossiers d'instruction liés au dossier d'autorisation |
272 |
|
|
$sql_count_di = "SELECT count(*) FROM ".DB_PREFIXE."dossier as di |
273 |
|
|
WHERE di.dossier_autorisation = '".$this->getVal("dossier_autorisation")."'"; |
274 |
|
|
|
275 |
|
|
$count_di = $this->db->getOne($sql_count_di); |
276 |
|
|
$this->addToLog("majDossierAutorisation(): db->getone(\"".$sql_count_di."\")", VERBOSE_MODE); |
277 |
|
|
database::isError($count_di); |
278 |
|
|
// Si pas de dossier : erreur |
279 |
|
|
if ($count_di == 0) { |
280 |
nhaye |
1642 |
return false; |
281 |
nhaye |
1636 |
} elseif ($count_di == 1) { // Cas P0 (en cours ou non) |
282 |
|
|
$sql_where = " WHERE dossier.dossier_autorisation = '".$this->getVal("dossier_autorisation")."'"; |
283 |
|
|
} else { // Cas ou un dossier d'instruction est soumis à arrété |
284 |
nhaye |
1642 |
$sql_where = " LEFT OUTER JOIN ".DB_PREFIXE."avis_decision ON |
285 |
nhaye |
1636 |
dossier.avis_decision = avis_decision.avis_decision |
286 |
|
|
WHERE dossier.dossier_autorisation = '".$this->getVal("dossier_autorisation")."' |
287 |
nhaye |
1642 |
AND date_decision IS NOT NULL AND avis_decision.typeavis='F'"; |
288 |
nhaye |
1636 |
} |
289 |
|
|
|
290 |
|
|
//terrain |
291 |
|
|
$res_terrain = $this->db->query($sql_terrain.$sql_where); |
292 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_terrain.$sql_where."\")", VERBOSE_MODE); |
293 |
|
|
database::isError($res_terrain); |
294 |
|
|
$row_terrain = $res_terrain->fetchRow(DB_FETCHMODE_ASSOC); |
295 |
|
|
// Tous les champs vides sont mis à NULL pour éviter les erreurs de base lors de l'update |
296 |
|
|
foreach ($row_terrain as $key => $champ) { |
297 |
|
|
if ($champ == "") { |
298 |
|
|
$row_terrain[$key] = NULL; |
299 |
|
|
} |
300 |
|
|
} |
301 |
|
|
$res_update_terrain = $this->db->autoExecute(DB_PREFIXE."dossier_autorisation", |
302 |
|
|
$row_terrain, |
303 |
|
|
DB_AUTOQUERY_UPDATE, |
304 |
|
|
"dossier_autorisation = '".$this->getVal("dossier_autorisation")."'"); |
305 |
|
|
database::isError($res_update_terrain); |
306 |
|
|
|
307 |
|
|
// Lots / demandeur |
308 |
|
|
// Suppression des anciens liens entre les lots et le DA |
309 |
|
|
$valLot['dossier_autorisation'] = NULL; |
310 |
|
|
$res_update_lots = $this->db->autoExecute(DB_PREFIXE."lot", |
311 |
|
|
$valLot, |
312 |
|
|
DB_AUTOQUERY_UPDATE, |
313 |
|
|
"dossier_autorisation='".$this->getVal("dossier_autorisation")."'"); |
314 |
|
|
database::isError($res_update_lots); |
315 |
|
|
// Suppression des anciens liens dossier_autorisation/demandeurs |
316 |
|
|
$sql_delete_liens_da_demandeur = "DELETE FROM ".DB_PREFIXE."lien_dossier_autorisation_demandeur |
317 |
|
|
WHERE dossier_autorisation='".$this->getVal("dossier_autorisation")."'"; |
318 |
|
|
$res_delete_liens_da_demandeur = $this->db->query($sql_delete_liens_da_demandeur); |
319 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_delete_liens_da_demandeur."\")", VERBOSE_MODE); |
320 |
|
|
database::isError($res_delete_liens_da_demandeur); |
321 |
|
|
// Si il ya des lots liés on les remonte au DA et on omet les demandeurs |
322 |
|
|
// car ils sont liés aux lots |
323 |
|
|
$res_lots = $this->db->query($sql_lots.$sql_where); |
324 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_lots.$sql_where."\")", VERBOSE_MODE); |
325 |
|
|
database::isError($res_lots); |
326 |
|
|
|
327 |
nhaye |
1642 |
// XXX Si il existe des lots (auxquels les demandeurs sont lié) faut-il recupérer la liste des demandeurs liés au DI ? |
328 |
|
|
//if ($res_lots->numRows() > 0) { |
329 |
nhaye |
1636 |
// Définition du lien entre lot et dossier_autorisation pour chaque lot |
330 |
|
|
$valLotUpdate['dossier_autorisation'] = $this->getVal("dossier_autorisation"); |
331 |
|
|
// On lie chaque lot en définissant l'id du dossier d'autorisation |
332 |
|
|
while ($rowlot = $res_lots->fetchRow(DB_FETCHMODE_ASSOC)) { |
333 |
|
|
$res_lots_update = $this->db->autoExecute(DB_PREFIXE."lot", |
334 |
|
|
$valLotUpdate, |
335 |
|
|
DB_AUTOQUERY_UPDATE, |
336 |
|
|
"lot=".$rowlot['lot']); |
337 |
|
|
database::isError($res_lots_update); |
338 |
|
|
} |
339 |
nhaye |
1642 |
//} else { // Si pas de lot liaison avec les demandeurs |
340 |
nhaye |
1636 |
// Récupération de la liste des demandeurs |
341 |
|
|
$res_demandeurs = $this->db->query($sql_demandeurs.$sql_where); |
342 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_demandeurs.$sql_where."\")", VERBOSE_MODE); |
343 |
|
|
database::isError($res_demandeurs); |
344 |
|
|
// Définition de l'id du DA |
345 |
|
|
$valDemandeurUpdate["lien_dossier_autorisation_demandeur"] = NULL; |
346 |
|
|
$valDemandeurUpdate['dossier_autorisation'] = $this->getVal("dossier_autorisation"); |
347 |
|
|
// Pour chaque demandeur on créer un lien avec le DA |
348 |
|
|
while ($rowDemandeur = $res_demandeurs->fetchRow(DB_FETCHMODE_ASSOC)) { |
349 |
|
|
// Ajout de l'id du demandeur et du flag petitionnaire_principal |
350 |
|
|
// aux données à insérer |
351 |
|
|
$valDemandeurUpdate["demandeur"] = $rowDemandeur["demandeur"]; |
352 |
|
|
$valDemandeurUpdate["petitionnaire_principal"] = $rowDemandeur["petitionnaire_principal"]; |
353 |
|
|
// Instanciation d'un lien dossier_autorisation/demandeur en ajout |
354 |
|
|
require_once "../obj/lien_dossier_autorisation_demandeur.class.php"; |
355 |
|
|
$ldad = new lien_dossier_autorisation_demandeur("]", $this->db, DEBUG); |
356 |
|
|
// Ajout d'un enregistrement avec les données des liens |
357 |
|
|
$ldad->ajouter($valDemandeurUpdate, $this->db, DEBUG); |
358 |
|
|
} |
359 |
nhaye |
1642 |
//} |
360 |
nhaye |
1639 |
|
361 |
|
|
|
362 |
|
|
/** |
363 |
|
|
* Mise à jour des dates |
364 |
|
|
*/ |
365 |
|
|
// Requêtes permettant de les recupérer |
366 |
|
|
$sql_date_depot_decision_validite = "SELECT MIN(dossier.date_depot) as date_depot, MIN(dossier.date_decision) as date_decision, MAX(dossier.date_validite) as date_validite FROM ".DB_PREFIXE."dossier |
367 |
|
|
WHERE dossier.dossier_autorisation='".$this->getVal("dossier_autorisation")."'"; |
368 |
|
|
|
369 |
|
|
$sql_date_doc_daact = "SELECT MAX(dossier.date_chantier) as date_chantier, MAX(dossier.date_achevement) as date_achevement FROM ".DB_PREFIXE."dossier |
370 |
|
|
LEFT OUTER JOIN ".DB_PREFIXE."avis_decision ON |
371 |
|
|
dossier.avis_decision = avis_decision.avis_decision |
372 |
|
|
WHERE dossier.dossier_autorisation = '".$this->getVal("dossier_autorisation")."' |
373 |
nhaye |
1642 |
AND date_decision IS NOT NULL AND avis_decision.typeavis='F'"; |
374 |
nhaye |
1639 |
// Récupération des infos avec la 1ere requête |
375 |
|
|
$res_date_depot_decision_validite = $this->db->query($sql_date_depot_decision_validite); |
376 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_date_depot_decision_validite."\")", VERBOSE_MODE); |
377 |
|
|
database::isError($res_date_depot_decision_validite); |
378 |
|
|
$row_date_depot_decision_validite = $res_date_depot_decision_validite->fetchRow(DB_FETCHMODE_ASSOC); |
379 |
|
|
// Récupération des infos avec la 2nd requête |
380 |
|
|
$res_date_doc_daact = $this->db->query($sql_date_doc_daact); |
381 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_date_doc_daact."\")", VERBOSE_MODE); |
382 |
|
|
database::isError($res_date_doc_daact); |
383 |
|
|
$row_date_doc_daact = $res_date_doc_daact->fetchRow(DB_FETCHMODE_ASSOC); |
384 |
|
|
// Fusion des 2 résultats |
385 |
|
|
$row_date = array_merge($row_date_depot_decision_validite, $row_date_doc_daact); |
386 |
|
|
// Si pas de date on remplace "" par NULL pour éviter les erreurs de base de données |
387 |
|
|
foreach($row_date as $key => $date) { |
388 |
|
|
if($date == "") { |
389 |
|
|
$row_date[$key] = NULL; |
390 |
|
|
} |
391 |
|
|
} |
392 |
|
|
// Mise à jour du DA avec ces nouvelles dates |
393 |
|
|
$res_update_date = $this->db->autoExecute(DB_PREFIXE."dossier_autorisation", |
394 |
|
|
$row_date, |
395 |
|
|
DB_AUTOQUERY_UPDATE, |
396 |
|
|
"dossier_autorisation = '".$this->getVal("dossier_autorisation")."'"); |
397 |
|
|
database::isError($res_update_date); |
398 |
|
|
|
399 |
nhaye |
1642 |
/** |
400 |
|
|
* Mise à jour de l'état |
401 |
|
|
*/ |
402 |
|
|
$sql_etat = "SELECT avis_decision.typeavis, avis_decision.avis_decision |
403 |
|
|
FROM ".DB_PREFIXE."dossier |
404 |
|
|
LEFT JOIN ".DB_PREFIXE."avis_decision ON |
405 |
|
|
dossier.avis_decision = avis_decision.avis_decision"; |
406 |
|
|
|
407 |
|
|
// Récupération de le décision du dernier dossier en cours ou non |
408 |
|
|
$sql_encours = $sql_etat." WHERE dossier.dossier_autorisation = '".$this->getVal("dossier_autorisation")."' ORDER BY dossier.date_decision DESC"; |
409 |
|
|
|
410 |
|
|
// Récupération de la décision du dernier dossier accepté |
411 |
|
|
$sql_cloture = $sql_etat." WHERE dossier.dossier_autorisation = '".$this->getVal("dossier_autorisation")."' |
412 |
|
|
AND date_decision IS NOT NULL AND avis_decision.typeavis='F' |
413 |
|
|
ORDER BY date_decision DESC"; |
414 |
|
|
|
415 |
|
|
$res_encours = $this->db->query($sql_encours); |
416 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_encours."\")", VERBOSE_MODE); |
417 |
|
|
database::isError($res_encours); |
418 |
|
|
|
419 |
|
|
$row_encours = $res_encours->fetchRow(DB_FETCHMODE_ASSOC); |
420 |
|
|
$etatDA = array(); |
421 |
|
|
|
422 |
|
|
// Cas initial : on défini les trois valeurs par défaut |
423 |
|
|
// (elles seront écrasées si $res_encours->numRows() > 1) |
424 |
|
|
|
425 |
|
|
// Correspondance entre typeavis et etat_dossier_autorisation |
426 |
|
|
switch ($row_encours['typeavis']) { |
427 |
|
|
case 'F': |
428 |
|
|
// typeavis F => Accordé |
429 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 2; |
430 |
|
|
$etatDA['etat_dossier_autorisation'] = 2; |
431 |
|
|
break; |
432 |
|
|
case 'D': |
433 |
|
|
// typeavis D => Refusé |
434 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 4; |
435 |
|
|
$etatDA['etat_dossier_autorisation'] = 4; |
436 |
|
|
break; |
437 |
|
|
case 'A': |
438 |
|
|
// typeavis A => Abandonné |
439 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 3; |
440 |
|
|
$etatDA['etat_dossier_autorisation'] = 3; |
441 |
|
|
break; |
442 |
|
|
default: |
443 |
|
|
// typeavis '' => En cours |
444 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 1; |
445 |
|
|
$etatDA['etat_dossier_autorisation'] = 1; |
446 |
|
|
break; |
447 |
|
|
} |
448 |
|
|
$etatDA['avis_decision'] = $row_encours['avis_decision']; |
449 |
|
|
|
450 |
|
|
// Si plus d'un dossier d'instruction |
451 |
|
|
if($res_encours->numRows() > 1) { |
452 |
|
|
$res_cloture = $this->db->query($sql_cloture); |
453 |
|
|
$this->addToLog("majDossierAutorisation(): db->query(\"".$sql_cloture."\")", VERBOSE_MODE); |
454 |
|
|
database::isError($res_cloture); |
455 |
|
|
|
456 |
|
|
$row_cloture = $res_cloture->fetchRow(DB_FETCHMODE_ASSOC); |
457 |
|
|
// Correspondance entre typeavis et etat_dossier_autorisation |
458 |
|
|
switch ($row_cloture['typeavis']) { |
459 |
|
|
case 'F': |
460 |
|
|
// typeavis F => Accordé |
461 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 2; |
462 |
|
|
break; |
463 |
|
|
case 'D': |
464 |
|
|
// typeavis D => Refusé |
465 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 4; |
466 |
|
|
break; |
467 |
|
|
case 'A': |
468 |
|
|
// typeavis A => Abandonné |
469 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 3; |
470 |
|
|
break; |
471 |
|
|
default: |
472 |
|
|
// typeavis '' => En cours |
473 |
|
|
$etatDA['etat_dernier_dossier_instruction_accepte'] = 1; |
474 |
|
|
break; |
475 |
|
|
} |
476 |
|
|
$etatDA['avis_decision'] = $row_cloture['avis_decision']; |
477 |
|
|
} |
478 |
|
|
|
479 |
|
|
// Mise à jour du DA avec ces nouvelles dates |
480 |
|
|
$res_update_etat = $this->db->autoExecute(DB_PREFIXE."dossier_autorisation", |
481 |
|
|
$etatDA, |
482 |
|
|
DB_AUTOQUERY_UPDATE, |
483 |
|
|
"dossier_autorisation = '".$this->getVal("dossier_autorisation")."'"); |
484 |
|
|
database::isError($res_update_date); |
485 |
nhaye |
1636 |
} |
486 |
vpihour |
688 |
}// fin classe |
487 |
mlimic |
783 |
?> |